Cooldown in Kit System

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

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


    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


    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>();
        public void onClickInventory(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§dKit Hero")){
                        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) {
                    cooldowns.put(p.getName(), System.currentTimeMillis());
                    //p.playSound(p.getLocation(), Sound.CHEST_OPEN, 1, 1);
  4. Online

    timtower Moderator Moderator

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


    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


    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