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;
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.
Oh if this what i think i am totally idiot Btw do i have to register the arguements in the plugin yml ?
@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.
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.
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.
@GODofCRAFTERS i changed the return statement to true and still getting the white letters in my chat,,
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 }
@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.
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!
@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.
I personally favour this solution. Although I suppose you could also register/deregister the listener, no?