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(); }
public void startGame() { currentTime = 0; for (Kit kit : HungergamesApi.getKitManager().getKits()) { final int amount = kit.getPlayerSize(); if (amount <= 0) continue; metrics .getKitsUsed() .addPlotter( new Metrics.Plotter(kit.getName()) { @Override public int getValue() { return amount; } }); } ScoreboardManager.hideScore( "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreBoardGameStartingIn()); ScoreboardManager.makeScore("Main", DisplaySlot.PLAYER_LIST, "", 0); if (mainConfig.getTimeForInvincibility() > 0) { ScoreboardManager.makeScore( "Main", DisplaySlot.SIDEBAR, translationsConfig.getScoreboardInvincibleRemaining(), mainConfig.getTimeForInvincibility()); } else { Bukkit.getPluginManager().callEvent(new InvincibilityWearOffEvent()); } Bukkit.broadcastMessage(translationsConfig.getBroadcastGameStartedMessage()); if (mainConfig.getTimeForInvincibility() > 0) Bukkit.broadcastMessage( String.format( translationsConfig.getBroadcastInvincibiltyWearsOffIn(), returnTime(mainConfig.getTimeForInvincibility() - currentTime))); for (Gamer gamer : pm.getGamers()) { if (mainConfig.isKitSelectorEnabled()) gamer .getPlayer() .getInventory() .remove(HungergamesApi.getInventoryManager().getKitSelector()); gamer.seeInvis(false); gamer.setAlive(true); if (mainConfig.isTeleportToSpawnLocationPregame() && mainConfig.isPreventMovingFromSpawnUsingPotions()) { gamer.getPlayer().removePotionEffect(PotionEffectType.SLOW); gamer.getPlayer().removePotionEffect(PotionEffectType.JUMP); } pm.sendToSpawn(gamer); } world.setGameRuleValue("doDaylightCycle", "true"); world.setTime(mainConfig.getTimeOfDay()); world.playSound(world.getSpawnLocation(), Sound.AMBIENCE_THUNDER, 1, 0.8F); Bukkit.getScheduler() .scheduleSyncDelayedTask( this, new Runnable() { public void run() { for (Gamer gamer : pm.getAliveGamers()) gamer.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS)); for (me.libraryaddict.Hungergames.Types.Kit kit : HungergamesApi.getKitManager().getKits()) kit.giveKit(); HungergamesApi.getAbilityManager().registerAbilityListeners(); Bukkit.getPluginManager().callEvent(new GameStartEvent()); for (Location l : entitysToSpawn.keySet()) l.getWorld().spawnEntity(l, entitysToSpawn.get(l)); entitysToSpawn.clear(); } }); checkWinner(); HungergamesApi.getInventoryManager().updateSpectatorHeads(); ScoreboardManager.doStage(); }