Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. package fr.helik.abilities;
  2.  
  3. import fr.helik.asia.Asia;
  4. import fr.helik.asia.utils.Kit;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import org.bukkit.Color;
  8. import org.bukkit.Material;
  9. import org.bukkit.Sound;
  10. import org.bukkit.entity.Entity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.inventory.InventoryClickEvent;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.inventory.PlayerInventory;
  18. import org.bukkit.inventory.meta.LeatherArmorMeta;
  19. import org.bukkit.scheduler.BukkitRunnable;
  20.  
  21. public class Phantom
  22. implements Listener
  23. {
  24. public Asia plugin;
  25. HashMap<Player, ItemStack[]> armor = new HashMap();
  26. HashMap<String, Long> cooldown = new HashMap();
  27. int time = 60;
  28.  
  29. public Phantom(Asia instance) {
  30. this.plugin = instance;
  31. }
  32.  
  33. private ItemStack colorIn(Material mat) {
  34. ItemStack armor = new ItemStack(mat);
  35. armor.setDurability((short)100);
  36. LeatherArmorMeta meta = (LeatherArmorMeta)armor.getItemMeta();
  37. meta.setColor(Color.WHITE);
  38. armor.setItemMeta(meta);
  39. return armor;
  40. }
  41.  
  42. @EventHandler
  43. public void onInteract(PlayerInteractEvent event)
  44. {
  45. final Player player = event.getPlayer();
  46. if ((player.getItemInHand().getType().equals(Material.FEATHER)) &&
  47. (Kit.getKit(player).equals("phantom"))) {
  48. if (Asia.hasSpawnProtection(player.getLocation()))
  49. return;
  50. if (this.cooldown.containsKey(player.getName())) {
  51. long secondes = ((Long)this.cooldown.get(player.getName()))
  52. .longValue() /
  53. 1000L +
  54. this.time -
  55. System.currentTimeMillis() / 1000L;
  56. if (secondes > 0L) {
  57. player.sendMessage("§cPlease wait " + secondes +
  58. " seconds before use your kit!");
  59. return;
  60. }
  61.  
  62. }
  63.  
  64. player.setAllowFlight(true);
  65. player.setFlying(true);
  66. this.armor.put(player, player.getInventory().getArmorContents());
  67. player.getInventory().setHelmet(
  68. new ItemStack(colorIn(Material.LEATHER_HELMET)));
  69. player.getInventory().setChestplate(
  70. new ItemStack(colorIn(Material.LEATHER_CHESTPLATE)));
  71. player.getInventory().setLeggings(
  72. new ItemStack(colorIn(Material.LEATHER_LEGGINGS)));
  73. player.getInventory().setBoots(
  74. new ItemStack(colorIn(Material.LEATHER_BOOTS)));
  75. player.updateInventory();
  76. player.playSound(player.getLocation(), Sound.WITHER_DEATH, 1.0F,
  77. 1.2F);
  78.  
  79. List nearby = player.getNearbyEntities(20.0D, 20.0D, 20.0D);
  80. for (Entity target : nearby) {
  81. if ((target instanceof Player)) {
  82. Player tmp = (Player)target;
  83. tmp.sendMessage("§f§lA phantom approaches...\n§f§lNote: they are not fly hacking, it's part of the kit.");
  84. }
  85. }
  86.  
  87. this.cooldown.put(player.getName(),
  88. Long.valueOf(System.currentTimeMillis()));
  89.  
  90. new BukkitRunnable() {
  91. int seconds = 5;
  92.  
  93. public void run() {
  94. this.seconds -= 1;
  95. if (this.seconds <= 3) {
  96. player.sendMessage("§c" + this.seconds +
  97. " seconds of flight remaining!");
  98. }
  99. if (this.seconds <= 0) {
  100. player.setAllowFlight(false);
  101. player.getInventory()
  102. .setArmorContents(
  103. (ItemStack[])Phantom.this.armor
  104. .remove(player));
  105. player.playSound(player.getLocation(),
  106. Sound.WITHER_SPAWN, 1.0F, 1.2F);
  107. player.setFallDistance(0.7F);
  108. cancel();
  109. }
  110. }
  111. }
  112. .runTaskTimer(this.plugin, 0L, 20L);
  113. }
  114. }
  115.  
  116. @EventHandler
  117. public void onClick(InventoryClickEvent event) {
  118. if ((event.getInventory() != null) && (event.getCurrentItem() != null) &&
  119. ((event.getWhoClicked() instanceof Player))) {
  120. Player player = (Player)event.getWhoClicked();
  121. if (this.armor.containsKey(event.getWhoClicked()))
  122. {
  123. if (event.getCurrentItem().getType().name()
  124. .contains("LEATHER_"))
  125. {
  126. if ((((LeatherArmorMeta)event.getCurrentItem()
  127. .getItemMeta()).getColor().equals(Color.WHITE)) &&
  128. (Kit.getKit(player).equals("phantom")))
  129. event.setCancelled(true);
  130. }
  131. }
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement