Uploaded image for project: 'SpigotPlugins'
  1. SpigotPlugins
  2. PLUG-385

Wierd error appearing only for events file.

XMLWordPrintable

    •  CraftBukkit version git-Spigot-21fe707-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    • Custom plugin
    • Yes

      I am coding a plugin that checks if someone is invincible or not, then cancels a hit event if they are. It is giving a NPE error.

      Here is the error:

      9:07:56 PM [WARN] java.lang.NullPointerException
      9:07:56 PM [WARN] at me.name.MyPlugin.Events.Events.onHitInSpawn(Events.java:24)
      9:07:56 PM [WARN] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      9:07:57 PM [WARN] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      9:07:57 PM [WARN] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      9:07:57 PM [WARN] at java.lang.reflect.Method.invoke(Method.java:498)
      9:07:57 PM [WARN] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
      9:07:57 PM [WARN] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
      9:07:57 PM [WARN] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
      9:07:57 PM [WARN] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
      9:07:57 PM [WARN] at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:87)
      9:07:57 PM [WARN] at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:553)
      9:07:57 PM [WARN] at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:466)
      9:07:57 PM [WARN] at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:585)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityLiving.d(EntityLiving.java:1102)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityHuman.d(EntityHuman.java:859)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityLiving.damageEntity(EntityLiving.java:743)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityHuman.damageEntity(EntityHuman.java:800)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityPlayer.damageEntity(EntityPlayer.java:496)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityHuman.attack(EntityHuman.java:1001)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.EntityPlayer.attack(EntityPlayer.java:1063)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1355)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:52)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.a(SourceFile:11)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
      9:07:57 PM [WARN] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      9:07:57 PM [WARN] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
      9:07:57 PM [WARN] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
      9:07:57 PM [WARN] at java.lang.Thread.run(Thread.java:748)
      

      Events class:

      public class Events implements Listener {
      	DesertMain main = DesertMain.getInstance;
      	
      	@EventHandler
      	public void onHitInSpawn(EntityDamageByEntityEvent event) {
      		try {
      			if(event.getEntity().getLocation().getY() > 1) {
      				if(event.getEntity() instanceof Player) {
      					
      					UUID uuid = event.getEntity().getUniqueId();
      		
      			
          if(main.getConfig().getBoolean("players." + event.getEntity().getUniqueId() + ".invincible") == true /* <- line with error*/) {
          	        			
                          //event.setCancelled(true); <- what i want to do.
      						
      	        		}
      				}
      			
      		}
      		} catch(Exception e) {
      			e.printStackTrace();
      		}
      		
      	}
      }
      

      Config.yml:

      players:
        a082eaf8-2e8d-4b23-a041-a33ba8d25d5d:
          invincible: true
        6d496747-a53f-4011-8557-708f2cb9eda5:
          invincible: true
      

      This is my commnds class, and the wierdest thing is that is accesses the same part of the config file using the same method, however it does not return an error while doing it. Only the events class does, but it is doing the same thing to get to it. Here it is:

      DesertMain main = DesertMain.getInstance;
      if(command.getName().equalsIgnoreCase("invincible")) {
                                       if(main.getConfig().getBoolean("players." +             p.getUniqueId() + ".invincible") == false) {
              			p.sendMessage(ChatColor.GREEN + "Made you invincible!");
              			main.getConfig().set("players." + p.getUniqueId() + ".invincible", true);
              			main.saveConfig();
              		} else {
              			main.getConfig().set("players." + p.getUniqueId() + ".invincible", false);
              			p.sendMessage(ChatColor.RED + "Turned off your invincibilty!");
              			main.saveConfig();
              		}
                  }
      

      Here is my main class which handles  the getInstance thing:

      public static DesertMain getInstance;
      	
      	public void onEnable() {
      		Bukkit.getPluginManager().registerEvents(new Events(), this);
      		getInstance = this;
      		getCommand("speed").setExecutor(new Commands());
      		getCommand("invincible").setExecutor(new Commands());
      		loadConfig();
      	}
      

       

            Unassigned Unassigned
            1_iq Zachary Cohen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: