diff --git a/README.md b/README.md index b83466c..316ca8e 100644 --- a/README.md +++ b/README.md @@ -389,6 +389,11 @@ portalInfoServer=Server: %server% # Changes +#### \[Version 0.9.2.2] EpicKnarvik97 fork + +- Prevents teleportation of a player holding creatures on a leash when handleLeashedCreatures is disabled to prevent + players accidentally losing the creatures during teleportation + #### \[Version 0.9.2.1] EpicKnarvik97 fork - Makes sure to only reload whatever is necessary when config values are changed using commands, instead of reloading diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 70dc495..3477847 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -7,6 +7,7 @@ import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.PortalActivator; import net.knarcraft.stargate.portal.PortalHandler; import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter; +import net.knarcraft.stargate.portal.teleporter.Teleporter; import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter; import net.knarcraft.stargate.utility.BungeeHelper; import net.knarcraft.stargate.utility.MaterialHelper; @@ -170,7 +171,9 @@ public class PlayerEventListener implements Listener { } return false; } - return true; + + //Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled + return Teleporter.noLeashedCreaturesPreventTeleportation(player, entrancePortal.getOptions().isSilent()); } /** diff --git a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java index 1cbd0b3..1adc928 100644 --- a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java @@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener; import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.PortalHandler; +import net.knarcraft.stargate.portal.teleporter.Teleporter; import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter; import net.knarcraft.stargate.utility.EconomyHelper; import net.knarcraft.stargate.utility.EntityHelper; @@ -166,10 +167,14 @@ public class VehicleEventListener implements Listener { //Check if the player is able to afford the teleport fee int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal); boolean canAffordFee = cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost); - if (!canAffordFee && !entrancePortal.getOptions().isSilent()) { - Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds")); + if (!canAffordFee) { + if (!entrancePortal.getOptions().isSilent()) { + Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds")); + } + return false; } - return canAffordFee; + + return Teleporter.noLeashedCreaturesPreventTeleportation(player, entrancePortal.getOptions().isSilent()); } } diff --git a/src/main/java/net/knarcraft/stargate/portal/teleporter/Teleporter.java b/src/main/java/net/knarcraft/stargate/portal/teleporter/Teleporter.java index 06befad..314a100 100644 --- a/src/main/java/net/knarcraft/stargate/portal/teleporter/Teleporter.java +++ b/src/main/java/net/knarcraft/stargate/portal/teleporter/Teleporter.java @@ -250,9 +250,35 @@ public abstract class Teleporter { return chunksToLoad; } + /** + * Checks whether a player has leashed creatures that block the teleportation + * + * @param player

The player trying to teleport

+ * @param silent

Whether the entrance portal is silent

+ * @return

False if the player has leashed any creatures that cannot go through the portal

+ */ + public static boolean noLeashedCreaturesPreventTeleportation(Player player, boolean silent) { + //Find any nearby leashed entities to teleport with the player + List nearbyEntities = getLeashedCreatures(player); + + //If this feature is disabled, just return + if (!Stargate.getGateConfig().handleLeashedCreatures()) { + boolean isAllowed = nearbyEntities.isEmpty(); + if (!isAllowed && !silent) { + Stargate.getMessageSender().sendErrorMessage(player, "Leashed teleportation is disabled"); + } + return isAllowed; + } else { + return true; + } + } + /** * Teleports any creatures leashed by the player * + *

Will return false if the teleportation should be aborted because the player has leashed creatures that + * aren't allowed to be teleported with the player.

+ * * @param player

The player which is teleported

* @param origin

The portal the player is teleporting from

*/ @@ -264,6 +290,7 @@ public abstract class Teleporter { //Find any nearby leashed entities to teleport with the player List nearbyEntities = getLeashedCreatures(player); + //Teleport all creatures leashed by the player to the portal the player is to exit from for (Creature creature : nearbyEntities) { creature.setLeashHolder(null); @@ -280,7 +307,7 @@ public abstract class Teleporter { * @param player

The player to check

* @return

A list of all creatures the player is holding in a leash (lead)

*/ - protected List getLeashedCreatures(Player player) { + protected static List getLeashedCreatures(Player player) { List leashedCreatures = new ArrayList<>(); //Find any nearby leashed entities to teleport with the player List nearbyEntities = player.getNearbyEntities(15, 15, 15);