3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-API-Patches/0069-Add-PlayerJumpEvent.patch
Spottedleaf 5c7081fecc Update upstream & fix some chunk related issues (#2177)
* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
2019-06-14 03:27:40 +01:00

122 Zeilen
3.8 KiB
Diff

From 3b3d6200514d4c75675a971831a3f303353cb1cd Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.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 000000000..289a0d784
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java
@@ -0,0 +1,106 @@
+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;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when the server detects the player is jumping.
+ * <p>
+ * Added to avoid the overhead and special case logic that many plugins use
+ * when checking for jumps via PlayerMoveEvent, this event is fired whenever
+ * the server detects that the player is jumping.
+ */
+public class PlayerJumpEvent extends PlayerEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private boolean cancel = false;
+ @NotNull private Location from;
+ @NotNull private Location to;
+
+ public PlayerJumpEvent(@NotNull final Player player, @NotNull final Location from, @NotNull 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
+ * <p>
+ * 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
+ * <p>
+ * 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
+ */
+ @NotNull
+ 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(@NotNull 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
+ */
+ @NotNull
+ 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 location with null world!");
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
--
2.21.0