aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCaleb Bassham <[email protected]>2018-10-18 15:53:10 -0500
committerZach <[email protected]>2018-10-18 16:53:10 -0400
commit3b358452ba7f0c6420570091641b6dce59d050a4 (patch)
tree79be48d8d148013178bf8730e2cb20560e60a00a
parent42772e476a5a3c7296b76ace6626048cda668e21 (diff)
downloadPaper-3b358452ba7f0c6420570091641b6dce59d050a4.tar.gz
Paper-3b358452ba7f0c6420570091641b6dce59d050a4.zip
Add events for player changing spectator target (#1498)
* Add events for player changing spectator target - Add PlayerStartSpectatingEntityEvent - Add PlayerStopSpectatingEntityEvent
-rw-r--r--Spigot-API-Patches/0070-Add-PlayerArmorChangeEvent.patch4
-rw-r--r--Spigot-API-Patches/0165-Add-spectator-target-events.patch135
-rw-r--r--Spigot-Server-Patches/0398-Call-player-spectator-target-events.patch59
3 files changed, 196 insertions, 2 deletions
diff --git a/Spigot-API-Patches/0070-Add-PlayerArmorChangeEvent.patch b/Spigot-API-Patches/0070-Add-PlayerArmorChangeEvent.patch
index 87882fba9b..a40842efcd 100644
--- a/Spigot-API-Patches/0070-Add-PlayerArmorChangeEvent.patch
+++ b/Spigot-API-Patches/0070-Add-PlayerArmorChangeEvent.patch
@@ -1,4 +1,4 @@
-From 4ceb745753f3bb90b932daacc58c3fc104e8a795 Mon Sep 17 00:00:00 2001
+From 418c1570fa8d0784cfaadd1a7070143ef2de5241 Mon Sep 17 00:00:00 2001
From: pkt77 <[email protected]>
Date: Fri, 10 Nov 2017 23:45:59 -0500
Subject: [PATCH] Add PlayerArmorChangeEvent
@@ -146,5 +146,5 @@ index 00000000..0783ac82
+ }
+}
--
-2.18.0
+2.19.1
diff --git a/Spigot-API-Patches/0165-Add-spectator-target-events.patch b/Spigot-API-Patches/0165-Add-spectator-target-events.patch
new file mode 100644
index 0000000000..1a357fca76
--- /dev/null
+++ b/Spigot-API-Patches/0165-Add-spectator-target-events.patch
@@ -0,0 +1,135 @@
+From 44a47707ed4cc9e39a4e054061e8b58c6eb02790 Mon Sep 17 00:00:00 2001
+From: Caleb Bassham <[email protected]>
+Date: Fri, 28 Sep 2018 02:30:56 -0500
+Subject: [PATCH] Add spectator target events
+
+- PlayerStartSpectatingEntityEvent
+- PlayerStopSpectatingEntityEvent
+
+diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java
+new file mode 100644
+index 00000000..d3b7cc27
+--- /dev/null
++++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java
+@@ -0,0 +1,62 @@
++package com.destroystokyo.paper.event.player;
++
++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;
++
++/**
++ * Triggered when a player starts spectating an entity in spectator mode.
++ */
++public class PlayerStartSpectatingEntityEvent extends PlayerEvent implements Cancellable {
++
++ private static final HandlerList handlers = new HandlerList();
++ private boolean cancelled;
++ private final Entity currentSpectatorTarget;
++ private final Entity newSpectatorTarget;
++
++ public PlayerStartSpectatingEntityEvent(Player player, Entity currentSpectatorTarget, Entity newSpectatorTarget) {
++ super(player);
++ this.currentSpectatorTarget = currentSpectatorTarget;
++ this.newSpectatorTarget = newSpectatorTarget;
++ }
++
++ /**
++ * Gets the entity that the player is currently spectating or themselves if they weren't spectating anything
++ *
++ * @return The entity the player is currently spectating (before they start spectating the new target).
++ */
++ public Entity getCurrentSpectatorTarget() {
++ return currentSpectatorTarget;
++ }
++
++ /**
++ * Gets the new entity that the player will now be spectating
++ *
++ * @return The entity the player is now going to be spectating.
++ */
++ public Entity getNewSpectatorTarget() {
++ return newSpectatorTarget;
++ }
++
++ @Override
++ public boolean isCancelled() {
++ return cancelled;
++ }
++
++ @Override
++ public void setCancelled(boolean cancel) {
++ this.cancelled = cancel;
++ }
++
++ @Override
++ public HandlerList getHandlers() {
++ return handlers;
++ }
++
++ public static HandlerList getHandlerList() {
++ return handlers;
++ }
++}
++
+diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java
+new file mode 100644
+index 00000000..ce23caaf
+--- /dev/null
++++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java
+@@ -0,0 +1,50 @@
++package com.destroystokyo.paper.event.player;
++
++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;
++
++/**
++ * Triggered when a player stops spectating an entity in spectator mode.
++ */
++public class PlayerStopSpectatingEntityEvent extends PlayerEvent implements Cancellable {
++
++ private static final HandlerList handlers = new HandlerList();
++ private boolean cancelled;
++ private final Entity spectatorTarget;
++
++ public PlayerStopSpectatingEntityEvent(Player player, Entity spectatorTarget) {
++ super(player);
++ this.spectatorTarget = spectatorTarget;
++ }
++
++ /**
++ * Gets the entity that the player is spectating
++ *
++ * @return The entity the player is currently spectating (before they will stop).
++ */
++ public Entity getSpectatorTarget() {
++ return spectatorTarget;
++ }
++
++ @Override
++ public boolean isCancelled() {
++ return cancelled;
++ }
++
++ @Override
++ public void setCancelled(boolean cancel) {
++ this.cancelled = cancel;
++ }
++
++ @Override
++ public HandlerList getHandlers() {
++ return handlers;
++ }
++
++ public static HandlerList getHandlerList() {
++ return handlers;
++ }
++}
+--
+2.19.1
+
diff --git a/Spigot-Server-Patches/0398-Call-player-spectator-target-events.patch b/Spigot-Server-Patches/0398-Call-player-spectator-target-events.patch
new file mode 100644
index 0000000000..0f908a2620
--- /dev/null
+++ b/Spigot-Server-Patches/0398-Call-player-spectator-target-events.patch
@@ -0,0 +1,59 @@
+From 7b0e1ee3eb6ff96297023b8d32b32dc1627bfd9f Mon Sep 17 00:00:00 2001
+From: Caleb Bassham <[email protected]>
+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 5ab4e01ed..4ca5cfe9a 100644
+--- a/src/main/java/net/minecraft/server/EntityPlayer.java
++++ b/src/main/java/net/minecraft/server/EntityPlayer.java
+@@ -62,7 +62,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
+ private EntityHuman.EnumChatVisibility cs;
+ private boolean ct = true;
+ private long cu = SystemUtils.b();
+- private Entity cv;
++ private Entity cv; private void setSpectatorTargetField(Entity e) { this.cv = e; } // Paper - OBFHELPER
+ public boolean worldChangeInvuln;
+ private boolean cx; private void setHasSeenCredits(boolean has) { this.cx = has; } // Paper - OBFHELPER
+ private final RecipeBookServer cy;
+@@ -1373,15 +1373,33 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
+ return (Entity) (this.cv == null ? this : this.cv);
+ }
+
+- public void setSpectatorTarget(Entity entity) {
++ public void setSpectatorTarget(Entity newSpectatorTarget) {
+ Entity entity1 = this.getSpecatorTarget();
+
+- this.cv = (Entity) (entity == null ? this : entity);
+- if (entity1 != this.cv) {
++ if (newSpectatorTarget == null) {
++ newSpectatorTarget = this;
++ }
++
++ if (entity1 != newSpectatorTarget) {
++ 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;
++ }
++ }
++
+ this.playerConnection.sendPacket(new PacketPlayOutCamera(this.cv));
+ this.playerConnection.a(this.cv.locX, this.cv.locY, this.cv.locZ, this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit
+ }
+
++ setSpectatorTargetField(newSpectatorTarget);
+ }
+
+ protected void E() {
+--
+2.19.1
+