I'm stuck on creating a small config file. What I want is, when someone types /blabla create <name> it adds the name of what they typed to a config file. Now if someone types it again and they enter the same name it will cancel it and say "this name already exists". Anyone know where I've gone wrong? Code: Code:java } else if (args.length == 2) { String name = args[1]; if (getConfig().getBoolean("Enable")) { if (getConfig().getString("Names").contains(name)) { Bukkit.getServer().broadcastMessage(Strings.prefix() + ChatColor.GREEN + p.getName() + ChatColor.GRAY + " has created: " + ChatColor.YELLOW + name+ ChatColor.GRAY + "."); getConfig().set(clanname, clanname); getConfig().set("Members", getConfig().getBoolean("Names")); saveConfig(); p.playSound(p.getLocation(), Sound.NOTE_BASS, 1.0F, 1.0F); } else { p.sendMessage(Strings.prefix() + "This Name already exists."); } } } Config setup: Code:java FileConfiguration config = getConfig(); config.addDefault("Names", "List:"); config.addDefault("Enable", true); getConfig().options().copyDefaults(true); saveConfig();
What happens? Because by looking at it 2 minutes after waking up I see you do a check like this: if 'names' contains name entered: create stuff else (if the name is not present): send message saying the name already exists
Konkz My bad, it just be the other way around. If name entered is in the config then cancel it, else, continue the creation. The error is, it keeps creating the name and not cancelling it. so i would type /blabla create test then I would type it again and it would still work.
messageofdeath that doesn't really help. Nevermind, figured it out! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Coopah With my library for yaml files this is how it would look somewhat. http://pastebin.com/6KqG7Kwy