No events occuring in EntityDamageByEntityEvent

Discussion in 'Plugin Development' started by Maulss, Jun 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Maulss

    I got this code where I want a certain task performed using the EntityDamageByEntityEvent event.

    Apparently nothing happens when I try to perform it. The plugin loads fine on startup and has no errors at all.
    Here is the code:
    Code:
    public class CriticalSlimeHitListener implements Listener {
      public CriticalSlimeHitListener(Smash instance)
      {
          Bukkit.getServer().getPluginManager().registerEvents(this, instance);
          }
          @EventHandler
          public void damage(EntityDamageByEntityEvent event) {
              if (!(event.getEntity() instanceof Player)) {
                  return;
              }
     
              Player target = (Player) event.getEntity();
              if ((event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK) && event.getDamager() instanceof Player)) {
                  Player attacker = (Player) event.getDamager();
                  if (attacker.getItemInHand().getType().equals(Material.SLIME_BALL)) {
                      if (attacker.getItemInHand().containsEnchantment(Enchantment.KNOCKBACK)) {
                          if (attacker.getPlayer().hasPermission("er.abilities")) {
               
                              Random rand = new Random();
                              int r = rand.nextInt(10) + 1;
                              if(r == 5) {
                                  target.damage(8);
                                  attacker.sendMessage(ChatColor.YELLOW + "You dealt " + ChatColor.GOLD + "4 hearts " + ChatColor.YELLOW + "to " + ChatColor.GOLD + target.getName());
                                  target.sendMessage(ChatColor.YELLOW + "You lost " + ChatColor.GOLD + "4 hearts" + ChatColor.YELLOW + " from " + ChatColor.GOLD + attacker.getName() + "'s " + ChatColor.YELLOW + "Critical Hit.");
     
  2. Offline

    Jnorr44

    Is this it? You do have closing brackets right?
    And are you ever calling "new CriticalSlimeHitListener(smash)"?
    And if it's loading fine at startup with no errors, it may not even be loading... does it say it is loading?
     
  3. Offline

    Maulss

    Yes, the plugin functions other than this part. And yes, I've got my closing brackets too.

    Here is the entire class:
    Code:
    *package*
     
    *imports*
     
    public class CriticalSlimeHitListener implements Listener {
      public CriticalSlimeHitListener(Smash instance)
      {
          Bukkit.getServer().getPluginManager().registerEvents(this, instance);
          }
          @EventHandler
          public void damage(EntityDamageByEntityEvent event) {
              if (!(event.getEntity() instanceof Player)) {
                  return;
              }
     
              Player target = (Player) event.getEntity();
              if ((event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK) && event.getDamager() instanceof Player)) {
                  Player attacker = (Player) event.getDamager();
                  if (attacker.getItemInHand().getType().equals(Material.SLIME_BALL)) {
                      if (attacker.getItemInHand().containsEnchantment(Enchantment.KNOCKBACK)) {
                          if (attacker.getPlayer().hasPermission("er.abilities")) {
               
                              Random rand = new Random();
                              int r = rand.nextInt(10) + 1;
                              if(r == 5) {
                                  target.damage(8);
                                  attacker.sendMessage(ChatColor.YELLOW + "You dealt " + ChatColor.GOLD + "4 hearts " + ChatColor.YELLOW + "to " + ChatColor.GOLD + target.getName());
                                  target.sendMessage(ChatColor.YELLOW + "You lost " + ChatColor.GOLD + "4 hearts" + ChatColor.YELLOW + " from " + ChatColor.GOLD + attacker.getName() + "'s " + ChatColor.YELLOW + "Critical Hit.");
                              }
                          }
                      }
                  }
              }
          }
    }
    And in my main class, in the onEnable, I register this:
    Code:
        new CriticalMagmaCubeHitListener(this);
    This usually works for me, I'm quite sure it's something tiny I've done that stopped it from working.
     
  4. Offline

    Jnorr44

    This is the CriticalSlimeHitListener through, not the CriticalMagmaCubeHitListener.
     
  5. Offline

    Maulss

    Oh right, sorry. I got multiple of those and I pasted the wrong one.
    new CriticalSlimeHitListener(this);
    That's the real one.

    Never mind, I just realized I had another class interfering with this one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page