mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
include relative flags in PlayerTeleportEvent (#8190)
This commit is contained in:
parent
524451e16c
commit
9f932e42bd
1 changed files with 22 additions and 7 deletions
|
@ -24,7 +24,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
if (event.isCancelled() || !to.equals(event.getTo())) {
|
if (event.isCancelled() || !to.equals(event.getTo())) {
|
||||||
- set.clear(); // Can't relative teleport
|
- set.clear(); // Can't relative teleport
|
||||||
+ //set.clear(); // Can't relative teleport // Paper - Teleport API: Now you can!
|
+ // set.clear(); // Can't relative teleport // Paper - Teleport API: Now you can!
|
||||||
to = event.isCancelled() ? event.getFrom() : event.getTo();
|
to = event.isCancelled() ? event.getFrom() : event.getTo();
|
||||||
d0 = to.getX();
|
d0 = to.getX();
|
||||||
d1 = to.getY();
|
d1 = to.getY();
|
||||||
|
@ -144,17 +144,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
+ public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
|
||||||
+ java.util.Set<net.minecraft.world.entity.RelativeMovement> relativeArguments;
|
+ Set<io.papermc.paper.entity.TeleportFlag.Relative> relativeArguments;
|
||||||
+ java.util.Set<io.papermc.paper.entity.TeleportFlag> allFlags;
|
+ Set<io.papermc.paper.entity.TeleportFlag> allFlags;
|
||||||
+ if (flags.length == 0) {
|
+ if (flags.length == 0) {
|
||||||
+ relativeArguments = Set.of();
|
+ relativeArguments = Set.of();
|
||||||
+ allFlags = Set.of();
|
+ allFlags = Set.of();
|
||||||
+ } else {
|
+ } else {
|
||||||
+ relativeArguments = java.util.EnumSet.noneOf(net.minecraft.world.entity.RelativeMovement.class);
|
+ relativeArguments = java.util.EnumSet.noneOf(io.papermc.paper.entity.TeleportFlag.Relative.class);
|
||||||
+ allFlags = new HashSet<>();
|
+ allFlags = new HashSet<>();
|
||||||
+ for (io.papermc.paper.entity.TeleportFlag flag : flags) {
|
+ for (io.papermc.paper.entity.TeleportFlag flag : flags) {
|
||||||
+ if (flag instanceof io.papermc.paper.entity.TeleportFlag.Relative relativeTeleportFlag) {
|
+ if (flag instanceof final io.papermc.paper.entity.TeleportFlag.Relative relativeTeleportFlag) {
|
||||||
+ relativeArguments.add(toNmsRelativeFlag(relativeTeleportFlag));
|
+ relativeArguments.add(relativeTeleportFlag);
|
||||||
+ }
|
+ }
|
||||||
+ allFlags.add(flag);
|
+ allFlags.add(flag);
|
||||||
+ }
|
+ }
|
||||||
|
@ -187,6 +187,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||||
|
// To = Players new Location if Teleport is Successful
|
||||||
|
Location to = location;
|
||||||
|
// Create & Call the Teleport Event.
|
||||||
|
- PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause);
|
||||||
|
+ PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause, Set.copyOf(relativeArguments)); // Paper - Teleport API
|
||||||
|
this.server.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
// Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
|
||||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +217,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
// Check if the fromWorld and toWorld are the same.
|
// Check if the fromWorld and toWorld are the same.
|
||||||
if (fromWorld == toWorld) {
|
if (fromWorld == toWorld) {
|
||||||
- entity.connection.teleport(to);
|
- entity.connection.teleport(to);
|
||||||
+ entity.connection.internalTeleport(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch(), relativeArguments); // Paper - Teleport API
|
+ // Paper start - Teleport API
|
||||||
|
+ final Set<net.minecraft.world.entity.RelativeMovement> nms = java.util.EnumSet.noneOf(net.minecraft.world.entity.RelativeMovement.class);
|
||||||
|
+ for (final io.papermc.paper.entity.TeleportFlag.Relative bukkit : relativeArguments) {
|
||||||
|
+ nms.add(toNmsRelativeFlag(bukkit));
|
||||||
|
+ }
|
||||||
|
+ entity.connection.internalTeleport(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch(), nms);
|
||||||
|
+ // Paper end - Teleport API
|
||||||
} else {
|
} else {
|
||||||
// The respawn reason should never be used if the passed location is non null.
|
// The respawn reason should never be used if the passed location is non null.
|
||||||
this.server.getHandle().respawn(entity, toWorld, true, to, !toWorld.paperConfig().environment.disableTeleportationSuffocationCheck, null); // Paper
|
this.server.getHandle().respawn(entity, toWorld, true, to, !toWorld.paperConfig().environment.disableTeleportationSuffocationCheck, null); // Paper
|
||||||
|
|
Loading…
Reference in a new issue