-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Commands
BDX edited this page Jun 1, 2023
·
5 revisions
- Start by creating a new file in the /plugins/Nhplugin/scripts/commands directory. For this example the command file will be called fly.js
- All commands created using the default configuration require the following function format:
function <command_name>(sender, commandName, args, nhplugin, event)- The sender is the instance of the CommmandSender
- The commandName is the name of the command that was invoked
- The args are the arguments that were provided on command invocation
- The event is the event that was called when the command was invoked (Provided for more granular control over command implementations)
- To write the command many of the default objects from both the Bukkit and Spigot APIs are loaded by default (For a full list see here)
- Below is an example of the fly command to put in the fly.js file
function fly(sender, commandName, args, nhplugin, event){
if(sender.hasPermission("nh.fly")){
sender.setAllowFlight(true); // The player is now flying
}else{
sender.sendMessage(permissionErrorMessage); // Sends the default lacking permissions to execute message
}
}- To register the command use the command.js file located in /plugins/Nhplugin/scripts
- Add the following line to the top of the file
load(fileLocationBase+"commands/fly.js")- Next add the command name and the function to the commandFunctions object. It will follow the format below (command name: function name):
var commandFunctions = {"fly":fly}- Lastly in the config.yml file the command can be added to support tab completion (see below):
commandNames:
- flyCongrats! You have created your first command using Nhplugin! However, this is only a sample of what can be done. Full command argument tab completion and many other customizations can still be done!
Thanks for using Nhplugin!