Solved Void instant kill

Discussion in 'Spigot Plugin Development' started by RoxioCZ, Jun 12, 2021.

  1. Hi,
    I'm trying to recreate the hypixel bedwars void insta kill. I am listening for void damage, cancelling it and calling my own death event. When I'm dying in the void, the event gets fired every time I loose health, but when I cancel the event, it starts firing like crazy, that means my custom death event gets called multiple times which causes crazy stuff to happen - respawning multiple times, etc.. I solved the issue using Thread.sleep, but that just doesnt feel right and I would love to replace that patch with a long term solution.

    Code (Java):
    @EventHandler
        public void onEntityDamage(EntityDamageEvent event) {
            if (event.getEntityType().equals(EntityType.PLAYER) && BedWars.gameInProgress) {
                Player player = (Player) event.getEntity();
                // Custom void instakill
                if (event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) {
                    // FIXME: 6/11/2021 i cannot cancel the event cuz it freaks out so the player looses a hearth in the process
                    event.setCancelled(true);
                    Bukkit.getPluginManager().callEvent(new BWPlayerDeathEvent(plugin, player));
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                // "replace" the default PlayerDeathEvent for my custom one
                else if (player.getHealth() - event.getFinalDamage() <= 0) death(event, player);
            }
        }
     
  2. Try to teleport the player to respawn location once they took void damage
     
  3. Thats basically the first thing that I do, I think that the event fires so rapidly, that it doesnt matter when I teleport them.
    Code (Java):
    public void onPlayerDeath(BWPlayerDeathEvent event) {
            Player player = event.getPlayer().getPlayer();
            event.getPlayer().setSpectator(true);
            player.teleport(plugin.getMap().getLobbySpawn());
     
  4. Don't use Thread.sleep(); in main thread!!
     
  5. Yeah, I know, it was a desperate solution I used, so I knew that the problem actually is what it is, thats why I'm here.
     
  6. Had this issue before when cause is void basicly just dont cancel the event and give damaged player heath

    or add an delay
     
  7. This code block is executed, right? I mean, did you try to add some log messages?
     
  8. Why are you fetching Player 2?
    Code (Text):
    Player player = event.getPlayer();
     
  9. i thought that it maybe that when you cancel event it dosn't set damage cooldown, so i googled and found this..
    cancelling EntityDamageEvent and Fire, it maybe the same thing is happening to you.
    you could try this.
     
    • Winner Winner x 1
  10. Yes of course.
    Well cuz the player object the event returns is not actually the Bukkit Player, its a custom object that encapsulates a Player object so yeah. A bit unintuitive i know.
     
  11. That makes sense, I'm going to try that one and let u know.
     
  12. Wait, does this modifies cooldown after when player get hit by another player? Or i am wrong?
     
  13. That actually worked, I am very pleased with the clean solution to my problem and also a bit embarassed by the fact, that I was not able to google that on my own. Thank you very much.
     
  14. Hello, I'm new at this. Could you pass me the plugin because you want to use it on my server. Thanks