From 74708914f33808845ac0f34f0177f3eb8a7c12b3 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 6 Mar 2024 14:02:28 +0100 Subject: [PATCH] Expands hit-box for END_GATEWAY for players with Bedrock names (WIP) --- .../listener/PlayerEventListener.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 04323e3..462357c 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -41,6 +41,7 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * This listener listens to any player-related events related to stargates @@ -176,16 +177,10 @@ public class PlayerEventListener implements Listener { return false; } - //Check if the player moved from a portal - Portal entrancePortal = PortalHandler.getByEntrance(toLocation); + //Get the portal the player entered, if any + Portal entrancePortal = getEnteredPortal(toLocation, player); if (entrancePortal == null) { - //Check an additional block away for BungeeCord portals using END_PORTAL as its material - entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation); - if (entrancePortal == null || !entrancePortal.getOptions().isBungee() || - !MaterialHelper.specifiersToMaterials( - entrancePortal.getGate().getPortalOpenMaterials()).contains(Material.END_PORTAL)) { - return false; - } + return false; } Portal destination = entrancePortal.getPortalActivator().getDestination(player); @@ -212,6 +207,36 @@ public class PlayerEventListener implements Listener { return TeleportHelper.noLeashedCreaturesPreventTeleportation(player); } + /** + * Gets the portal a player entered + * + * @param toLocation

The location the player moved to

+ * @param player

The player that moved

+ * @return

The portal the player entered, or null if no portal was entered

+ */ + private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) { + Portal entrancePortal = PortalHandler.getByEntrance(toLocation); + // Return if in an entrance + if (entrancePortal != null) { + return entrancePortal; + } + + //Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material + entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation); + if (entrancePortal == null) { + return null; + } + + Set entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials()); + + if ((player.getName().matches("^[a-zA-Z0-9_]{2,16}$") || !entranceMaterials.contains(Material.END_GATEWAY)) && + (!entrancePortal.getOptions().isBungee() || !entranceMaterials.contains(Material.END_PORTAL))) { + return null; + } + + return entrancePortal; + } + /** * This event handler detects if a player clicks a button or a sign *