LeWimbes
LeWimbes

Reputation: 507

Create Permissions plugin (aplugin.*) - Spigot/Bukkit - Java

I tried to create something like a little Permissions plugin, but my problem is that I don't know how to give a Player for example the Permissions aplugin.chat and aplugin.color when I only give him the Permission aplugin.*. Of course it is no problem if the Permission is registered and I can check every Permission from Bukkit.getPluginManager().getPermissions(). How can I solve it if it isn't registered? In BungeeCord there is a Event where I can see the required Permission, but in Spigot/Bukkit?

Here is my newest version of code for setting the permissions:

// setPerms
public static void setPerms(Player p) {
    try {
        PreparedStatement ps = MySQL.getConnection()
                .prepareStatement("SELECT Permission FROM Permissions WHERE Gruppe = ?");
        ps.setString(1, User.getPermGroup(p.getName()));
        ResultSet rs = ps.executeQuery();
        PermissionAttachment pa;
        if (main.perms.containsKey(p.getName())) {
            pa = main.perms.get(p.getName());
        } else {
            pa = p.addAttachment(plugin);
        }
        while (rs.next() == true) {
            String perm = rs.getString("Permission");
            boolean value = true;
            if (perm.startsWith("-")) {
                perm = perm.substring(1);
                value = false;
            }
            if (perm.endsWith("*")) {
                if (perm.equals("*")) {
                    for (Permission pe : Bukkit.getPluginManager().getPermissions()) {
                        pa.setPermission(pe, value);
                    }
                    pa.setPermission(perm, value);
                } else {
                    String search = perm.substring(0, perm.length() - 1);
                    for (Permission pe : Bukkit.getPluginManager().getPermissions()) {
                        if (pe.getName().startsWith(search)) {
                            pa.setPermission(pe, value);
                        }
                    }
                    pa.setPermission(perm, value);
                }
            }
            pa.setPermission(perm, value);
        }
        main.perms.replace(p.getName(), pa);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

Thank you for your help and sorry for my bad English ;)

Upvotes: 0

Views: 3347

Answers (1)

Lightspeed360
Lightspeed360

Reputation: 161

You can create this '*' permission by overriding permission checks. Info(Click me)

PermissionBase is your class that extends PermissibleBase that override the hasPermission methods.

Simply use the reflection in the thread to set any player's PermissibleBase to yours allowing you to override bukkit's permission checks.

This will override bukkit meaning all other plugins will follow the same rules in your PermissionBase(Or whatever you name it) class.

For 'plugin.*' >

To create a 'plugin.' permission you will have to get all permission of said 'plugin'only enabling access if the checked permission is in said plugin AND said user has permission 'plugin.'.

This will simply give the user access to all of a plugins permission ONLY if your system knows said permission is said plugins permission and if user has access to all of the plugins permission('plugin.*') allow access no matter what.

Upvotes: 1

Related Questions