本文整理汇总了Java中org.bukkit.entity.Player.getWorld方法的典型用法代码示例。如果您正苦于以下问题:Java Player.getWorld方法的具体用法?Java Player.getWorld怎么用?Java Player.getWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.getWorld方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerDeath
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
World world = player.getWorld();
Location location = player.getLocation();
Collection<ItemStack> drops = event.getDrops();
if (!drops.isEmpty()) {
Iterator<ItemStack> iterator = drops.iterator();
// Drop the items manually so we can add meta to prevent
// PVP Protected players from collecting them.
long stamp = System.currentTimeMillis() + +ITEM_PICKUP_DELAY;
while (iterator.hasNext()) {
itemUUIDPickupDelays.put(world.dropItemNaturally(location, iterator.next()).getUniqueId(), stamp);
iterator.remove();
}
}
clearCooldown(player);
}
示例2: execute
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public boolean execute(CommandSender sender, String[] args) throws CommandException {
if (!(sender instanceof Player)){
throw new CommandException("Only players can use this command!");
}
Player player = (Player) sender;
if (args.length != 4){
player.sendMessage(ChatColor.RED + "Please specify all arguments!");
return false;
}
try {
new LootChest(parseInt(args[3]), new Location(player.getWorld(), Double.parseDouble(args[0]), Double.parseDouble(args[1]), Double.parseDouble(args[2])));
} catch (IOException | ParseException | NoSuchFieldException e) {
e.printStackTrace();
}
player.sendMessage(ChatColor.RED + "Loot chest spawned at desired location!");
return true;
}
示例3: onInteract
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
Player p = e.getPlayer();
if(hasPermission(enchant_open, p))
{
Location loc = new Location(p.getWorld(), 10000.0D, 255.0D, 10000.0D);
//Can't be handled differently :(
Block im5 = loc.getBlock();
if(im5.getType() != Material.ENCHANTMENT_TABLE)
{
im5.setType(Material.ENCHANTMENT_TABLE);
}
p.openEnchanting(loc, true);
}
super.onInteract(e, es);
}
示例4: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (isDeathSign(block)) {
BlockState state = block.getState();
Sign sign = (Sign) state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(DEATH_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
if (player.getGameMode() != GameMode.CREATIVE && world.isGameRule("doTileDrops")) {
world.dropItemNaturally(block.getLocation(), stack);
}
// Manually handle the dropping
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例5: start
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public void start(Player player) {
if (!player.hasPermission("skipnight.vote")) // If player doesn't have permission
player.sendMessage(ChatColor.RED + "You don't have permission to run this!");
else if (!isInOverworld(player)) // If player isn't in the overworld
player.sendMessage(ChatColor.RED + "You must be in the overworld to start a vote!");
else if (player.getWorld().getTime() < 14000) // If it's day
player.sendMessage(ChatColor.RED + "You can only start a vote at night!");
else if (!(timer == Timer.COMPLETE)) // If there's a vote happening
player.sendMessage(ChatColor.RED + "Vote already in progress!");
else {
timer = Timer.INIT;
this.player = player;
world = player.getWorld();
Messages.voteStarted().send(player);
Messages.youVoteYes().send(player);
run();
}
}
示例6: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
Block block = event.getBlock();
if (isEventSign(block))
{
BlockState state = block.getState();
Sign sign = (Sign)state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(EVENT_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
Location blockLocation = block.getLocation();
if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) {
world.dropItemNaturally(blockLocation, stack);
}
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例7: EntityBossBar
import org.bukkit.entity.Player; //导入方法依赖的package包/类
protected EntityBossBar(Player player, String message, float percentage, int timeout, float minHealth) {
this.ID = new Random().nextInt();
this.uuid = UUID.randomUUID();
this.receiver = player;
this.message = message;
this.health = percentage / 100F * this.getMaxHealth();
this.minHealth = minHealth;
this.world = player.getWorld();
this.location = this.makeLocation(player.getLocation());
if (percentage <= minHealth) {
BossBarAPI.removeBar(player);
}
if (timeout > 0) {
this.healthMinus = this.getMaxHealth() / timeout;
this.runTaskTimer(PACore.getInstance(), 20, 20);
}
}
示例8: onClickEndPortalFrame
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onClickEndPortalFrame(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
Block clickedBlock = event.getClickedBlock();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || world.getEnvironment() != Environment.THE_END
|| clickedBlock.getType() != Material.BEDROCK || event.getHand() != EquipmentSlot.HAND
|| (player.getInventory().getItemInMainHand() != null || player.getInventory().getItemInOffHand() != null)) return;
NMSAbstract nmsAbstract = plugin.getNMSAbstract();
DragonBattle dragonBattle = nmsAbstract.getEnderDragonBattleFromWorld(world);
Location portalLocation = dragonBattle.getEndPortalLocation();
if (event.getClickedBlock().getLocation().distanceSquared(portalLocation) > 36) return; // 5 blocks
EndWorldWrapper endWorld = plugin.getDEDManager().getWorldWrapper(world);
int secondsRemaining = endWorld.getTimeUntilRespawn();
if (secondsRemaining <= 0) return;
plugin.sendMessage(player, "Dragon will respawn in " + ChatColor.YELLOW + secondsRemaining);
}
示例9: handleWinner
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Handles the winner for this event.
*
* @param winner
* the {@link Player} that won
*/
public void handleWinner(Player winner) {
if (this.eventFaction == null)
return;
PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(winner);
Bukkit.broadcastMessage(ChatColor.GOLD + "[" + "WIN" + "] " + ChatColor.RED + winner.getName() + ChatColor.AQUA
+ ChatColor.YELLOW + " has captured " + ChatColor.RED + this.eventFaction.getName()
+ ChatColor.YELLOW + " after " + ChatColor.RED + DurationFormatUtils.formatDurationWords(getUptime(), true, true) + " of up-time" + ChatColor.YELLOW + '.');
EventType eventType = this.eventFaction.getEventType();
World world = winner.getWorld();
Location location = winner.getLocation();
EventKey eventKey = plugin.getKeyManager().getEventKey();
Collection<Inventory> inventories = eventKey.getInventories(eventType);
ItemStack keyStack = eventKey.getItemStack(new EventKey.EventKeyData(eventType, inventories.isEmpty() ? 1 : plugin.getRandom().nextInt(inventories.size()) + 1));
Map<Integer, ItemStack> excess = winner.getInventory().addItem(keyStack, EventSignListener.getEventSign(eventFaction.getName(), winner.getName()));
for (ItemStack entry : excess.values()) {
world.dropItemNaturally(location, entry);
}
this.clearCooldown(); // must always be cooled last as this nulls some variables.
}
示例10: updateBlockTileEntity
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.y);
if (tileEntity == null) {
return;
}
Packet<?> packet = tileEntity.getUpdatePacket();
if (packet != null) {
CraftPlayer player2 = (CraftPlayer)player;
player2.getHandle().playerConnection.sendPacket(packet);
}
}
示例11: clearBlocksForOldWorld
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void clearBlocksForOldWorld(Player player) {
synchronized (proximityHiderTracker) {
ProximityHiderPlayer playerInfo = proximityHiderTracker.get(player);
if(playerInfo != null) {
World world = player.getWorld();
if(!playerInfo.getWorld().equals(world)) {
playerInfo.setWorld(world);
playerInfo.clearChunks();
}
}
}
}
示例12: onWorldChanged
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onWorldChanged(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
World from = event.getFrom();
World to = player.getWorld();
if (from.getEnvironment() != World.Environment.THE_END && to.getEnvironment() == World.Environment.THE_END && player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) {
player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
}
}
示例13: onPlayerJoin
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// Version notification
Player player = event.getPlayer();
if (player.isOp() && plugin.isNewVersionAvailable()) {
this.plugin.sendMessage(player, ChatColor.GRAY + "A new version is available for download (Version " + this.plugin.getNewVersion() + "). " + RESOURCE_PAGE);
}
World world = player.getWorld();
if (world.getEnvironment() != Environment.THE_END) return;
EndWorldWrapper worldWrapper = manager.getWorldWrapper(world);
// Reset end crystal states just in case something went awry
if (!worldWrapper.isRespawnInProgress()) {
world.getEntitiesByClass(EnderCrystal.class).forEach(e -> {
e.setInvulnerable(false);
e.setBeamTarget(null);
});
}
// Dragon respawn logic
if (!plugin.getConfig().getBoolean("respawn-on-join", false)) return;
if (!world.getPlayers().isEmpty() || manager.getWorldWrapper(world).isRespawnInProgress()
|| world.getEntitiesByClass(EnderDragon.class).size() == 0)
return;
manager.getWorldWrapper(world).startRespawn(RespawnType.JOIN);
}
示例14: getPlayersWithin
import org.bukkit.entity.Player; //导入方法依赖的package包/类
private List<Player> getPlayersWithin(Player player, int distance) {
List<Player> res = new ArrayList<Player>();
int d2 = distance * distance;
for (Player p : server.getOnlinePlayers()) {
if (p.getWorld() == player.getWorld()
&& p.getLocation().distanceSquared(player.getLocation()) <= d2) {
res.add(p);
}
}
return res;
}
示例15: onCommand
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is only executable by players.");
return true;
}
final Player player = (Player)sender;
World world = player.getWorld();
Location spawn = world.getSpawnLocation().clone().add(0.5, 0.5, 0.5);
if (!sender.hasPermission(command.getPermission() + ".teleport")) {
sender.sendMessage(ChatColor.RED + "This server does not have a spawn command, you must travel there. " + "Spawn can be found at " + ChatColor.GRAY + '(' + spawn.getBlockX() + ", " + spawn.getBlockZ() + ')');
return true;
}
if (!sender.hasPermission(command.getPermission() + ".teleport")) {
this.plugin.getTimerManager().teleportTimer.teleport(player, Bukkit.getWorld("world").getSpawnLocation(), TimeUnit.SECONDS.toMillis(15L), ChatColor.GRAY + "Teleporting to spawn in " + 15 + " seconds.", PlayerTeleportEvent.TeleportCause.COMMAND);
return true;
}
if (args.length > 0) {
world = Bukkit.getWorld(args[0]);
if (world == null) {
sender.sendMessage(ChatColor.RED + "There is not a world named " + args[0] + '.');
return true;
}
spawn = world.getSpawnLocation().clone().add(0.5, 0.0, 0.5);
}
player.teleport(spawn, PlayerTeleportEvent.TeleportCause.COMMAND);
return true;
}