How can i prevent ender crystal explosion?

Discussion in 'Plugin Development' started by spiroulis, Jan 29, 2015.

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

    spiroulis

    Hi, i know i made another post about this some weeks ago but i updated some stuff so i thought nvm...So i want to prevent the specific ender crystals i spawn from exploding. To only stop the crystals in my plugin from exploding i added a location comparation. The problem is that the event works perfectly and does stop the ender crystals from exploding...until i add my location comparation. I get an error at line 20 (which is my location comparation).
    CrystalEvent Class:
    Code:
    public class CrystalEvents implements Listener {
        private main main;
    
    
        @EventHandler
        public void damage(EntityDamageEvent event){
            Entity entity = event.getEntity();
            if(entity.getType().equals(EntityType.ENDER_CRYSTAL)){
                Bukkit.broadcastMessage("Qu");
               /*line 20*/ if(entity.getLocation().equals(new Location(entity.getWorld(), main.getConfig().getDouble("FirstCrystal.x"), main.getConfig().getDouble("FirstCrystal.y"), main.getConfig().getDouble("FirstCrystal.z")))){//line 20
                Bukkit.broadcastMessage("NOT TODAY");
                    event.setCancelled(true);
                }
            }
        }
    }
    And the error just in case i read it wrong:
    Code:
    Could not pass event EntityDamageByEntityEvent to McDungeonDefenders v0.6
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:108) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:533) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:446) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.handleNonLivingEntityDamageEvent(CraftEventFactory.java:563) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.EntityEnderCrystal.damageEntity(EntityEnderCrystal.java:63) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.EntityHuman.attack(EntityHuman.java:931) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.a(SourceFile:55) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.handle(SourceFile:10) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
    Caused by: java.lang.NullPointerException
        at me.spiroulis.MCDD.CrystalEvents.damage(CrystalEvents.java:20) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_67]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_67]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        ... 19 more
    
    Thanks in advance :)
     
  2. Offline

    16davidjm6

    best way to test what is giving you a NPE is to debug. Best way to debug is to print everything out:
    Code:
    System.out.println("Entity Location: "+ entity.getLocation());
    System.out.println("Entity World: " + entity.getWorld());
    System.out.println("Crystal x: " + main.getConfig().getDouble("FirstCrystal.x"));
    System.out.prinltn("Crystal y; " + main.getConfig().getDouble("FirstCrystal.y"));
    System.out.println("Crystal z: " + main.getConfig().getDouble("FirstCrystal.z"));
    Whichever of these prints out Null is your issue.
     
    spiroulis likes this.
  3. Offline

    spiroulis

    @16davidjm6 Thanks. I added this into my code but instead of printing out Null, it gave me this error at the line:
    Code:
    System.out.println("Crystal x: " + main.getConfig().getDouble("FirstCrystal.x"));
    Error:
    Code:
     Could not pass event EntityDamageByEntityEvent to McDungeonDefenders v0.6
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:108) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:533) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:446) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.handleNonLivingEntityDamageEvent(CraftEventFactory.java:563) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.EntityEnderCrystal.damageEntity(EntityEnderCrystal.java:63) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.EntityHuman.attack(EntityHuman.java:931) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.a(SourceFile:55) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInUseEntity.handle(SourceFile:10) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
    Caused by: java.lang.NullPointerException
        at me.spiroulis.MCDD.CrystalEvents.damage(CrystalEvents.java:21) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_67]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_67]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        ... 19 more
    
     
  4. Offline

    guitargun

    @spiroulisdid you initialize your main main in a constructor somewhere? Also it is better to start classes with a capital letter to avoid confusion with instance
     
  5. Offline

    teej107

  6. Offline

    spiroulis

    @guitargun woops forgot to initialize it in a constructor. Also i am starting classes names with capital letters except from main which i just noticed xd.
    Now although it did print stuff, nothing printed null
    Edit: @teej107 i have read that, i just posted the error in case i didnt get something. And by read i mean that the only thing i understood from that tutorial is how to read the line in which the error is located :3
     
  7. Offline

    guitargun

    @spiroulis sounds like it is fixed? I have this mistake also sometim. It is just a matter of backtracking for your code
     
  8. Offline

    spiroulis

    @guitargun nope the entity still dies/explodes.
     
  9. Offline

    Funergy

  10. Offline

    Konato_K

  11. Offline

    spiroulis

    @Funergy Whatever event im going to try, its going to stop working once i do that location comparation :)

    @Konato_K The on the initial code (that one on the post on on the replies) the Qu broadcast is being sent. That location comparation messes up things so everything below it, including the "NOT TODAY" Message arent being sent.
     
  12. Offline

    Konato_K

    @spiroulis Then the problem is your conditional, using equals in a location means everything must be equals

    Code:
    public boolean equals(Object obj)
    { if (obj == null) {
        return false;
      }
      if (getClass() != obj.getClass()) {
        return false;
      }
      Location other = (Location)obj;
      if ((world != other.world) && ((world == null) || (!world.equals(other.world)))) {
        return false;
      }
      if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) {
        return false;
      }
      if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) {
        return false;
      }
      if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z)) {
        return false;
      }
      if (Float.floatToIntBits(pitch) != Float.floatToIntBits(other.pitch)) {
        return false;
      }
      if (Float.floatToIntBits(yaw) != Float.floatToIntBits(other.yaw)) {
        return false;
      }
      return true;
    }
    So, if your yaml file says X is 56 but your entity is 56.5 then it wont wont, consider also yaw and pitch must be the same.

    I suggest comparing the x, y and z values manually with getBlockXYZ instead of using equals.
     
Thread Status:
Not open for further replies.

Share This Page