Permission handler

With my permissions handler I aim to make it easier to support more permissions engines then just 1. Without having to worry about which engine the player actually wants to use. The reason to speak to a permissions engine directly as opposed to through Bukkit SuperPerms is because the latter does not for example have group support. It also offers an easier way to grant all permissions to operators, whilst keeping the defaults in the plugin.yml as false. It also features a "no permissions" driver, although this requires the "op has permissions" parameter to be set as "true".

Hooking into the permissions handler

Now that we have hooked into GiantCore already, we can continue with using that object to hook into the permissions engine of our choice! :)

public class MyEpicPlugin extends JavaPlugin {
    
    private static MyEpicPlugin instance;

    private PermHandler pH;

    @Override
    public void onEnable() {
        GiantCore gc = GiantCore.getInstance();
        if(gc == null) {
            getLogger().severe("Failed to hook into required GiantCore!");
            this.getPluginLoader().disablePlugin(this);
            return;
        }
	
        // Optional protocol version check.
        if(gc.getProtocolVersion() != 0.1) {
            getLogger().severe("The GiantCore version you are using is not compatible with this plugin!");
            this.getPluginLoader().disablePlugin(this);
            return;
        }
	
        // Set instance for easier obtaining from other classes.
        MyEpicPlugin.instance = this;
        
        // Hook into Bukkit SuperPerms, op does not have all permissions!
        this.pH = gc.getPermHandler(PermHandler.findEngine("SPERM"), false);
    }

    public PermHandler getPermHandler() {
        return this.pH;
    }

    public static MyEpicPlugin getInstance() {
        return MyEpicPlugin.instance;
    }
}

Using the permissions handler

Now that we have also successfully hooked into the permissions handler, lets move on, and actually start using it! :)

public class MyEpicCommandExecutor implements CommandExecutor {
    private MyEpicPlugin plugin;
    public MyEpicCommandExecutor(MyEpicPlugin plugin) {
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if(sender instanceof Player) {
            if(this.plugin.getPermHandler().getEngine().has((Player) sender, "myepiccommand.use")) {
                sender.sendMessage("It's epic indeed!");
            return false;
            }
        }
        return true;
    }
}