Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
  2. public HashMap<String, Long> arrowcooldowns = new HashMap<String, Long>();
  3.  
  4. public void shotBow(Player p) {
  5.  
  6. if (p.isSneaking()) {
  7. double cooldownTime = 0.1;
  8.  
  9.  
  10. int i = 0;
  11.  
  12. while (!(i == 11)) {
  13. if (arrowcooldowns.containsKey(p.getName())) {
  14. double secondsLeft = ((arrowcooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
  15. if (!(secondsLeft>0)) {
  16. p.launchProjectile(Arrow.class);
  17. i++;
  18. arrowcooldowns.put(p.getName(), System.currentTimeMillis());
  19. }
  20. }
  21. else {
  22. p.launchProjectile(Arrow.class);
  23. i++;
  24. arrowcooldowns.put(p.getName(), System.currentTimeMillis());
  25. }
  26. }
  27. }
  28. }
  29.  
  30. @EventHandler
  31. public void test(EntityShootBowEvent event) {
  32. if (event.getEntity() instanceof Player) {
  33. Player p = (Player) event.getEntity();
  34. int cooldownTime = 2;
  35. if (cooldowns.containsKey(p.getName())) {
  36. long secondsLeft = ((cooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
  37. if(secondsLeft>0) {
  38. p.sendMessage(ChatColor.RED + "You have to wait " + secondsLeft + " seconds to use your special attack");
  39. }
  40. else {
  41. event.setCancelled(true);
  42. shotBow(p);
  43. cooldowns.put(p.getName(), System.currentTimeMillis());
  44. }
  45. }
  46. else {
  47. event.setCancelled(true);
  48. shotBow(p);
  49. cooldowns.put(p.getName(), System.currentTimeMillis());
  50. }
  51.  
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement