Modules
public class Main extends Module {
}public class Main extends Module {
@Override
public void onEnable() {
// Some code here
}
}public class ExampleCommand extends BukkitCommand {
public BukkitCommand exampleCommand;
public ExampleCommand(@NotNull String permission, @NotNull String name, @NotNull String description, @NotNull String usage, @NotNull List<String> aliases) {
super(name, description, usage, aliases);
this.setName(name);
this.setDescription(description);
this.setUsage(usage);
this.setAliases(aliases);
this.setPermission(permission);
try {
Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
CommandMap commandMap = (CommandMap) f.get(Bukkit.getServer());
commandMap.register(name, this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public boolean execute(@NotNull CommandSender commandSender, @NotNull String name, @NotNull String[] args) {
// Code of command here
return true;
}
public void registerCommands() {
if(exampleCommand != null) exampleCommand.unregister(getCommandMap());
registerTestCommand();
}
private void registerTestCommand() {
ArrayList<String> aliases = new ArrayList<>();
aliases.add("example"); // Our main command name
aliases.add("ex"); // Aliases for main command
String usage = "/<command>"; // How to use this command
String description = "An example command"; // Description of this command
String permission = "example.command"; // And permission of this command
BukkitCommand command = new ExampleCommand(permission, aliases.get(0), description, usage, aliases);
exampleCommand = command;
}
public CommandMap getCommandMap() {
CommandMap commandMap = null;
try {
Field f = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
commandMap = (CommandMap) f.get(Bukkit.getPluginManager());
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
e.printStackTrace();
}
return commandMap;
}
}Last updated