13
0
geforkt von Mirrors/Paper

Add cancellability to PlayerTrackEntityEvent (#8605)

Dieser Commit ist enthalten in:
Yannick Lamprecht 2023-08-21 09:38:55 +02:00
Ursprung b0439eea91
Commit 183462c9f0
2 geänderte Dateien mit 36 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -14,17 +14,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+import org.bukkit.entity.Entity; +import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player; +import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList; +import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent; +import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNull;
+ +
+/** +/**
+ * Is called when a {@link Player} tracks an {@link Entity}. + * Is called when a {@link Player} tracks an {@link Entity}.
+ * <p>
+ * If cancelled entity is not shown to the player and interaction in both directions is not possible.
+ */ + */
+public class PlayerTrackEntityEvent extends PlayerEvent { +public class PlayerTrackEntityEvent extends PlayerEvent implements Cancellable {
+ +
+ private static final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList();
+ private final Entity entity; + private final Entity entity;
+ private boolean cancelled;
+ +
+ public PlayerTrackEntityEvent(@NotNull Player player, @NotNull Entity entity) { + public PlayerTrackEntityEvent(@NotNull Player player, @NotNull Entity entity) {
+ super(player); + super(player);
@ -51,6 +55,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public Entity getEntity() { + public Entity getEntity() {
+ return entity; + return entity;
+ } + }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+} +}
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerUntrackEntityEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerUntrackEntityEvent.java diff --git a/src/main/java/io/papermc/paper/event/player/PlayerUntrackEntityEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerUntrackEntityEvent.java
new file mode 100644 new file mode 100644

Datei anzeigen

@ -4,31 +4,26 @@ Date: Wed, 30 Mar 2022 18:16:52 +0200
Subject: [PATCH] Player Entity Tracking Events Subject: [PATCH] Player Entity Tracking Events
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { @@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
EnchantmentHelper.doPostDamageEffects(attacker, target); // CraftBukkit end
} if (flag) {
if (this.seenBy.add(player.connection)) {
+ // Paper start - entity tracking events
+ if (io.papermc.paper.event.player.PlayerTrackEntityEvent.getHandlerList().getRegisteredListeners().length == 0 || new io.papermc.paper.event.player.PlayerTrackEntityEvent(player.getBukkitEntity(), this.entity.getBukkitEntity()).callEvent()) {
this.serverEntity.addPairing(player);
+ }
+ // Paper end
}
} else if (this.seenBy.remove(player.connection)) {
+ // Paper start - entity tracking events
+ if (io.papermc.paper.event.player.PlayerUntrackEntityEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ new io.papermc.paper.event.player.PlayerUntrackEntityEvent(player.getBukkitEntity(), this.entity.getBukkitEntity()).callEvent();
+ }
+ // Paper end
this.serverEntity.removePairing(player);
}
- public void startSeenByPlayer(ServerPlayer player) {}
+ // Paper start
+ public void startSeenByPlayer(ServerPlayer player) {
+ if (io.papermc.paper.event.player.PlayerTrackEntityEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ new io.papermc.paper.event.player.PlayerTrackEntityEvent(player.getBukkitEntity(), this.getBukkitEntity()).callEvent();
+ }
+ }
+ // Paper end
- public void stopSeenByPlayer(ServerPlayer player) {}
+ // Paper start
+ public void stopSeenByPlayer(ServerPlayer player) {
+ if(io.papermc.paper.event.player.PlayerUntrackEntityEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ new io.papermc.paper.event.player.PlayerUntrackEntityEvent(player.getBukkitEntity(), this.getBukkitEntity()).callEvent();
+ }
+ }
+ // Paper end
public float rotate(Rotation rotation) {
float f = Mth.wrapDegrees(this.getYRot());