Expands hit-box for END_GATEWAY for players with Bedrock names (WIP)

This commit is contained in:
2024-03-06 14:02:28 +01:00
parent c2ab3dd8b2
commit 74708914f3

View File

@@ -41,6 +41,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* This listener listens to any player-related events related to stargates * This listener listens to any player-related events related to stargates
@@ -176,16 +177,10 @@ public class PlayerEventListener implements Listener {
return false; return false;
} }
//Check if the player moved from a portal //Get the portal the player entered, if any
Portal entrancePortal = PortalHandler.getByEntrance(toLocation); Portal entrancePortal = getEnteredPortal(toLocation, player);
if (entrancePortal == null) { if (entrancePortal == null) {
//Check an additional block away for BungeeCord portals using END_PORTAL as its material return false;
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
if (entrancePortal == null || !entrancePortal.getOptions().isBungee() ||
!MaterialHelper.specifiersToMaterials(
entrancePortal.getGate().getPortalOpenMaterials()).contains(Material.END_PORTAL)) {
return false;
}
} }
Portal destination = entrancePortal.getPortalActivator().getDestination(player); Portal destination = entrancePortal.getPortalActivator().getDestination(player);
@@ -212,6 +207,36 @@ public class PlayerEventListener implements Listener {
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player); return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
} }
/**
* Gets the portal a player entered
*
* @param toLocation <p>The location the player moved to</p>
* @param player <p>The player that moved</p>
* @return <p>The portal the player entered, or null if no portal was entered</p>
*/
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<Material> 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 * This event handler detects if a player clicks a button or a sign
* *