Command Creation

Command Creation

Adding the Template

WorldProtect comes with a neat modular command system that allows you to easily load and unload commands. You can also create your own command, and I have created a NetBeans template simplifying this process.

  • Copy and Paste the template below
  • Click Tools -> Templates
    • Then select the Java folder
    • Click the "Add..." button
  • Name and open your new Template (name it something easy like 'WP Command")
  • Clear everything inside it so it's blank and paste the template text found here
<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};
</#if>

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.bjornke.worldprotect.utilities;

public class ${name} {
  public String name = "${name}";
  public String description = "";
  public String usage = "/${name} <required> [optional]";
  public String permission = "wp.${name}";
  public String permdefault = "true";
  public String[] aliases = {"one", "two"};
  public boolean events = false;

  public ${name}() {
  }
  
  public void execute(String[] args, CommandSender sender, Command cmd) {
    if(!sender.hasPermission(permission)){
      utilities.sendNoPerm(sender);
      return;
    }
    if(args != null) {
      
    }
  }
}

Using the Template

  • Create a new project or class file
    • If creating a new project, add a new java file and select Other and find the template in the list under Java
    • if creating a new class file select the template from the dialogue window under Java
  • Add bukkit as a dependency
  • Write your code and compile!

Comments

Posts Quoted:
Reply
Clear All Quotes