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
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
This commit is contained in:
@@ -63,18 +63,25 @@ public class StargateTeleportListener implements Listener {
|
|||||||
*
|
*
|
||||||
* @param event <p>The event to check and possibly cancel</p>
|
* @param event <p>The event to check and possibly cancel</p>
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
||||||
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
||||||
|
|
||||||
//Block normal portal teleportation if teleporting from a stargate
|
//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)
|
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
||||||
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||||
Stargate.debug("StargateTeleportListener::onPlayerTeleport",
|
Stargate.debug("StargateTeleportListener::onPlayerTeleport",
|
||||||
"Cancelled vanilla portal event to " + event.getTo());
|
"Cancelled vanilla portal event to " + event.getTo());
|
||||||
event.setCancelled(true);
|
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) {
|
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
||||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||||
|
|
||||||
// Return if in an entrance
|
// Return if in an entrance
|
||||||
if (entrancePortal != null) {
|
if (entrancePortal != null) {
|
||||||
|
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered portal " + entrancePortal);
|
||||||
return entrancePortal;
|
return entrancePortal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,6 +486,8 @@ public class StargateTeleportListener implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stargate.debug("StargateTeleportListener::getEnteredPortal", "Player entered adjacent portal " + entrancePortal);
|
||||||
|
|
||||||
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
||||||
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
||||||
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user