FHandler is a simple annotation based command handler for Minecraft plugins. The library has support for bungeecord and spigot.
Technologies used in the project:
- Create a instance of the FHandler
@Override
public void onEnable() {
FConfiguration config = null;
try {
config = FHandler.getFConfiguration()
.setInstance(this)
.setScope(FScope.SPIGOT)
.build();
} catch (FHandlerException e) {
e.printStackTrace();
}
}
- Register commands via the instance
@Override
public void onEnable() {
FConfiguration config = null;
try {
config = FHandler.getFConfiguration()
.setInstance(this)
.setScope(FScope.SPIGOT)
.build();
} catch (FHandlerException e) {
e.printStackTrace();
}
if (config != null) {
CommandRegistrar commandRegistrar = config.getCommandRegistrar();
commandRegistrar.getSpigotRegistrar().register(TestCommand.class);
}
}
- Create a command:
public class MSGCommand {
@Command("msg")
public void msg(@Sender CommandSender sender, @Name("player") String player, @Name("message") String message) {
Player t = Bukkit.getPlayer(player);
Player p = (Player) sender;
if (t == null) {
sender.sendMessage("Player not found!");
return;
}
t.sendMessage(message);
sender.sendMessage("Message sent to " + player + "!");
t.setMetadata("replyTo", new FixedMetadataValue(TestPlugin.getInstance(), p.getName()));
p.setMetadata("replyTo", new FixedMetadataValue(TestPlugin.getInstance(), t.getName()));
}
@Command("r")
public void r(@Sender CommandSender sender, @Name("message") String message) {
Player p = (Player) sender;
MetadataValue replyTo = p.getMetadata("replyTo").getFirst();
Player t = Bukkit.getPlayer(replyTo.asString());
if (t == null) {
sender.sendMessage("Player not found!");
return;
}
t.sendMessage(message);
sender.sendMessage("Message sent to " + t.getName() + "!");
}
}
- Fedox-die-Ente - Creator of the project
- Austria7 - Contributor and helper of the project
This project is licensed under the AGPL-3.0
Leave a ⭐ on this repository :D