There is no reliable method to permanently identify a CommandSender. To permanently identify the console, the plugin has to check instanceof ConsoleCommandSender, but that assumes the knowledge that console is single-instance (or that other instances are supposed to imply the same thing as the console). To permanently identify a player, the plugin has to check for player UUID, which is not even in the CommandSender interface. To permanently identify plugin-defined CommandSender implementations... there is simply no reliable method.
Proposal
Introduce a getUniqueId method that returns ?UUID. If it returns null, the CommandSender cannot be uniquely identified. If it returns a UUID, users of CommandSender can rely on this value to identify a CommandSender over multiple sessions.
The ConsoleCommandSender unique ID can be generated from the server unique ID, which should be consistent throughout srever restarts.
Backward compatibility
This proposal is BC-breaking since CommandSender can be implemented
Is there an obvious use-case for this? Seems to me like spl_object_id() or similar would be sufficient for stuff that has to be run multiple times (like a confirmation command)
Introduction
There is no reliable method to permanently identify a CommandSender. To permanently identify the console, the plugin has to check
instanceof ConsoleCommandSender
, but that assumes the knowledge that console is single-instance (or that other instances are supposed to imply the same thing as the console). To permanently identify a player, the plugin has to check for player UUID, which is not even in the CommandSender interface. To permanently identify plugin-defined CommandSender implementations... there is simply no reliable method.Proposal
Introduce a
getUniqueId
method that returns?UUID
. If it returns null, the CommandSender cannot be uniquely identified. If it returns aUUID
, users ofCommandSender
can rely on this value to identify aCommandSender
over multiple sessions.The
ConsoleCommandSender
unique ID can be generated from the server unique ID, which should be consistent throughout srever restarts.Backward compatibility
This proposal is BC-breaking since CommandSender can be implemented