some code help please

Discussion in 'Spigot Plugin Development' started by liwaa, Jun 27, 2015.

  1. i am making a plugin for my server, but 2 commands wont work, and there are no errors
    code:
    Code (Text):
    package me.liwaa.mm;


    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;

    public class commands extends JavaPlugin{
        @Override
        public void onEnable(){
            getConfig().options().copyDefaults(true);
            saveConfig();
            getLogger().info("Plugin mm enabled");
            new PlayerListener(this);
        }
     
        @Override  
        public void onDisable() {
         
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args){
      //this command works
                if (cmd.getName().equalsIgnoreCase("mmp")){
                String p4p = getConfig().getString("permission to view permissions");
                if (sender.hasPermission(p4p)){
                String pex2 = getConfig().getString("Permission so that players cant enter the server");
                String pex3 = getConfig().getString("mm perm");
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3MaintainceMode&c=-=-=-=-=-=-=-="));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3Permissions&c=-=-=-=-=-=-=-="));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6permission so players cant enter the server: &f" + pex2 ));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6permission to view permissions: &f" + p4p));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6permission to do /mm: &f" + pex3));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3Permissions&c=-=-=-=-=-=-=-="));
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3MaintainceMode&c=-=-=-=-=-=-=-="));
    //this does not work
                }if (cmd.getName().equalsIgnoreCase("mm")){
                    String pex3 = getConfig().getString("mm perm");
                    if (sender.hasPermission(pex3)){
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3MaintainceMode&c=-=-=-=-=-=-=-="));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3Help&c=-=-=-=-=-=-=-="));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4MM&8] &b/mm help for MaintainceMode"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4MM&8] &b/mmp permissions for MaintainceMode"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4MM&8] &b/mme do your job, gives the players the permission so they cant enter the server"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3Help&c=-=-=-=-=-=-=-="));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c=-=-=-=-=-=-=-=&3MaintainceMode&c=-=-=-=-=-=-=-="));
                    }
    //this does not work, please help me
                    }else if(cmd.getName().equalsIgnoreCase("mme")){
                    String mme = getConfig().getString("command on mme");
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), mme);
                    sender.sendMessage("success");
                    return true;
                }
             
            }
             
         
     
            return false;
     
    }

    }
     
     
  2. Fix up your tab formatting and you will see that all three commands are nested inside the first if statement. It means that the 2nd and 3rd if statements will never be true because the command cant be mmp AND mm at the same time.
     
  3. Creeoer

    Supporter

    Also, I don't think creating a new instance of your player listener registers it..
     
  4. Unless he is registering it as a listener from within the constructor in the listener class.
     
  5. i really wanna do that but i don't know how to make the command as: mm enable
    two words if you can help please do :)
     
  6. in the Listener thing i got the join event
     
  7. All you have to do is move one of the } from just above return false; and put it before the if statement that checks for the command "mm".
    If you use the standard java conventions for indentations in your code it will be much easier to read and you will be much less likely to make mistakes.
     
  8. You need to use arguments. if(args[0].equals("enable")) for example
     
  9. you need to register the command by getcommand("name").setexecutor(this); in the onenable and check your if statements i think you have if(bla){
    if(nextcommand){}
    if(nextcommand){}
    }
     
  10. Creeoer

    Supporter

    You don't register commands if its in the same class as main
     
  11. and btw forgot to mention you need to implements CommandExecutor atfer the extends JavaPlugin
     
  12. and btw Creeper your right thought it was in a seperate class sry :d
     
  13. Error! Put " " in player.hasPermission("test.plugin")

    if (sender.hasPermission(pex3)){
    if (sender.hasPermission("pex.3")){