From fb826f722117ed872e69edb25d6e088dbbe4152a Mon Sep 17 00:00:00 2001 From: Caleb Bassham Date: Fri, 28 Sep 2018 02:30:56 -0500 Subject: [PATCH] Add spectator target events - PlayerStartSpectatingEntityEvent - PlayerStopSpectatingEntityEvent --- .../PlayerStartSpectatingEntityEvent.java | 68 +++++++++++++++++++ .../PlayerStopSpectatingEntityEvent.java | 55 +++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java create mode 100644 paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java new file mode 100644 index 0000000000..5ce2f30c09 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStartSpectatingEntityEvent.java @@ -0,0 +1,68 @@ +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; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Triggered when a player starts spectating an entity in spectator mode. + */ +@NullMarked +public class PlayerStartSpectatingEntityEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Entity currentSpectatorTarget; + private final Entity newSpectatorTarget; + + private boolean cancelled; + + @ApiStatus.Internal + public PlayerStartSpectatingEntityEvent(final Player player, final Entity currentSpectatorTarget, final 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 this.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 this.newSpectatorTarget; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(final boolean cancel) { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} + diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java new file mode 100644 index 0000000000..ebda87b791 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/player/PlayerStopSpectatingEntityEvent.java @@ -0,0 +1,55 @@ +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; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Triggered when a player stops spectating an entity in spectator mode. + */ +@NullMarked +public class PlayerStopSpectatingEntityEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Entity spectatorTarget; + private boolean cancelled; + + @ApiStatus.Internal + public PlayerStopSpectatingEntityEvent(final Player player, final 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 this.spectatorTarget; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(final boolean cancel) { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +}