本文整理匯總了Java中org.spongepowered.api.entity.living.player.Player.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Player.setLocation方法的具體用法?Java Player.setLocation怎麽用?Java Player.setLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.spongepowered.api.entity.living.player.Player
的用法示例。
在下文中一共展示了Player.setLocation方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adminHomeCommand
import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Command(name = "home", description = "Teleport to a clan home", isPlayerOnly = true, spongePermission = "mcclans.admin.home")
public void adminHomeCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer, @Parameter(name = "clanTag") ClanImpl clan) {
Player player = (Player) commandSource;
Location<World> teleportLocation = clan.getHome();
if (teleportLocation == null) {
Messages.sendWarningMessage(commandSource, Messages.CLAN_HOME_LOCATION_IS_NOT_SET);
return;
}
ClanHomeTeleportEvent.Admin event = EventDispatcher.getInstance().dispatchAdminClanHomeTeleportEvent(clanPlayer, clan);
if (event.isCancelled()) {
Messages.sendWarningMessage(player, event.getCancelMessage());
} else {
player.setLocation(teleportLocation);
}
}
示例2: execute
import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
if(source instanceof Player)
{
Player player = (Player)source;
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
if(playerFactionName != null)
{
if(FactionLogic.getHome(playerFactionName) != null)
{
//TODO: Wait 5-10 seconds before teleporting.
World world = player.getWorld();
if(FactionLogic.isHomeInWorld(world.getUniqueId(), playerFactionName))
{
Vector3i home = FactionLogic.getHome(playerFactionName);
player.setLocation(player.getLocation().setBlockPosition(home));
source.sendMessage(Text.of(PluginInfo.PluginPrefix, "You were teleported to faction's home"));
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, "Faction's home is not in this world."));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Faction's home is not set!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You must be in a faction in order to use this command!"));
}
}
else
{
source.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "Only in-game players can use this command!"));
}
return CommandResult.success();
}
示例3: teleport
import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
private void teleport(Player player, ClanPlayerImpl clanPlayer, Location<World> teleportLocation) {
// TODO SPONGE rotation missing, and no teleport cause?
player.setLocation(teleportLocation);
clanPlayer.setLastClanHomeTeleport(new LastClanHomeTeleport());
}
示例4: viewCamera
import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
public void viewCamera(Player player){
if(!this.canUseCamera(player)){
return; // shouldn't have the ability to even execute the command
}
if (player.supports(VigilateKeys.OLD_GAME_MODE)) {
player.get(VigilateKeys.CAMERA).orElse("");
if(Vigilate.getInstance().getCameras().containsKey(id)){
Vigilate.getInstance().getCameras().get(id).endViewCamera(player);
}
}
player.offer(new ViewerDataManipulatorBuilder().create());
player.getValue(Keys.GAME_MODE).ifPresent(
(value -> player.offer(VigilateKeys.OLD_GAME_MODE, value.get()))
);
player.getValue(Keys.IS_FLYING).ifPresent(
(value -> player.offer(VigilateKeys.OLD_IS_FLYING, value.get()))
);
player.getValue(Keys.AFFECTS_SPAWNING).ifPresent(
(value -> player.offer(VigilateKeys.OLD_AFFECTS_SPAWNING, value.get()))
);
player.getValue(Keys.VANISH).ifPresent(
(value -> player.offer(VigilateKeys.OLD_VANISH, value.get()))
);
player.getValue(Keys.VANISH_PREVENTS_TARGETING).ifPresent(
(value -> player.offer(VigilateKeys.OLD_VANISH_PREVENTS_TARGETING, value.get()))
);
player.getValue(Keys.VANISH_IGNORES_COLLISION).ifPresent(
(value -> player.offer(VigilateKeys.OLD_VANISH_IGNORES_COLLISION, value.get()))
);
player.getValue(Keys.FLYING_SPEED).ifPresent(
(value -> player.offer(VigilateKeys.OLD_FLYING_SPEED, value.get()))
);
player.offer(VigilateKeys.OLD_LOCATION_WORLD, player.getLocation().getExtent().getName());
player.offer(VigilateKeys.OLD_LOCATION_X, player.getLocation().getX());
player.offer(VigilateKeys.OLD_LOCATION_Y, player.getLocation().getY());
player.offer(VigilateKeys.OLD_LOCATION_Z, player.getLocation().getZ());
player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
player.offer(Keys.AFFECTS_SPAWNING, false);
player.offer(Keys.VANISH, true);
player.offer(Keys.VANISH_PREVENTS_TARGETING, true);
player.offer(Keys.VANISH_IGNORES_COLLISION, true);
player.offer(Keys.FLYING_SPEED, 0.0);
player.offer(Keys.IS_FLYING, true);
player.offer(VigilateKeys.CAMERA, this.getId());
player.setLocation(this.getLocation());
Title title = Title.builder()
.fadeIn(20)
.fadeOut(20)
.title(Text.EMPTY)
.subtitle(plugin.translations.CAMERA_VIEW_TITLE.apply(this.templateVariables()).toText())
.stay(100000)
.build();
player.sendTitle(title);
player.sendMessage(plugin.translations.CAMERA_VIEW, this.templateVariables());
}
示例5: resetPlayer
import org.spongepowered.api.entity.living.player.Player; //導入方法依賴的package包/類
static public void resetPlayer(Player player){
if (player.supports(VigilateKeys.OLD_GAME_MODE)) {
player.getValue(VigilateKeys.OLD_GAME_MODE).ifPresent(
(value -> player.offer(Keys.GAME_MODE, value.get()))
);
player.getValue(VigilateKeys.OLD_IS_FLYING).ifPresent(
(value -> player.offer(Keys.IS_FLYING, value.get()))
);
player.getValue(VigilateKeys.OLD_AFFECTS_SPAWNING).ifPresent(
(value -> player.offer(Keys.AFFECTS_SPAWNING, value.get()))
);
player.getValue(VigilateKeys.OLD_VANISH).ifPresent(
(value -> player.offer(Keys.VANISH, value.get()))
);
player.getValue(VigilateKeys.OLD_VANISH_PREVENTS_TARGETING).ifPresent(
(value -> player.offer(Keys.VANISH_PREVENTS_TARGETING, value.get()))
);
player.getValue(VigilateKeys.OLD_VANISH_IGNORES_COLLISION).ifPresent(
(value -> player.offer(Keys.VANISH_IGNORES_COLLISION, value.get()))
);
player.getValue(VigilateKeys.OLD_FLYING_SPEED).ifPresent(
(value -> player.offer(Keys.FLYING_SPEED, value.get()))
);
World world = Sponge.getServer().getWorld(
player.get(VigilateKeys.OLD_LOCATION_WORLD).orElse("world")
).orElse(Sponge.getServer().getWorlds().iterator().next());
Location<World> loc = new Location<>(
world,
player.get(VigilateKeys.OLD_LOCATION_X).orElse(0.0),
player.get(VigilateKeys.OLD_LOCATION_Y).orElse(0.0),
player.get(VigilateKeys.OLD_LOCATION_Z).orElse(0.0)
);
player.setLocation(loc);
player.remove(ViewerData.class);
}
player.clearTitle();
}
示例6: 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;
}