3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00

Handle CraftPlayer#setSpectatorTarget better

Use a proper teleport for teleporting to entities in different
worlds.

Validate that the target entity is valid and deny spectate
requests from frozen players.

Also, make sure the entity is spawned to the client before
sending the camera packet. If the entity isn't spawned clientside
when it receives the camera packet, then the client will not
spectate the target entity.
Dieser Commit ist enthalten in:
Spottedleaf 2020-05-14 18:05:00 -05:00 committet von Zach Brown
Ursprung 4ae089597b
Commit bb4002d82e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: CC9DA35FC5450B76
13 geänderte Dateien mit 123 neuen und 90 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,101 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Caleb Bassham <caleb.bassham@gmail.com>
Date: Fri, 28 Sep 2018 02:32:19 -0500
Subject: [PATCH] Call player spectator target events and improve
implementation
Use a proper teleport for teleporting to entities in different
worlds.
Implementation improvements authored by Spottedleaf <Spottedleaf@users.noreply.github.com>
Validate that the target entity is valid and deny spectate
requests from frozen players.
Also, make sure the entity is spawned to the client before
sending the camera packet. If the entity isn't spawned clientside
when it receives the camera packet, then the client will not
spectate the target entity.
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index f43584f0e31a1c3d0e9b4356b7021cd79226d8b5..3175b0735f3b5f4d7e3e02dc083d32262d463de7 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -1586,15 +1586,59 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
return (Entity) (this.spectatedEntity == null ? this : this.spectatedEntity);
}
- public void setSpectatorTarget(Entity entity) {
+ public void setSpectatorTarget(Entity newSpectatorTarget) {
+ // Paper start - Add PlayerStartSpectatingEntityEvent and PlayerStopSpectatingEntity Event and improve implementation
Entity entity1 = this.getSpecatorTarget();
- this.spectatedEntity = (Entity) (entity == null ? this : entity);
- if (entity1 != this.spectatedEntity) {
- this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
- this.playerConnection.a(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ(), this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
+ if (newSpectatorTarget == null) {
+ newSpectatorTarget = this;
}
+ if (entity1 == newSpectatorTarget) return; // new spec target is the current spec target
+
+ if (newSpectatorTarget == this) {
+ com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent playerStopSpectatingEntityEvent = new com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent(this.getBukkitEntity(), entity1.getBukkitEntity());
+
+ if (!playerStopSpectatingEntityEvent.callEvent()) {
+ return;
+ }
+ } else {
+ com.destroystokyo.paper.event.player.PlayerStartSpectatingEntityEvent playerStartSpectatingEntityEvent = new com.destroystokyo.paper.event.player.PlayerStartSpectatingEntityEvent(this.getBukkitEntity(), entity1.getBukkitEntity(), newSpectatorTarget.getBukkitEntity());
+
+ if (!playerStartSpectatingEntityEvent.callEvent()) {
+ return;
+ }
+ }
+ // Validate
+ if (newSpectatorTarget != this) {
+ if (newSpectatorTarget.dead || newSpectatorTarget.shouldBeRemoved || !newSpectatorTarget.valid || newSpectatorTarget.world == null) {
+ MinecraftServer.LOGGER.info("Blocking player " + this.toString() + " from spectating invalid entity " + newSpectatorTarget.toString());
+ return;
+ }
+ if (this.isFrozen()) {
+ // use debug: clients might maliciously spam this
+ MinecraftServer.LOGGER.debug("Blocking frozen player " + this.toString() + " from spectating entity " + newSpectatorTarget.toString());
+ return;
+ }
+ }
+
+ this.spectatedEntity = newSpectatorTarget; // only set after validating state
+
+ if (newSpectatorTarget != this) {
+ // Make sure we're in the right place
+ this.ejectPassengers(); // teleport can fail if we have passengers...
+ this.getBukkitEntity().teleport(new Location(newSpectatorTarget.getWorld().getWorld(), newSpectatorTarget.locX(), newSpectatorTarget.locY(), newSpectatorTarget.locZ(), this.yaw, this.pitch), TeleportCause.SPECTATE); // Correctly handle cross-world entities from api calls by using CB teleport
+
+ // Make sure we're tracking the entity before sending
+ PlayerChunkMap.EntityTracker tracker = ((WorldServer)newSpectatorTarget.world).getChunkProvider().playerChunkMap.trackedEntities.get(newSpectatorTarget.getId());
+ if (tracker != null) { // dumb plugins...
+ tracker.updatePlayer(this);
+ }
+ } else {
+ this.playerConnection.teleport(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ(), this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
+ }
+ this.playerConnection.sendPacket(new PacketPlayOutCamera(newSpectatorTarget));
+ // Paper end
}
@Override
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 6627d8402f784c16519adaabca967b8e1d365ddc..fde38c4243b340eb2dc5a4e6e5af77f8a978ba83 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1110,6 +1110,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
}
// CraftBukkit start - Delegate to teleport(Location)
+ public final void teleport(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { this.a(d0, d1, d2, f, f1, cause); } // Paper - OBFHELPER
public void a(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) {
this.a(d0, d1, d2, f, f1, Collections.<PacketPlayOutPosition.EnumPlayerTeleportFlags>emptySet(), cause);
}

Datei anzeigen

@ -1,68 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Caleb Bassham <caleb.bassham@gmail.com>
Date: Fri, 28 Sep 2018 02:32:19 -0500
Subject: [PATCH] Call player spectator target events
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index f43584f0e31a1c3d0e9b4356b7021cd79226d8b5..bc62a9f08e9eb39dc20a69f397bc74eab13031a9 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -61,7 +61,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
private EnumChatVisibility ch;
private boolean ci = true;
private long cj = SystemUtils.getMonotonicMillis();
- private Entity spectatedEntity;
+ private Entity spectatedEntity; private void setSpectatorTargetField(Entity e) { this.spectatedEntity = e; } // Paper - OBFHELPER
public boolean worldChangeInvuln;
private boolean cm; private void setHasSeenCredits(boolean has) { this.cm = has; } // Paper - OBFHELPER
private final RecipeBookServer recipeBook;
@@ -1586,15 +1586,35 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
return (Entity) (this.spectatedEntity == null ? this : this.spectatedEntity);
}
- public void setSpectatorTarget(Entity entity) {
+ public void setSpectatorTarget(Entity newSpectatorTarget) {
+ // Paper start - Add PlayerStartSpectatingEntityEvent and PlayerStopSpectatingEntity Event
Entity entity1 = this.getSpecatorTarget();
- this.spectatedEntity = (Entity) (entity == null ? this : entity);
- if (entity1 != this.spectatedEntity) {
- this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
- this.playerConnection.a(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ(), this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
+ if (newSpectatorTarget == null) {
+ newSpectatorTarget = this;
}
+ if (entity1 == newSpectatorTarget) return; // new spec target is the current spec target
+
+ if (newSpectatorTarget == this) {
+ com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent playerStopSpectatingEntityEvent = new com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent(this.getBukkitEntity(), entity1.getBukkitEntity());
+
+ if (!playerStopSpectatingEntityEvent.callEvent()) {
+ return;
+ }
+ } else {
+ com.destroystokyo.paper.event.player.PlayerStartSpectatingEntityEvent playerStartSpectatingEntityEvent = new com.destroystokyo.paper.event.player.PlayerStartSpectatingEntityEvent(this.getBukkitEntity(), entity1.getBukkitEntity(), newSpectatorTarget.getBukkitEntity());
+
+ if (!playerStartSpectatingEntityEvent.callEvent()) {
+ return;
+ }
+ }
+
+ setSpectatorTargetField(newSpectatorTarget);
+
+ this.playerConnection.sendPacket(new PacketPlayOutCamera(newSpectatorTarget));
+ this.playerConnection.a(this.spectatedEntity.locX(), this.spectatedEntity.locY(), this.spectatedEntity.locZ(), this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
+ // Paper end
}
@Override
@@ -1602,7 +1622,6 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
if (this.portalCooldown > 0 && !this.worldChangeInvuln) {
--this.portalCooldown;
}
-
}
@Override

Datei anzeigen

@ -17,10 +17,10 @@ index 4609e402b419ed21e17ad34d02dca55b47c1c95e..ce0eadbae95a9f6b4e5a46a9d0ee1ccf
return 300;
}
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index bc62a9f08e9eb39dc20a69f397bc74eab13031a9..cf71ad016a028a539e3d7155ad44408ac851473e 100644
index 3175b0735f3b5f4d7e3e02dc083d32262d463de7..8c1cd0673e4b070ebbc9ecf7d9d4acf01d33ba3b 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -1862,6 +1862,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -1887,6 +1887,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
this.setHealth(this.getMaxHealth());

Datei anzeigen

@ -5,10 +5,10 @@ Subject: [PATCH] Don't allow digging into unloaded chunks
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index bde60377ee6e48aad61d36b8e1401cb770986d9f..b21fca9e5c98bd23c8553dd7c19a4ed6a83cae9a 100644
index fe25754521d5cf7059130f14acaf61a6646c5360..ab94132590e3743e45ca345c3e30b811e5c54dfd 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1272,6 +1272,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -1273,6 +1273,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK:
case STOP_DESTROY_BLOCK:

Datei anzeigen

@ -6,10 +6,10 @@ Subject: [PATCH] Fix sign edit memory leak
when a player edits a sign, a reference to their Entity is never cleand up.
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 4b3ddfd9907969eb73856cd7298bad4b03c6fa96..2c94ca6a8e8a13959f2d89650587181060767b1a 100644
index e334a3d8fee12a0051a54e49b54e4533baa493e0..f2f7a958153acd6a595b0ca85efe0d8322305ffe 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2546,7 +2546,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -2547,7 +2547,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
TileEntitySign tileentitysign = (TileEntitySign) tileentity;

Datei anzeigen

@ -22,7 +22,7 @@ it only impacts data sent from the client.
Set -DPaper.maxSignLength=XX to change limit or -1 to disable
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 2c94ca6a8e8a13959f2d89650587181060767b1a..94d3d602ccd9bc8fdf82eb75f12b1bc39359e1f8 100644
index f2f7a958153acd6a595b0ca85efe0d8322305ffe..dca5e1363a8a850a8363cccab360109bd359aea5 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -103,6 +103,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
@ -33,7 +33,7 @@ index 2c94ca6a8e8a13959f2d89650587181060767b1a..94d3d602ccd9bc8fdf82eb75f12b1bc3
private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
@@ -2562,6 +2563,15 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -2563,6 +2564,15 @@ public class PlayerConnection implements PacketListenerPlayIn {
String[] lines = new String[4];
for (int i = 0; i < astring.length; ++i) {

Datei anzeigen

@ -22,10 +22,10 @@ index 3ff7a7b4a853068eba2fb034246a58116a846523..3a88c9a67062eb73ad8257ea786efca7
this.f.accept(packet);
if (this.tracker instanceof EntityPlayer) {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 94d3d602ccd9bc8fdf82eb75f12b1bc39359e1f8..f496006f3cc373ec2c9d8ef73d38389c6574d90b 100644
index dca5e1363a8a850a8363cccab360109bd359aea5..de742d6a8c0a28d524850288eb4e2e548237d61e 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2006,7 +2006,14 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -2007,7 +2007,14 @@ public class PlayerConnection implements PacketListenerPlayIn {
if (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != origItem) {
// Refresh the current entity metadata

Datei anzeigen

@ -599,7 +599,7 @@ index 32bea1dea9ebb05ed94f5b47e6ad2145f6319431..7a4e2c350e78b22dc035471ad0d7191d
}
}
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index f375c9507c0ec0c2f810f8fff5304e70e02b7064..fcd887ce30dac081712811d740049d03c73db83d 100644
index 57b393c22448910c3ecc34353c3aa8480c58c074..3db173fb5559e62150192a28dbdccdff16787401 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -81,6 +81,11 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@ -622,7 +622,7 @@ index f375c9507c0ec0c2f810f8fff5304e70e02b7064..fcd887ce30dac081712811d740049d03
}
// Yes, this doesn't match Vanilla, but it's the best we can do for now.
@@ -1766,6 +1772,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -1791,6 +1797,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}

Datei anzeigen

@ -19,10 +19,10 @@ index 24594aa0e9b8741811acfc9f84f4db7552832bd2..aada8d3b08b437f81f68f8e988412c10
if (enumhand == EnumHand.MAIN_HAND) {
return this.getEquipment(EnumItemSlot.MAINHAND);
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index cf3e15e70ac22bbdd39153956cfdc6d2f8f44e2b..fd2b5148f885b79d7779ee1a04bfc4a445b2b618 100644
index 6ba6fd6157985ae9d7bb048c2d42b268d08697bc..c2820d45b1b0b95dff5112105f33cf423fb858cb 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1437,6 +1437,10 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -1438,6 +1438,10 @@ public class PlayerConnection implements PacketListenerPlayIn {
if (cancelled) {
this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
} else {

Datei anzeigen

@ -5,10 +5,10 @@ Subject: [PATCH] Prevent teleporting dead entities
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index fd2b5148f885b79d7779ee1a04bfc4a445b2b618..f675892e45b033cac5cbb6d86b70ba38bf67ebb3 100644
index c2820d45b1b0b95dff5112105f33cf423fb858cb..1673e5b8f13978cd4a47555b9806d801cbbdf3c8 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1216,6 +1216,10 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -1217,6 +1217,10 @@ public class PlayerConnection implements PacketListenerPlayIn {
}
private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<PacketPlayOutPosition.EnumPlayerTeleportFlags> set) {

Datei anzeigen

@ -5,7 +5,7 @@ Subject: [PATCH] Prevent opening inventories when frozen
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index d51af68a92021e4f45631805529424831ca9b090..f453ccdb020e911d84658f630a289612e1557db4 100644
index 4e4c0acc6c103c85b7ba2a390a54d3513939d547..49fe2d1a0376e5aa8a5ec00d010e6c834633e7b7 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -380,7 +380,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@ -26,7 +26,7 @@ index d51af68a92021e4f45631805529424831ca9b090..f453ccdb020e911d84658f630a289612
// CraftBukkit end
container.addSlotListener(this);
return OptionalInt.of(this.containerCounter);
@@ -1908,7 +1908,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -1933,7 +1933,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
@Override

Datei anzeigen

@ -98,7 +98,7 @@ index c4d433430503e844121f1917c6caf05823af0a34..7df24be46e4471ae0ddad5cded5eef49
protected static final DataWatcherObject<NBTTagCompound> bs = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.p);
protected static final DataWatcherObject<NBTTagCompound> bt = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.p);
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index f453ccdb020e911d84658f630a289612e1557db4..bf2ba0548d93280651d89c2039a298c56a83b0bf 100644
index 49fe2d1a0376e5aa8a5ec00d010e6c834633e7b7..64e00275edf38739fe6e2d79dbcb93243e765678 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -2,6 +2,7 @@ package net.minecraft.server;
@ -116,7 +116,7 @@ index f453ccdb020e911d84658f630a289612e1557db4..bf2ba0548d93280651d89c2039a298c5
- private boolean ci = true;
+ private boolean ci = true; public boolean hasChatColorsEnabled() { return this.ci; } // Paper - OBFHELPER
private long cj = SystemUtils.getMonotonicMillis();
private Entity spectatedEntity; private void setSpectatorTargetField(Entity e) { this.spectatedEntity = e; } // Paper - OBFHELPER
private Entity spectatedEntity;
public boolean worldChangeInvuln;
@@ -1573,6 +1574,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}

Datei anzeigen

@ -13,7 +13,7 @@ it is triggering a massive movement velocity.
This will ensure that the servers position is synchronized anytime player is teleported.
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 066438f4ace35310d363e856a22e2f8b48445768..38775d0eec4b6e25f5b2b39e85463190dee92515 100644
index 625479b97adf19df67f04dcbe445d78bccb0fc2c..f692276617d9c24ded5e887090e00642b0d63eba 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -498,6 +498,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
@ -24,7 +24,7 @@ index 066438f4ace35310d363e856a22e2f8b48445768..38775d0eec4b6e25f5b2b39e85463190
if (this.player.H()) {
this.player.I();
}
@@ -1276,6 +1277,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
@@ -1277,6 +1278,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
this.A = this.e;
this.player.setLocation(d0, d1, d2, f, f1);