Simple commands is a command framework for Spigot. It's currently under heavy development, so stay tuned.
Note: This project is inspired by Aikar. So checkout the other command framework, if you find this project interesting.
Spigot features its own command framework by using the command design pattern.
It's quite simple to create own commands. But if you have multiple commands with even more sub commands, there will be a lot of redundant and duplicated code.
The intention behind the framework is to handle and check the arguments, so that the implementation of the command only features the actual logic. This will be achieved by using annotations and interfaces for command arguments.
plugin.yml
@Inject
Just add the following repository and dependency to your Maven project.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Paul2708</groupId>
<artifactId>simple-commands</artifactId>
<version>0.4.1</version>
</dependency>
If you don't use a build tool like Maven or Gradle, you can download the latest release here.
git clone https://github.com/Paul2708/simple-commands.git
mvn clean install
<dependency>
<groupId>de.paul2708</groupId>
<artifactId>simple-commands-core</artifactId>
<version>0.4.1</version>
</dependency>
The following code snippet represents a simple teleport command.
@Command(name = "teleport", desc = "Teleport you to a player", permission = "example.tp")
public void test(Player sender, Player target) {
condition(!sender.equals(target), "You cannot teleport you to yourself");
sender.teleport(target);
sender.sendMessage("You got teleported to " + target.getName() + ".");
}
An example plugin with all current features like language selection and dependency injection can be found here. It's really recommended as it is a real working plugin with features implemented.
Some wiki pages will follow soon.
The following commands teleport a target player to a given y-height.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("This command is for players only.");
return false;
}
if (!sender.hasPermission("example.tp")) {
sender.sendMessage("You do not have enough permissions.");
return false;
}
if (args.length != 2) {
sender.sendMessage("False usage. Please use 3 parameters instead of " + args.length);
return false;
}
Player player = Bukkit.getPlayer(args[0]);
if (player == null || !player.isOnline()) {
sender.sendMessage("The player is not online.");
return false;
}
int yHeight;
try {
yHeight = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage("This argument is not a number.");
return false;
}
if (yHeight <= 0) {
sender.sendMessage("The height has to be positive.");
return false;
}
// Finally done...
Location location = player.getLocation().clone();
location.setY(yHeight);
player.teleport(location);
sender.sendMessage("You teleported " + player.getName() + " to " + yHeight);
return true;
}
@Command(name = "teleport", desc = "Teleport a player to y", permission = "example.tp")
public void test(Player sender, Player target, int yHeight) {
condition(yHeight > 0, "The height has to be positive.");
Location location = target.getLocation().clone();
location.setY(yHeight);
target.teleport(location);
sender.sendMessage("You teleported " + target.getName() + " to " + yHeight);
}
I think, you can spot the differences and the boilerplate by spigot.
Here is a set of instructions that will guide you through your contribution.
If you find any issues, please let me know! Just open a bug report or another issue.