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 Any solutions? Thanks
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
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;