Matthew Lack

Permissions Plugin

A Minecraft plugin for managing player and group permission hierarchies.

  • Minecraft
  • OOP
  • Java

https://github.com/mattlack15/Perms

Purpose

This is a permissions plugin for Minecraft servers that I wrote between 2020 and 2021, originally for the Soraxus server. On a Minecraft server, almost everything a player can do is guarded by a permission node like essentials.fly, and a permissions plugin decides who has which ones. It ended up being about 20,000 lines of Java.

Features

  • Users and groups, where users inherit from groups and groups inherit from other groups
  • Permissions and inheritances that only apply in certain contexts, like a specific server or world, or until a certain time
  • Negated permissions (-some.permission) and wildcards (some.plugin.*)
  • Group prefixes and suffixes, and chat formatting
  • Rank ladders with promote and demote
  • An extensive in-game GUI for managing everything (screenshots: https://imgur.com/a/xbDBbWT)
  • SQL, MongoDB or file storage
  • BungeeCord support for networks of servers
  • Vault and PlaceholderAPI integration
  • A verbose mode for debugging permission checks
  • An API for other plugins

Contexts

Contexts are the most interesting part of the plugin. A context is a key and a value, like server:prison or world:spawn, and a permission or inheritance can be given a set of contexts that decide when it applies.

A set of contexts is split into groups by key. For a set A to be satisfied by a set B, every group in A needs at least one match in B. For example, if A is {server:sv1, server:sv2, world:w1} and B is {server:sv1}, A is not satisfied, because nothing in B matches the world group. If B is {server:sv1, world:w1} instead, A is satisfied, because both groups have a match.

This means one permission can apply on two different servers but only in one world, without having to duplicate it. In code it looks like this:

Context context = new Context("key", "value");
Context serverContext = new Context(Context.SERVER_IDENTIFIER, "prison");
ContextSet contexts = new MutableContextSet(context, serverContext);

user.addPermission(new PPermission("hey.wassup", contexts));

Expiry works through contexts too, so a temporary rank is just an inheritance that stops applying after a certain time.

How permission checks work

Bukkit checks permissions through a Permissible object attached to every player. When a player joins, the plugin uses reflection to replace that object with its own, so that every player.hasPermission(...) call from any plugin on the server goes through it.

A check collects every permission the player has in their current context (this server and the world they're in), including everything inherited from groups, and then evaluates negations and wildcards:

for (String perm : perms) {
    boolean value = true;
    while (perm.startsWith("-")) {
        perm = perm.substring(1);
        value = !value;
    }
    if (perm.length() == 0) {
        continue;
    }
    if (perm.equals("*") || perm.equalsIgnoreCase(requ)) {
        if (!value)
            return false;
        returnValue = true;
        continue;
    }
    if (perm.endsWith("*") && requ.startsWith(perm.substring(0, perm.length() - 1))) {
        if (!value)
            return false;
        returnValue = true;
    }
}

A negated permission always wins, so you can give a group essentials.* and still take away -essentials.ban.

Verbose Mode

Since every permission check goes through the plugin, it can also show them. With verbose mode on, an admin sees each permission check live in chat, including the permission, whether it passed, and which class made the check (taken from the stack trace), with filters to narrow it down. This makes it much easier to figure out which permission a plugin actually wants.

Permission Index

Every permission the plugin sees, both the ones registered by other plugins and every permission that gets checked, is added to an index in the background, grouped by plugin. The GUI uses it to let you pick permissions from a list instead of having to know and type out every node.

Saving

Users and groups automatically queue their changes to be saved to whichever storage backend is configured. Auto-queueing can be turned off with setAutoQueue(false), and a save can be queued manually with queueSave().

Next projectBedwars Clone