Skip to content
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

ExperienceOrb: no possibility of interfering in search for target entity #4589

Closed
ColinHDev opened this issue Nov 22, 2021 · 0 comments · Fixed by #4623
Closed

ExperienceOrb: no possibility of interfering in search for target entity #4589

ColinHDev opened this issue Nov 22, 2021 · 0 comments · Fixed by #4623
Labels
Category: API Related to the plugin API Resolution: Implemented Type: Enhancement Contributes features or other improvements to PocketMine-MP
Milestone

Comments

@ColinHDev
Copy link
Contributor

Description

Currently, you have the possibility by listening for PlayerExperienceChangeEvent, stop a player, or human entity to be more specific, from receiving experience.
But by the way the experience orb entity searches for its target, there is no way for plugin developers to interfere and for example, block experience orbs to be attracted to certain players / human entities, apart from extending the whole ExperienceOrb class and overwriting the ExperienceOrb::entityBaseTick() method.
https://github.com/pmmp/PocketMine-MP/blob/master/src/entity/object/ExperienceOrb.php#L179#L175

Justification

There is a variety of situations, where you wouldn't want experience orbs being attracted to specific entities, for example:

  • Human entities are an easy way to create non-player entities with player skins, for example in the Slapper plugin or player skull plugins (e.g.: https://github.com/ColinHDev/CSkull/blob/main/src/ColinHDev/CSkull/entities/SkullEntity.php#L21). In these usages, you would not want experience orbs to be attracted to your entities and rather ignore them entirely.
  • When writing a plugin that allows your staff members to go completely invisible, without them going into spectator mode and pretending they left the server, you would not want experience orbs flying to your hidden staff members, which would expose them.

Possible solutions

  • One suggestion was a Human::canPickupExperience() method which could be overwritten by plugins in their entity classes. But this suggestion has two flaws in my opinion: First, the method could be misleading with ExperienceManager::canPickupXp() and second, this would work for those kinds of plugins listed in the first example. But for that method to be useful for plugins listed in the second example, they would need to overwrite the Player class, which is also rather impractical, even more than overwriting the ExperienceOrb class. (The second point can be ruled out if such a method would be implemented with a class attribute, a setter and getter like Entity::hasGravity() and Entity::setHasGravity().)
  • Another suggestion was an ExperienceOrbAttractEvent, which could be called before the following line https://github.com/pmmp/PocketMine-MP/blob/master/src/entity/object/ExperienceOrb.php#L178. This event would be very useful for both given plugin examples, as they could just cancel the event or maybe also provide a replacement entity with an inbuilt ExperienceOrbAttractEvent::setEntity() method, so that these plugins could not only remove experience orbs from being attracted to their entities but also give plugin developers a way to implement their own system of searching.

Alternative methods

  • It should be possible to create your own ExperienceOrb class which overwrites the ExperienceOrb::entityBaseTick() method so that you would be able to make a custom search, but that approach is rather impractical.
  • In the case of the first example, it would also be possible for plugins to make their entities an instance of Living or only Entity but not Human because experience orbs only search for human entities. But this is also rather impractical because you would end up just copying many methods like skin and inventory handling from the Human to your own class.
@dktapps dktapps added Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Dec 3, 2021
ShockedPlot7560 added a commit to ShockedPlot7560/PocketMine-MP that referenced this issue Dec 7, 2021
dktapps added a commit that referenced this issue Dec 15, 2021
…4623)

Fixes #4589

The following API methods are added:

- `XpManager->canAttractXpOrbs()`
- `XpManager->setCanAttractXpOrbs()`

Possible future scope: flip this on its head to allow spectator players to attract XP orbs, in case someone wants that for some reason ???

Co-authored-by: Dylan K. Taylor <dktapps@pmmp.io>
@dktapps dktapps added this to the 4.1 milestone Dec 15, 2021
@dktapps dktapps closed this as completed Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Resolution: Implemented Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants