Set coordinates?

Discussion in 'Plugin Development' started by Fillefixsweden, Feb 13, 2015.

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

    Fillefixsweden

    Hey guys, my plugin DisconnectReset is about to update and one of the new features is that you can set reset position through a command, but, i get an error.

    I have no idea what i should do.

    New command code:
    Code:
    public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
            if(label.equalsIgnoreCase("dr")){
                if(args[0].equalsIgnoreCase("setspawn")){
                    Player p = (Player) sender;
                    if(p.hasPermission("dr.setspawn")){
                Location l = p.getLocation();
                double x = l.getX();
                double y = l.getY();
                double z = l.getZ();
                World w = l.getWorld();
                String ws = w.toString();
                String wse = ws.replace("CraftWorld{name=", "");
                String wst = wse.replace("}", "");
                this.getConfig().set(path + ".x", x);
                 this.getConfig().set(path + ".y", y);
                 this.getConfig().set(path + ".z", z);
                 this.getConfig().set("Spawn world", ws);
                 this.saveConfig();
    
                    p.sendMessage(ChatColor.GREEN + "New spawn set.");
    
                    }else{
                        p.sendMessage(ChatColor.RED + "Sorry, you ain't got permissions to do that.");
                      
                    }
                  
                }else{
                  
                  
                }
              
              
            }
    
          
          
          
            return false;
        }
    The code that reads the config:
    Code:
          @EventHandler
            public void onPlayerDisconnect(PlayerQuitEvent event) {
              Player p = event.getPlayer();
            if(!p.hasPermission("dr.bypass")) {
              PlayerInventory pi = p.getInventory();
              int x = this.getConfig().getInt(path + ".x");
              int y = this.getConfig().getInt(path + ".y");
              int z = this.getConfig().getInt(path + ".z");
              World w = Bukkit.getWorld(this.getConfig().getString("Spawn world"));
              Location loc = new Location(w, x, y, z);
              p.teleport(loc);
    
              pi.clear();
              pi.setHelmet(new ItemStack(Material.AIR));
              pi.setChestplate(new ItemStack(Material.AIR));
              pi.setLeggings(new ItemStack(Material.AIR));
              pi.setBoots(new ItemStack(Material.AIR));
        
            }
    The config:
    Code:
    Spawn coordinates:
      x: 456
      y: 115
      z: 443
    Spawn world: world
    

    The error:
    Code:
    [00:59:06 ERROR]: Could not pass event PlayerQuitEvent to DisconnectReset v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.PlayerList.disconnect(PlayerList.java:313) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:832) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.NetworkManager.l(NetworkManager.java:242) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:79) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:785) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-081dfa5-5e6c347]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlayer.java:464) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity.teleport(CraftEntity.java:223) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            at se.fillefixsweden.dr.DR.onPlayerDisconnect(DR.java:91) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            ... 12 more
    Please help!
    Thank you in advance!
     
  2. Offline

    Ruptur

    Code:
    Caused by: java.lang.NullPointerException
    Could not pass event PlayerQuitEvent to DisconnectReset v1.0
    org.bukkit.event.EventException
    
    Where is 'path' defined?
     
  3. Offline

    Fillefixsweden

    Path is a string defined in the beginning of the class,

    Code:
    public class DR extends JavaPlugin implements Listener{
        String path = "Spawn coordinates";
    @Ruptur

    *EDITED*

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  4. Offline

    Ruptur

    @Fillefixsweden
    Doubt anyone would go through your code to see what wrong but l can try to give it a go
    Have to tried to find the source of the problem - like disabling certain parts of the plugin till you get what the problem is?
     
  5. Offline

    Fillefixsweden

    @Ruptur

    Yes, i have tried debugging it but i could'nt get it working, that's why i posted it here.

    I think it's something about the world, it saves as CraftWorld etc. and then can't read it because of that. That's why i have tried to replace the surrounding with nothing.
     
  6. Offline

    a810587921

    The use of PlayerJoinEvent
     
  7. Offline

    Dudemister1999

    @Fillefixsweden Not a whole lot of people actually use the error to its fullest extent:

    Code:
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlayer.java:464) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity.teleport(CraftEntity.java:223) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
            [B]at se.fillefixsweden.dr.DR.onPlayerDisconnect(DR.java:91) ~[?:?][/B]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-081dfa5-5e6c347]
    Go find line 91 in your DR class. That is what is causing the error.
     
  8. Offline

    Fillefixsweden

    @Dudemister1999 Yes i'm fully aware of that, the problem is what in that line is causing the error.
     
Thread Status:
Not open for further replies.

Share This Page