Deleting Info from a YamlConfiguration help!

Discussion in 'Plugin Development' started by x_Jake_s, Apr 13, 2015.

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

    x_Jake_s

    so for some time now i have vigorously been working on a oitq plugin and its all working except for the deleting of arenas, so here is the command that deletes the arena:

    Code(CommandExecutor) (open)

    Code:
    if (args[0].equalsIgnoreCase("delete")) {
                    if (player.hasPermission("oitq.delete")) {
                        if (args.length < 2) {
                            player.sendMessage(prefix + "Usage: /oitq delete [arenaName]");
                        } else
                            if (ArenaStorage.arenaExists(args[1])) {
                                Main.arenas.getDefaults().set("Arenas." + args[1], null);
                                Main.arenas.getDefaults().set("Arenas." + args[1] + ".Signs.Counter", null);
                                this.plugin.getConfig().getDefaults().set(args[1] + ".Countdown", null);
                                this.plugin.getConfig().getDefaults().set(args[1] + ".MaxPlayers", null);
                                this.plugin.getConfig().getDefaults().set(args[1] + ".KillsToWin", null);
                                this.plugin.getConfig().getDefaults().set(args[1] + ".AutoStartPlayers", null);
                                this.plugin.getConfig().getDefaults().set(args[1] + ".EndTime", null);
                                ArenaProcess arena = new ArenaProcess(args[1]);
                                ArenaStorage.deleteArena(arena);
                                Utils.removeFromList(arena);
                                player.sendMessage(prefix + "You have deleted the Arena " + ChatColor.GOLD + arena.getName());
                                Utils.saveYamls();
                                this.plugin.saveConfig();
                            } else {
                        player.sendMessage(prefix + "That Arena doesn't Exist!");
                    }
                } else {
                    player.sendMessage(np);
                }
                }

    However this isnt removing the arenas!
    Here is my onEnable();
    if you need any other information please tell me, dont spoon feed me code either unless there is no other way to get the idea to me please.

    onEnable() (open)

    Code:
        public static File playersFile;
        public static FileConfiguration players;
        public static File arenasFile;
        public static FileConfiguration arenas;
     
        @Override
        public void onEnable() {
            //Enable
            this.getServer().getConsoleSender().sendMessage(prefix + "Enabled.");
            //Commands
            getCommand("oitq").setExecutor(new Executor(this));
            //Files
            Main.playersFile = new File(getDataFolder(), "players.yml");
            Main.arenasFile = new File(getDataFolder(), "arenas.yml");
            Main.arenas = new YamlConfiguration();
            Main.players = new YamlConfiguration();
            //Config setups
            Main.arenas.options().copyDefaults(true);
            Main.players.options().copyDefaults(true);
            this.getConfig().options().copyDefaults(true);
            this.saveDefaultConfig();
            getServer().getPluginManager().registerEvents(this.gl, this);
            getServer().getPluginManager().registerEvents(this.sl, this);
            try
            {
              for (String s : Main.arenas.getStringList("Arenas.List"))
              {
                ArenaProcess arena = new ArenaProcess(s);
                ArenaStorage.addArena(arena);
                arena.updateSigns();
              }
            }
            catch (Exception e)
            {
              this.logger.severe("[OITQ] Failed to load arenas!");
            }
            try
            {
              this.m.firstRun();
            }
            catch (Exception localException1) {}
            Utils.loadYamls();
        }
        @Override
        public void onDisable() {
            this.getServer().getConsoleSender().sendMessage(prefix + "Disabled.");
        }
     
    }

    Any help would be greatly appreciated!
     
    Last edited: Apr 14, 2015
  2. You're setting the defaults to null... Set the config keys to null, i.e. Remove all the usages of getDefaults(). E.g.
    Code:
    Main.arenas.set("Arenas." + args[1], null);
     
  3. Offline

    nverdier

    @x_Jake_s Well a nice start would be to stop abusing statics.
     
  4. Offline

    x_Jake_s

    so like this im asuming.
    Code:
    if (args[0].equalsIgnoreCase("delete")) {
                    if (player.hasPermission("oitq.delete")) {
                        if (args.length < 2) {
                            player.sendMessage(prefix + "Usage: /oitq delete [arenaName]");
                        } else
                            if (ArenaStorage.arenaExists(args[1])) {
                                Main.arenas.set("Arenas." + args[1], null);
                                ArenaProcess arena = new ArenaProcess(args[1]);
                                ArenaStorage.deleteArena(arena);
                                Utils.removeFromList(arena);
                                player.sendMessage(prefix + "You have deleted the Arena " + ChatColor.GOLD + arena.getName());
                                Utils.saveYamls();
                                this.plugin.saveConfig();
                            } else {
                        player.sendMessage(prefix + "That Arena doesn't Exist!");
                    }
                } else {
                    player.sendMessage(np);
                }
                }
    
    When i use this code, it sends the delete message but nothing happens to the actual arena inside my config files.
     
    Last edited: Apr 13, 2015
  5. Offline

    x_Jake_s

    Still need help please <Bump>
     
  6. If the arena is also in your config.yml, you've gotta do: this.plugin.getConfig().set("Arenas." + args[1], null);

    Does Utils.saveYamls(); actually save Main.arenas config? That looks like yours should work.

    Wait a second... Don't tell me "arenas" config is the exact same file as the plugin's config file?
     
Thread Status:
Not open for further replies.

Share This Page