Loction gets removed from config?

Discussion in 'Spigot Plugin Development' started by Griffdragon, Jul 13, 2018.

  1. Hell so im making a sort of warp plugin. When you do /setland it saves the location to the config. And then you can do /warpland and it takes you there just fine. But for some reason whenever the server restarts. The location part gets removed from the config? why is this?
    Setland:
    Code (Text):
    if (cmd.getName().equalsIgnoreCase("setland") && sender instanceof Player) {
                Player p = (Player) sender;
                if (args.length == 1) {
                    String land = String.valueOf(args[0]);
                    Location loc = new Location(p.getLocation().getWorld(), (int) p.getLocation().getX() - .5,
                            (int) p.getLocation().getY(), (int) p.getLocation().getZ() - .5);
                    p.teleport(loc);
                    if (land.equals("Forest") || land.equals("Desert") || land.equals("Tundra") || land.equals("Jungle")
                            || land.equals("Mountain")) {
                        config.set("LandConfig." + land + ".Location", p.getLocation());
                        config.set("LandConfig." + land + ".Owner", "none");
                        Location locs = (Location) config.get("LandConfig." + land + ".Location");
                        Block beacon = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1, (int) locs.getY() - 2, (int) locs.getZ() - 1);
                        Block glass = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1, (int) locs.getY() - 1, (int) locs.getZ() - 1);

                        Block iron1 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1, (int) locs.getY() - 3, (int) locs.getZ() + 1 - 1);
                        Block iron2 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() + 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() + 1 - 1);
                        Block iron3 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() + 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1);
                        Block iron4 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1 - 1);
                        Block iron5 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1);
                        Block iron6 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1 - 1);
                        Block iron7 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() + 1 - 1);
                        Block iron8 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() + 1 - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1 - 1);
                        Block iron9 = ((Location) config.get("LandConfig." + land + ".Location")).getWorld()
                                .getBlockAt((int) locs.getX() - 1, (int) locs.getY() - 3, (int) locs.getZ() - 1);

                        beacon.setType(Material.BEACON);
                        glass.setType(Material.GLASS);
                        iron1.setType(Material.IRON_BLOCK);
                        iron2.setType(Material.IRON_BLOCK);
                        iron3.setType(Material.IRON_BLOCK);
                        iron4.setType(Material.IRON_BLOCK);
                        iron5.setType(Material.IRON_BLOCK);
                        iron6.setType(Material.IRON_BLOCK);
                        iron7.setType(Material.IRON_BLOCK);
                        iron8.setType(Material.IRON_BLOCK);
                        iron9.setType(Material.IRON_BLOCK);
                        saveConfig();
                        p.sendMessage(ChatColor.GREEN + "Successfully set location for " + land + "!");
                    } else {
                        p.sendMessage(ChatColor.RED + "Please use, Forest, Mountain, Tundra, Jungle, or Desert.");
                    }
                }
            }
    Warpland:
    Code (Text):
    if (cmd.getName().equalsIgnoreCase("warpland") && sender instanceof Player) {
                Player p = (Player) sender;
                if (args.length == 1) {
                    String land = String.valueOf(args[0]);
                    if (land.equals("Forest") || land.equals("Desert") || land.equals("Tundra") || land.equals("Jungle")
                            || land.equals("Mountain")) {
                        if (config != null) {
                            if (getRace(p).equalsIgnoreCase(config.getString("LandConfig." + land + ".Owner"))) {
                                Location loc = (Location) config.get("LandConfig." + land + ".Location");
                                p.teleport(loc);
                                p.sendMessage(ChatColor.GREEN + "Warping to " + land + "...");
                            } else {
                                p.sendMessage(ChatColor.RED + "Your race does not control this land!");
                            }
                        }
                    } else {
                        p.sendMessage(ChatColor.RED + "Please use, Forest, Mountain, Tundra, Jungle, or Desert.");
                    }
                }
    Code (Text):
    private ConfigManager cfgm;

        public Inventory i;

        FileConfiguration config = this.getConfig();

        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);

            loadConfig();
            loadConfigmanager();

        }

        public void onDisable() {

        }

        public void loadConfigmanager() {
            cfgm = new ConfigManager();
            cfgm.setup();

        }

        public void loadConfig() {
            getConfig().options().copyDefaults(false);
            saveConfig();
        }
     
     
  2. your re-copying the default config that in your plugin. you should check if it there config file, if not then save it.
     
    • Winner Winner x 1
  3. In the on enable? Or in the command?
     
  4. on enable, the method call loadConfig()
     
  5. how do i check this? if (!(config ==null)){}?
     
  6. Ive completely made it so it doesnt copy defaults and it still deletes on restsart
     
  7. then it must be in your ConfigManager(). so far that class was inspiration from a youtuber.
     
  8. JanTuck

    Supporter

    Have you tried just to do saveDefaultConfig()?
     
    • Like Like x 1
  9. the config manager was inspiration but im not saving the config under the config manager the other files are though
     
  10. Hmm i tried saveDefaultConfig() and now it saves to the config when i restart, but then it acts like it doesnt when i try warpland.
    Code (Text):
    [06:06:11 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'warpland' in plugin BaronRaces v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1354) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1189) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.base/java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer.teleport(CraftPlayer.java:497) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity.teleport(CraftEntity.java:260) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at me.griffdragon.races.Main.onCommand(Main.java:119) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            ... 15 more
     
  11. line 119
    Code (Text):
    p.teleport(loc);
     
  12. this also happens when the server starts up, im not sure if it has to do with my plugin though
    Code (Text):
    [06:15:22 ERROR]: Could not call method 'public static org.bukkit.Location org.bukkit.Location.deserialize(java.util.Map)' of class org.bukkit.Location for deserialization
    java.lang.IllegalArgumentException: unknown world
            at org.bukkit.Location.deserialize(Location.java:595) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:77) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:117) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:195) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:35) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:147) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:354) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:489) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:147) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:354) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:489) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:147) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:354) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:489) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:369) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:184) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:130) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:179) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:167) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:142) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at me.griffdragon.races.Main.<init>(Main.java:26) [BaronRaces.jar:?]
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [?:?]
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [?:?]
            at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [?:?]
            at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source) [?:?]
            at java.base/java.lang.Class.newInstance(Unknown Source) [?:?]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:301) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.base/java.lang.Thread.run(Unknown Source) [?:?]