1.15.2 Simple event repeating a lot of times.

Discussion in 'Spigot Plugin Development' started by Doron1803, Jan 28, 2020.

  1. Hello,
    I've got a simple event to check if a person is falling into the void. and for some reason, it's teleporting the person a million times until the server is stopped/the player logs out.

    Here's my code:
    Code (Text):
        @EventHandler
        public void antiVoid(EntityDamageEvent event) {
            if(event.getEntity() instanceof Player) {
               if(event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) {
                   event.setCancelled(true);
                   Location location = new Location(Bukkit.getWorld("hub"), 0.417,104.18750,0.684, 0, 0);
                    event.getEntity().teleport(location);
                    System.out.println("Teleported");
               }
            }
        }
    I added the print to see if it is what I suspected and it's not just teleporting once [​IMG]

    Any solutions?
    Thanks
     
  2. check if the player's y location is less than 0. If they are less than 0, then teleport them.
     
    • Like Like x 1
  3. Yeah that would be my answer
     
  4. The problem with the code above is, that every time you teleport your player back up, he still gets the void damage, so he is getting teleported back up again and again and again. Do as the others said on top of the thread and it will work just fine
     
  5. This could be solved by making some kind of "cooldown".
    Just use a HashMap<Player, Long> and check if it contains the player.
    If yes, check how long ago it was put inside.
    Semi Code:
    Code (Java):
    if((System.currentTimeMillis()-cooldownHashMap.get(player))<1000) return;