當前位置: 首頁>>代碼示例>>Java>>正文


Java Player.getLocation方法代碼示例

本文整理匯總了Java中org.spongepowered.api.entity.living.player.Player.getLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Player.getLocation方法的具體用法?Java Player.getLocation怎麽用?Java Player.getLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.entity.living.player.Player的用法示例。


在下文中一共展示了Player.getLocation方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
/**
 * Callback for the execution of a command.
 *
 * @param src  The commander who is executing this command
 * @param args The parsed command arguments for this command
 * @return the result of executing this command
 * @throws CommandException If a user-facing error occurs while executing this command
 */
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player))
		return execServer(src, args);

	Player player = (Player) src;
	Region region = new Region(player.getLocation());
	LoadedRegion.ChunkType type = args.<LoadedRegion.ChunkType>getOne("type").orElse(LoadedRegion.ChunkType.WORLD);
	LoadedRegion loadedRegion = new LoadedRegion(region, player, type);

	if (dataStore.isRegionLoaded(loadedRegion))
		throw new CommandException(Text.of(TextColors.RED, "You've already allocated this region."));

	loadedRegion.assignTicket();
	if (loadedRegion.isValid())
		throw new CommandException(Text.of(TextColors.RED, "Failed to allocate a loading ticket and force region."));

	dataStore.addPlayerRegion(player, loadedRegion);
	loadedRegion.forceChunks();
	database.saveRegionData(loadedRegion);

	player.sendMessage(Text.of(TextColors.GREEN, "Successfully loaded the region."));

	return CommandResult.success();
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:33,代碼來源:CommandLoad.java

示例2: onOpened

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Listener
public void onOpened(PlayerOpenedCrateEvent event) {
    Player player = event.getPlayer();
    Manager manager = event.getManager();
    Drop drop = event.getDrop();
    if (manager.isSendOpenMessage()) {
        Optional<String> optional_custom_open_message = manager.getCustomOpenMessage();
        if (optional_custom_open_message.isPresent()) {
            player.sendMessage(TextSerializers.FORMATTING_CODE.
                    deserialize(optional_custom_open_message.get().
                            replace("%MANAGER%", manager.getName())));
        } else {
            player.sendMessage(LanguageUtils.getText("SUCCESSFULLY_OPENED_MANAGER",
                    new Pair<String, String>("%MANAGER%", manager.getName())));
        }
    }
    if (GWMCrates.getInstance().isLogOpenedCrates()) {
        try {
            String time = LocalTime.now().withNano(0).format(DateTimeFormatter.ISO_LOCAL_TIME);
            String player_name = player.getName();
            String player_uuid = player.getUniqueId().toString();
            String manager_name = manager.getName();
            String manager_id = manager.getId();
            String drop_name = drop == null ? "null" : drop.getId().orElse("Unknown ID");
            Location<World> location = player.getLocation();
            String player_location = location.getExtent().getName() + ' ' + location.getBlockX() + ' ' + location.getBlockY() + ' ' + location.getBlockZ();
            LOG_FILE_WRITER.write(LanguageUtils.getPhrase("CRATE_OPENING_LOG_MESSAGE",
                    new Pair("%TIME%", time),
                    new Pair("%PLAYER%", player_name),
                    new Pair("%PLAYER_UUID%", player_uuid),
                    new Pair("%MANAGER_NAME%", manager_name),
                    new Pair("%MANAGER_ID%", manager_id),
                    new Pair("%DROP%", drop_name),
                    new Pair("%LOCATION%", player_location)) + '\n');
            LOG_FILE_WRITER.flush();
        } catch (Exception e) {
            GWMCrates.getInstance().getLogger().warn("Exception logging crate opening!", e);
        }
    }
}
 
開發者ID:GreWeMa,項目名稱:gwm_Crates,代碼行數:41,代碼來源:DebugCrateListener.java

