i want to make a cooltime system

Discussion in 'Plugin Development' started by chanCraft, Dec 6, 2019.

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

    chanCraft

    Code:
    int diamondExplorer_Duration = 0;
        int diamondExplorer_CoolTime = 5; 
        int diamondExplorer_CoolTempTime = 0;
    
    
    
    public void onRightClick(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            if(event.getAction() == Action.RIGHT_CLICK_AIR && player.getInventory().getItemInMainHand().hasItemMeta())
            {
                //Diamond Explorer SKill
    if(player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(diamondExplorer_Name)
                        && diamondExplorer_Duration <= 0 && diamondExplorer_CoolTempTime <=0)
                {
                    diamondExplorer_Duration = 10;
                    diamondExplorer_CoolTempTime = 3;
                    Bukkit.getServer().broadcastMessage("right button Click");
                   
                   
                    new BukkitRunnable() {
                       
                        @Override
                        public void run() {
                            if(diamondExplorer_Duration > 0)
                            {
                                diamondExplorer_Duration --;
                                ExplorerNearbyBlock(player);
                                Bukkit.getServer().broadcastMessage("" + diamondExplorer_Duration);
                               
                            }
                            else           
                            {
                                SkillCoolTime(diamondExplorer_CoolTime);
                                //Bukkit.getServer().broadcastMessage("Done");
                               
                                this.cancel();
                               
                            }
                           
                        }
                    }.runTaskTimer(Main.getInstance(), 0L , 20L);
               
                }
            }
        }
       
        void SkillCoolTime(int Time)
        {
            diamondExplorer_CoolTempTime = Time;
           
            new BukkitRunnable() {
               
                @Override
                public void run() {
                    if(diamondExplorer_CoolTempTime > 0)
                    {
                        diamondExplorer_CoolTempTime--;
                        Bukkit.getServer().broadcastMessage("" + diamondExplorer_CoolTempTime);
                    }
                    else           
                    {
                        //Bukkit.getServer().broadcastMessage("");
                        this.cancel();
                    }
                   
                }
            }.runTaskTimer(Main.getInstance(), 0L, 20L);
           
           
        }
    i executed the SkillCoolTime when DiamondExplorer_Duration gonna be zero
    but if i right click many time , can be executed SkillCoolTime and DiamondExplorer skill at the same time
    i want to prevent execute after DiamondExplorer skill ended before execute SkillCoolTime
     
  2. Offline

    MrGeneralQ

    The cool time needs to be stored somewhere separate then your event class. The event class will reset all your values.

    Sent from my ONEPLUS A3003 using Tapatalk
     
  3. Offline

    Strahan

    It's not so much that the data needs stored in another class more that the data needs to be indexed by player. OP, remember, this code gets ran for every player that interacts so you can't use a generic variable like that. You'd want a map or something.
     
    MrGeneralQ likes this.
  4. Offline

    MrGeneralQ

    Correct, I forgot the class does not get initialed every time , but the method does.

    Sent from my ONEPLUS A3003 using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page