Help with config and commands

Discussion in 'Plugin Development' started by matcracker, Nov 30, 2015.

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

    matcracker

    Hello developers! I'm doing a plugin that from a config file take some commands and execute other but it doesn't work :(
    For example, if one player do the command "/warp warpname" the must send at player the command "/fly off".
    This is the config:
    Code:
    #Config plugin
    #Commands that the player run
    commands:
        - warp warpname
    #Commands that the plugin send to do at player
    commandtoexecute:
        - fly off
    The code:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ){
            String ncmd = cmd.getName().toLowerCase();
            List<String> commands = this.getConfig().getStringList("commands");
            List<String> commandstoexecute = this.getConfig().getStringList("commandstoexecute");
                   
            if(sender instanceof Player){
               if(ncmd == commands){
                    for(String s : commandstoexecute)
                           this.getServer().dispatchCommand(sender, s);
                   
                    return true;
               
                switch(ncmd){
                    case "commandblockerexecutor":
                        if(args[0].equalsIgnoreCase("reload") && (sender.isOp() == true)){
                            this.saveDefaultConfig();
                            this.reloadConfig();
                            sender.sendMessage("§a[" + getName() + "] Configuration reloaded!"); 
                        }
                        return true;
                }
            }
           
            return false;
        }
    So, I do a small resume for the code, if ncmd (command of player sent) = commands (one or more commands in config) then for each string "s" in commandstoexecute it send a commands (one or more commands of section "commandstoexecute").

    Thanks for you help! :D
     
  2. Offline

    Zombie_Striker

    How does it "not work"? How do you know it doesn't work? Did you debug? What did you do to try to fix the problem?

    [Edit]
    So you're checking if a single string is equal to an entire array of strings.
     
  3. Offline

    matcracker

    Yes, I test it but when I send the exactly command of "commands config" the command of fly doesn't work...
     
  4. Offline

    Mrs. bwfctower

    What doesn't work about it? How is it broken?
     
  5. Offline

    matcracker

    I don't know how to do, I try to set commands like a String so:
    Code:
    #Config plugin
    commands: warp warpname
    commandtoexecute:
          - fly off
    Code:
    String commands = this.getConfig().getString("commands");
    but don't work anyway :(
     
  6. Offline

    Zombie_Striker

    @matcracker
    Did you null check commands? Are you sure the config is correct/working?
     
Thread Status:
Not open for further replies.

Share This Page