1.8.8 One Hit to get two Damage event....How to fix it.

Discussion in 'Spigot Plugin Development' started by megasmall, Feb 12, 2020 at 12:51 AM.

  1. First, Sorry for not good English.

    The problem is
    When I use this code and hit player with barrage,
    Damager got 1 hit and attacker get two times EntityDamageByEntityEvent..

    Code (Text):
        public void onEntityDamage(EntityDamageByEntityEvent event)
        {

            if (event.getDamager() instanceof Player && event.getEntity() instanceof Player)
                {
                    Player player = (Player) event.getEntity();
                    player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 10);
                }
           

        }
    Specifically, I got two orb sound when I hit player once.

    How to fix it.
    I tried to use this code too

    Code (Text):
        public void onEntityDamage(EntityDamageByEntityEvent event)
        {
            Entity damager = event.getEntity();
           
            if(damager instanceof Player && event.getDamage() <= 0)
            {
            }
            else
            {
                if (event.getDamager() instanceof Player && event.getEntity() instanceof Player)
                {
                    Player player = (Player) event.getEntity();
                    player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 10);
                }
            }

        }
    But didn't fix.

    Please your opinions!!
     
  2. edbee isnt generally called multiple times. youre likely registering the listener more than once. going to need to see more code.
     
  3. What do you mean?

    I got two sounds when I hit once.
     
  4.  
  5. Ur right about that one

    ".registerEvents" is called twice somewhere,maybe a new instance...
     
  6. i mean the event is being called once, but youre listening to it twice, so you're playing two sounds for 1 event. this is likely because you have more than 1 listener instance being registered. gonna need to see more code, main class and the rest of your listener class
     
  7. Here is main class

    Code (Text):
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(new AAA(), this);
            getServer().getPluginManager().registerEvents(new BBB(), this);
            getCommand("kit").setExecutor(new Cmds(this));
            super.onEnable();
        }
       
     
  8. Code (Text):
    import org.bukkit.Sound;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;

    public class AAA implements Listener
    {
        @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent event)
        {
            Entity damager = event.getEntity();
       
            if(damager instanceof Player && event.getDamage() <= 0)
            {
            }
            else
            {
                if (event.getDamager() instanceof Player && event.getEntity() instanceof Player)
                {
                    Player player = (Player) event.getEntity();
                    player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 10);
                }
            }

        }
     
     
     
       
     
  9. ADDED
     
  10. AND If I didn't barrage, there is no bugs
     
  11. what do you mean "barrage"? spam clicking? or something else?
    does your BBB class do anything with the entitydamage event?
    also you dont need to call super.onEnable, its an empty method.