Help pls with cooldown

Discussion in 'Plugin Development' started by Lowes, Jan 6, 2021.

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

    Lowes

    Hello I beginner developer and I see error in my Cooldown when cooldown is put I dont use again
    Code:
    Help pls for cooldown:

    @EventHandler
    public void PlayerInteract(PlayerInteractEvent e) {
    if(e.getPlayer().getInventory().getItemInMainHand().getType() == (Material.IRON_HOE)) {

    Player p = (Player) e.getPlayer();

    if(e.getAction() == Action.LEFT_CLICK_AIR) {

    if(cooldown.containsKey(p.getUniqueId())) {
    long secleft = ((cooldown.get(p.getUniqueId()) / 1000)+cooldowntime) - (System.currentTimeMillis() / 1000);

    if(secleft > 0) {

    p.sendMessage(ChatColor.GREEN + "Reloading..."+ secleft + " seconds");

    }
    e.setCancelled(true);
    if(secleft == 3) {
    cooldown.put(p.getUniqueId(), System.currentTimeMillis());
    p.launchProjectile(Arrow.class);
    }


    }
     
  2. Offline

    CraftCreeper6

    @Lowes
    What does the cooldown Map store?
     
  3. Offline

    Ago19

    There is not need to cast e.getPlayer() to Player

    As far as I know, the following symbol == in java compares the address of the 2 variables. If possible try to use .equals()

    What is the cooldown variable? What does it contains?

    Does the console give you any errors? If so pls post them so that we can take a look. Also tell us on which occasion it gives the error, for example when left_clicking with an iron hoe.
    I'm a C++ developer that just started coding java, so if you know that I'm saying something wrong tell me
     
  4. Offline

    CraftCreeper6

    @Ago19
    It's permissible to use == on Enum types as there is only one instance of each enum constant.

    The official JDK in fact uses == instead of .equals()
     
  5. Offline

    Ago19

Thread Status:
Not open for further replies.

Share This Page