Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

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

wants to merge 5 commits into from

Conversation

jasonw4331
Copy link
Contributor

No description provided.

@lukeeey
Copy link

lukeeey commented Jun 2, 2019

Getting an offline player isnt the intended behaviour for this argument

@lukeeey
Copy link

lukeeey commented Jun 2, 2019

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

@jasonw4331
Copy link
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
Copy link
Owner

CortexPE commented Jun 3, 2019 via email

@jasonw4331
Copy link
Contributor Author

Isn't that just a micro optimization?

@CortexPE
Copy link
Owner

CortexPE commented Jun 3, 2019 via email

@lukeeey
Copy link

lukeeey commented Jun 3, 2019

@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
Copy link
Contributor Author

jasonw4331 commented Jun 3, 2019

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

lukeeey commented Jun 3, 2019

@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
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
Copy link
Owner

CortexPE commented Jun 4, 2019

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
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
Copy link
Owner

CortexPE commented Jun 5, 2019

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

@jasonw4331
Copy link
Contributor Author

how is it misleading?

@CortexPE
Copy link
Owner

CortexPE commented Jun 5, 2019

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

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

@CortexPE
Copy link
Owner

CortexPE commented Jun 5, 2019

Or it could be named "PlayerNameArgument" 🤔

@jasonw4331 jasonw4331 closed this Mar 30, 2023
@inxomnyaa
Copy link
Collaborator

🤔

@jasonw4331
Copy link
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