Help me with args

Discussion in 'Spigot Plugin Development' started by DimoKouli, May 14, 2015.

  1. I want to make 2 commands for my plugin that actually Enable the plugin and Disable the plugin but when i run the commands nothing happenes and the command itself appears in the chat




    public boolean OnCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(sender instanceof Player){

    if(cmd.getName().toLowerCase().equalsIgnoreCase("ttt")){
    if(args[0].length() == 1){
    if(args[0].toLowerCase().equalsIgnoreCase("Enable")){
    Bukkit.getServer().getPluginManager().enablePlugin(Main.p);

    }


    }

    }

    }
    return false;
    }
    public boolean OnCommand2(CommandSender sender, Command cmd, String label, String[] args){
    if(sender instanceof Player){
    if(cmd.getName().toLowerCase().equalsIgnoreCase("ttt")){
    if(args[0].length() == 1){
    if(args[0].toLowerCase().equalsIgnoreCase("Disable")){
    Bukkit.getServer().getPluginManager().disablePlugin(Main.p);
    }
    }
    }
    }
    return false;
     
  2. Please use the code syntax or
    Code (Text):
     at the start and
    at the end.

    You're basically checking, if argument 0's length is 1? There's no point.

    What you want to do is check if the args are the correct length or.

    if(args.length() == 1) {

    This will check if your argument length or "amount" is 1.
     
    #2 Bladian, May 14, 2015
    Last edited: May 14, 2015
  3. Oh if this what i think i am totally idiot :D Btw do i have to register the arguements in the plugin yml ?
     
  4. No you don't, only the command name itself
     
  5. i changed everything but i still getting with white letters the command in chat and no result :(
     
  6. @DimoKouli You need to have a "return true;" somewhere. Only then will you not get the white letters. Since you don't have it right now, it keeps proceeding to your "return false;" statement.
     
  7. Serializator

    Supporter

    Its quite pointless to have two commands to enable and disable the plugin, when you use the command to disable the plugin you won't be able to enable it again, so you also won't be able to disable it again.
     
  8. how can i do it so i can re enable it ?? its one command now with else if
     
  9. Serializator

    Supporter

    If you disable the plugin with a command all the other commands from the plugin will also be disabled and not able to be used, so its not even possible what you're trying to achieve.
     
  10. Inkzzz

    Resource Staff

    Unless he has another plugin which enables a certain plugin.
     
  11. Well i would actually prefer if i could only disable the PlayerListener class but is this possible ?
     
  12. @GODofCRAFTERS i changed the return statement to true and still getting the white letters in my chat,, :(
     
  13. Inkzzz

    Resource Staff

    You can cancel events, but calling them, then cancelling them. event#setCanceled(true);
     
  14. DimoKouli, add a boolean check into your Listener Events and return if false.

    add to your main plugin class
    Code (Java):
    public boolean usePlayerListener = true;
     
    and this to your listeners.
    Code (Java):

    @EventHandler
    public void whateverEvent(Event event){
    if(!plugin.usePlayerListener)
        return;
    //Event instructions here
    }
     
     
    • Agree Agree x 1
  15. @DimoKouli The only way you can enable and disable a plugin, is from outside a plugin. Disabling is possible within the plugin itself. But once disabled, the plugin's code is no longer connected to your server. This means that any commands within the plugin's code will not be executed. I suggest you write the plugin code by itself and then write a separate plugin (it will be extremely short) which will enable/disable other plugins. It's the easiest way to go, the most effective too, probably the only way to go too.
     
  16. Just a tip: If you want to post code, click the text-looking page on the top bar, and click code. It formats it a lot better!
     
    • Informative Informative x 1
  17. Maybe i could keep the main class enabled and disable the PlayerListener class itself ??
     
  18. @DimoKouli
    Instead of that, I'd suggest making a hasmap and/or a boolean variable which you check in your "@EventHandler" methods and if they are present/ are true, you can proceed with the method. This will prove much more useful compared to disabling your classes, which I'm not sure is even possible.
     
    • Agree Agree x 1
  19. I personally favour this solution. Although I suppose you could also register/deregister the listener, no?