1.8.8 Occur Double Entity Damege in single Damage

Discussion in 'Spigot Plugin Development' started by Methodghost, Feb 14, 2020 at 7:23 PM.

  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.

    Main class is
    public void onEnable()
    {
    getServer().getPluginManager().registerEvents(new AAA(), this);
    getServer().getPluginManager().registerEvents(new BBB(), this);
    getCommand("kit").setExecutor(new Cmds(this));
    }

    If I didn't spam with swor, There is no bugs.


    Please your opinions!!
     
    • Agree Agree x 1
  2. I forgot password old account, so i posted again..

    AND

    Main class
    Code (Text):
    package kit.plugin;

    import org.bukkit.plugin.java.JavaPlugin;

    public class Core extends JavaPlugin

    {
       
        public void onDisable()
        {
            super.onDisable();
        }

        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(new AAA(), this);
            getServer().getPluginManager().registerEvents(new BBB(), this);
            getCommand("kit").setExecutor(new Cmds(this));
            super.onEnable();
        }
       
    }
    Code (Text):
    package kit.plugin;

    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;

    public class BBB implements Listener
    {  
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            ItemStack hand = player.getItemInHand();
            if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                if (hand.getType() == Material.DIAMOND_SWORD || hand.getType() == Material.IRON_SWORD ||
                    hand.getType() == Material.GOLD_SWORD || hand.getType() == Material.STONE_SWORD ||
                    hand.getType() == Material.WOOD_SWORD)
                {
                        player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP, 10, 20);
                }
            }
        }
       
    }
    Code (Text):
    package kit.plugin;

    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);
                }
            }

        }
     
  3. Hmm try with another sound and see if it doubles as well,this shouldnt have a problem
     
  4. Remove the super.onEnable(), it may be causing your onEnable to run twice and therefore register your events twice. Plus the actual super method is empty so there's no point in calling it.
     
  5. No.
    Still remove it
     
  6. Another sound was same,
    and I tried to display message.I got twice messages..

    ill try

    what do you mean
     
  7. Attention

    this bugs on ONLY SPAMMING sword.
     
  8. If this is indeed 1.8 I'm not sure why else it would do it. In 1.9 it could be triggering for both hands independently
     
  9. The super.onEnable() does not trigger your code twice. Since the super-method is empty, you should remove it. Makes stuff more clear.
     
  10. I meant the method in the actual org.bukkit JavaPlugin class has an empty onEnable() method in it but that's simply so you aren't required to specify it when you create a plugin. I tested it and you are correct that super.onEnable() wouldn't be the cause of that, that was just the only thing I noticed was out of place at the moment.
     
  11. Well lets get everything out first

    Is there any plugin that can affect the pvp? Some may alter how the damage is sent and stuff