/** * Whether the hostile mob can despawn immediately. * * @return true if the mob can despawn immediately, false otherwise */ public boolean canDespawnImmediately() { if (isRemoved()) { return false; } if (world.getPlayerCount() == 0) { return false; } if (isCustomNameVisible()) { return false; } boolean hasNearbyPlayer = world.getPlayers().stream() .anyMatch(player -> location.distanceSquared(player.getLocation()) <= DESPAWN_RANGE_IMMEDIATE * DESPAWN_RANGE_IMMEDIATE); if (hasNearbyPlayer) { return false; } return true; }
@Override public void pulse() { super.pulse(); if (tickSkipped) { // find player to give experience // todo: drag self towards player Optional<Player> player = getWorld().getPlayers().stream() .filter(p -> p.getLocation().distanceSquared(location) <= 1) .findAny(); if (player.isPresent()) { player.get().giveExp(experience); world.playSound(location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F); remove(); return; } } if (getTicksLived() > LIFETIME) { remove(); return; } if (!tickSkipped) { tickSkipped = true; } }
@Override public com.sk89q.worldedit.util.Location getLocation() { Location nativeLocation = player.getLocation(); Vector3 position = BukkitAdapter.asVector(nativeLocation); return new com.sk89q.worldedit.util.Location( getWorld(), position, nativeLocation.getYaw(), nativeLocation.getPitch()); }
/** * Removes this fishing hook. Drops loot and xp if a player is fishing. */ public void reelIn() { if (location.getBlock().getType() == Material.WATER) { ProjectileSource shooter = getShooter(); if (shooter instanceof Player) { PlayerFishEvent fishEvent = new PlayerFishEvent((Player) shooter, this, null, CAUGHT_FISH); fishEvent.setExpToDrop(ThreadLocalRandom.current().nextInt(1, 7)); fishEvent = EventFactory.getInstance().callEvent(fishEvent); if (!fishEvent.isCancelled()) { // TODO: Item should "fly" towards player world.dropItemNaturally(((Player) getShooter()).getLocation(), getRewardItem()); ((Player) getShooter()).giveExp(fishEvent.getExpToDrop()); } } } remove(); }
Location location = player.getLocation();
final Location location = player.getLocation();
@Override public void render(MapView map, MapCanvas canvas, Player player) { World world = map.getWorld(); int scaleShift = map.getScale().getValue(); Location playerLoc = player.getLocation(); int playerX = playerLoc.getBlockX(); int playerZ = playerLoc.getBlockZ(); int cornerX = map.getCenterX() - ((MAP_SIZE / 2) << scaleShift); int cornerZ = map.getCenterZ() - ((MAP_SIZE / 2) << scaleShift); for (int pixelX = 0; pixelX < MAP_SIZE; pixelX++) { for (int pixelY = 0; pixelY < MAP_SIZE; pixelY++) { int worldX = cornerX + (pixelX << scaleShift); int worldZ = cornerZ + (pixelY << scaleShift); if (((worldX - playerX) * (worldX - playerX) + (worldZ - playerZ) * (worldZ - playerZ)) < MAP_SIGHT_DISTANCE_SQUARED) { // TODO: Should the highest block be skipped over if it's e.g. a flower or a // technical block? byte blockColor = colorFor(world.getHighestBlockAt(worldX, worldZ), worldX, worldZ); canvas.setPixel(pixelX, pixelY, blockColor); } } } }
@Override public void pulse() { super.pulse(); if (getInvulnerableTicks() > 0) { setInvulnerableTicks(getInvulnerableTicks() - 1); if (ticksLived % 10 == 0) { setHealth(getHealth() + 10); } if (getInvulnerableTicks() == 1) { getWorld().createExplosion(getLocation(), Explosion.POWER_WITHER_CREATION); for (Player player : getServer().getOnlinePlayers()) { player.playSound(player.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0f, 1.0f); } } } else if (ticksLived % 20 == 0) { setHealth(getHealth() + 1); } }
for (World world : Bukkit.getWorlds()) { world.getWorldBorder().setCenter(CommandUtils .getLocation(((Player) sender).getLocation(), args[1], "0", args[2]));
Location location = player.getLocation(); player.setBedSpawnLocation(location, true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + location.getX() + ", " + location.getY() + ", " + location.getZ());
Command.broadcastCommandMessage(sender, "Teleported " + player.getDisplayName() + " to " + target.getDisplayName()); } else if (player.getWorld() != null) { Location playerLocation = player.getLocation(); double x = getCoordinate(sender, playerLocation.getX(), args[args.length - 3]); double y = getCoordinate(sender, playerLocation.getY(), args[args.length - 2], 0, 0);
Player targetPlayer = Bukkit.getPlayerExact(args[0]); if (targetPlayer != null) { location = targetPlayer.getLocation();
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onPlayerMove(PlayerMoveEvent event) { Location loc = event.getPlayer().getLocation(); mapManager.touch(getWorld(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playermove"); } };
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onPlayerJoin(PlayerJoinEvent event) { if(onplayerjoin) { Location loc = event.getPlayer().getLocation(); mapManager.touch(getWorld(loc.getWorld()).getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playerjoin"); } } };
public McMMOPartyTeleportEvent(Player player, Player target, String party) { super(player, player.getLocation(), target.getLocation(), TeleportCause.COMMAND); this.party = party; this.target = target; }
public Location getBlockLocation(Player player) { return player.getLocation().getBlock().getLocation(); } }
public static void sendSkillMessage(Player player, NotificationType notificationType, String key) { Location location = player.getLocation(); for (Player otherPlayer : player.getWorld().getPlayers()) { if (otherPlayer != player && Misc.isNear(location, otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) { NotificationManager.sendNearbyPlayersInformation(player, notificationType, key, player.getName()); } } }
public void levelUpApril(Player player, FakeSkillType fakeSkillType) { int levelTotal = Misc.getRandom().nextInt(1 + UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.MINING)) + 1; SoundManager.sendSound(player, player.getLocation(), SoundType.LEVEL_UP); NotificationManager.sendPlayerInformation(player, NotificationType.HOLIDAY, "Holiday.AprilFools.Levelup", StringUtils.getCapitalized(fakeSkillType.toString()), String.valueOf(levelTotal)); ParticleEffectUtils.fireworkParticleShower(player, ALL_COLORS.get(Misc.getRandom().nextInt(ALL_COLORS.size()))); }
private static void awardDrop(Player winningPlayer, ItemStack drop) { if (winningPlayer.getInventory().addItem(drop).size() != 0) { winningPlayer.getWorld().dropItem(winningPlayer.getLocation(), drop); } winningPlayer.updateInventory(); } }
private void resendChunkRadiusAt(Player player, int radius) { Chunk chunk = player.getLocation().getChunk(); World world = player.getWorld(); int chunkX = chunk.getX(); int chunkZ = chunk.getZ(); for (int x = chunkX - radius; x <= chunkX + radius; x++) { for (int z = chunkZ - radius; z <= chunkZ + radius; z++) { world.refreshChunk(x, z); } } } }