Skip to content

Allow unrestricting commands - #14358

Merged
Warriorrrr merged 1 commit into
PaperMC:mainfrom
masmc05:restrictedcmd
Oct 8, 2026
Merged

Warriorrrr merged 1 commit into
PaperMC:mainfrom
masmc05:restrictedcmd

Conversation

@masmc05

@masmc05 masmc05 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

In 1.21.11 plugin predicates stopped being ignored by vanilla, meaning that a plugin whose predicate was improperly detected as restricted couldn't force it off. Now plugin developers would be able to both explicitly restrict or unrestrict a command. An example usage being

public final class TestPlugin extends JavaPlugin implements Listener {
    private static final Component TEST = Component.textOfChildren(
        Component.text("restricted1", Style.style().clickEvent(ClickEvent.runCommand("testrestriction restricted1")).build()),
        Component.newline(),
        Component.text("unrestricted1", Style.style().clickEvent(ClickEvent.runCommand("testrestriction unrestricted1")).build()),
        Component.newline(),
        Component.text("restricted2", Style.style().clickEvent(ClickEvent.runCommand("testrestriction restricted2")).build()),
        Component.newline(),
        Component.text("unrestricted2", Style.style().clickEvent(ClickEvent.runCommand("testrestriction unrestricted2")).build())
    );

    @Override
    public void onEnable() {
        this.getServer().getPluginManager().registerEvents(this, this);

        this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
            event.registrar().register(
                Commands.literal("testrestriction")
                    .then(
                        Commands.literal("restricted1")
                            .requires(c -> c.getSender() instanceof Player) // Null sender isn't a player
                            .executes(_ -> 0)
                    ).then(
                        Commands.literal("unrestricted1")
                            .requires(Commands.unrestricted(c -> c.getSender() instanceof Player)) // Ignores the test
                            .executes(_ -> 0)
                    ).then(
                        Commands.literal("restricted2")
                            .requires(Commands.restricted(c -> c.getSender().hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE))) // Ignores the test
                            .executes(_ -> 0)
                    ).then(
                        Commands.literal("unrestricted2")
                            .requires(c -> c.getSender().hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE)) // Null sender has all permissions
                            .executes(_ -> 0)
                    ).build()
            );
        });

        // io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this);
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        event.getPlayer().sendMessage(TEST);
    }
}

@masmc05
masmc05 requested a review from a team as a code owner October 6, 2026 17:00
@masmc05

masmc05 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Potentially also closes #13590

@MartinRedheLind

Copy link
Copy Markdown
Contributor

Potentially also closes #13590

It would indeed close that issue

@Warriorrrr Warriorrrr added type: feature Request for a new Feature. scope: api labels Oct 8, 2026
@Warriorrrr
Warriorrrr merged commit 65ba985 into PaperMC:main Oct 8, 2026
11 checks passed
@masmc05
masmc05 deleted the restrictedcmd branch October 8, 2026 19:58
granny added a commit to PurpurMC/Purpur that referenced this pull request Oct 8, 2026
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b3c6bcb8 Sync latest Moonrise changes PaperMC/Paper#14367
PaperMC/Paper@65ba9855 Allow unrestricting commands PaperMC/Paper#14358
PaperMC/Paper@e8750e1c [ci/skip] Resolve Schrödinger's accessor in HumanEntity starvation API PaperMC/Paper#14364
PaperMC/Paper@8097898e Refresh learnable recipes on recipe changes PaperMC/Paper#14302
PaperMC/Paper@615e915d Document undefined tracker behavior in track/untrack events. PaperMC/Paper#14189
PaperMC/Paper@16db2422 Add PersistentDataKey API PaperMC/Paper#14337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api type: feature Request for a new Feature.

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

Any plugin Brig command with a req. predicate is now restricted with no opt-out

4 participants