Commands - Lukario45/MCThunder GitHub Wiki
How to make a command for MCThunder
This page is for making command for MCThunder.
Making a command without a plugin
You can make commands for MCThunder without any need to install any plugins. Making a command for a plugin and a non plugin is overall the same process except a few steps that differ.
For commands without a plugin you should be able to open the MCThunder jar and throw the commands in the package for commands, regardless of whether this works or not we will be adding a commands folder and loading them from that folder.
Making commands for plugins
This process will be simple, there will be no silly registering commands in a plugin.yml you will take all of your plugin's commands and put them in your.plugins.package.commands package. This will either be automatically registered upon plugin load or we will have you say the package somewhere in your plugins main class.
The process of making a command
I am doing this using the broadcast command as an example, I am making this command as we do this, I am not using an IDE to prove how easy this can be!
Beginning
Make your command's class, for broadcast it will be a simple "Broadcast.java" or in your case"MyCommand.java"
Put this class in your.plugins.package.commands if you are making a command for a plugin, if not do not use a package.
You will need several imports that will be necissary for ALL Commands.
import net.mcthunder.MCThunder;
import net.mcthunder.api.Command;
import net.mcthunder.entity.Player;
You need your class to extend Command
public class Broadcast extends Command {/*your command code here*/}
Your constructing method is the method that sets everything for the command, there are six different pieces of information your command will need.
First argument is the commands name, all lower case
Second argument is for any alias for a command
Thrid argument is what the description for the command is, this will be shown in /help
Fourth argument is what is shown in help for the actual command, also shows when someone does not give enough arguments for the command
Fifth argument is for rankmanager, this is an integer that is between -9999 and 9999 Even if the server user does not use the default MCThunder rankmanager this MUST be set
Sixth argument is the permission node
Example:
public Broadcast(){
super("broadcast", Arrays.asList("say"), "Broadcast a sever message", "/broadcast {message}", 5000, "core.broadcast");
}
The argument for alias is Arrays.asList("say")
because you can have many alias for each command, do not put the commands name as an alias, it is not needed and will cause error.
The fifth argument is set to 5000 because with the default RankManager ranks (This can be change) 5000 is Moderator's permission level, meaning any rank with a permlevel below Moderator can not use the command, and respectivly any rank above CAN use it
The last argument is set to 'core.broadcast' since all of MCThunders commands are "core" This is used for special permissions in rankmanager, for plugin users just use "yourpluginname.commandname", not the whole package name.
You will need an execute method.
@Override
public boolean execute(Player player, String[] args) {
return true;
}
This should return false if the command user does not give enough args
Executing the command
The default Rank Manager will check for all of the permissions needed.
The arguments of the command do not include the command itself.
You must check the amount of arguments yourself, this is a simple task.
If your command requires 1 argument, check if it is equal to 0 and return false
if (args.length == 0)
return false;
For broadcast we will need all of the arguments to combine and send as a message to the entire server, we will need to use a StringBuilder