Modules
Modules expand the capabilities of the main plugin. They are practically a plugin themselves. That is why module can have own folder inside the modules folder inside the main plugin's folder. Because of this you can easily create any config or any other file and put it inside separate folder to store information for example. By default it's turned off, but below you can find how to enable it.
Creating a module is almost similar to plugin creation. So, to create addon you need follow this:
Main class of your module should extend Module class of our plugin
public class Main extends Module {
}Main class of Module also has own onEnable method, so your Main should look like this:
public class Main extends Module {
@Override
public void onEnable() {
// Some code here
}
}But Module also needs commands and listeners, right? So, you need to use this command system:
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;
}
}So, you need to register this command. Go to your Main class and make some changes:
Also you can use ColorManager class from DiscordWhitelist to color your text, or build something into one String. For example:
Event listeners. They're default, but for now we found only one method of how to register them.
Nice, but our module needs description. Without this it won't startup.
Find resources directory where usually plugin.yml is located in, and create there module.yml. This file should contain next information:
For example:
Now you made your own module for DiscordWhitelist β₯οΈ
Last updated
Was this helpful?