Ok this is my first time trying to put commands into my plugin so please bear with me. I was wondering how i would add commands to my plugin to that i can simply toggle it on and off. Im pretty sure you dont just slap this code in there and it works after you also setup the plugin.yml public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ if(cmd.getName().equalsIgnoreCase("firec")){ getServer().broadcastMessage(ChatColor.GREEN + "Whatever Message"); return true; } else if (cmd.getName().equalsIgnoreCase("fire")){ getServer().broadcastMessage(ChatColor.GREEN + "Whatever Message"); return true; } return false; }
Try adding this to your main plugin class: Code: getCommand("firec").setExecutor(new MyCommandHandler(this)); getCommand("fire").setExecutor(new MyCommandHandler(this)); Also, in your plugin YML (though im pretty sure it's only for the help files) Code: commands: firec: description: broadcasts the green Whatever Message fire: description: broadcasts the green Whatever Message You may find it easier however, to simply have one or two commands for your plugin, for example /fc to access all the commands, this means you only need to set the executor of the one command (/fc). Then you would have the first parameter control the use. For example, instead of '/firec' you could have '/fc firec' Just something to think about to save time.... here's a starter: Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if(cmd.getName().equalsIgnoreCase("fc")){ if(args.length > 0) { if (args[0].equalsIgnoreCase("firec")) { getServer().broadcastMessage(ChatColor.GREEN + "Whatever Message"); return true; } else if (args[0].equalsIgnoreCase("fire")) { getServer().broadcastMessage(ChatColor.GREEN + "Whatever Message"); return true; } } else { //You could mention they need to add more parameters here, or maybe give them a list of all commands here. } return false; } Code: commands: fc: description: gives access to all fire container commands
Is there a way to actually toggle my plugin though? Cause what mine does is just cancels the BlockIgnite event. So would i have to make it so when one of those commands are typed that it wont cancel that event?
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (label.equalsIgnoreCase("command) || label.equalsIgnoreCase("alias")) { Player player = (Player)sender; player.sendMessage(ChatColor.RED + "A message that wil be privately sent to the player!"); }
As said by cjc343, Just store a group of public variables in your main plugin class. You could make them static for ease, but i'd avoid that.