Solved Configuration

Discussion in 'Plugin Development' started by Coopah, Jul 30, 2014.

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

    Coopah

    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
    1. } else if (args.length == 2) {
    2. String name = args[1];
    3. if (getConfig().getBoolean("Enable")) {
    4. if (getConfig().getString("Names").contains(name)) {
    5. Bukkit.getServer().broadcastMessage(Strings.prefix() + ChatColor.GREEN + p.getName() + ChatColor.GRAY + " has created: " + ChatColor.YELLOW + name+ ChatColor.GRAY + ".");
    6. getConfig().set(clanname, clanname);
    7. getConfig().set("Members", getConfig().getBoolean("Names"));
    8. saveConfig();
    9. p.playSound(p.getLocation(), Sound.NOTE_BASS, 1.0F, 1.0F);
    10. } else {
    11. p.sendMessage(Strings.prefix() + "This Name already exists.");
    12. }
    13. }
    14. }

    Config setup:
    Code:java
    1. FileConfiguration config = getConfig();
    2. config.addDefault("Names", "List:");
    3. config.addDefault("Enable", true);
    4. getConfig().options().copyDefaults(true);
    5. saveConfig();
     
  2. Offline

    Konkz

    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
     
  3. Offline

    Coopah

    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.
     
  4. Offline

    messageofdeath

  5. Offline

    Coopah

    messageofdeath
    that doesn't really help.

    Nevermind, figured it out! :D

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

    messageofdeath

Thread Status:
Not open for further replies.

Share This Page