Cooldown in Kit System

Discussion in 'Plugin Development' started by FlowLox, Jan 16, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    FlowLox

    Hello, im developing now a Kit-system for my Skypvp server, but i my Cooldown dont work, can anyone please help me. Thanks!
     
  2. Online

    timtower Moderator Moderator

  3. Offline

    FlowLox

    Code:
    package me.kodpvp.kit;
    
    import java.util.HashMap;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    
    import me.kodpvp.main.Main;
    
    public class kits implements Listener{
        public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
        @EventHandler
        public void onClickInventory(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            e.setCancelled(true);
            if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§dKit Hero")){
                if(p.hasPermission("skypvp.hero")){               
                    if(cooldowns.containsKey(p.getName())){ 
                        long secondsLeft = ((cooldowns.get(p.getName()) / 1000) + 2000)- (System.currentTimeMillis() / 1000); 
                        p.sendMessage(Main.prefix+"Du musst noch "+  secondsLeft + " §7sekunden warten, bis du dir das §aKit §7nochmal abholen kannst.");
                        if(secondsLeft > 0) {
                           
                            return;
                        }
                    }
                    cooldowns.put(p.getName(), System.currentTimeMillis());
                    //p.playSound(p.getLocation(), Sound.CHEST_OPEN, 1, 1);
                    //p.openInventory(Main.kits);
                }
            }
    
           
        }
    
    }
     
  4. Online

    timtower Moderator Moderator

    @FlowLox Set the player only when you give them a kit.
     
  5. Offline

    A5H73Y

    Have you tried to debug your code? Print out the variables and stages to see where the code is getting to.
    Also, you are cancelling the inventory click straight away, which could break all inventory interactions essentially.
     
  6. Offline

    FlowLox

    But when i not cancelling the inventory click event, i can move the items in the inventory

    Im only want, when i click on the Item the player become his items and can not do it again before the time is end

    Thanks timtower i try it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 16, 2017
Thread Status:
Not open for further replies.

Share This Page