本文整理汇总了Java中org.spongepowered.api.entity.living.player.Player.getWorld方法的典型用法代码示例。如果您正苦于以下问题:Java Player.getWorld方法的具体用法?Java Player.getWorld怎么用?Java Player.getWorld使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.entity.living.player.Player
的用法示例。
在下文中一共展示了Player.getWorld方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: onEntityDamage
import org.spongepowered.api.entity.living.player.Player; //导入方法依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event)
{
if(event.getCause().root() instanceof DamageSource)
{
DamageSource source = (DamageSource) event.getCause().root();
if(event.getTargetEntity().getType() == EntityTypes.PLAYER)
{
Player attackedPlayer = (Player) event.getTargetEntity();
World world = attackedPlayer.getWorld();
if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), attackedPlayer.getLocation().getChunkPosition()).equals("SafeZone"))
{
event.setBaseDamage(0);
event.setCancelled(true);
return;
}
if(source instanceof Player)
{
Player player = (Player) source;
if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), player.getLocation().getChunkPosition()).equals("SafeZone"))
{
event.setBaseDamage(0);
event.setCancelled(true);
return;
}
else
{
if(FactionLogic.getFactionName(player.getUniqueId()) != null)
{
//Check if players are in the same faction
if(FactionLogic.getFactionName(player.getUniqueId()) == FactionLogic.getFactionName(attackedPlayer.getUniqueId()))
{
if(!FactionLogic.getFactionFriendlyFire(FactionLogic.getFactionName(player.getUniqueId())))
{
event.setBaseDamage(0);
event.setCancelled(true);
return;
}
else
{
if(event.willCauseDeath())
{
PowerService.punish(player.getUniqueId());
return;
}
}
}//Check if players are in the alliance.
else if(FactionLogic.getAlliances(FactionLogic.getFactionName(player.getUniqueId())).contains(FactionLogic.getFactionName(attackedPlayer.getUniqueId())) && !MainLogic.getAllianceFriendlyFire())
{
event.setBaseDamage(0);
event.setCancelled(true);
return;
}
else if(FactionLogic.getAlliances(FactionLogic.getFactionName(player.getUniqueId())).contains(FactionLogic.getFactionName(attackedPlayer.getUniqueId())) && MainLogic.getAllianceFriendlyFire())
{
if(event.willCauseDeath())
{
PowerService.punish(player.getUniqueId());
return;
}
}
}
else
{
if(event.willCauseDeath())
{
PowerService.addPower(player.getUniqueId(), true);
return;
}
}
}
}
}
}
return;
}
示例3: onBlockPlace
import org.spongepowered.api.entity.living.player.Player; //导入方法依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player)
{
if(!EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
World world = player.getWorld();
Vector3i claim = transaction.getFinal().getLocation().get().getChunkPosition();
if(FactionLogic.isClaimed(world.getUniqueId(), claim))
{
if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals("SafeZone") && player.hasPermission("eaglefactions.safezone.build"))
{
// EagleFactions.getEagleFactions().getLogger().info("Player has permissions in SafeZone");
return;
}
else if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals("WarZone") && player.hasPermission("eaglefactions.warzone.build"))
{
// EagleFactions.getEagleFactions().getLogger().info("Player has permissions in WarZone");
return;
}
else if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals(playerFactionName))
{
return;
}
else
{
event.setCancelled(true);
player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "This land belongs to someone else!"));
return;
}
}
else return;
}
}
return;
}
示例4: onPlayerInteract
import org.spongepowered.api.entity.living.player.Player; //导入方法依赖的package包/类
@Listener
public void onPlayerInteract(InteractBlockEvent.Secondary event, @Root Player player)
{
if(!EagleFactions.AdminList.contains(player.getUniqueId().toString()))
{
String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());
Optional<Location<World>> location = event.getTargetBlock().getLocation();
if(location.isPresent())
{
World world = player.getWorld();
Vector3i claim = location.get().getChunkPosition();
if(FactionLogic.isClaimed(world.getUniqueId(), claim))
{
if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals("SafeZone") && player.hasPermission("eaglefactions.safezone.interact"))
{
// EagleFactions.getEagleFactions().getLogger().info("Player has permissions in SafeZone");
return;
}
else if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals("WarZone") && player.hasPermission("eaglefactions.warzone.interact"))
{
// EagleFactions.getEagleFactions().getLogger().info("Player has permissions in WarZone");
return;
}
else if(FactionLogic.getFactionNameByChunk(world.getUniqueId(), claim).equals(playerFactionName))
{
return;
}
else
{
event.setCancelled(true);
player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, "You don't have access to do this!"));
return;
}
}
else
{
return;
}
}
}
}
示例5: 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;
}