From acb9c231494dfef697dc11fd956107483f7f0ee8 Mon Sep 17 00:00:00 2001 From: Allink <44676012+allinkdev@users.noreply.github.com> Date: Tue, 5 Jul 2022 15:32:47 +0100 Subject: [PATCH] Add spectator teleport event (#27) --- .../0002-Add-spectator-teleport-event.patch | 73 +++++++++++++++++++ .../0034-Add-spectator-teleport-event.patch | 32 ++++++++ 2 files changed, 105 insertions(+) create mode 100644 patches/api/0002-Add-spectator-teleport-event.patch create mode 100644 patches/server/0034-Add-spectator-teleport-event.patch diff --git a/patches/api/0002-Add-spectator-teleport-event.patch b/patches/api/0002-Add-spectator-teleport-event.patch new file mode 100644 index 0000000..4622e4a --- /dev/null +++ b/patches/api/0002-Add-spectator-teleport-event.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Allink +Date: Tue, 5 Jul 2022 03:59:18 +0100 +Subject: [PATCH] Add spectator teleport event + + +diff --git a/src/main/java/com/github/atlasmediagroup/scissors/event/player/SpectatorTeleportEvent.java b/src/main/java/com/github/atlasmediagroup/scissors/event/player/SpectatorTeleportEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..6941549c8f15177569f9ce7243b73255c7c5988e +--- /dev/null ++++ b/src/main/java/com/github/atlasmediagroup/scissors/event/player/SpectatorTeleportEvent.java +@@ -0,0 +1,61 @@ ++package com.github.atlasmediagroup.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) ++ { ++ System.out.println("[DEBUG] Spectator teleport event called!"); ++ 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; ++ } ++} diff --git a/patches/server/0034-Add-spectator-teleport-event.patch b/patches/server/0034-Add-spectator-teleport-event.patch new file mode 100644 index 0000000..60dafb9 --- /dev/null +++ b/patches/server/0034-Add-spectator-teleport-event.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Allink +Date: Tue, 5 Jul 2022 04:00:42 +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 1901a14556b197b70a2e8bb46d07a216d5d6c07e..047eef16aa457757f968e2210dcba03207cf7448 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 com.github.atlasmediagroup.scissors.event.player.SpectatorTeleportEvent; + import com.google.common.collect.Lists; + import com.google.common.primitives.Floats; + import com.mojang.brigadier.ParseResults; +@@ -1948,6 +1949,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; + }