[SPIGOT-4029] DeclareCommandsEvent - allow modifying list of server commands before being sent to a client Created: 16/Jul/18  Updated: 31/Jul/18  Resolved: 31/Jul/18

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Zedadias Wick Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: 1.13,, API, Bukkit, commands, tab-completion

Version: 1.13

 Description   

Forgive me if my understanding of this is not accurate/complete. I had thought this would simply be a list of command names, but I can see it is more complicated than than.

The server will send a declare commands packet to the client outlining all of the commands and arguments for those command available. I would like to be able to view and modify the list of nodes, removing those relating to a particular command before it is sent to a player.

I don't really understand the format of the packet/command data, but I imagine it would be something like an Event.getNodes() which would return a collection of the nodes available, each of which would have methods to determine which command they pertain to. Along with an Event.setNodes().

I would use this, alongside PlayerCommandPreprocessEvent, to implement a white-list for commands to avoid unexpected commands added by plugins being made unintentionally available. I would also use it to hide legacy commands which are no longer officially support on a server after being replaced/aliased, but are still available for those who are accustomed to using them. In this case the player would have permission to the command, but should not have the command promoted to them via tab complete as they shouldn't be learning to use/rely on it.

 

 



 Comments   
Comment by Lorenzo Lapucci [ 24/Jul/18 ]

I've made a test: https://pastebin.com/Gz85Df4v

I've decomposed the method
a(CommandNode<> commandnode, CommandNode<> commandnode1, CommandListenerWrapper commandlistenerwrapper, Map<> map)
in 3 different methods to test it, but it can be done by simply adding a boolean as parameter (is it the command root?)

Comment by md_5 [ 24/Jul/18 ]

Yeah, you can see the work that's already gone on there

Comment by Lorenzo Lapucci [ 24/Jul/18 ]

Do you think that patching this method would be enough?

Comment by md_5 [ 24/Jul/18 ]

There's an option in spigot.yml for removing the plugin:command display from the client.

Providing an event + removal API is not straightforward, but progress was made towards this in the commit that fixed tab completion for /execute run and aliasing.

Comment by Lorenzo Lapucci [ 24/Jul/18 ]

When using the command char / in the chat you'll get the list of commands you have access to, this includes /command and /plugin:command, causing duplicates.

If we had a DeclareCommandsEvent with methods like getPlayer(), getCommandList(), getCommands() and setCommands(List<String>) will allow plugins to choose which command to send, if there is the need to send new ones or remove existing

Comment by md_5 [ 20/Jul/18 ]

>All registered commands are sent in that packet, regardless of if you have permission. Could be perhaps considered a bug? Fixing would require creating a CommandDispatcher instance per player and only adding commands they have permission for to it, before forming the packet.

This is false. Only commands with permission are sent.

You can easily test this by opping yourself, observing commands like /setblock, /op etc appearing; and then deopping yourself and observing them no longer appear.

Same applies for plugins with defined permissions (n.b. Essentials in particular does not define permissions on commands).

Comment by Luck [ 19/Jul/18 ]

All registered commands are sent in that packet, regardless of if you have permission. Could be perhaps considered a bug? Fixing would require creating a CommandDispatcher instance per player and only adding commands they have permission for to it, before forming the packet.

Comment by Hex [ 17/Jul/18 ]

As far as I'm aware, the commands declared to the client are dependent upon permission, so the use scope of this seems sort of small.

Generated at Tue Apr 15 08:23:04 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.