public void sendToSpawn(Gamer gamer) { final Player p = gamer.getPlayer(); Location originalSpawn = p.getWorld().getSpawnLocation(); MainConfig main = HungergamesApi.getConfigManager().getMainConfig(); int spawnRadius = main.getSpawnRadius(); int spawnHeight = main.getSpawnHeight(); if (spawns.size() > 0) { if (spawnItel == null || !spawnItel.hasNext()) spawnItel = spawns.keySet().iterator(); originalSpawn = spawnItel.next(); spawnRadius = Math.max(1, spawns.get(originalSpawn)[0]); spawnHeight = Math.max(1, spawns.get(originalSpawn)[1]); } Location spawn = originalSpawn.clone(); int chances = 0; if (p.isInsideVehicle()) p.leaveVehicle(); p.eject(); while (chances < main.getTimesToCheckForValidSpawnPerPlayer()) { chances++; Location newLoc = new Location( p.getWorld(), spawn.getX() + returnChance(-spawnRadius, spawnRadius), spawn.getY() + new Random().nextInt(spawnHeight), spawn.getZ() + returnChance(-spawnRadius, spawnRadius)); if (nonSolid.contains(newLoc.getBlock().getTypeId()) && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.UP).getTypeId())) { while (newLoc.getBlockY() >= 1 && nonSolid.contains(newLoc.getBlock().getRelative(BlockFace.DOWN).getTypeId())) { newLoc = newLoc.add(0, -1, 0); } if (newLoc.getBlockY() <= 1) continue; spawn = newLoc; break; } } if (spawn.equals(originalSpawn)) { spawn = new Location( p.getWorld(), spawn.getX() + returnChance(-spawnRadius, spawnRadius), 0, spawn.getZ() + returnChance(-spawnRadius, spawnRadius)); spawn.setY(spawn.getWorld().getHighestBlockYAt(spawn)); if (gamer.isAlive() && spawn.getY() <= 1) { spawn.getBlock().setType(Material.GLASS); spawn.setY(spawn.getY() + 1); } } final Location destination = spawn.add(0.5, 0.1, 0.5); p.teleport(destination); Bukkit.getScheduler() .scheduleSyncDelayedTask( hg, new Runnable() { public void run() { p.teleport(destination); } }); }
public void manageDeath(PlayerKilledEvent event) { Gamer killed = event.getKilled(); final Player p = killed.getPlayer(); p.setHealth(20); if (event.isCancelled()) return; for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory(); p.leaveVehicle(); p.eject(); p.setLevel(0); p.setExp(0F); if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage()))) event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage()); event.setDeathMessage( this.formatDeathMessage( event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p)); if (event.getKillerPlayer() != null) { event.getKillerPlayer().addKill(); event.setDeathMessage( this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer())); } Bukkit.broadcastMessage(event.getDeathMessage()); int reward = hg.getPrize(getAliveGamers().size()); if (reward > 0) killed.addBalance(reward); hg.cannon(); killed.clearInventory(); World world = p.getWorld(); for (ItemStack item : event.getDrops()) { if (item == null || item.getType() == Material.AIR || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue; else if (item.hasItemMeta()) world .dropItemNaturally(event.getDropsLocation(), item.clone()) .getItemStack() .setItemMeta(item.getItemMeta()); else world.dropItemNaturally(event.getDropsLocation(), item); } setSpectator(killed); ScoreboardManager.makeScore( "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size()); hg.checkWinner(); p.setVelocity(new Vector()); for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType()); p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0)); p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true); p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0); p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0); for (Entity entity : p.getWorld().getEntities()) { if (entity instanceof Tameable && ((Tameable) entity).isTamed() && ((Tameable) entity).getOwner().getName().equals(p.getName())) { if (entity instanceof Wolf) ((Wolf) entity).setSitting(true); else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true); else entity.remove(); } if (entity instanceof Creature && ((Creature) entity).getTarget() == p) ((Creature) entity).setTarget(null); } if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath() && !p.hasPermission("hungergames.spectate")) p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage())); HungergamesApi.getAbilityManager().unregisterPlayer(p); HungergamesApi.getInventoryManager().updateSpectatorHeads(); }
@Override public boolean eject() { return caller.eject(); }