Paper/Spigot-API-Patches/0165-Add-spectator-target-events.patch
Caleb Bassham 3b358452ba Add events for player changing spectator target (#1498)
* Add events for player changing spectator target

- Add PlayerStartSpectatingEntityEvent
- Add PlayerStopSpectatingEntityEvent
2018-10-18 16:53:10 -04:00

136 lines
4.1 KiB
Diff

From 44a47707ed4cc9e39a4e054061e8b58c6eb02790 Mon Sep 17 00:00:00 2001
From: Caleb Bassham <caleb.bassham@gmail.com>
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