samolego / FabricTailor

A server-side or singleplayer skin changing mod for fabric.
https://modrinth.com/mod/FabricTailor
GNU Lesser General Public License v3.0
109 stars 17 forks source link

Allow selectors in `/skin set player` #75

Closed eggohito closed 1 year ago

eggohito commented 1 year ago

This PR changes the /skin set player sub-command to make it accept either a username of a player (online or offline) or a target selector limited to a single player.

I apologize in advance if the code is not that great, but the only method I can think of for allowing input of offline player usernames is to use an accessor to get the player name from the EntitySelector, which will be null if the user were to input a target selector

eggohito commented 1 year ago

...if you meant to suggest player names

Ah, no no, sorry if I haven't explained it correctly. Say, for example, one wants to use the skin of a random player or a player that has a certain tag. With this PR, it can be done by using /skin set player @a[limit = 1, sort = random] and /skin set player @a[limit = 1, tag = <tagName>] respectively

This PR also allows using usernames of offline players. Since EntitySelectors throw a CommandSyntaxException if the player couldn't be found (e.g: by being offline), I used a try-catch and check if the playerName of the EntitySelector is null, which will be the case if the user used a target selector (e.g: @a[limit = 1, ...]). If it is null, then the exception (in this case, it will be EntityArgument.PLAYER_NOT_FOUND) will be thrown again. Otherwise, it will use playerName to fetch the skin

Here's a video that demonstrates the change

samolego commented 1 year ago

Ah, ok, totally forgot about the @ selectors 😅.

Thanks!