EntityDamageByEntityEvent delete?

Discussion in 'Spigot Plugin Development' started by julien0312, Jan 8, 2020.

  1. Hello, I have a problem with my code, I am trying to detect if a player is killed by another player and when the player dies put it in GameMode 3. it worked but suddenly without changing the code all the dead by players are going to commit suicide.

    EntityDamageByEntity at as been replaced by EntityDamageEvent ...

    Code (Text):

        @EventHandler(priority = EventPriority.HIGH)
        public void onDamagerbyKiller(EntityDamageByEntityEvent event) {
            if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
                Player player = (Player)event.getEntity();
                Player damager = (Player)event.getDamager();
                    if (player.getHealth() - event.getFinalDamage() <= 0) {
    Code (Text):

        @EventHandler
        public void onDamager(EntityDamageEvent event) {
            if (event.getEntity() instanceof Player) {
                Player player = (Player)event.getEntity();
                    if (player.getHealth() - event.getFinalDamage() <= 0) {
     
  2. What exactly is the problem?
    Is there any reason not to use the EntityDeathEvent or even the PlayerRespawnEvent?
    You can always get the killer afterwards with player#getKiller()
     
  3. I'm guessing OP decided to go with damage event so that the player who dies doesn't need to go through the death screen. There are ways to cancel that screen but all-together, it's a bit complicated and simple is often better hence canceling lethal damage where all information is still available.


    What do you mean? The wording here is a bit odd. Do you mean to say that your events are triggering twice? That might make sense if you are listening to both events since a single player can trigger both events. I'd recommend deleting one of your event listeners, adding some fields or global variables to track if a player was already handled, or canceling the event using "event.setCanceled(true)" depending on what the rest of your methods do.
     
  4. This game does not run when a player kills another player. It is the other method that runs instead :/
    Code (Text):
        @EventHandler(priority = EventPriority.HIGH)
        public void onDamagerbyKiller(EntityDamageByEntityEvent event) {
            if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
                Player player = (Player)event.getEntity();
                Player damager = (Player)event.getDamager();
                    if (player.getHealth() - event.getFinalDamage() <= 0) {
                        event.setDamage(0.0);
                        player.setHealth(20.0);
                        death.add(player);
                        player.setFoodLevel(20);
                        Title.sendTitle(player, "", "§8§l» §cVous êtes mort(e) §8§l«", 80);
                        if(damager.getItemInHand().getItemMeta().getDisplayName() != null) {
                            for(Player p : Bukkit.getOnlinePlayers()) {
                                sendActionBar(p, player.getName() + " §7a été tué(e) par §r" + damager.getName() + " §7avec §r" + damager.getItemInHand().getItemMeta().getDisplayName() + "§7.");
                            }
                        }else {
                            for(Player p : Bukkit.getOnlinePlayers()) {
                                sendActionBar(p, player.getName() + " §7a été tué(e) par §r" + damager.getName() + "§7.");
                            }
                        }
                        Bukkit.getScheduler().runTaskLater(this, () -> {
                            player.teleport(getLocation(1));
                            player.setGameMode(GameMode.SURVIVAL);
                            death.remove(player);
                            return;
                        }, 80L);
                    }
                }
            }
     
  5. you cancelling the other one?

    this is a blind but educated guess. edbee extends ede. so any declaration of ede event will also handle edbee events. so basically, your edbee event is being handled twice, once by ede, again by edbee. with edbee being a higher priority, its going after ede. this may be why youre having issues.

    do you know if the edbee method is called at all? put a debug on the first method line
     
  6. I’m just trying to detect whether the player killed was killed by a player or not
     
  7. ok? did u read anything i said? i gave you a hypothetical reason why edbee isnt being called like you want it to. and then i gave you a method of trying it out to be sure.