示例3: adminSetHomeCommand

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Command(name = "sethome", description = "Set the location of a clan home", isPlayerOnly = true, spongePermission = "mcclans.admin.sethome")
public void adminSetHomeCommand(CommandSource commandSource, @Parameter(name = "clanTag") ClanImpl clan) {
    Player player = (Player) commandSource;
    Location<World> location = player.getLocation();
    ClanSetHomeEvent.Admin clanSetHomeEvent = EventDispatcher.getInstance().dispatchClanSetHomeAdmin(clan, location, commandSource);
    if (clanSetHomeEvent.isCancelled()) {
        Messages.sendWarningMessage(commandSource, clanSetHomeEvent.getCancelMessage());
    } else {
        clan.setHomeInternal(location);
        Messages.sendBasicMessage(commandSource, Messages.CLAN_HOME_LOCATION_SET);
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:13,代碼來源:ClanAdminCommands.java

示例4: clanHomeCommand

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Command(name = "home", description = "Телепортироваться в дом клана", isPlayerOnly = true, isClanOnly = true, clanPermission = "home", spongePermission = "mcclans.user.home")
public void clanHomeCommand(Player player, ClanPlayerImpl clanPlayer) {
    ClanImpl clan = clanPlayer.getClan();
    Location<World> teleportLocation = clan.getHome();
    if (teleportLocation == null) {
        Messages.sendWarningMessage(player, Messages.CLAN_HOME_LOCATION_IS_NOT_SET);
        return;
    }

    LastClanHomeTeleport lastClanHomeTeleport = clanPlayer.getLastClanHomeTeleport();
    if (lastClanHomeTeleport == null || lastClanHomeTeleport.canPlayerTeleport()) {
        Location<World> currentPlayerLocation = player.getLocation();
        Location<World> lastTeleportInitiationLocation = clanPlayer.getLastTeleportInitiationLocation();
        if (lastTeleportInitiationLocation == null
                || !lastTeleportInitiationLocation.getExtent().getName().equalsIgnoreCase(currentPlayerLocation.getExtent().getName())
                || lastTeleportInitiationLocation.getPosition().distance(currentPlayerLocation.getPosition()) != 0) {
            ClanHomeTeleportEvent.User event = EventDispatcher.getInstance().dispatchUserClanHomeTeleportEvent(clanPlayer, clan);
            if (event.isCancelled()) {
                Messages.sendWarningMessage(player, event.getCancelMessage());
            } else {
                startTeleportTask(player, clanPlayer, teleportLocation, currentPlayerLocation);
            }
        } else {
            Messages.sendWarningMessage(player, Messages.YOU_NEED_TO_MOVE_BEFORE_ATTEMPTING_ANOTHER_TELEPORT);
        }
    } else {
        Messages.sendYouCanTeleportInXSeconds(player, lastClanHomeTeleport.secondsBeforePlayerCanTeleport());
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:30,代碼來源:ClanCommands.java

示例5: clanSetHomeCommand

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Command(name = "sethome", description = "Установить локацию кланового дома", isPlayerOnly = true, isClanOnly = true, clanPermission = "sethome", spongePermission = "mcclans.user.sethome")
public void clanSetHomeCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer) {
    Player player = (Player) commandSource;
    ClanImpl clan = clanPlayer.getClan();
    long setTimeDifference = (System.currentTimeMillis() - clan.getHomeSetTimeStamp()) / 1000;
    if (clan.getHomeSetTimeStamp() == -1 || setTimeDifference > Config.getInteger(Config.RE_SET_CLANHOME_COOLDOWN_SECONDS)) {
        ClanSetHomeEvent.User event = EventDispatcher.getInstance().dispatchClanSetHomeUser(clanPlayer, clan, player.getLocation());
        if (event.isCancelled()) {
            Messages.sendWarningMessage(commandSource, event.getCancelMessage());
        } else {
            if (Config.getBoolean(Config.USE_ECONOMY)) {
                double setClanhomeBaseCost = Config.getDouble(Config.SET_CLANHOME_COST);
                double reSetClanhomeCostIncrease = Config.getDouble(Config.RE_SET_CLANHOME_COST_INCREASE);

                int homeSetTimes = clan.getHomeSetTimes();
                double setClanhomeCost = setClanhomeBaseCost + (homeSetTimes * reSetClanhomeCostIncrease);
                String currencyName = MCClans.getPlugin().getServiceHelper().currency.getDisplayName().toPlain();
                boolean success = EconomyUtils.withdraw(clanPlayer.getUUID(), setClanhomeCost);
                if (!success) {
                    Messages.sendYouDoNotHaveEnoughCurrency(player, setClanhomeCost, currencyName);
                    return;
                }
                Messages.sendYouWereChargedCurrency(player, setClanhomeCost, currencyName);
            }
            Location<World> location = player.getLocation();
            clan.setHomeInternal(location);
            clan.increaseHomeSetTimes();
            clan.setHomeSetTimeStamp(System.currentTimeMillis());
            Messages.sendBasicMessage(player, Messages.CLAN_HOME_LOCATION_SET);
        }
    } else {
        Messages.sendCannotSetClanhomeForAnotherXTime(commandSource, Config.getInteger(Config.RE_SET_CLANHOME_COOLDOWN_SECONDS) - setTimeDifference);
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:35,代碼來源:ClanCommands.java

示例6: ClanHomeTeleportTask

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
public ClanHomeTeleportTask(Player player, ClanPlayerImpl clanPlayer, Location<World> teleportLocation, int countdownSeconds, boolean forceNoCurrency) {
    this.player = player;
    this.clanPlayer = clanPlayer;
    this.teleportLocation = teleportLocation;
    this.playerPreviousLocation = player.getLocation();
    this.playerPreviousHealth = player.health().get();
    this.countdownSeconds = countdownSeconds;
    this.forceNoCurrency = forceNoCurrency;
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:10,代碼來源:ClanHomeTeleportTask.java

示例7: open

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Override
public void open(Player player, Manager manager) {
    PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
    Sponge.getEventManager().post(open_event);
    if (open_event.isCancelled()) return;
    Location<World> location = player.getLocation();
    Vector3i position = player.getLocation().getBlockPosition();
    World world = location.getExtent();
    int loc_x = position.getX();
    int loc_y = position.getY();
    int loc_z = position.getZ();
    HashMap<Location<World>, BlockState> original_block_states = new HashMap<Location<World>, BlockState>();
    for (int x = -2; x <= 2; x++) {
        for (int y = -1; y <= 3; y++) {
            for (int z = -2; z <= 2; z++) {
                Location loc = new Location<World>(
                        world, loc_x + x, loc_y + y, loc_z + z);
                BlockState loc_state = loc.getBlock();
                original_block_states.put(loc, loc_state);
                location.setBlockType(BlockTypes.AIR, BlockChangeFlags.NONE);
            }
        }
    }
    for (int x = -2; x <= 2; x++) {
        for (int z = -2; z <= 2; z++) {
            new Location<World>(world, loc_x + x, loc_y - 1, loc_z + z).
                    setBlockType(floor_block_type, BlockChangeFlags.NONE);
            if (z == 2 || z == -2 || x == 2 || x == -2) {
                new Location<World>(world, loc_x + x, loc_y , loc_z + z).
                        setBlockType(fence_block_type, BlockChangeFlags.NONE);
            }
        }
    }
    HashSet<HologramsService.Hologram> holograms = new HashSet<HologramsService.Hologram>();
    Location<World> loc1 = new Location<World>(world, loc_x + 2, loc_y, loc_z);
    loc1.setBlock(BlockState.builder().
                    blockType(crate_block_type).
                    add(Keys.DIRECTION, Direction.WEST).
                    build(),
            BlockChangeFlags.NONE);
    Location<World> loc2 = new Location<World>(world, loc_x - 2, loc_y, loc_z);
    loc2.setBlock(BlockState.builder().
                    blockType(crate_block_type).
                    add(Keys.DIRECTION, Direction.EAST).
                    build(),
            BlockChangeFlags.NONE);
    Location<World> loc3 = new Location<World>(world, loc_x, loc_y, loc_z + 2);
    loc3.setBlock(BlockState.builder().
                    blockType(crate_block_type).
                    add(Keys.DIRECTION, Direction.NORTH).
                    build(),
            BlockChangeFlags.NONE);
    Location<World> loc4 = new Location<World>(world, loc_x, loc_y, loc_z - 2);
    loc4.setBlock(BlockState.builder().
                    blockType(crate_block_type).
                    add(Keys.DIRECTION, Direction.SOUTH).
                    build(),
            BlockChangeFlags.NONE);
    Utils.tryCreateHologram(loc1, hologram).ifPresent(holograms::add);
    Utils.tryCreateHologram(loc2, hologram).ifPresent(holograms::add);
    Utils.tryCreateHologram(loc3, hologram).ifPresent(holograms::add);
    Utils.tryCreateHologram(loc4, hologram).ifPresent(holograms::add);
    getOpenSound().ifPresent(sound -> player.playSound(sound, player.getLocation().getPosition(), 1.));
    PLAYERS_OPENING_ANIMATION1.put(player, new Information(this, manager,
            new HashMap<Location<World>, Boolean>(){{
                put(loc1, false);
                put(loc2, false);
                put(loc3, false);
                put(loc4, false);
            }}, original_block_states, holograms));
}
 
開發者ID:GreWeMa,項目名稱:gwm_Crates,代碼行數:72,代碼來源:Animation1OpenManager.java

示例8: onPlayerMove

import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Listener
    public void onPlayerMove(MoveEntityEvent event, @Root Player player)
    {

        //Check if player changed chunk.
        World world = player.getWorld();
        Location lastLocation = new Location(world, PlayerService.getPlayerChunkPosition(player.getUniqueId()));
        Location newLocation = player.getLocation();

        if(!lastLocation.getChunkPosition().toString().equals(player.getLocation().getChunkPosition().toString()))
        {
            //World world = player.getWorld();
            Vector3i oldChunk = lastLocation.getChunkPosition();
            Vector3i newChunk = newLocation.getChunkPosition();

            //Inform a player about entering faction's land.
            if(!FactionLogic.getFactionNameByChunk(world.getUniqueId(), oldChunk).equals(FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk)))
            {
                if(!FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk).equals("SafeZone") && !FactionLogic.getFactionNameByChunk(world.getUniqueId(),newChunk).equals("WarZone") && !FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk).equals(""))
                {
                    if(!EagleFactions.AdminList.contains(player.getUniqueId().toString()))
                    {
                        if(!FactionLogic.hasOnlinePlayers(FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk)) && MainLogic.getBlockEnteringFactions())
                        {
                            //Teleport player back if all entering faction's players are offline.
                            player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You can't enter this faction! None of this faction's players are online!"));
                            player.setLocation(new Location<World>(world, lastLocation.getBlockPosition()));
                            return;
                        }
                    }
                }

                else if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), oldChunk).equals("WarZone") && FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk).equals("SafeZone"))
                {
                    if(!EagleFactions.AdminList.contains(player.getUniqueId().toString()) && MainLogic.shouldBlockSafeZoneFromWarZone())
                    {
                        //Block player before going to SafeZone from WarZone
                        player.setLocation(new Location<World>(world, lastLocation.getBlockPosition()));
                        player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You can't enter SafeZone when you are in WarZone"));
                        return;
                    }
                }

                String factionName = FactionLogic.getFactionNameByChunk(world.getUniqueId(), newChunk);
                if(factionName == "") factionName = "Wilderness";

                //TODO: Show respective colors for enemy faction, alliance & neutral.
                Text information = Text.builder()
                        .append(Text.of("You have entered faction ", TextColors.GOLD, factionName))
                        .build();

                player.sendMessage(ChatTypes.ACTION_BAR, information);
            }
            //Check if player has tuned on AutoClaim
            if(EagleFactions.AutoClaimList.contains(player.getUniqueId().toString()))
            {
                Sponge.getCommandManager().process(player, "f claim");
            }

            //Check if player has turned on AutoMap
            if(EagleFactions.AutoMapList.contains(player.getUniqueId().toString()))
            {
                Sponge.getCommandManager().process(player, "f map");
            }

        }

        //TODO:Bad approach... change it so that the player's position does not set every time player moves. This will increase performance.
        //Set new player chunk location.
        PlayerService.setPlayerChunkPosition(player.getUniqueId(), player.getLocation().getBlockPosition());
        return;
    } 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:73,代碼來源:PlayerMoveListener.java


注:本文中的org.spongepowered.api.entity.living.player.Player.getLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。