Skip to content

Add the 'target' type of argument for player selections#7

Closed
jasonw4331 wants to merge 5 commits into
CortexPE:masterfrom
jasonw4331:patch-1
Closed

Add the 'target' type of argument for player selections#7
jasonw4331 wants to merge 5 commits into
CortexPE:masterfrom
jasonw4331:patch-1

Conversation

@jasonw4331

Copy link
Copy Markdown
Contributor

No description provided.

@lukeeey

lukeeey commented Jun 2, 2019

Copy link
Copy Markdown

Getting an offline player isnt the intended behaviour for this argument

@lukeeey

lukeeey commented Jun 2, 2019

Copy link
Copy Markdown

Also should it not return the player object so we dont have to make another call to getplayer?

@jasonw4331

Copy link
Copy Markdown
Contributor Author

It obviously doesn't return a player object. Read the code.

The provided code doesn't get an offline player either. That function creates a fake offline player any time it's called, so I am using it to ensure there are no "function getName() on null" errors. The client will only ever be able to see names of online players but I still want to provide usage for players that dont exist so that they can use the argument as a normal string the way vanilla handles it.

@CortexPE

CortexPE commented Jun 3, 2019 via email

Copy link
Copy Markdown
Owner

@jasonw4331

Copy link
Copy Markdown
Contributor Author

Isn't that just a micro optimization?

@CortexPE

CortexPE commented Jun 3, 2019 via email

Copy link
Copy Markdown
Owner

@lukeeey

lukeeey commented Jun 3, 2019

Copy link
Copy Markdown

@jasonwynn10 Look at Cortex's own implementation of something similar to this: https://github.com/CortexPE/Hierarchy/blob/master/src/CortexPE/Hierarchy/command/args/MemberArgument.php

This is why i suggested returning the player object. Nowadays we should be checking if the player is null in vanilla pmmp and we can continue doing that with commando.

Also, i get that that you would like to support online players but could this not be implemented in a seperate argument, or left to the developer to implement as a custom argument?

@jasonw4331

jasonw4331 commented Jun 3, 2019

Copy link
Copy Markdown
Contributor Author

could this not be implemented in a seperate argument, or left to the developer to implement as a custom argument?

It matches vanilla's behaviour.

@lukeeey

lukeeey commented Jun 3, 2019

Copy link
Copy Markdown

@jasonwynn10 ??

public function parse(string $argument, CommandSender $sender) {
// TODO: handle @a @e @p @r @s @c @v
$player = $this->server->getPlayer($argument) ?? $this->server->getOfflinePlayer($argument);
return $player->getName();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, also why does it return the name instead of Player or OfflinePlayer? Wouldn't that be more versatile?

And we don't need to call Server->getPlayer() because Server->getOfflinePlayer() already returns a Player if it's available:
https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/Server.php#L778-L792

@CortexPE

CortexPE commented Jun 4, 2019

Copy link
Copy Markdown
Owner

If it only needed the name and nothing else, why not just validate the input if it's a valid name?

And imho, I really don't see most people using this type of argument assuming that it would return just a name...

@jasonw4331

Copy link
Copy Markdown
Contributor Author

I make it find an actual online player for name auto-complete. If there is no one online with that name, then it will not autocomplete.

@CortexPE

CortexPE commented Jun 5, 2019

Copy link
Copy Markdown
Owner

Oh so autocomplete.... Isn't the name misleading? 🤔

@jasonw4331

Copy link
Copy Markdown
Contributor Author

how is it misleading?

@CortexPE

CortexPE commented Jun 5, 2019

Copy link
Copy Markdown
Owner

We're usually returning the actual object and usually not just the names... From the name TargetArgument I'd assume that it would either return a Player or null... But here, it returns a string.

@jasonw4331

Copy link
Copy Markdown
Contributor Author

oh, well I can have it return a player or null without the auto-complete I guess

@CortexPE

CortexPE commented Jun 5, 2019

Copy link
Copy Markdown
Owner

Or it could be named "PlayerNameArgument" 🤔

@jasonw4331 jasonw4331 closed this Mar 30, 2023
@inxomnyaa

Copy link
Copy Markdown
Collaborator

🤔

@jasonw4331

Copy link
Copy Markdown
Contributor Author

Closed in favor of #15

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants