Prevents teleportation of players holding one or more creatures on a leash if handleLeashedCreatures is disabled
This commit is contained in:
parent
6ddc15eeef
commit
bab51d76fd
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()) {
|
||||
if (!canAffordFee) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
}
|
||||
return canAffordFee;
|
||||
return false;
|
||||
}
|
||||
|
||||
return Teleporter.noLeashedCreaturesPreventTeleportation(player, entrancePortal.getOptions().isSilent());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -250,9 +250,35 @@ public abstract class Teleporter {
|
||||
return chunksToLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has leashed creatures that block the teleportation
|
||||
*
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @param silent <p>Whether the entrance portal is silent</p>
|
||||
* @return <p>False if the player has leashed any creatures that cannot go through the portal</p>
|
||||
*/
|
||||
public static boolean noLeashedCreaturesPreventTeleportation(Player player, boolean silent) {
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> 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
|
||||
*
|
||||
* <p>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.</p>
|
||||
*
|
||||
* @param player <p>The player which is teleported</p>
|
||||
* @param origin <p>The portal the player is teleporting from</p>
|
||||
*/
|
||||
@ -264,6 +290,7 @@ public abstract class Teleporter {
|
||||
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> 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 <p>The player to check</p>
|
||||
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
||||
*/
|
||||
protected List<Creature> getLeashedCreatures(Player player) {
|
||||
protected static List<Creature> getLeashedCreatures(Player player) {
|
||||
List<Creature> leashedCreatures = new ArrayList<>();
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
||||
|
Loading…
x
Reference in New Issue
Block a user