NullPointerException when using PlayerMoveEvent

Discussion in 'Spigot Discussion' started by Giorno420, Aug 11, 2021.

  1. So I was messing around with the Spigot API, and I kept getting this error:

    Could not pass event PlayerMoveEvent to TestingFeatures v1.0
    java.lang.NullPointerException: null
    at com.giornosmp.testingfeatures.Experience.ToolsRequireExperience.ToolsRequireExperience(ToolsRequireExperience.java:80) ~[?:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor47.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.16.5.jar:git-Paper-785]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.16.5.jar:git-Paper-785]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.16.5.jar:git-Paper-785]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:624) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1424) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.PacketPlayInFlying.a(SourceFile:122) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:56) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$ensureMainThread$1(PlayerConnectionUtils.java:35) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1266) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1259) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1220) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1134) ~[patched_1.16.5.jar:git-Paper-785]
    at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-785]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]

    The following is the statement which caused this error to happen
    if (player.getEquipment().getChestplate().equals(new ItemStack(Material.DIAMOND_CHESTPLATE))){

    if (player.getLevel() < 7){
    ExperienceManager.diamondArmor(player);
    }
    }


    Can someone tell me what I did wrong?

    My IDE doesn't throw any errors, and the code works fine as well, it just spams the console on every player move event
     
  2. Hi. Try this:
    Code (Text):
    if(player.getEquipment().getChestplate() != null && player.getEquipment().getChestplate() == Material.DIAMOND_CHESTPLATE) {

    if(player.getLevel() < 7 {
    ExperienceManager.diamondArmor(player);
    }
    }
     
  3. Or you can also use:


    Code (Text):
    if(player.getEquipment().getChesplate() == null) return;

    if(player.getEquipment().getChestplate() == Material.DIAMOND_CHESTPLATE) {

    if(player.getLevel() < 7 {
    ExperienceManager.diamondArmor(player);
    }
    }
     
  4. nevermind im stupid, and @_Neko1 thank you for the solution I originally used that
     
  5. I think so, bye!
     
  6. Your equipment was null, check it before, see you next time ,)