Skip to content

Allow unrestricting commands - #14358

Open
masmc05 wants to merge 1 commit into
PaperMC:mainfrom
masmc05:restrictedcmd
Open

masmc05 wants to merge 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Delayed approval

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

3 participants