geforkt von Mirrors/Paper
f6636fca9e
Upstream has released updates that appear 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: ebb0e28d #631: Add Villager#shakeHead 751469c6 #629: Add LivingEntity#isClimbing CraftBukkit Changes: 622cf611 SPIGOT-6555: Cannot access shield BlockStateMeta 8b2e78ec SPIGOT-6542: Fix counting players with fauxSleeping = true f66c437a SPIGOT-6561: Add events for dripleaf tilting 6ed40004 SPIGOT-6560: Crash when falling stalactite hits player 72a2901b SPIGOT-6557: PlayerEditBookEvent#setNewBookMeta does not update meta a07e783a #865: Implement Villager#shakeHead 3252ff18 #863: Add LivingEntity#isClimbing 77058c79 SPIGOT-6554: Worlds created with the bukkit ChunkGenerator cannot save
109 Zeilen
5.9 KiB
Diff
109 Zeilen
5.9 KiB
Diff
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/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 76be554b8266f1cb2b2eebb4db9777bda727f421..e6b64def52915114edb7a5e53fdc8816afd809a9 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1822,14 +1822,58 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
public void setCamera(Entity entity) {
|
|
+ // Paper start - Add PlayerStartSpectatingEntityEvent and PlayerStopSpectatingEntity Event and improve implementation
|
|
Entity entity1 = this.getCamera();
|
|
|
|
- this.camera = (Entity) (entity == null ? this : entity);
|
|
- if (entity1 != this.camera) {
|
|
- this.connection.send(new ClientboundSetCameraPacket(this.camera));
|
|
- this.connection.b(this.camera.getX(), this.camera.getY(), this.camera.getZ(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
|
|
+ if (entity == null) {
|
|
+ entity = this;
|
|
}
|
|
|
|
+ if (entity1 == entity) return; // new spec target is the current spec target
|
|
+
|
|
+ if (entity == 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(), entity.getBukkitEntity());
|
|
+
|
|
+ if (!playerStartSpectatingEntityEvent.callEvent()) {
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // Validate
|
|
+ if (entity != this) {
|
|
+ if (entity.isRemoved() || !entity.valid || entity.level == null) {
|
|
+ MinecraftServer.LOGGER.info("Blocking player " + this.toString() + " from spectating invalid entity " + entity.toString());
|
|
+ return;
|
|
+ }
|
|
+ if (this.isImmobile()) {
|
|
+ // use debug: clients might maliciously spam this
|
|
+ MinecraftServer.LOGGER.debug("Blocking frozen player " + this.toString() + " from spectating entity " + entity.toString());
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ this.camera = entity; // only set after validating state
|
|
+
|
|
+ if (entity != this) {
|
|
+ // Make sure we're in the right place
|
|
+ this.ejectPassengers(); // teleport can fail if we have passengers...
|
|
+ this.getBukkitEntity().teleport(new Location(entity.getCommandSenderWorld().getWorld(), entity.getX(), entity.getY(), entity.getZ(), this.getYRot(), this.getXRot()), TeleportCause.SPECTATE); // Correctly handle cross-world entities from api calls by using CB teleport
|
|
+
|
|
+ // Make sure we're tracking the entity before sending
|
|
+ ChunkMap.TrackedEntity tracker = ((ServerLevel)entity.level).getChunkSource().chunkMap.entityMap.get(entity.getId());
|
|
+ if (tracker != null) { // dumb plugins...
|
|
+ tracker.updatePlayer(this);
|
|
+ }
|
|
+ } else {
|
|
+ this.connection.teleport(this.camera.getX(), this.camera.getY(), this.camera.getZ(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
|
|
+ }
|
|
+ this.connection.send(new ClientboundSetCameraPacket(entity));
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 2917632c5e974dbfb7d78c497ebd49e742b8ef3c..deb6352604b7cbda7de9df0d654410399f4ce159 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1068,7 +1068,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
}
|
|
}
|
|
|
|
- private void a(List<TextFilter.FilteredText> list, UnaryOperator<String> unaryoperator, ItemStack itemstack, int slot, ItemStack handItem) { // CraftBukkit
|
|
+ public void a(List<TextFilter.FilteredText> list, UnaryOperator<String> unaryoperator, ItemStack itemstack, int slot, ItemStack handItem) { // CraftBukkit // Paper - make public
|
|
ListTag nbttaglist = new ListTag();
|
|
|
|
if (this.player.isTextFilteringEnabled()) {
|
|
@@ -1381,6 +1381,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
this.a(x, y, z, yaw, pitch, PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
|
}
|
|
|
|
+ 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.emptySet(), true, cause);
|
|
}
|