Skip to content

FHandler is a simple annotation based command handler for Minecraft plugins. The library has support for bungeecord and spigot.

License

Notifications You must be signed in to change notification settings

Fedox-die-Ente/fhandler

Repository files navigation

This project is still wip!

FHandler

project-image

FHandler is a simple annotation based command handler for Minecraft plugins. The library has support for bungeecord and spigot.

shields shields

💻 Built with

Technologies used in the project:

🧑‍💻 Examples

  1. 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();
    }
}
  1. 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);
        }
    }
  1. 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() + "!");
    }

}

🤵 Credits

🛡️ License:

This project is licensed under the AGPL-3.0

💖Like my work?

Leave a ⭐ on this repository :D

About

FHandler is a simple annotation based command handler for Minecraft plugins. The library has support for bungeecord and spigot.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages