saving location....

Discussion in 'Plugin Development' started by stamline, Dec 18, 2015.

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

    stamline

    Hi, im making a mingame plugin and want to save many locations to the Config file. So i made a method so i can type the path where i should save the location. this method is in a seperated class.

    This i my code.
    Code:
    public class MPCommand implements CommandExecutor {
        public Locations loc;
        public Messages mes;
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if(args[0].equalsIgnoreCase("setloc")){
                if(sender instanceof Player){
                    Player player = (Player) sender;
                    if(args.length == 3){
                        if(McParty.plugin.games.contains(args[1].toLowerCase())){
                            if(args[2].equalsIgnoreCase("spawn")){
                                String path = args[1].toLowerCase() + ".loc";
                                loc.setLocation(player.getLocation(), path);
                                player.sendMessage("You have set spawn location for " + mes.stringupper(args[1].toLowerCase()));
                            }else if(args[2].equalsIgnoreCase("spec")){
                                String path = args[1].toLowerCase() + ".spec";
                                loc.setLocation(player.getLocation(), path);
                                player.sendMessage("You have set spec location for " + mes.stringupper(args[1].toLowerCase()));
                            }
                        }
                    }
                }
            }
            return false;
        }
    
    }
    
    So this command is also in a seperated method from the main class. But the command works, that have i tested, Its jut when i call the method who saves the location when it crash.

    This is the Location class:

    Code:
    public class Locations {
        public void setLocation(Location loc, String path){
            McParty.plugin.getConfig().set(path + ".world", loc.getWorld().toString());
            McParty.plugin.getConfig().set(path + ".x", loc.getX());
            McParty.plugin.getConfig().set(path + ".y", loc.getY());
            McParty.plugin.getConfig().set(path + ".z", loc.getZ());
            McParty.plugin.saveConfig();
        }
    }
    Mcparty is my Main class...

    This is the error:

    HTML:
    [14:50:52] [Server thread/INFO]: Babbssan99 issued server command: /mp setloc chickenkiller spawn
    [14:50:52] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'mp' in plugin McParty v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:714) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
        at me.stamline.mcparty.commands.MPCommand.onCommand(MPCommand.java:24) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
        ... 15 more
    chickenkiller is in the List, just so you know, i have tested also tested that.
     
  2. Offline

    mcdorli

    Caused by: java.lang.NullPointerException
    at me.stamline.mcparty.commands.MPCommand.onCommand(MPCommand.java:24) ~[?:?]
    What's line 24?
     
  3. Offline

    mine-care

    How do you know that the command has arguments?
    Dont abuse that poor static!

    Now back to the error, You may read THIS and resolve it yourself :p
     
  4. Offline

    mcdorli

    And you don't need an instance inside your class, if you're using static.
    And NEVER. EVER. have a static instance of the class, what if something tries to use that instance before the class is even created?
     
  5. Offline

    mine-care

    Well... For singleton objects a static instance is fine as long as it is encapsulated properly...
     
  6. Offline

    iAmGuus

    @mine-care & @mcdorli , you guys are great for all the support, but for example @stamline should first read through the stickies of the Plugin Development forums. There is a thread made about common mistakes, about reading stack-traces. And if he hasn't done this, use your best friend (Google).
     
    mine-care likes this.
  7. Offline

    mine-care

    @iAmGuus Indeed, you are right. Unfortunately none seems to be doing it nowadays, and because i myself dislike reading (Various reasons), i prefer getting straight to the point instead of throwing a massive post to be read. Hopefully this way they will put their minds down and think what can be done to change this (Thus i dont spoonfeed)

    Also about google, it is bizare that none does a 10 second search, but they prefer to spend endless hours on the forums waiting for an answer that sparks a discussion taking hours/days or even weeks to be settled...
     
  8. Offline

    iAmGuus

    @mine-care, exactly. This is the exact reason why I am not giving an answer to most of the topics posted on Bukkit Forums. It is like we are on the forums 24/7 to give an instant response to their questions...
     
Thread Status:
Not open for further replies.

Share This Page