Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. package to.epac.factorycraft.CombinedHit.Events;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Material;
  6. import org.bukkit.Sound;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.block.Action;
  11. import org.bukkit.event.player.PlayerInteractEvent;
  12. import org.bukkit.inventory.EquipmentSlot;
  13. import org.bukkit.metadata.FixedMetadataValue;
  14. import org.bukkit.plugin.Plugin;
  15.  
  16. import to.epac.factorycraft.CombinedHit.Main;
  17. import to.epac.factorycraft.CombinedHit.Utils.ActionBar;
  18. import to.epac.factorycraft.CombinedHit.Utils.CastPhase;
  19. import to.epac.factorycraft.CombinedHit.Utils.FileManager;
  20.  
  21. public class ClickHandler implements Listener {
  22. private Plugin plugin = Main.instance;
  23.  
  24. /*
  25. *
  26. * ########## CLICK ##########
  27. * Please beware that EVERY event in this class only apply on CLICK entities/players
  28. * Damaging entities/players are not detected in this class
  29. * ########## CLICK ##########
  30. *
  31. */
  32.  
  33. @EventHandler
  34. public void lv1(PlayerInteractEvent event) {
  35. Player p = (Player) event.getPlayer();
  36.  
  37. /*if (!p.getItemInHand().getItemMeta().getLore().contains("")) {
  38. return;
  39. }*/
  40.  
  41. if (!FileManager.isConfigFileValid()) return;
  42. if (p.getInventory().getItemInMainHand().getType() == Material.AIR) return;
  43.  
  44. if (FileManager.getLevel(p) == 1 || !FileManager.isPlayerInDataBase(p)) {
  45.  
  46. // Preventing players from no-cooldown casting and multiple casting
  47. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK ||
  48. event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  49.  
  50. if (!(event.getHand().equals(EquipmentSlot.HAND))) return;
  51.  
  52. if (p.hasMetadata("CombinedHit.Lv1")) {
  53. ActionBar.sendActionBar(p, ChatColor.DARK_RED + "" + ChatColor.BOLD + "Lv1 Cooling down !");
  54. return;
  55. }
  56. }
  57.  
  58. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  59.  
  60. if (p.hasMetadata("CombinedHit.Lv1.1")) {
  61. p.removeMetadata("CombinedHit.Lv1.1", plugin);
  62. p.removeMetadata("CombinedHit.Lv1", plugin);
  63.  
  64. p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 2);
  65.  
  66. ActionBar.sendActionBar(p, ChatColor.GRAY + "[R] [L]");
  67.  
  68. return;
  69. }
  70.  
  71. if (!p.hasMetadata("CombinedHit:Lv1") && !p.hasMetadata("CombinedHit:Lv1.1")) {
  72. ActionBar.sendActionBar(p, CastPhase.getPhaseText(1, 1));
  73. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 0);
  74. p.removeMetadata("CombinedHit.Lv1", plugin);
  75. p.setMetadata("CombinedHit.Lv1.1", new FixedMetadataValue(plugin, p.getUniqueId()));
  76. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  77. MetadataHandler.erase(p, 1);
  78. }
  79. }
  80. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
  81. if (p.hasMetadata("CombinedHit.Lv1.1")) {
  82. ActionBar.sendActionBar(p, CastPhase.getPhaseText(1, 2));
  83. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 2);
  84. p.setMetadata("CombinedHit.Lv1", new FixedMetadataValue(plugin, p.getUniqueId()));
  85. }
  86. }
  87. }
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. @EventHandler
  95. public void lv2(PlayerInteractEvent event) {
  96. Player p = (Player) event.getPlayer();
  97.  
  98. if (!FileManager.isConfigFileValid()) return;
  99. if (p.getInventory().getItemInMainHand().getType() == Material.AIR) return;
  100.  
  101. if (FileManager.getLevel(p) == 2) {
  102.  
  103. // Prohibiting players from no-cooldown casting and multiple right click
  104. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK ||
  105. event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  106.  
  107. if (!(event.getHand().equals(EquipmentSlot.HAND))) return;
  108.  
  109. if (p.hasMetadata("CombinedHit.Lv2")) {
  110. ActionBar.sendActionBar(p, ChatColor.DARK_RED + "" + ChatColor.BOLD + "Lv2 Cooling down !");
  111. return;
  112. }
  113. }
  114.  
  115. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  116.  
  117. if (p.hasMetadata("CombinedHit.Lv2.1")) {
  118. p.removeMetadata("CombinedHit.Lv2.1", plugin);
  119. p.removeMetadata("CombinedHit.Lv2.2", plugin);
  120. p.removeMetadata("CombinedHit.Lv2", plugin);
  121.  
  122. p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 2);
  123.  
  124. ActionBar.sendActionBar(p, ChatColor.GRAY + "[R] [L] [L]");
  125.  
  126. return;
  127. }
  128.  
  129. if (!p.hasMetadata("CombinedHit:Lv2") && !p.hasMetadata("CombinedHit:Lv2.1")) {
  130. ActionBar.sendActionBar(p, CastPhase.getPhaseText(2, 1));
  131. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 0);
  132. p.setMetadata("CombinedHit.Lv2.1", new FixedMetadataValue(plugin, p.getUniqueId()));
  133.  
  134. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  135. MetadataHandler.erase(p, 2);
  136. }
  137. }
  138. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
  139.  
  140. if (p.hasMetadata("CombinedHit.Lv2.1") && !p.hasMetadata("CombinedHit.Lv2.2")) {
  141. ActionBar.sendActionBar(p, CastPhase.getPhaseText(2, 2));
  142. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 2);
  143. p.setMetadata("CombinedHit.Lv2.2", new FixedMetadataValue(plugin, p.getUniqueId()));
  144.  
  145. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  146. MetadataHandler.erase(p, 2);
  147. }
  148. else if (p.hasMetadata("CombinedHit.Lv2.2") && !p.hasMetadata("CombinedHit.Lv2")) {
  149. ActionBar.sendActionBar(p, CastPhase.getPhaseText(2, 3));
  150. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 2);
  151. p.setMetadata("CombinedHit.Lv2", new FixedMetadataValue(plugin, p.getUniqueId()));
  152.  
  153. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  154. MetadataHandler.erase(p, 2);
  155. }
  156. }
  157. }
  158. }
  159.  
  160.  
  161.  
  162.  
  163. @EventHandler
  164. public void lv3(PlayerInteractEvent event) {
  165. Player p = (Player) event.getPlayer();
  166.  
  167. if (!FileManager.isConfigFileValid()) return;
  168. if (p.getInventory().getItemInMainHand().getType() == Material.AIR) return;
  169.  
  170. if (FileManager.getLevel(p) == 3) {
  171.  
  172. // Prohibiting players from no-cooldown casting and multiple right click
  173. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK ||
  174. event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  175.  
  176. if (!(event.getHand().equals(EquipmentSlot.HAND))) return;
  177.  
  178. if (p.hasMetadata("CombinedHit.Lv3")) {
  179. ActionBar.sendActionBar(p, ChatColor.DARK_RED + "" + ChatColor.BOLD + "Lv3 Cooling down !");
  180. return;
  181. }
  182. }
  183.  
  184. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
  185. if (p.hasMetadata("CombinedHit.Lv3.1") && !p.hasMetadata("CombinedHit.Lv3.2")) {
  186. p.removeMetadata("CombinedHit.Lv3.1", plugin);
  187. p.removeMetadata("CombinedHit.Lv3.2", plugin);
  188. p.removeMetadata("CombinedHit.Lv3.3", plugin);
  189. p.removeMetadata("CombinedHit.Lv3", plugin);
  190.  
  191. p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 3);
  192.  
  193. ActionBar.sendActionBar(p, ChatColor.GRAY + "[R] [L] [R] [L]");
  194.  
  195. return;
  196. }
  197. if (p.hasMetadata("CombinedHit.Lv3.3") && !p.hasMetadata("CombinedHit.Lv3")) {
  198. p.removeMetadata("CombinedHit.Lv3.1", plugin);
  199. p.removeMetadata("CombinedHit.Lv3.2", plugin);
  200. p.removeMetadata("CombinedHit.Lv3.3", plugin);
  201. p.removeMetadata("CombinedHit.Lv3", plugin);
  202.  
  203. p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 3);
  204.  
  205. ActionBar.sendActionBar(p, ChatColor.GRAY + "[R] [L] [R] [L]");
  206.  
  207. return;
  208. }
  209.  
  210.  
  211. if (!p.hasMetadata("CombinedHit:Lv3") && !p.hasMetadata("CombinedHit:Lv3.1") && !p.hasMetadata("CombinedHit.Lv3.2")) {
  212. ActionBar.sendActionBar(p, CastPhase.getPhaseText(3, 1));
  213. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 0);
  214. p.setMetadata("CombinedHit.Lv3.1", new FixedMetadataValue(plugin, p.getUniqueId()));
  215.  
  216. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  217. MetadataHandler.erase(p, 3);
  218. }
  219. else if (!p.hasMetadata("CombinedHit:Lv3") && p.hasMetadata("CombinedHit.Lv3.2") && !p.hasMetadata("CombinedHit:Lv3.3")) {
  220. ActionBar.sendActionBar(p, CastPhase.getPhaseText(3, 3));
  221. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 0);
  222. p.setMetadata("CombinedHit.Lv3.3", new FixedMetadataValue(plugin, p.getUniqueId()));
  223.  
  224. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  225. MetadataHandler.erase(p, 3);
  226. }
  227. }
  228. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
  229. if (p.hasMetadata("CombinedHit.Lv3.1") && !p.hasMetadata("CombinedHit.Lv3.2")) {
  230. ActionBar.sendActionBar(p, CastPhase.getPhaseText(3, 2));
  231. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 3);
  232. p.setMetadata("CombinedHit.Lv3.2", new FixedMetadataValue(plugin, p.getUniqueId()));
  233.  
  234. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  235. MetadataHandler.erase(p, 3);
  236. }
  237. else if (p.hasMetadata("CombinedHit.Lv3.3") && !p.hasMetadata("CombinedHit.Lv3")) {
  238. ActionBar.sendActionBar(p, CastPhase.getPhaseText(3, 0));
  239. p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 3);
  240. p.setMetadata("CombinedHit.Lv3", new FixedMetadataValue(plugin, p.getUniqueId()));
  241.  
  242. Bukkit.getServer().getScheduler().cancelTask(MetadataHandler.schedulerId);
  243. MetadataHandler.erase(p, 3);
  244. }
  245.  
  246. else if (p.hasMetadata("CombinedHit.Lv3.2") && !p.hasMetadata("CombinedHit.Lv3.3")) {
  247. p.removeMetadata("CombinedHit.Lv3.1", plugin);
  248. p.removeMetadata("CombinedHit.Lv3.2", plugin);
  249. p.removeMetadata("CombinedHit.Lv3.3", plugin);
  250. p.removeMetadata("CombinedHit.Lv3", plugin);
  251.  
  252. p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 3);
  253.  
  254. ActionBar.sendActionBar(p, ChatColor.GRAY + "[R] [L] [R] [L]");
  255.  
  256. return;
  257. }
  258. }
  259. }
  260. }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement