Moves some code to TeleportHelper
This commit is contained in:
parent
e7b711efcf
commit
8643a44df6
@ -23,8 +23,9 @@ public class CommandAbout implements CommandExecutor {
|
||||
commandSender.sendMessage(textColor + "Go to " + highlightColor +
|
||||
"https://git.knarcraft.net/EpicKnarvik97/Stargate " + textColor + "for the official repository");
|
||||
String author = Stargate.getStargateConfig().getLanguageLoader().getString("author");
|
||||
if (!author.isEmpty())
|
||||
if (!author.isEmpty()) {
|
||||
commandSender.sendMessage(textColor + "Language created by " + highlightColor + author);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -113,7 +112,7 @@ public class VehicleEventListener implements Listener {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("invalidMsg"));
|
||||
}
|
||||
} else if (!playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
||||
} else if (!TeleportHelper.playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
||||
cancelTeleport = true;
|
||||
}
|
||||
}
|
||||
@ -145,35 +144,4 @@ public class VehicleEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to and can afford to teleport
|
||||
*
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @param entrancePortal <p>The portal the player is entering</p>
|
||||
* @param destinationPortal <p>The portal the player is to exit from</p>
|
||||
* @return <p>True if the player is allowed to teleport and is able to pay necessary fees</p>
|
||||
*/
|
||||
private static boolean playerCanTeleport(Player player, Portal entrancePortal, Portal destinationPortal) {
|
||||
//Make sure the user can access the portal
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destinationPortal)) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
//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) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -196,4 +196,35 @@ public final class TeleportHelper {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to and can afford to teleport
|
||||
*
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @param entrancePortal <p>The portal the player is entering</p>
|
||||
* @param destinationPortal <p>The portal the player is to exit from</p>
|
||||
* @return <p>True if the player is allowed to teleport and is able to pay necessary fees</p>
|
||||
*/
|
||||
public static boolean playerCanTeleport(Player player, Portal entrancePortal, Portal destinationPortal) {
|
||||
//Make sure the user can access the portal
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destinationPortal)) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
//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) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user