NPE Error

Discussion in 'Plugin Development' started by Xp10d3, Feb 6, 2020.

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

    Xp10d3

    When I move, I get this error:
    Code:
    Could not pass event PlayerMoveEvent to RepalceCommandBlocks v1.0
    org.bukkit.event.EventException: null
            at us.Myles.PWP.TransparentListeners.PerWorldPluginLoader$1.execute(PerWorldPluginLoader.java:122) ~[?:?]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at us.Myles.PWP.TransparentListeners.PWPRegisteredListener.callEvent(PWPRegisteredListener.java:30) ~[?:?]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:529) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:514) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:998) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.PacketPlayInFlying.a(SourceFile:122) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:56) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.MinecraftServer.aZ(MinecraftServer.java:917) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:910) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeAll(SourceFile:103) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:893) [server.jar:git-Spigot-f39a89e-4633e6c]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:827) [server.jar:git-Spigot-f39a89e-4633e6c]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    
    I have PerWorldPlugins with the same plugin, but I doubt it has an issue with it.
    PlayerListeners.java:
    Code:
    package xp10d3.replace.corelia;
    import java.text.SimpleDateFormat;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import com.mysql.fabric.xmlrpc.base.Data;
    public class PlayerListeners implements Listener {
        private Core core;
      
        @EventHandler
        public void savePlayerLocation(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            core.getConfig().set(player.getUniqueId().toString() + ".lastlocation.x", player.getLocation().getX());
            core.getConfig().set(player.getUniqueId().toString() + ".lastlocation.y", player.getLocation().getY());
            core.getConfig().set(player.getUniqueId().toString() + ".lastlocation.z", player.getLocation().getZ());
            core.getConfig().set(player.getUniqueId().toString() + ".lastlocation.world", player.getLocation().getWorld().getName());
            core.saveConfig();
        }
      
        @EventHandler
        public void checkLocation(PlayerMoveEvent event) {
          
            Player player = event.getPlayer();
            int locationX = core.getConfig().getInt(player.getUniqueId().toString() + ".lastlocation.x");
            int locationY = core.getConfig().getInt(player.getUniqueId().toString() + ".lastlocation.y");
            int locationZ = core.getConfig().getInt(player.getUniqueId().toString() + ".lastlocation.z");
            String locationWorld = core.getConfig().getString(player.getUniqueId().toString() + ".lastlocation.world");
          
            ConfigurationSection command = core.getConfig().getConfigurationSection("command.commands");
            for (String key : command.getKeys(false)) {
                int x = core.getConfig().getInt("command.commands." + key + ".x");
                int y = core.getConfig().getInt("command.commands." + key + ".y");
                int z = core.getConfig().getInt("command.commands." + key + ".z");
                String world = core.getConfig().getString("command.commands." + key + ".world");
                if (x == locationX && y == locationY && z == locationZ && world == locationWorld) {
                    core.getServer().dispatchCommand(core.getServer().getConsoleSender(), key.replace("%player%", player.getName()));
                    Data now = new Data();
                    SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
                  
                    core.logFile("[" + format.format(now) + "]" + " Dispatched command " + "'" + key + "'" + " at X value " + locationX + " Y value " + locationY + " Z value " + locationZ + " in world " + locationWorld + ".");
                }
            }
        }
    }
    
    How do I fix this error?

    Config:
    Code:
    command:
      commands:
        effect give @p slowness 500 50:
          x: 50
          y: 75
          z: 3
          world: world
    
    I don't know the exact numbers for the x, y, and z values but this is pretty much it.
     
    Last edited: Feb 6, 2020
  2. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page