INTRODUCTION
This library will speed up your plugin devolpment without the need to create complex classes or any other complex infrastructure.It will help you to declare your commands, events, mobs very easily keeping the SOLID principles.
This plugins include: Commands, Tasks, Mobs and Event listener auto register
- Commands
- Separe each command execution in different classes
- Create subcommands easily
- Map command args to an object
- Auto generated help commands & for subcommands
- Tasks. Auto register, scheduled tasks
- Mobs. Register mob click events in a class
- Auto register eventlisteners. Not needed to register your eventlistener to bukkit.
For more detailed documentation: https://github.com/JaimeTruman/Bukkit-Class-Mapper
SETUP
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.JaimeTruman</groupId>
<artifactId>Bukkit-Class-Mapper</artifactId>
<version>2.4.1</version>
</dependency>
To make this library work you have declare: Mapper.build(<base package to scan for classes>, <main plugin class instance>). Now you have to declare what you want to use the plugin for and at the end type startScanning();
@Override
public void onEnable() {
String onWrongCommand = ChatColor.DARK_RED + "Command not found";
String onWrongPermissions = ChatColor.DARK_RED + "You have to be not enough permissions";
Mapper.build("com.your.package", this)
.commandMapper(onWrongCommand, onWrongSender)
.mobMapper()
.eventListenerMapper()
.taskMapper()
.startScanning();
}
COMMAND MAPPER
A single command can be run in a class called command runner. To achieve this:
- The command should be declared in plugin.yaml as usual
- . The command runner class will have to be annotated with "@command" annoation, which will include data of the command (name, permissions, usage etc).
- You will have to implement an interface:
- If the command has no arguments, it will have to implement CommandRunnerNonArgs, with method: void execute(CommandSender sender)
- If the command has arguments, it will have to import CommandRunnerArgs void execute(T args, CommandSender sender). The args will be mapped to T args object via usage property in "@command"
@Command("helloworld")
public class HelloWorldCommand implements CommandRunnerNonArgs {
@Override
public void execute(CommandSender sender) {
commandSender.sendMessage("Hello " + sender.getName());
}
}
For arguments & subcommand:
@Command(value = "balance pay", usage = {"money", "to"})
public class PayCommandRunner implements CommandRunnerArgs<PayCommand> {
@Override
public void execute(PayCommand command, CommandSender sender) {
sender.sendMessage(String.format("You paid %s %d$", command.getTo.getName(), command.getMoney));
}
}
class PayCommand {
private double money;
private Player to; //Needs to be online
//Getters...
}
The mapped command class will have to have a empty constructor & its fields should match with the args in " @command"
For optional arguments:
@Command(value = "balance pay", usage = {"money", "to", " [reason]"})
public class PayCommandRunner implements CommandRunnerArgs<PayCommand> {
@Override
public void execute(PayCommand command, CommandSender sender) {
//command.getReason() can be null
sender.sendMessage(String.format("You will pay %s %d$", command.getTo, command.getMoney));
}
}
User can "/balance pay 12 otherplayer" or "/balance pay 12 otherplayer reason" both will work
For optional arguments with default values:
@Command(value = "balance pay", usage = {"money", "to", "[reason]¡why not!"})
public class PayCommandRunner implements CommandRunnerArgs<PayCommand> {
@Override
public void execute(PayCommand command, CommandSender sender) {
//if reason not specify command.getReason() will return "why not"
commandSender.sendMessage(String.format("You will pay %s %d$", command.getTo, command.getMoney));
}
}
For long text arguments:
@Command(value = "message", usage = {"to", "...message"})
public class PayCommandRunner implements CommandRunnerArgs<MessageCommand> {
@Override
public void execute(MessageCommand command, CommandSender sender) {
//Player can do: "/message otherplayer hello bro"
}
}
Wrapping all together:
@Command(value = "balance pay", usage = {"money", "to", " ...[reason]¡why not!"})
public class PayCommandRunner implements CommandRunnerArgs<PayCommand> {
@Override
public void execute(PayCommand command, CommandSender sender) {
//if reason not specify command.getReason() will return "why not"
//if user types "/balance pay 10 otherplayer I love you" command.getReason() will return "I love you"
commandSender.sendMessage(String.format("You will pay %s %d$", command.getTo, command.getMoney));
}
}
This library gives you the option to autogenerate a command help for all your commands that will display the usage & explanation (to add explanation to a command, add "explanation" value in " @command":
@Command(value = "helpme", isHelper = true)
public final class HelpMeCommand implements CommandRunner {
//Nothing necesary
}
The help for subcommands: /<subcommand name> help
You still have to declare your commands in plugin.yaml
TASK MAPPER
You can create your own task (the ones that extends BukktiRunnable) without taking care to start them. To do it, every task will represent a task. This class needs to:
@Task(40) //It will be executed every 2 seconds
public class TestTask extends TaskRunner {
@Override
public void run () {
//TODO...
}
}
If you want an initial delay of 1 minute and a period of 30 seconds:
@Task(value = 30 * BukkitTimeUnit.SECOND, delay = BukkitTimeUnit.MINUTE)
public class TestTask extends TaskRunner {
@Override
public void run () {
//TODO...
}
}
These classes will need to have an empty constructor.
MOB MAPPER
If you want a mob/entity in a fixed location that the player can interact with, you can use this part of the plugin. get executed when the player interacts with the mob. Example.
@Mob(x = 0, y = 70, z = 0)
public class StatsMob implements OnPlayerInteractMob {
@Override
public void execute (PlayerInteractEntityEvent event) {
//TODO...
}
}
These classes will need to have an empty constructor.
EVENT LISTENER MAPPER
When you create your plugin event listener you always have to register them. Now with this library you don't need to do it. It will register them for you. The event listener classes need to have an empty constructor.
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta