Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
- public HashMap<String, Long> arrowcooldowns = new HashMap<String, Long>();
- public void shotBow(Player p) {
- if (p.isSneaking()) {
- double cooldownTime = 0.1;
- int i = 0;
- while (!(i == 11)) {
- if (arrowcooldowns.containsKey(p.getName())) {
- double secondsLeft = ((arrowcooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
- if (!(secondsLeft>0)) {
- p.launchProjectile(Arrow.class);
- i++;
- arrowcooldowns.put(p.getName(), System.currentTimeMillis());
- }
- }
- else {
- p.launchProjectile(Arrow.class);
- i++;
- arrowcooldowns.put(p.getName(), System.currentTimeMillis());
- }
- }
- }
- }
- @EventHandler
- public void test(EntityShootBowEvent event) {
- if (event.getEntity() instanceof Player) {
- Player p = (Player) event.getEntity();
- int cooldownTime = 2;
- if (cooldowns.containsKey(p.getName())) {
- long secondsLeft = ((cooldowns.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
- if(secondsLeft>0) {
- p.sendMessage(ChatColor.RED + "You have to wait " + secondsLeft + " seconds to use your special attack");
- }
- else {
- event.setCancelled(true);
- shotBow(p);
- cooldowns.put(p.getName(), System.currentTimeMillis());
- }
- }
- else {
- event.setCancelled(true);
- shotBow(p);
- cooldowns.put(p.getName(), System.currentTimeMillis());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement