Need CoolDown for my Plugin (the healstick)

Discussion in 'Plugin Development' started by Azznozik13, Dec 5, 2019.

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

    Azznozik13

    Code:
    package fr.gravenilvec.monplugin;
    import java.util.Arrays;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerPortalEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class MonPluginlisteners implements Listener {
    @EventHandler
      public void onJoin (PlayerPortalEvent event){
      
        Player player = event.getPlayer();
        
        
        
        ItemStack customaxe = new ItemStack (Material.STICK,1);
        ItemMeta customM = customaxe.getItemMeta();
        customM.setDisplayName("§cHealStick");
        customM.setLore(Arrays.asList("Stick qui regen les Coeurs"));
        customaxe.setItemMeta(customM);
        
        
        player.getInventory().setItemInHand(customaxe);
        
      
        
        player.updateInventory();
        
      }
    @EventHandler
    public void onInteract(PlayerInteractEvent event){
        
        Player player = event.getPlayer() ;
        Action action = event.getAction();
        ItemStack it = event.getItem();
      
        if(it == null) return;
      
           if( it.getType() == Material.DIAMOND_PICKAXE) {
            if (action == Action.RIGHT_CLICK_AIR) {
            player.sendMessage("Vous Venez D'utilisez votre Pioche");
            }
        }
          
        if(it.getType() == Material.STICK && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().getDisplayName().equalsIgnoreCase("§cHealStick")){
            player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 20*1 , 1)) ;
        }
          
          
    }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Azznozik13 Make a List of UUID's.
    When the user clicks check if they are in the list. If so:
    They are on cooldown.
    If not:
    They are not on cooldown.
    Add them to the list and do the action.
    Also start a delayed runnable to remove the UUID from the list again.
     
  3. Offline

    Strahan

    Ehh.. personally, I prefer to use a Map and avoid cluttering resources with runnables. Make a Map<UUID, Long> and store the time the cooldown expires. Then when the user goes to use whatever has cooldown applied, you check if they are in the map. If so, check if the value of the map against the current time to determine if the cooldown has expired. If so, remove from map. If not, complain at user and return.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Strahan Also depends a little bit on the experience of the user, but yes, a map is also a very good option.
     
Thread Status:
Not open for further replies.

Share This Page