From 12bf7a15ad7f457ebcf46a3d6b8f7e1638d0de9c Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Thu, 28 Sep 2017 17:38:17 -0400 Subject: [PATCH] Add PlayerJumpEvent --- Spigot-API-Patches/Add-PlayerJumpEvent.patch | 110 ++++++++++++++++++ .../Add-PlayerJumpEvent.patch | 43 +++++++ 2 files changed, 153 insertions(+) create mode 100644 Spigot-API-Patches/Add-PlayerJumpEvent.patch create mode 100644 Spigot-Server-Patches/Add-PlayerJumpEvent.patch diff --git a/Spigot-API-Patches/Add-PlayerJumpEvent.patch b/Spigot-API-Patches/Add-PlayerJumpEvent.patch new file mode 100644 index 0000000000..8c69d98738 --- /dev/null +++ b/Spigot-API-Patches/Add-PlayerJumpEvent.patch @@ -0,0 +1,110 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zach Brown <1254957+zachbr@users.noreply.github.com> +Date: Thu, 28 Sep 2017 17:21:32 -0400 +Subject: [PATCH] Add PlayerJumpEvent + + +diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java +new file mode 100644 +index 00000000..1ea9c65f +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java +@@ -0,0 +0,0 @@ ++package com.destroystokyo.paper.event.player; ++ ++import com.google.common.base.Preconditions; ++import org.bukkit.Location; ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.player.PlayerEvent; ++ ++/** ++ * Holds information for player jump events ++ */ ++public class PlayerJumpEvent extends PlayerEvent implements Cancellable { ++ private static final HandlerList handlers = new HandlerList(); ++ private boolean cancel = false; ++ private Location from; ++ private Location to; ++ ++ public PlayerJumpEvent(final Player player, final Location from, final Location to) { ++ super(player); ++ this.from = from; ++ this.to = to; ++ } ++ ++ /** ++ * Gets the cancellation state of this event. A cancelled event will not ++ * be executed in the server, but will still pass to other plugins ++ *

++ * If a jump event is cancelled, the player will be moved or ++ * teleported back to the Location as defined by getFrom(). This will not ++ * fire an event ++ * ++ * @return true if this event is cancelled ++ */ ++ public boolean isCancelled() { ++ return cancel; ++ } ++ ++ /** ++ * Sets the cancellation state of this event. A cancelled event will not ++ * be executed in the server, but will still pass to other plugins ++ *

++ * If a jump event is cancelled, the player will be moved or ++ * teleported back to the Location as defined by getFrom(). This will not ++ * fire an event ++ * ++ * @param cancel true if you wish to cancel this event ++ */ ++ public void setCancelled(boolean cancel) { ++ this.cancel = cancel; ++ } ++ ++ /** ++ * Gets the location this player jumped from ++ * ++ * @return Location the player jumped from ++ */ ++ public Location getFrom() { ++ return from; ++ } ++ ++ /** ++ * Sets the location to mark as where the player jumped from ++ * ++ * @param from New location to mark as the players previous location ++ */ ++ public void setFrom(Location from) { ++ validateLocation(from); ++ this.from = from; ++ } ++ ++ /** ++ * Gets the location this player jumped to ++ * ++ * This information is based on what the client sends, it typically ++ * has little relation to the arc of the jump at any given point. ++ * ++ * @return Location the player jumped to ++ */ ++ public Location getTo() { ++ return to; ++ } ++ ++ private void validateLocation(Location loc) { ++ Preconditions.checkArgument(loc != null, "Cannot use null location!"); ++ Preconditions.checkArgument(loc.getWorld() != null, "Cannot use null location with null world!"); ++ } ++ ++ @Override ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/Add-PlayerJumpEvent.patch b/Spigot-Server-Patches/Add-PlayerJumpEvent.patch new file mode 100644 index 0000000000..538cab6a38 --- /dev/null +++ b/Spigot-Server-Patches/Add-PlayerJumpEvent.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zach Brown <1254957+zachbr@users.noreply.github.com> +Date: Thu, 28 Sep 2017 17:21:44 -0400 +Subject: [PATCH] Add PlayerJumpEvent + + +@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { + d8 = d5 - this.p; + d9 = d6 - this.q; + if (this.player.onGround && !packetplayinflying.a() && d8 > 0.0D) { +- this.player.cu(); ++ // Paper start - Add player jump event ++ Player player = this.getPlayer(); ++ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. ++ Location to = player.getLocation().clone(); // Start off the To location as the Players current location. ++ ++ // If the packet contains movement information then we update the To location with the correct XYZ. ++ if (packetplayinflying.hasPos) { ++ to.setX(packetplayinflying.x); ++ to.setY(packetplayinflying.y); ++ to.setZ(packetplayinflying.z); ++ } ++ ++ // If the packet contains look information then we update the To location with the correct Yaw & Pitch. ++ if (packetplayinflying.hasLook) { ++ to.setYaw(packetplayinflying.yaw); ++ to.setPitch(packetplayinflying.pitch); ++ } ++ ++ PlayerJumpEvent event = new PlayerJumpEvent(player, from, to); ++ ++ if (event.callEvent()) { ++ this.player.cu(); ++ } else { ++ from = event.getFrom(); ++ this.internalTeleport(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch(), Collections.emptySet()); ++ return; ++ } ++ // Paper end + } + + this.player.move(EnumMoveType.PLAYER, d7, d8, d9); +-- \ No newline at end of file