Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package to.epac.factorycraft.CombinationHits.Events;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  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.plugin.Plugin;
  14.  
  15. import to.epac.factorycraft.CombinationHits.CooldownHandler;
  16. import to.epac.factorycraft.CombinationHits.Main;
  17. import to.epac.factorycraft.CombinationHits.SkillsHandler;
  18. import to.epac.factorycraft.CombinationHits.Utils.ActionBar;
  19. import to.epac.factorycraft.CombinationHits.Utils.ConfigManager;
  20. import to.epac.factorycraft.CombinationHits.Utils.Utils;
  21.  
  22. public class ClickHandler implements Listener {
  23. private static Plugin plugin = Main.instance;
  24. public static int schedulerId2 = 0;
  25. public static HashMap<Player, String> playerDB = new HashMap<Player, String>();
  26. public static HashMap<Player, String> playerDB2 = new HashMap<Player, String>();
  27.  
  28. @EventHandler
  29. public void LeftClick(PlayerInteractEvent event) {
  30. Player p = (Player) event.getPlayer();
  31.  
  32. if (!ConfigManager.isConfigFileValid()) return;
  33. if (p.getInventory().getItemInMainHand().getType() == Material.AIR) return;
  34. if (!(event.getHand().equals(EquipmentSlot.HAND))) return;
  35.  
  36. String click = "";
  37. if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) click = "L";
  38. else if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) click = "R";
  39. else return;
  40.  
  41. if (Utils.hasSkillLore(p, playerDB)) {
  42. if (playerDB.get(p) != null) {
  43. String currentPhase = playerDB.get(p);
  44. playerDB.remove(p);
  45. playerDB.put(p, currentPhase + click);
  46. }
  47. else playerDB.put(p, "CombinationHits." + click);
  48.  
  49. // Implement ActionBar when click here, playerDB2 should store those data
  50. // You can use %Right% %Left% and add new config section
  51.  
  52. p.sendMessage("You have" + click + "clicked.");
  53. p.sendMessage(playerDB.get(p));
  54.  
  55. if (HitsChecker.isHitValid(p, playerDB)) {
  56. Bukkit.broadcastMessage("Valid hits");
  57.  
  58. SkillsHandler.castSkills(p, playerDB);
  59. }
  60. Bukkit.getServer().getScheduler().cancelTask(schedulerId2);
  61. schedulerId2 = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  62. @Override
  63. public void run() {
  64. // If player's cooldown time is set
  65. // Which means what player is in cooldown
  66. // He cant multiple casting skills
  67. if (CooldownHandler.cooldown <= 0) {
  68. playerDB.remove(p);
  69. ActionBar.sendActionBar(p, ConfigManager.getCombinationClearMessage());
  70. }
  71. }
  72. }, ConfigManager.getCombinationExpireTime());
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement