BaconIsBest

k

Feb 3rd, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. /* 1: */ package com.tips48.kits.kits.impl;
  2. /* 2: */
  3. /* 3: */ import com.tips48.kits.kits.Kit;
  4. /* 4: */ import java.util.Random;
  5. /* 5: */ import org.bukkit.Material;
  6. /* 6: */ import org.bukkit.Server;
  7. /* 7: */ import org.bukkit.block.Block;
  8. /* 8: */ import org.bukkit.block.BlockFace;
  9. /* 9: */ import org.bukkit.enchantments.Enchantment;
  10. /* 10: */ import org.bukkit.entity.Entity;
  11. /* 11: */ import org.bukkit.entity.LivingEntity;
  12. /* 12: */ import org.bukkit.entity.Player;
  13. /* 13: */ import org.bukkit.event.EventHandler;
  14. /* 14: */ import org.bukkit.event.block.Action;
  15. /* 15: */ import org.bukkit.event.entity.EntityDamageByEntityEvent;
  16. /* 16: */ import org.bukkit.event.player.PlayerInteractEvent;
  17. /* 17: */ import org.bukkit.inventory.ItemStack;
  18. /* 18: */ import org.bukkit.plugin.Plugin;
  19. /* 19: */ import org.bukkit.potion.PotionEffect;
  20. /* 20: */ import org.bukkit.potion.PotionEffectType;
  21. /* 21: */ import org.bukkit.scheduler.BukkitScheduler;
  22. /* 22: */
  23. /* 23: */ public class Spider
  24. /* 24: */ extends Kit
  25. /* 25: */ {
  26. /* 26: 26 */ private static final Random random = new Random();
  27. /* 27: 28 */ private static final ItemStack[] armorSlots = { new ItemStack(Material.LEATHER_BOOTS, 1), new ItemStack(Material.LEATHER_LEGGINGS, 1), new ItemStack(Material.IRON_CHESTPLATE, 1), new ItemStack(Material.LEATHER_HELMET, 1) };
  28. /* 28: */ private final ItemStack stoneAxe;
  29. /* 29: */ private Block spiderWeb;
  30. /* 30: */
  31. /* 31: */ public Spider(Plugin plugin, String playerName)
  32. /* 32: */ {
  33. /* 33: 38 */ super(plugin, playerName);
  34. /* 34: */
  35. /* 35: 40 */ this.stoneAxe = new ItemStack(Material.STONE_AXE, 1);
  36. /* 36: 41 */ this.stoneAxe.addEnchantment(Enchantment.DAMAGE_ALL, 1);
  37. /* 37: */
  38. /* 38: 43 */ this.spiderWeb = null;
  39. /* 39: */ }
  40. /* 40: */
  41. /* 41: */ public String getName()
  42. /* 42: */ {
  43. /* 43: 48 */ return "Spider";
  44. /* 44: */ }
  45. /* 45: */
  46. /* 46: */ public ItemStack[] getArmorSlots()
  47. /* 47: */ {
  48. /* 48: 53 */ return armorSlots;
  49. /* 49: */ }
  50. /* 50: */
  51. /* 51: */ public ItemStack[] getInventory()
  52. /* 52: */ {
  53. /* 53: 58 */ return new ItemStack[] { this.stoneAxe };
  54. /* 54: */ }
  55. /* 55: */
  56. /* 56: */ @EventHandler
  57. /* 57: */ public void handle(EntityDamageByEntityEvent event)
  58. /* 58: */ {
  59. /* 59: 65 */ Entity entity = event.getDamager();
  60. /* 60: 66 */ if (!(entity instanceof Player)) {
  61. /* 61: 67 */ return;
  62. /* 62: */ }
  63. /* 63: 70 */ Player player = (Player)entity;
  64. /* 64: 71 */ if (!player.getName().equalsIgnoreCase(this.playerName)) {
  65. /* 65: 72 */ return;
  66. /* 66: */ }
  67. /* 67: 75 */ ItemStack hand = player.getItemInHand();
  68. /* 68: 76 */ if (hand.getType() != Material.STONE_AXE) {
  69. /* 69: 77 */ return;
  70. /* 70: */ }
  71. /* 71: 80 */ if (random.nextInt(5) == 0)
  72. /* 72: */ {
  73. /* 73: 81 */ Entity damaged = event.getEntity();
  74. /* 74: 82 */ if (!(damaged instanceof LivingEntity)) {
  75. /* 75: 83 */ return;
  76. /* 76: */ }
  77. /* 77: 85 */ LivingEntity living = (LivingEntity)damaged;
  78. /* 78: 86 */ PotionEffect effect = new PotionEffect(PotionEffectType.POISON, 100, 1);
  79. /* 79: 87 */ living.addPotionEffect(effect);
  80. /* 80: */ }
  81. /* 81: */ }
  82. /* 82: */
  83. /* 83: */ @EventHandler
  84. /* 84: */ public void handle(PlayerInteractEvent event)
  85. /* 85: */ {
  86. /* 86: 93 */ Action action = event.getAction();
  87. /* 87: 94 */ if (action != Action.RIGHT_CLICK_BLOCK) {
  88. /* 88: 95 */ return;
  89. /* 89: */ }
  90. /* 90: 98 */ Player player = event.getPlayer();
  91. /* 91: 99 */ if (!player.getName().equalsIgnoreCase(this.playerName)) {
  92. /* 92:100 */ return;
  93. /* 93: */ }
  94. /* 94:103 */ if (this.spiderWeb != null) {
  95. /* 95:104 */ return;
  96. /* 96: */ }
  97. /* 97:107 */ this.spiderWeb = event.getClickedBlock().getRelative(BlockFace.UP);
  98. /* 98:108 */ this.spiderWeb.setType(Material.WEB);
  99. /* 99: */
  100. /* 100:110 */ SpiderWebRunnable runnable = new SpiderWebRunnable(null);
  101. /* 101:111 */ this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, runnable, 60L);
  102. /* 102: */ }
  103. /* 103: */
  104. /* 104: */ private class SpiderWebRunnable
  105. /* 105: */ implements Runnable
  106. /* 106: */ {
  107. /* 107: */ private SpiderWebRunnable() {}
  108. /* 108: */
  109. /* 109: */ public void run()
  110. /* 110: */ {
  111. /* 111:118 */ if (Spider.this.spiderWeb == null) {
  112. /* 112:119 */ return;
  113. /* 113: */ }
  114. /* 114:122 */ if (Spider.this.spiderWeb.getType() == Material.WEB) {
  115. /* 115:123 */ Spider.this.spiderWeb.setType(Material.AIR);
  116. /* 116: */ }
  117. /* 117:125 */ Spider.this.spiderWeb = null;
  118. /* 118: */ }
  119. /* 119: */ }
  120. /* 120: */ }
Advertisement
Add Comment
Please, Sign In to add comment