pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.28k stars 1.56k forks source link

Add a permanent identifier method to CommandSender #3048

Open SOF3 opened 5 years ago

SOF3 commented 5 years ago

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 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

dktapps commented 1 day ago

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)