Interface PermissionProvider


public interface PermissionProvider
Provider interface for external permission plugins.

Permission plugins like LuckPerms should implement this interface and register it with the proxy to provide permission checking.

Registration

public class LuckPermsProvider implements PermissionProvider {
    @Override
    public PermissionFunction createFunction(PermissionSubject subject) {
        if (!(subject instanceof Player player)) {
            // Return a default function for non-player subjects (e.g., console)
            return PermissionFunction.ALWAYS_TRUE;
        }

        User user = luckPerms.getUserManager().getUser(player.getUniqueId());
        return permission -> {
            if (user == null) return Tristate.UNDEFINED;
            return Tristate.fromBoolean(user.getCachedData()
                .getPermissionData().checkPermission(permission).asBoolean());
        };
    }
}

// Register with proxy
Numdrassl.getProxy().getPermissionManager().setProvider(new LuckPermsProvider());

Subject Types

The subject passed to createFunction(PermissionSubject) can be:

  • Player - a connected player
  • Console command source - the server console

Lifecycle

The createFunction(PermissionSubject) method is called when a subject needs permissions set up. For players, this happens during connection. The function may be cached and reused for the duration of the session.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a permission function for the given subject.
    default void
    Called when this provider is registered.
    default void
    Called when this provider is unregistered.
  • Method Details

    • createFunction

      @Nonnull PermissionFunction createFunction(@Nonnull PermissionSubject subject)
      Creates a permission function for the given subject.

      This method is called when a subject's permissions need to be set up. The returned function will be used for all permission checks for this subject.

      Implementations should handle both player and non-player subjects appropriately. Use instanceof to distinguish between subject types:

      if (subject instanceof Player player) {
          // Player-specific logic
      } else {
          // Console or other subject types
      }
      
      Parameters:
      subject - the permission subject to create a function for
      Returns:
      the permission function for this subject
    • onRegister

      default void onRegister()
      Called when this provider is registered.

      Override this to perform initialization when the provider is installed.

    • onUnregister

      default void onUnregister()
      Called when this provider is unregistered.

      Override this to perform cleanup when the provider is removed.