Change config variable via a command?

Discussion in 'Plugin Development' started by PolarCraft, May 11, 2014.

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

    PolarCraft

    Okay so i am trying to change a config variable via a command.
    My problem is when i execute /prefix &2[&5Hi&2] it does not change the config.yml variable prefix.

    Command:
    Code:java
    1. } else if(cmd.getName().equalsIgnoreCase("prefix")) {
    2. if (sender instanceof Player) {
    3. if(sender.hasPermission("cb.prefix")) {
    4. if (args.length == 0) {
    5. sender.sendMessage("/prefix <prefix>");
    6. } else {
    7. StringBuilder sb1 = new StringBuilder();
    8. for (int f = 0; f < args.length; f++){
    9. sb1.append(args[f]).append(" ");
    10. }
    11. String allArgs2 = sb1.toString().trim();
    12. plugin.getConfig().set("prefix", allArgs2);
    13. plugin.saveConfig();
    14. sender.sendMessage("Prefix changed to: "+ ChatColor.translateAlternateColorCodes('&', allArgs2));
    15. }
    16. }
    17. }
    18. }


    Main:
    Code:java
    1. public void onEnable(){
    2. getCommand("prefix").setExecutor(new BroadcastCommand(this));
    3. this.getConfig().options().copyDefaults(true);
    4. }
    5.  


    Plugin.yml:
    Code:java
    1. name: CustomBroadcast
    2. main: net.jc.minecraft.Main
    3. version: 5.11.2014
    4. commands:
    5. broadcast:
    6. description: This will allow you to broadcast messages with a custom prefix!
    7. prefix:
    8. description: This will allow you to change you're prefix!


    Config.yml:
    Code:java
    1. prefix: '&5[&bPolarcraft&5]'
     
  2. Offline

    thecrystalflame

    before getting further help, i suggest adding debug System.out.println()'s and making a seperate executer for prefix rather than using broadcasts' one.
     
Thread Status:
Not open for further replies.

Share This Page