mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
port Add EntityTeleportHinderedEvent patch
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Mariell Hoversholm <proximyst@proximyst.com>
|
||||
Date: Sat, 9 Jan 2021 15:26:04 +0100
|
||||
Subject: [PATCH] Add EntityTeleportHinderedEvent
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/event/entity/EntityTeleportHinderedEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/EntityTeleportHinderedEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..daf3bbf83ee76322828a38814b483fa2b337bd60
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/event/entity/EntityTeleportHinderedEvent.java
|
||||
@@ -0,0 +1,114 @@
|
||||
+package org.purpurmc.purpur.event.entity;
|
||||
+
|
||||
+import org.bukkit.entity.Entity;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.entity.EntityEvent;
|
||||
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * Fired when an entity is hindered from teleporting.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public class EntityTeleportHinderedEvent extends EntityEvent {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ private final Reason reason;
|
||||
+
|
||||
+ private final @Nullable TeleportCause teleportCause;
|
||||
+
|
||||
+ private boolean retry = false;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public EntityTeleportHinderedEvent(Entity what, Reason reason, @Nullable TeleportCause teleportCause) {
|
||||
+ super(what);
|
||||
+ this.reason = reason;
|
||||
+ this.teleportCause = teleportCause;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @return why the teleport was hindered.
|
||||
+ */
|
||||
+ public Reason getReason() {
|
||||
+ return reason;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @return why the teleport occurred if cause was given, otherwise {@code null}.
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public TeleportCause getTeleportCause() {
|
||||
+ return teleportCause;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Whether the teleport should be retried.
|
||||
+ * <p>
|
||||
+ * Note that this can put the server in a never-ending loop of trying to teleport someone resulting in a stack
|
||||
+ * overflow. Do not retry more than necessary.
|
||||
+ * </p>
|
||||
+ *
|
||||
+ * @return whether the teleport should be retried.
|
||||
+ */
|
||||
+ public boolean shouldRetry() {
|
||||
+ return retry;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets whether the teleport should be retried.
|
||||
+ * <p>
|
||||
+ * Note that this can put the server in a never-ending loop of trying to teleport someone resulting in a stack
|
||||
+ * overflow. Do not retry more than necessary.
|
||||
+ * </p>
|
||||
+ *
|
||||
+ * @param retry whether the teleport should be retried.
|
||||
+ */
|
||||
+ public void setShouldRetry(boolean retry) {
|
||||
+ this.retry = retry;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Calls the event and tests if should retry.
|
||||
+ *
|
||||
+ * @return whether the teleport should be retried.
|
||||
+ */
|
||||
+ @Override
|
||||
+ public boolean callEvent() {
|
||||
+ super.callEvent();
|
||||
+ return shouldRetry();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Reason for hindrance in teleports.
|
||||
+ */
|
||||
+ public enum Reason {
|
||||
+ /**
|
||||
+ * The teleported entity is a passenger of another entity.
|
||||
+ */
|
||||
+ IS_PASSENGER,
|
||||
+
|
||||
+ /**
|
||||
+ * The teleported entity has passengers.
|
||||
+ */
|
||||
+ IS_VEHICLE,
|
||||
+
|
||||
+ /**
|
||||
+ * The teleport event was cancelled.
|
||||
+ * <p>
|
||||
+ * This is only caused by players teleporting.
|
||||
+ * </p>
|
||||
+ */
|
||||
+ EVENT_CANCELLED,
|
||||
+ }
|
||||
+}
|
||||
@@ -1,121 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Mariell Hoversholm <proximyst@proximyst.com>
|
||||
Date: Sat, 9 Jan 2021 15:27:46 +0100
|
||||
Subject: [PATCH] Add EntityTeleportHinderedEvent
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/EndGatewayBlock.java b/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
index af46f2885ead1e3ec1734504d8ba134c886e04fb..47ee0538c8ea94136b2416c324c8a264e54d2c09 100644
|
||||
--- a/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
+++ b/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
@@ -104,6 +104,13 @@ public class EndGatewayBlock extends BaseEntityBlock implements Portal {
|
||||
TheEndGatewayBlockEntity tileentityendgateway = (TheEndGatewayBlockEntity) tileentity;
|
||||
|
||||
if (!tileentityendgateway.isCoolingDown()) {
|
||||
+ // Purpur start
|
||||
+ if (world.purpurConfig.imposeTeleportRestrictionsOnGateways && (entity.isVehicle() || entity.isPassenger())) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, PlayerTeleportEvent.TeleportCause.END_GATEWAY).callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end
|
||||
entity.setAsInsidePortal(this, pos);
|
||||
TheEndGatewayBlockEntity.triggerCooldown(world, pos, state, tileentityendgateway);
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/block/EndPortalBlock.java b/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
index 8cb4142562db0be1f1a7d961ec5a10d4abf31692..84ecb012cb0a47e47799dc73c7fadc75f462f47a 100644
|
||||
--- a/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
+++ b/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
@@ -70,6 +70,13 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
|
||||
protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
|
||||
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
|
||||
if (entity.canUsePortal(false)) {
|
||||
+ // Purpur start
|
||||
+ if (world.purpurConfig.imposeTeleportRestrictionsOnEndPortals && (entity.isVehicle() || entity.isPassenger())) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, PlayerTeleportEvent.TeleportCause.END_PORTAL).callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end
|
||||
// CraftBukkit start - Entity in portal
|
||||
EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.ENDER); // Paper - add portal type
|
||||
world.getCraftServer().getPluginManager().callEvent(event);
|
||||
diff --git a/net/minecraft/world/level/block/NetherPortalBlock.java b/net/minecraft/world/level/block/NetherPortalBlock.java
|
||||
index 3e9642e5236d9a1cc8e8f3b375d76810f4bc7c6c..5169cba4c43d80ce3597c57bf7d40bd0148ec8a0 100644
|
||||
--- a/net/minecraft/world/level/block/NetherPortalBlock.java
|
||||
+++ b/net/minecraft/world/level/block/NetherPortalBlock.java
|
||||
@@ -117,6 +117,13 @@ public class NetherPortalBlock extends Block implements Portal {
|
||||
protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
|
||||
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
|
||||
if (entity.canUsePortal(false)) {
|
||||
+ // Purpur start
|
||||
+ if (world.purpurConfig.imposeTeleportRestrictionsOnNetherPortals && (entity.isVehicle() || entity.isPassenger())) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.NETHER_PORTAL).callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end
|
||||
// CraftBukkit start - Entity in portal
|
||||
EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.NETHER); // Paper - add portal type
|
||||
world.getCraftServer().getPluginManager().callEvent(event);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
index c105d0cce462df46e106eb502355225b83be32b7..51772356a3c64da7b29fa204ffec03a70cd4406a 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
@@ -246,6 +246,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
boolean ignorePassengers = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS);
|
||||
// Don't allow teleporting between worlds while keeping passengers
|
||||
if (flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS) && this.entity.isVehicle() && location.getWorld() != this.getWorld()) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, cause).callEvent()) // Purpur
|
||||
return false;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index 16671636da1b6da62a0bdf0daab745fcd89143b7..ea8b1f01b2dd626c422649488c1e605a8054dbf2 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
@@ -1449,6 +1449,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
// Paper start - Teleport passenger API
|
||||
// Don't allow teleporting between worlds while keeping passengers
|
||||
if (ignorePassengers && entity.isVehicle() && location.getWorld() != this.getWorld()) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, cause).callEvent()) // Purpur start
|
||||
return false;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index a71a380f20dad2f43183d128e7a487420248a671..07bbe52a858fa3f0cc9c9de709bf2ef013ac33f5 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -125,6 +125,9 @@ public class PurpurWorldConfig {
|
||||
public boolean fireballsBypassMobGriefing = false;
|
||||
public boolean projectilesBypassMobGriefing = false;
|
||||
public boolean noteBlockIgnoreAbove = false;
|
||||
+ public boolean imposeTeleportRestrictionsOnGateways = false;
|
||||
+ public boolean imposeTeleportRestrictionsOnNetherPortals = false;
|
||||
+ public boolean imposeTeleportRestrictionsOnEndPortals = false;
|
||||
private void miscGameplayMechanicsSettings() {
|
||||
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
|
||||
boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
|
||||
@@ -140,6 +143,10 @@ public class PurpurWorldConfig {
|
||||
fireballsBypassMobGriefing = getBoolean("gameplay-mechanics.fireballs-bypass-mob-griefing", fireballsBypassMobGriefing);
|
||||
projectilesBypassMobGriefing = getBoolean("gameplay-mechanics.projectiles-bypass-mob-griefing", projectilesBypassMobGriefing);
|
||||
noteBlockIgnoreAbove = getBoolean("gameplay-mechanics.note-block-ignore-above", noteBlockIgnoreAbove);
|
||||
+ imposeTeleportRestrictionsOnGateways = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-gateways", imposeTeleportRestrictionsOnGateways);
|
||||
+ imposeTeleportRestrictionsOnNetherPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-nether-portals", imposeTeleportRestrictionsOnNetherPortals);
|
||||
+ imposeTeleportRestrictionsOnEndPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-end-portals", imposeTeleportRestrictionsOnEndPortals);
|
||||
+
|
||||
}
|
||||
|
||||
public int daytimeTicks = 12000;
|
||||
Reference in New Issue
Block a user