Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package me.winx.varo.misc;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  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.  
  13. import me.winx.varo.main.Main;
  14.  
  15. public class ItemCooldown implements Listener {
  16.  
  17. private HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
  18. private int cooldowntime = 10;
  19.  
  20. public void onEnable() {
  21.  
  22. }
  23.  
  24. @EventHandler
  25. public void onRightClick(PlayerInteractEvent e) {
  26. Player p = e.getPlayer();
  27. if(p.getItemInHand().getType().equals(Material.ENDER_PEARL)) {
  28. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK);
  29. if(!cooldown.containsKey(p.getUniqueId())) {
  30. cooldown.put(p.getUniqueId(), System.currentTimeMillis());
  31. } else {
  32. long secondsleft = ((cooldown.get(p.getUniqueId()) / 1000) + cooldowntime) - (System.currentTimeMillis() / 1000);
  33. e.setCancelled(true);
  34. if(secondsleft <= 0) {
  35. e.setCancelled(false);
  36. cooldown.remove(p.getUniqueId(), System.currentTimeMillis());
  37. cooldown.put(p.getUniqueId(), System.currentTimeMillis());
  38. cooldowntime = 10;
  39. } else {
  40. p.sendMessage(Main.prefix + "§cDu kannst die Enderperle in §e" + secondsleft + " §cSekunden wieder benutzen!");
  41. }
  42. }
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement