2023-03-14 20:24:52 +01:00
|
|
|
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
|
2024-08-14 21:26:38 +02:00
|
|
|
index fa8640f961b93dc811296131dfda58faa1908add..15328d344a26f5c40011ee6ba0bc54dd5ab0b87b 100644
|
2023-03-14 20:24:52 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-08-14 21:26:38 +02:00
|
|
|
@@ -2182,6 +2182,21 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
2023-03-14 20:24:52 +01:00
|
|
|
|
|
|
|
this.camera = (Entity) (entity == null ? this : entity);
|
|
|
|
if (entity1 != this.camera) {
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper start - Add PlayerStartSpectatingEntityEvent and PlayerStopSpectatingEntity
|
2023-03-14 20:24:52 +01:00
|
|
|
+ if (this.camera == this) {
|
|
|
|
+ com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent playerStopSpectatingEntityEvent = new com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent(this.getBukkitEntity(), entity1.getBukkitEntity());
|
|
|
|
+ if (!playerStopSpectatingEntityEvent.callEvent()) {
|
2023-10-29 02:45:07 +02:00
|
|
|
+ this.camera = entity1; // rollback camera entity again
|
2023-03-14 20:24:52 +01:00
|
|
|
+ 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()) {
|
2023-10-29 02:45:07 +02:00
|
|
|
+ this.camera = entity1; // rollback camera entity again
|
2023-03-14 20:24:52 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
2024-01-21 13:56:22 +01:00
|
|
|
+ // Paper end - Add PlayerStartSpectatingEntityEvent and PlayerStopSpectatingEntity
|
2023-06-07 22:41:26 +02:00
|
|
|
Level world = this.camera.level();
|
2023-03-14 20:24:52 +01:00
|
|
|
|
|
|
|
if (world instanceof ServerLevel) {
|