-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add ability to get cause in EntityTeleportEvent (#5767) #5861
Conversation
public const CAUSE_ITEM = 1; | ||
public const CAUSE_WORLD = 2; | ||
public const CAUSE_RESPAWN = 3; | ||
public const CAUSE_PATCH = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming is very unintuitive, I have no idea what it's supposed to mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Item: this is when an item cause the teleportation, like chorus fruit or enderpearl
- World: this is when the world cause teleportation like changing world or being teleported in safe spawn due to world unload
- Respawn: this is when the player respawn cause teleportation
- Patch: I think we can merge it with "Respawn" as "Player"
So, I can suggest this changes:
public const CAUSE_ITEM = 1;
public const CAUSE_WORLD = 2;
- public const CAUSE_RESPAWN = 3;
- public const CAUSE_PATCH = 4;
+ public const CAUSE_PLAYER = 3;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is even less clear than the initial, and additionally provides less information.
src/entity/projectile/EnderPearl.php
Outdated
@@ -40,7 +41,7 @@ protected function onHit(ProjectileHitEvent $event) : void{ | |||
|
|||
$this->getWorld()->addParticle($origin = $owner->getPosition(), new EndermanTeleportParticle()); | |||
$this->getWorld()->addSound($origin, new EndermanTeleportSound()); | |||
$owner->teleport($target = $event->getRayTraceResult()->getHitVector()); | |||
$owner->teleport($target = $event->getRayTraceResult()->getHitVector(), null, null, EntityTeleportEvent::CAUSE_ITEM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAUSE_PROJECTILE
seems better
src/item/ChorusFruit.php
Outdated
@@ -76,7 +77,7 @@ public function onConsume(Living $consumer) : void{ | |||
|
|||
//Sounds are broadcasted at both source and destination | |||
$world->addSound($origin, new EndermanTeleportSound()); | |||
$consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5)); | |||
$consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5), null, null, EntityTeleportEvent::CAUSE_ITEM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAUSE_CHORUS_FRUIT
seems better
src/player/Player.php
Outdated
@@ -1339,7 +1340,7 @@ protected function processMostRecentMovements() : void{ | |||
} | |||
|
|||
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination | |||
$this->teleport($ev->getTo()); | |||
$this->teleport($ev->getTo(), null, null, EntityTeleportEvent::CAUSE_PATCH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAUSE_SYNCHRONIZE
seems better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAUSE_PLUGIN would be sufficient.
This is specific, but let's see what @dktapps think about it |
+ EntityTeleportEvent: Code style improve
@@ -89,7 +90,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args | |||
return true; | |||
} | |||
|
|||
$subject->teleport($targetPlayer->getLocation()); | |||
$subject->teleport($targetPlayer->getLocation(), null, null, EntityTeleportEvent::CAUSE_COMMAND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$subject->teleport($targetPlayer->getLocation(), null, null, EntityTeleportEvent::CAUSE_COMMAND); | |
$subject->teleport($targetPlayer->getLocation(), cause: EntityTeleportEvent::CAUSE_COMMAND); |
Seems better
Refering to pmmp#5861 (comment) Co-Authored-By: ShockedPlot7560 <no-reply@tchallon.fr>
return $this->cause; | ||
} | ||
|
||
public function setCause(int $cause) : void{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it can be used for plugin conflicts 🤷♂️
@@ -36,10 +36,10 @@ class EntityTeleportEvent extends EntityEvent implements Cancellable{ | |||
use CancellableTrait; | |||
|
|||
public const CAUSE_PLUGIN = 0; | |||
public const CAUSE_ITEM = 1; | |||
public const CAUSE_PROJECTILE = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAUSE_PROJECTILE doesn't tell us what type of projectile was used. Maybe CAUSE_ENDER_PEARL would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I think the cause should be a string so plugins can specify their custom causes like "morepearls:snowball". That way we can be specific while also allowing customization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah agree, with ints its really easy to mess up if someone was to create custom one
What's now ? Should be the reason a string or a int (like seeing PlayerPreLoginEvent) ? |
I think a string would allow greater flexibility. An integer is very restrictive and doesn't give direct information for plugins that want to get the values. |
Plugins won't be able to interpret values they don't know about anyway. I think an integer is fine. Really this should probably use an |
@@ -35,10 +35,18 @@ | |||
class EntityTeleportEvent extends EntityEvent implements Cancellable{ | |||
use CancellableTrait; | |||
|
|||
public const CAUSE_PLUGIN = 0; | |||
public const CAUSE_PROJECTILE = 1; | |||
public const CAUSE_WORLD = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what this is supposed to mean.
Introduction
Relevant issues
#5767
Changes
API changes
The following method now accepts
int $cause
parameter. Defaults is 0 for EntityTeleportEvent::CAUSE_PLUGIN.Backwards compatibility
No BC-breaking changes, because there is a default parameter to this method signature change.