geforkt von Mirrors/Paper
Add cancellability to PlayerTrackEntityEvent (#8605)
Dieser Commit ist enthalten in:
Ursprung
b0439eea91
Commit
183462c9f0
@ -14,17 +14,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import org.bukkit.entity.Entity;
|
||||
+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;
|
||||
+
|
||||
+/**
|
||||
+ * 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 final Entity entity;
|
||||
+ private boolean cancelled;
|
||||
+
|
||||
+ public PlayerTrackEntityEvent(@NotNull Player player, @NotNull Entity entity) {
|
||||
+ super(player);
|
||||
@ -51,6 +55,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ public Entity getEntity() {
|
||||
+ 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
|
||||
new file mode 100644
|
||||
|
@ -4,31 +4,26 @@ Date: Wed, 30 Mar 2022 18:16:52 +0200
|
||||
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
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
||||
EnchantmentHelper.doPostDamageEffects(attacker, target);
|
||||
}
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
// 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());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren