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.
SETUP
Code (XML):
<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>
<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>
Code (Java):
@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 ( ) ;
}
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"
Code (Java):
@Command
(
"helloworld"
)
public class HelloWorldCommand implements CommandRunnerNonArgs {
@Override
public void execute (CommandSender sender ) {
commandSender. sendMessage ( "Hello " + sender. getName ( ) ) ;
}
}
public class HelloWorldCommand implements CommandRunnerNonArgs {
@Override
public void execute (CommandSender sender ) {
commandSender. sendMessage ( "Hello " + sender. getName ( ) ) ;
}
}
For arguments & subcommand:
Code (Java):
@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...
}
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...
}
For optional arguments:
Code (Java):
@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
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:
Code (Java):
@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 ) ) ;
}
}
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:
Code (Java):
@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"
}
}
public class PayCommandRunner implements CommandRunnerArgs <MessageCommand > {
@Override
public void execute (MessageCommand command, CommandSender sender ) {
//Player can do: "/message otherplayer hello bro"
}
}
Wrapping all together:
Code (Java):
@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 ) ) ;
}
}
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":
Code (Java):
@Command
(value
=
"helpme", isHelper
=
true
)
public final class HelpMeCommand implements CommandRunner {
//Nothing necesary
}
public final class HelpMeCommand implements CommandRunner {
//Nothing necesary
}
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:
Code (Java):
@Task
(
40
)
//It will be executed every 2 seconds
public class TestTask extends TaskRunner {
@Override
public void run ( ) {
//TODO...
}
}
public class TestTask extends TaskRunner {
@Override
public void run ( ) {
//TODO...
}
}
Code (Java):
@Task
(value
=
30
* BukkitTimeUnit.
SECOND, delay
= BukkitTimeUnit.
MINUTE
)
public class TestTask extends TaskRunner {
@Override
public void run ( ) {
//TODO...
}
}
public class TestTask extends TaskRunner {
@Override
public void run ( ) {
//TODO...
}
}
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.
Code (Java):
@Mob
(x
=
0, y
=
70, z
=
0
)
public class StatsMob implements OnPlayerInteractMob {
@Override
public void execute (PlayerInteractEntityEvent event ) {
//TODO...
}
}
public class StatsMob implements OnPlayerInteractMob {
@Override
public void execute (PlayerInteractEntityEvent event ) {
//TODO...
}
}
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.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.16, 1.17, 1.18
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[API] Class Mapper Api is a free Minecraft Java mod. Compatible with Minecraft 1.16, 1.17, 1.18. Downloaded 620 times (via Spigot). Download it and open it directly in the game.