Skip to content

Permissions

Gugas749 edited this page Nov 5, 2026 · 1 revision

Permissions

AbyssCore has three levels, shared by every Abyss mod:

public enum AbyssPermissionLevel { PLAYER, MODERATOR, ADMIN }
Level Who has it
ADMIN Any player with vanilla OP level 2+. Checked live against OP status, not the file.
MODERATOR Players granted it with /abysscore permission grant or AbyssPermissionHandler.grant(...). They don't need OP.
PLAYER Everyone else

Higher levels include the lower ones: ADMIN.isAtLeast(MODERATOR) == true.

Levels are saved in config/abysscore/abysscore_permissions.json.

Server-side checks — AbyssPermissionHandler

import com.gugas749.abysscore.api.permission.AbyssPermissionHandler;
import com.gugas749.abysscore.api.permission.AbyssPermissionLevel;

// Plain check
if (AbyssPermissionHandler.has(serverPlayer, AbyssPermissionLevel.MODERATOR)) {
    // staff-only logic
}

// Check + tell the player "you need MODERATOR" if they don't have it.
// Use this in packet handlers so a click is never silently ignored.
if (!AbyssPermissionHandler.require(serverPlayer, AbyssPermissionLevel.ADMIN)) return;

// In a Brigadier command
Commands.literal("purge")
        .requires(src -> AbyssPermissionHandler.sourceHas(src, AbyssPermissionLevel.ADMIN))
        .executes(ctx -> { ... });

Granting and revoking from code

AbyssPermissionHandler.grant(player.getUUID(), AbyssPermissionLevel.MODERATOR);  // saved immediately
AbyssPermissionHandler.revoke(player.getUUID());                                 // back to PLAYER

Works for offline players too, because it's keyed by UUID. The player's client learns the new level within 5 seconds, since AbyssPermissionSync re-checks every online player every 100 ticks.

Granting ADMIN does nothing useful. has(player, ADMIN) only checks OP status, and a non-OP player with ADMIN in the file is reset to PLAYER on their next join. Give OP to make someone ADMIN.

Full method list

Method Description
has(ServerPlayer, AbyssPermissionLevel) true if the player is at least that level
sourceHas(CommandSourceStack, AbyssPermissionLevel) For .requires(...). A player is checked with has(...). Any other source (server console, command blocks, functions, /execute without as <player>) counts as ADMIN if it has vanilla permission level 2, the same bar a player needs for ADMIN.
require(ServerPlayer, AbyssPermissionLevel) has(...), plus a chat message when it's false
grant(UUID, AbyssPermissionLevel) Set a level and save
revoke(UUID) Set back to PLAYER and save
load() / save() Re-read or write the JSON file (/abysscore reload calls load())
onPlayerJoin(ServerPlayer) Internal: auto-grants ADMIN to OPs, called by AbyssCore

Commands that need a player. Since sourceHas lets the console through, a command that acts on "the player who ran it" must check that itself:

.requires(src -> AbyssPermissionHandler.sourceHas(src, AbyssPermissionLevel.MODERATOR))
.executes(ctx -> {
    ServerPlayer self = ctx.getSource().getPlayerOrException();   // console → "a player is required" error
    ...
})

Commands that take a <player> argument (/mymod heal <target>) work from the console as they are.

Client-side checks — AbyssClientPermission

The client knows its own level, as last sent by the server. Use it to hide buttons or refuse to open staff screens. Never use it for security.

import com.gugas749.abysscore.api.permission.AbyssClientPermission;

if (AbyssClientPermission.has(AbyssPermissionLevel.MODERATOR)) {
    addRenderableWidget(staffButton);
}

AbyssPermissionLevel mine = AbyssClientPermission.get();   // PLAYER until the server says otherwise

It resets to PLAYER on logout.

AbyssPermissionSync (server)

Method Description
levelOf(ServerPlayer) The effective level: ADMIN if OP, otherwise MODERATOR or PLAYER
sync(ServerPlayer) Sends the level now, but only if it changed since the last send. Call it after grant/revoke if you don't want to wait up to 5 s.
AbyssPermissionHandler.grant(target.getUUID(), AbyssPermissionLevel.MODERATOR);
AbyssPermissionSync.sync(target);   // their staff buttons appear immediately

Clone this wiki locally