Blocks 1-block END_GATEWAY teleportation events which prevented sneaking from triggering a teleportation
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good

This commit is contained in:
2026-01-23 13:18:02 +01:00
parent bbb5c5184e
commit 07463f77d9

View File

@@ -63,18 +63,25 @@ public class StargateTeleportListener implements Listener {
*
* @param event <p>The event to check and possibly cancel</p>
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
PlayerTeleportEvent.TeleportCause cause = event.getCause();
//Block normal portal teleportation if teleporting from a stargate
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
if ((cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
Stargate.debug("StargateTeleportListener::onPlayerTeleport",
"Cancelled vanilla portal event to " + event.getTo());
event.setCancelled(true);
}
// Cancel end gateway teleportation to the same destination
if (event.getTo() != null && cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY &&
PortalHandler.getByAdjacentEntrance(event.getFrom()) != null &&
event.getFrom().distance(event.getTo()) <= 1) {
event.setCancelled(true);
}
}
/**
@@ -466,8 +473,10 @@ public class StargateTeleportListener implements Listener {
*/
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
// Return if in an entrance
if (entrancePortal != null) {
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered portal " + entrancePortal);
return entrancePortal;
}
@@ -477,6 +486,8 @@ public class StargateTeleportListener implements Listener {
return null;
}
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered adjacent portal " + entrancePortal);
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {