Add spectator teleport event (#28)

This commit is contained in:
Allink 2022-07-05 19:52:02 +01:00 committed by GitHub
parent df406d6f6d
commit bc4782d2d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,72 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Tue, 5 Jul 2022 04:10:29 +0100
Subject: [PATCH] Add spectator teleport event
diff --git a/src/main/java/me/totalfreedom/scissors/event/player/SpectatorTeleportEvent.java b/src/main/java/me/totalfreedom/scissors/event/player/SpectatorTeleportEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..d7efa63c316ed99c3eccfeadc1b0873b2ccb5d8a
--- /dev/null
+++ b/src/main/java/me/totalfreedom/scissors/event/player/SpectatorTeleportEvent.java
@@ -0,0 +1,60 @@
+package me.totalfreedom.scissors.event.player;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called whenever a spectator attempts to teleport to an entity
+ */
+public class SpectatorTeleportEvent extends Event implements Cancellable
+{
+ private static final HandlerList handlerList = new HandlerList();
+ private final Player player;
+ private final Entity target;
+ private boolean cancelled;
+
+ public SpectatorTeleportEvent(@NotNull Player player, @NotNull Entity target)
+ {
+ this.player = player;
+ this.target = target;
+ }
+
+ @NotNull
+ public Player getPlayer() {
+ return this.player;
+ }
+
+ @NotNull
+ public Entity getTarget() {
+ return this.target;
+ }
+
+ @Override
+ public boolean isCancelled()
+ {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancelled)
+ {
+ this.cancelled = cancelled;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers()
+ {
+ return handlerList;
+ }
+
+ @NotNull
+ public static org.bukkit.event.HandlerList getHandlerList()
+ {
+ return handlerList;
+ }
+}

View file

@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Tue, 5 Jul 2022 04:12:31 +0100
Subject: [PATCH] Add spectator teleport event
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 1416ab1cf80b53db1bc0f1485777b74cdb6bcf59..d053c7547db965cd103a6edf56916f3c6e98a673 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1,5 +1,6 @@
package net.minecraft.server.network;
+import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent;
import com.google.common.collect.Lists;
import com.google.common.primitives.Floats;
import com.mojang.brigadier.ParseResults;
@@ -1979,6 +1980,14 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
Entity entity = packet.getEntity(worldserver);
if (entity != null) {
+ // Scissors start - Add spectator teleport event
+ final SpectatorTeleportEvent event = new SpectatorTeleportEvent(this.player.getBukkitEntity(), entity.getBukkitEntity());
+
+ if(!event.callEvent()) {
+ return;
+ }
+ // Scissors end
+
this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
return;
}