Advertisement
Guest User

DeathEvents Class

a guest
Mar 7th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. package com.rektwarfare.dtp.events;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.GameMode;
  6. import org.bukkit.Material;
  7. import org.bukkit.Sound;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.entity.PlayerDeathEvent;
  12. import org.bukkit.inventory.ItemStack;
  13.  
  14. import com.rektwarfare.dtp.DTP;
  15. import com.rektwarfare.dtp.game.EndGame;
  16. import com.rektwarfare.dtp.listeners.MainMenu;
  17. import com.rektwarfare.dtp.timer.GameEndTimer;
  18. import com.rektwarfare.dtp.utils.TabUtils;
  19.  
  20. import net.milkbowl.vault.economy.EconomyResponse;
  21.  
  22. public class DeathEvents implements Listener {
  23.  
  24. public DTP plugin;
  25. public GameEndTimer endGameTimer;
  26.  
  27. public DeathEvents(DTP plugin) {
  28. this.plugin = plugin;
  29. }
  30.  
  31. public MainMenu kitClass = new MainMenu(plugin);
  32. public EndGame endGame = new EndGame(plugin);
  33.  
  34. @SuppressWarnings("static-access")
  35. @EventHandler
  36. public void onDeathEvents(PlayerDeathEvent e) {
  37.  
  38. Player player = e.getEntity();
  39. Player killer = e.getEntity().getKiller();
  40.  
  41. e.getDrops().clear();
  42. e.setDroppedExp(0);
  43. e.setDeathMessage(null);
  44. plugin.updatescoreonQuit(player);
  45.  
  46. player.spigot().respawn();
  47. if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) {
  48. player.setGameMode(GameMode.SPECTATOR);
  49. }
  50.  
  51. player.sendMessage(ChatColor.RED + "You're now a spectator for the remainder of the game.");
  52.  
  53. if (player.getName().equals(plugin.presidentPlayer)) {
  54. for (Player p : Bukkit.getOnlinePlayers()) {
  55. p.playSound(p.getLocation(), Sound.ENDERMAN_SCREAM, 1, 1);
  56. }
  57. Bukkit.broadcastMessage(ChatColor.RED + killer.getName() + ChatColor.YELLOW + " has assassinated the "
  58. + ChatColor.BLUE + "President!");
  59.  
  60. endGame.gameOver(0);
  61. Bukkit.broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD + "Attackers win!" + ChatColor.YELLOW + " The President has been killed.");
  62.  
  63. EconomyResponse r = plugin.econ.depositPlayer(killer, 5);
  64. if (r.transactionSuccess()) {
  65. killer.sendMessage(plugin.prefix + "+5 Coins for killing the President!");
  66. }
  67. }
  68.  
  69. EconomyResponse r = plugin.econ.depositPlayer(killer, 1);
  70. if (r.transactionSuccess()) {
  71. killer.sendMessage(plugin.prefix + "+1 Coins for killing " + player.getName() + "!");
  72. }
  73.  
  74. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  75. @SuppressWarnings("deprecation")
  76. public void run() {
  77. player.spigot().respawn();
  78. player.teleport(plugin.maplobby);
  79.  
  80. player.getInventory().clear();
  81. player.updateInventory();
  82.  
  83. for (Player p : Bukkit.getOnlinePlayers()) {
  84. if (!p.equals(player)) {
  85. p.hidePlayer(player);
  86. }
  87. }
  88. kitClass.kitselected.remove(player.getUniqueId());
  89. TabUtils.sendFullTitle(player, 10, 10, 10, ChatColor.BLUE + "" + ChatColor.BOLD + "YOU DIED",
  90. ChatColor.YELLOW + "You are now a spectator");
  91. player.sendMessage(ChatColor.YELLOW + "You are now a " + ChatColor.BLUE + "Spectator");
  92. if (player.getPlayer().getGameMode() == GameMode.SURVIVAL
  93. || (player.getPlayer().getGameMode() == GameMode.ADVENTURE)) {
  94. player.getPlayer().setGameMode(GameMode.SPECTATOR);
  95. }
  96. player.getPlayer().setGameMode(GameMode.SPECTATOR);
  97. player.getInventory().setHelmet(new ItemStack(Material.AIR));
  98. player.getInventory().setChestplate(new ItemStack(Material.AIR));
  99. player.getInventory().setLeggings(new ItemStack(Material.AIR));
  100. player.getInventory().setBoots(new ItemStack(Material.AIR));
  101. player.setHealth(20);
  102. player.getInventory().clear();
  103. player.updateInventory();
  104. }
  105. }, 2L);
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement