2021-02-07 03:37:25 +01:00
|
|
|
package net.knarcraft.stargate;
|
|
|
|
|
2021-02-16 21:58:31 +01:00
|
|
|
import net.knarcraft.stargate.command.CommandStarGate;
|
|
|
|
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
2021-09-18 21:51:29 +02:00
|
|
|
import net.knarcraft.stargate.container.BlockChangeRequest;
|
2021-02-07 03:37:25 +01:00
|
|
|
import net.knarcraft.stargate.event.StargateAccessEvent;
|
2021-02-11 15:53:54 +01:00
|
|
|
import net.knarcraft.stargate.listener.BlockEventListener;
|
|
|
|
import net.knarcraft.stargate.listener.BungeeCordListener;
|
|
|
|
import net.knarcraft.stargate.listener.EntityEventListener;
|
2021-09-02 00:31:03 +02:00
|
|
|
import net.knarcraft.stargate.listener.PlayerEventListener;
|
2021-02-11 15:53:54 +01:00
|
|
|
import net.knarcraft.stargate.listener.PluginEventListener;
|
2021-09-10 23:38:56 +02:00
|
|
|
import net.knarcraft.stargate.listener.PortalEventListener;
|
2021-02-11 15:53:54 +01:00
|
|
|
import net.knarcraft.stargate.listener.VehicleEventListener;
|
|
|
|
import net.knarcraft.stargate.listener.WorldEventListener;
|
2021-02-22 17:01:47 +01:00
|
|
|
import net.knarcraft.stargate.portal.Gate;
|
|
|
|
import net.knarcraft.stargate.portal.GateHandler;
|
|
|
|
import net.knarcraft.stargate.portal.Portal;
|
|
|
|
import net.knarcraft.stargate.portal.PortalHandler;
|
|
|
|
import net.knarcraft.stargate.portal.PortalOption;
|
2021-09-11 15:33:45 +02:00
|
|
|
import net.knarcraft.stargate.thread.BlockChangeThread;
|
2021-02-11 15:53:54 +01:00
|
|
|
import net.knarcraft.stargate.thread.StarGateThread;
|
2021-02-22 20:26:10 +01:00
|
|
|
import net.knarcraft.stargate.utility.EconomyHandler;
|
2021-02-07 03:37:25 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2021-02-16 21:58:31 +01:00
|
|
|
import org.bukkit.command.PluginCommand;
|
2021-02-07 03:37:25 +01:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2021-02-09 21:12:04 +01:00
|
|
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
2021-02-07 03:37:25 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Queue;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public class Stargate extends JavaPlugin {
|
|
|
|
|
2021-02-20 13:57:04 +01:00
|
|
|
public static final ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<>();
|
|
|
|
private static final int activeTime = 10;
|
|
|
|
private static final int openTime = 10;
|
2021-02-07 03:37:25 +01:00
|
|
|
public static Logger log;
|
|
|
|
public static Server server;
|
|
|
|
public static Stargate stargate;
|
2021-02-16 21:58:31 +01:00
|
|
|
public static LanguageLoader languageLoader;
|
2021-02-07 03:37:25 +01:00
|
|
|
public static int maxGates = 0;
|
|
|
|
public static boolean destMemory = false;
|
|
|
|
public static boolean handleVehicles = true;
|
|
|
|
public static boolean sortLists = false;
|
|
|
|
public static boolean protectEntrance = false;
|
|
|
|
public static boolean enableBungee = true;
|
|
|
|
public static boolean verifyPortals = true;
|
|
|
|
public static ChatColor signColor;
|
|
|
|
// Temp workaround for snowmen, don't check gate entrance
|
|
|
|
public static boolean ignoreEntrance = false;
|
|
|
|
// Used for debug
|
2021-09-18 21:51:29 +02:00
|
|
|
public static boolean debuggingEnabled = false;
|
|
|
|
public static boolean permissionDebuggingEnabled = false;
|
2021-09-09 15:25:08 +02:00
|
|
|
public static final ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<>();
|
2021-02-07 03:37:25 +01:00
|
|
|
// Used for populating gate open/closed material.
|
2021-09-11 15:33:45 +02:00
|
|
|
public static final Queue<BlockChangeRequest> blockChangeRequestQueue = new LinkedList<>();
|
2021-02-07 03:37:25 +01:00
|
|
|
// HashMap of player names for Bungee support
|
2021-09-09 15:25:08 +02:00
|
|
|
public static final Map<String, String> bungeeQueue = new HashMap<>();
|
2021-09-18 21:51:29 +02:00
|
|
|
//World names that contain stargates
|
2021-09-09 15:25:08 +02:00
|
|
|
public static final HashSet<String> managedWorlds = new HashSet<>();
|
2021-02-20 13:57:04 +01:00
|
|
|
private static String pluginVersion;
|
|
|
|
private static String portalFolder;
|
|
|
|
private static String gateFolder;
|
2021-09-11 17:02:43 +02:00
|
|
|
private static String defaultGateNetwork = "central";
|
2021-02-20 13:57:04 +01:00
|
|
|
private static boolean destroyExplosion = false;
|
|
|
|
private static String langName = "en";
|
|
|
|
private FileConfiguration newConfig;
|
|
|
|
private PluginManager pm;
|
2021-02-07 03:37:25 +01:00
|
|
|
|
2021-02-09 21:12:04 +01:00
|
|
|
public Stargate() {
|
|
|
|
super();
|
2021-02-20 13:57:04 +01:00
|
|
|
|
2021-02-09 21:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special constructor used for MockBukkit
|
2021-02-20 13:57:04 +01:00
|
|
|
*
|
|
|
|
* @param loader <p>The plugin loader to be used.</p>
|
2021-02-09 21:12:04 +01:00
|
|
|
* @param descriptionFile <p>The description file to be used.</p>
|
2021-02-20 13:57:04 +01:00
|
|
|
* @param dataFolder <p>The data folder to be used.</p>
|
|
|
|
* @param file <p>The file to be used</p>
|
2021-02-09 21:12:04 +01:00
|
|
|
*/
|
|
|
|
protected Stargate(JavaPluginLoader loader, PluginDescriptionFile descriptionFile, File dataFolder, File file) {
|
|
|
|
super(loader, descriptionFile, dataFolder, file);
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:58:31 +01:00
|
|
|
public static String getPluginVersion() {
|
|
|
|
return pluginVersion;
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-11 15:53:54 +01:00
|
|
|
public static boolean destroyedByExplosion() {
|
|
|
|
return destroyExplosion;
|
|
|
|
}
|
|
|
|
|
2021-02-07 03:37:25 +01:00
|
|
|
public static int getOpenTime() {
|
|
|
|
return openTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getActiveTime() {
|
|
|
|
return activeTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void debug(String rout, String msg) {
|
2021-09-18 21:51:29 +02:00
|
|
|
if (Stargate.debuggingEnabled) {
|
2021-02-07 03:37:25 +01:00
|
|
|
log.info("[stargate::" + rout + "] " + msg);
|
|
|
|
} else {
|
|
|
|
log.log(Level.FINEST, "[stargate::" + rout + "] " + msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendMessage(CommandSender player, String message) {
|
|
|
|
sendMessage(player, message, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendMessage(CommandSender player, String message, boolean error) {
|
|
|
|
if (message.isEmpty()) return;
|
|
|
|
message = message.replaceAll("(&([a-f0-9]))", "\u00A7$2");
|
|
|
|
if (error)
|
|
|
|
player.sendMessage(ChatColor.RED + Stargate.getString("prefix") + ChatColor.WHITE + message);
|
|
|
|
else
|
|
|
|
player.sendMessage(ChatColor.GREEN + Stargate.getString("prefix") + ChatColor.WHITE + message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLine(Sign sign, int index, String text) {
|
|
|
|
sign.setLine(index, Stargate.signColor + text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getSaveLocation() {
|
|
|
|
return portalFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getGateFolder() {
|
|
|
|
return gateFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getDefaultNetwork() {
|
2021-09-11 17:02:43 +02:00
|
|
|
return defaultGateNetwork;
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getString(String name) {
|
|
|
|
return languageLoader.getString(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void openPortal(Player player, Portal portal) {
|
|
|
|
Portal destination = portal.getDestination();
|
|
|
|
|
|
|
|
// Always-open gate -- Do nothing
|
|
|
|
if (portal.isAlwaysOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Random gate -- Do nothing
|
|
|
|
if (portal.isRandom())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Invalid destination
|
|
|
|
if ((destination == null) || (destination == portal)) {
|
|
|
|
Stargate.sendMessage(player, Stargate.getString("invalidMsg"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gate is already open
|
|
|
|
if (portal.isOpen()) {
|
|
|
|
// Close if this player opened the gate
|
|
|
|
if (portal.getActivePlayer() == player) {
|
|
|
|
portal.close(false);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gate that someone else is using -- Deny access
|
|
|
|
if ((!portal.isFixed()) && portal.isActive() && (portal.getActivePlayer() != player)) {
|
|
|
|
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the player can use the private gate
|
|
|
|
if (portal.isPrivate() && !Stargate.canPrivate(player, portal)) {
|
|
|
|
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destination blocked
|
|
|
|
if ((destination.isOpen()) && (!destination.isAlwaysOn())) {
|
|
|
|
Stargate.sendMessage(player, Stargate.getString("blockMsg"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open gate
|
|
|
|
portal.open(player, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the player has the given permissions.
|
|
|
|
*/
|
2021-09-18 21:51:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a player has the given permission
|
|
|
|
*
|
|
|
|
* <p>This is the same as player.hasPermission(), but this function allows for printing permission debugging info.</p>
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param perm <p>The permission to check</p>
|
|
|
|
* @return <p>True if the player has the permission</p>
|
|
|
|
*/
|
|
|
|
public static boolean hasPermission(Player player, String perm) {
|
|
|
|
if (permissionDebuggingEnabled) {
|
2021-02-07 03:37:25 +01:00
|
|
|
Stargate.debug("hasPerm::SuperPerm(" + player.getName() + ")", perm + " => " + player.hasPermission(perm));
|
2021-09-18 21:51:29 +02:00
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
return player.hasPermission(perm);
|
|
|
|
}
|
|
|
|
|
2021-09-12 01:23:16 +02:00
|
|
|
/**
|
2021-02-07 03:37:25 +01:00
|
|
|
* Check a deep permission, this will check to see if the permissions is defined for this use
|
2021-09-12 01:23:16 +02:00
|
|
|
*
|
|
|
|
* <p>If using Permissions it will return the same as hasPerm. If using SuperPerms will return true if the node
|
|
|
|
* isn't defined, or the value of the node if it is</p>
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param permission <p>The permission to check</p>
|
|
|
|
* @return <p>True if the player has the permission or it is not set</p>
|
2021-02-07 03:37:25 +01:00
|
|
|
*/
|
2021-09-12 01:23:16 +02:00
|
|
|
public static boolean hasPermDeep(Player player, String permission) {
|
|
|
|
if (!player.isPermissionSet(permission)) {
|
2021-09-18 21:51:29 +02:00
|
|
|
if (permissionDebuggingEnabled) {
|
2021-09-12 01:23:16 +02:00
|
|
|
Stargate.debug("hasPermDeep::SuperPerm", permission + " => true");
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-09-18 21:51:29 +02:00
|
|
|
if (permissionDebuggingEnabled) {
|
2021-09-12 01:23:16 +02:00
|
|
|
Stargate.debug("hasPermDeep::SuperPerms", permission + " => " + player.hasPermission(permission));
|
|
|
|
}
|
|
|
|
return player.hasPermission(permission);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether player can teleport to dest world
|
|
|
|
*/
|
2021-09-18 21:51:29 +02:00
|
|
|
public static boolean cannotAccessWorld(Player player, String world) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Can use all stargate player features or access all worlds
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.use") || hasPermission(player, "stargate.world")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks this specific world node
|
2021-09-18 21:51:29 +02:00
|
|
|
return !hasPermDeep(player, "stargate.world." + world);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
// Can access dest world
|
2021-09-18 21:51:29 +02:00
|
|
|
return !hasPermission(player, "stargate.world." + world);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
2021-09-19 15:05:19 +02:00
|
|
|
/**
|
|
|
|
* Checks whether a player can access the given network
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param network <p>The network to check</p>
|
|
|
|
* @return <p>True if the player is denied from accessing the network</p>
|
2021-02-07 03:37:25 +01:00
|
|
|
*/
|
2021-09-18 21:51:29 +02:00
|
|
|
public static boolean cannotAccessNetwork(Player player, String network) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Can user all stargate player features, or access all networks
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.use") || hasPermission(player, "stargate.network")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks this specific network node
|
2021-09-18 21:51:29 +02:00
|
|
|
return !hasPermDeep(player, "stargate.network." + network);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
2021-09-19 15:05:19 +02:00
|
|
|
//Check if the player can access this network
|
|
|
|
if (hasPermission(player, "stargate.network." + network)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
// Is able to create personal gates (Assumption is made they can also access them)
|
|
|
|
String playerName = player.getName();
|
|
|
|
if (playerName.length() > 11) playerName = playerName.substring(0, 11);
|
2021-09-18 21:51:29 +02:00
|
|
|
return !network.equals(playerName) || !hasPermission(player, "stargate.create.personal");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the player can access this server
|
|
|
|
*/
|
|
|
|
public static boolean canAccessServer(Player player, String server) {
|
|
|
|
// Can user all stargate player features, or access all servers
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.use") || hasPermission(player, "stargate.servers")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks this specific server node
|
|
|
|
return hasPermDeep(player, "stargate.server." + server);
|
|
|
|
}
|
|
|
|
// Can access this server
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, "stargate.server." + server);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the StargateAccessPortal event, used for other plugins to bypass Permissions checks
|
|
|
|
*/
|
2021-09-11 17:02:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a stargate access event and gives the result
|
|
|
|
*
|
|
|
|
* <p>The event is used for other plugins to bypass the permission checks</p>
|
|
|
|
*
|
|
|
|
* @param player <p>The player trying to use the portal</p>
|
|
|
|
* @param portal <p>The portal the player is trying to use</p>
|
|
|
|
* @param deny <p>Whether the player's access has already been denied by a check</p>
|
|
|
|
* @return <p>False if the player should be allowed through the portal</p>
|
|
|
|
*/
|
|
|
|
public static boolean cannotAccessPortal(Player player, Portal portal, boolean deny) {
|
2021-02-07 03:37:25 +01:00
|
|
|
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
|
|
|
Stargate.server.getPluginManager().callEvent(event);
|
2021-09-11 17:02:43 +02:00
|
|
|
return event.getDeny();
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 21:58:31 +01:00
|
|
|
/**
|
2021-09-11 17:02:43 +02:00
|
|
|
* Checks whether a given user cannot travel between two portals
|
2021-02-20 13:57:04 +01:00
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
2021-02-16 21:58:31 +01:00
|
|
|
* @param entrancePortal <p>The portal the user wants to enter</p>
|
2021-02-20 13:57:04 +01:00
|
|
|
* @param destination <p>The portal the user wants to exit</p>
|
2021-09-11 17:02:43 +02:00
|
|
|
* @return <p>False if the user is allowed to access the portal</p>
|
2021-02-16 21:58:31 +01:00
|
|
|
*/
|
2021-09-11 17:02:43 +02:00
|
|
|
public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) {
|
2021-02-16 21:58:31 +01:00
|
|
|
boolean deny = false;
|
|
|
|
// Check if player has access to this server for Bungee gates
|
|
|
|
if (entrancePortal.isBungee() && !Stargate.canAccessServer(player, entrancePortal.getNetwork())) {
|
2021-09-12 01:23:16 +02:00
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
2021-02-16 21:58:31 +01:00
|
|
|
deny = true;
|
2021-09-18 21:51:29 +02:00
|
|
|
} else if (Stargate.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
2021-09-12 01:23:16 +02:00
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
2021-02-16 21:58:31 +01:00
|
|
|
deny = true;
|
2021-09-18 21:51:29 +02:00
|
|
|
} else if (!entrancePortal.isBungee() && Stargate.cannotAccessWorld(player, destination.getWorld().getName())) {
|
2021-09-12 01:23:16 +02:00
|
|
|
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
2021-02-16 21:58:31 +01:00
|
|
|
deny = true;
|
|
|
|
}
|
2021-09-11 17:02:43 +02:00
|
|
|
return Stargate.cannotAccessPortal(player, entrancePortal, deny);
|
2021-02-16 21:58:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-07 03:37:25 +01:00
|
|
|
/*
|
|
|
|
* Return true if the portal is free for the player
|
|
|
|
*/
|
|
|
|
public static boolean isFree(Player player, Portal src, Portal dest) {
|
|
|
|
// This gate is free
|
|
|
|
if (src.isFree()) return true;
|
|
|
|
// Player gets free use
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.free") || Stargate.hasPermission(player, "stargate.free.use")) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Don't charge for free destination gates
|
|
|
|
return dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the player can see this gate (Hidden property check)
|
|
|
|
*/
|
2021-09-12 15:23:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the player can see this gate (Hidden property check)
|
|
|
|
*
|
|
|
|
* <p>This decides if the player can see the gate on the network selection screen</p>
|
|
|
|
*
|
|
|
|
* @param player <p>The player to check</p>
|
|
|
|
* @param portal <p>The portal to check</p>
|
|
|
|
* @return <p>True if the given player can see the given portal</p>
|
|
|
|
*/
|
2021-02-07 03:37:25 +01:00
|
|
|
public static boolean canSee(Player player, Portal portal) {
|
|
|
|
// The gate is not hidden
|
2021-09-12 15:23:22 +02:00
|
|
|
if (!portal.isHidden()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
// The player is an admin with the ability to see hidden gates
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.admin") || hasPermission(player, "stargate.admin.hidden")) {
|
2021-09-12 15:23:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
// The player is the owner of the gate
|
|
|
|
return portal.isOwner(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player can use this private gate
|
|
|
|
*/
|
|
|
|
public static boolean canPrivate(Player player, Portal portal) {
|
|
|
|
// Check if the player is the owner of the gate
|
|
|
|
if (portal.isOwner(player)) return true;
|
|
|
|
// The player is an admin with the ability to use private gates
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, "stargate.admin") || hasPermission(player, "stargate.admin.private");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player has access to {option}
|
|
|
|
*/
|
2021-02-20 13:57:04 +01:00
|
|
|
public static boolean canOption(Player player, PortalOption option) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check if the player can use all options
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.option") || option == PortalOption.BUNGEE) {
|
2021-02-20 13:57:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check if they can use this specific option
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, option.getPermissionString());
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player can create gates on {network}
|
|
|
|
*/
|
|
|
|
public static boolean canCreate(Player player, String network) {
|
|
|
|
// Check for general create
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.create")) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check for all network create permission
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.create.network")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks this specific network node
|
|
|
|
return hasPermDeep(player, "stargate.create.network." + network);
|
|
|
|
}
|
|
|
|
// Check for this specific network
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, "stargate.create.network." + network);
|
2021-02-07 03:37:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player can create a personal gate
|
|
|
|
*/
|
|
|
|
public static boolean canCreatePersonal(Player player) {
|
|
|
|
// Check for general create
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.create")) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check for personal
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, "stargate.create.personal");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player can create this gate layout
|
|
|
|
*/
|
|
|
|
public static boolean canCreateGate(Player player, String gate) {
|
|
|
|
// Check for general create
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.create")) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check for all gate create permissions
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.create.gate")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks this specific gate node
|
|
|
|
return hasPermDeep(player, "stargate.create.gate." + gate);
|
|
|
|
}
|
|
|
|
// Check for this specific gate
|
2021-09-18 21:51:29 +02:00
|
|
|
return hasPermission(player, "stargate.create.gate." + gate);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the player can destroy this gate
|
|
|
|
*/
|
|
|
|
public static boolean canDestroy(Player player, Portal portal) {
|
|
|
|
String network = portal.getNetwork();
|
|
|
|
// Check for general destroy
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.destroy")) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check for all network destroy permission
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.destroy.network")) {
|
2021-02-07 03:37:25 +01:00
|
|
|
// Do a deep check to see if the player lacks permission for this network node
|
|
|
|
return hasPermDeep(player, "stargate.destroy.network." + network);
|
|
|
|
}
|
|
|
|
// Check for this specific network
|
2021-09-18 21:51:29 +02:00
|
|
|
if (hasPermission(player, "stargate.destroy.network." + network)) return true;
|
2021-02-07 03:37:25 +01:00
|
|
|
// Check for personal gate
|
2021-09-18 21:51:29 +02:00
|
|
|
return portal.isOwner(player) && hasPermission(player, "stargate.destroy.personal");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 20:10:17 +01:00
|
|
|
/**
|
|
|
|
* Replaces a list of variables in a string in the order they are given
|
2021-02-20 13:57:04 +01:00
|
|
|
*
|
|
|
|
* @param input <p>The input containing the variables</p>
|
2021-02-09 20:10:17 +01:00
|
|
|
* @param search <p>The variables to replace</p>
|
|
|
|
* @param values <p>The replacement values</p>
|
|
|
|
* @return <p>The input string with the search values replaced with the given values</p>
|
2021-02-07 03:37:25 +01:00
|
|
|
*/
|
2021-02-09 20:10:17 +01:00
|
|
|
public static String replaceVars(String input, String[] search, String[] values) {
|
|
|
|
if (search.length != values.length) {
|
|
|
|
throw new IllegalArgumentException("The number of search values and replace values do not match.");
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
for (int i = 0; i < search.length; i++) {
|
2021-02-09 20:10:17 +01:00
|
|
|
input = replaceVars(input, search[i], values[i]);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
2021-02-09 20:10:17 +01:00
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces a variable in a string
|
2021-02-20 13:57:04 +01:00
|
|
|
*
|
|
|
|
* @param input <p>The input containing the variables</p>
|
2021-02-09 20:10:17 +01:00
|
|
|
* @param search <p>The variable to replace</p>
|
2021-02-20 13:57:04 +01:00
|
|
|
* @param value <p>The replacement value</p>
|
2021-02-09 20:10:17 +01:00
|
|
|
* @return <p>The input string with the search replaced with value</p>
|
|
|
|
*/
|
|
|
|
public static String replaceVars(String input, String search, String value) {
|
|
|
|
return input.replace(search, value);
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
2021-02-20 13:57:04 +01:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
PortalHandler.closeAllGates();
|
|
|
|
PortalHandler.clearGates();
|
|
|
|
managedWorlds.clear();
|
|
|
|
getServer().getScheduler().cancelTasks(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
PluginDescriptionFile pluginDescriptionFile = this.getDescription();
|
|
|
|
pm = getServer().getPluginManager();
|
|
|
|
newConfig = this.getConfig();
|
|
|
|
log = Logger.getLogger("Minecraft");
|
|
|
|
Stargate.server = getServer();
|
|
|
|
Stargate.stargate = this;
|
|
|
|
|
|
|
|
// Set portalFile and gateFolder to the plugin folder as defaults.
|
|
|
|
String dataFolderPath = getDataFolder().getPath().replaceAll("\\\\", "/");
|
|
|
|
portalFolder = dataFolderPath + "/portals/";
|
|
|
|
gateFolder = dataFolderPath + "/gates/";
|
2021-09-18 21:51:29 +02:00
|
|
|
String languageFolder = dataFolderPath + "/lang/";
|
2021-02-20 13:57:04 +01:00
|
|
|
|
|
|
|
pluginVersion = pluginDescriptionFile.getVersion();
|
|
|
|
|
|
|
|
log.info(pluginDescriptionFile.getName() + " v." + pluginDescriptionFile.getVersion() + " is enabled.");
|
|
|
|
|
|
|
|
// Register events before loading gates to stop weird things happening.
|
2021-09-02 00:31:03 +02:00
|
|
|
pm.registerEvents(new PlayerEventListener(), this);
|
2021-02-20 13:57:04 +01:00
|
|
|
pm.registerEvents(new BlockEventListener(), this);
|
|
|
|
|
|
|
|
pm.registerEvents(new VehicleEventListener(), this);
|
|
|
|
pm.registerEvents(new EntityEventListener(), this);
|
2021-09-10 23:38:56 +02:00
|
|
|
pm.registerEvents(new PortalEventListener(), this);
|
2021-02-20 13:57:04 +01:00
|
|
|
pm.registerEvents(new WorldEventListener(), this);
|
|
|
|
pm.registerEvents(new PluginEventListener(this), this);
|
|
|
|
|
|
|
|
this.loadConfig();
|
|
|
|
|
|
|
|
// Enable the required channels for Bungee support
|
|
|
|
if (enableBungee) {
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordListener());
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is important to load languages here, as they are used during reloadGates()
|
2021-09-18 21:51:29 +02:00
|
|
|
languageLoader = new LanguageLoader(languageFolder, Stargate.langName);
|
2021-02-20 13:57:04 +01:00
|
|
|
|
|
|
|
this.migrate();
|
|
|
|
this.loadGates();
|
|
|
|
this.loadAllPortals();
|
|
|
|
|
|
|
|
// Check to see if Economy is loaded yet.
|
|
|
|
if (EconomyHandler.setupEconomy(pm)) {
|
|
|
|
if (EconomyHandler.economy != null) {
|
|
|
|
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
|
|
|
|
log.info(Stargate.getString("prefix") +
|
|
|
|
replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 17:01:47 +01:00
|
|
|
getServer().getScheduler().runTaskTimer(this, new StarGateThread(), 0L, 100L);
|
2021-09-11 15:33:45 +02:00
|
|
|
getServer().getScheduler().runTaskTimer(this, new BlockChangeThread(), 0L, 1L);
|
2021-02-20 13:57:04 +01:00
|
|
|
|
|
|
|
this.registerCommands();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerCommands() {
|
|
|
|
PluginCommand stargateCommand = this.getCommand("stargate");
|
|
|
|
if (stargateCommand != null) {
|
|
|
|
stargateCommand.setExecutor(new CommandStarGate(this));
|
|
|
|
stargateCommand.setTabCompleter(new StarGateTabCompleter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadConfig() {
|
|
|
|
reloadConfig();
|
|
|
|
newConfig = this.getConfig();
|
|
|
|
// Copy default values if required
|
|
|
|
newConfig.options().copyDefaults(true);
|
|
|
|
|
|
|
|
// Load values into variables
|
|
|
|
portalFolder = newConfig.getString("portal-folder");
|
|
|
|
gateFolder = newConfig.getString("gate-folder");
|
2021-09-11 17:02:43 +02:00
|
|
|
|
|
|
|
String defaultNetwork = newConfig.getString("default-gate-network");
|
|
|
|
defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null;
|
2021-02-20 13:57:04 +01:00
|
|
|
destroyExplosion = newConfig.getBoolean("destroyexplosion");
|
|
|
|
maxGates = newConfig.getInt("maxgates");
|
|
|
|
langName = newConfig.getString("lang");
|
|
|
|
destMemory = newConfig.getBoolean("destMemory");
|
|
|
|
ignoreEntrance = newConfig.getBoolean("ignoreEntrance");
|
|
|
|
handleVehicles = newConfig.getBoolean("handleVehicles");
|
|
|
|
sortLists = newConfig.getBoolean("sortLists");
|
|
|
|
protectEntrance = newConfig.getBoolean("protectEntrance");
|
|
|
|
enableBungee = newConfig.getBoolean("enableBungee");
|
|
|
|
verifyPortals = newConfig.getBoolean("verifyPortals");
|
|
|
|
// Sign color
|
2021-09-11 17:02:43 +02:00
|
|
|
loadSignColor(newConfig.getString("signColor"));
|
2021-02-20 13:57:04 +01:00
|
|
|
// Debug
|
2021-09-18 21:51:29 +02:00
|
|
|
debuggingEnabled = newConfig.getBoolean("debug");
|
|
|
|
permissionDebuggingEnabled = newConfig.getBoolean("permdebug");
|
2021-02-20 13:57:04 +01:00
|
|
|
// Economy
|
|
|
|
EconomyHandler.economyEnabled = newConfig.getBoolean("useeconomy");
|
2021-02-22 20:26:10 +01:00
|
|
|
EconomyHandler.setCreateCost(newConfig.getInt("createcost"));
|
|
|
|
EconomyHandler.setDestroyCost(newConfig.getInt("destroycost"));
|
|
|
|
EconomyHandler.setUseCost(newConfig.getInt("usecost"));
|
2021-02-20 13:57:04 +01:00
|
|
|
EconomyHandler.toOwner = newConfig.getBoolean("toowner");
|
|
|
|
EconomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination");
|
|
|
|
EconomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen");
|
|
|
|
|
|
|
|
this.saveConfig();
|
|
|
|
}
|
|
|
|
|
2021-09-11 17:02:43 +02:00
|
|
|
/**
|
|
|
|
* Loads the correct sign color given a sign color string
|
|
|
|
* @param signColor <p>A string representing a sign color</p>
|
|
|
|
*/
|
|
|
|
private void loadSignColor(String signColor) {
|
|
|
|
if (signColor != null) {
|
|
|
|
try {
|
|
|
|
Stargate.signColor = ChatColor.valueOf(signColor.toUpperCase());
|
|
|
|
return;
|
|
|
|
} catch (IllegalArgumentException | NullPointerException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.warning(Stargate.getString("prefix") + "You have specified an invalid color in your config.yml." +
|
|
|
|
" Defaulting to BLACK");
|
|
|
|
Stargate.signColor = ChatColor.BLACK;
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:57:04 +01:00
|
|
|
public void closeAllPortals() {
|
|
|
|
// Close all gates prior to reloading
|
|
|
|
for (Portal p : openList) {
|
|
|
|
p.close(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadGates() {
|
2021-02-22 17:01:47 +01:00
|
|
|
GateHandler.loadGates(gateFolder);
|
|
|
|
log.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
|
2021-02-20 13:57:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void loadAllPortals() {
|
|
|
|
for (World world : getServer().getWorlds()) {
|
|
|
|
if (!managedWorlds.contains(world.getName())) {
|
|
|
|
PortalHandler.loadAllGates(world);
|
|
|
|
managedWorlds.add(world.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void migrate() {
|
|
|
|
// Only migrate if new file doesn't exist.
|
|
|
|
File newPortalDir = new File(portalFolder);
|
|
|
|
if (!newPortalDir.exists()) {
|
|
|
|
if (!newPortalDir.mkdirs()) {
|
|
|
|
log.severe("Unable to create portal directory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
|
2021-09-09 15:42:30 +02:00
|
|
|
if (!newFile.exists() && !newFile.getParentFile().exists()) {
|
2021-02-20 13:57:04 +01:00
|
|
|
if (!newFile.getParentFile().mkdirs()) {
|
2021-09-09 15:25:08 +02:00
|
|
|
log.severe("Unable to create portal database folder: " + newFile.getParentFile().getPath());
|
2021-02-20 13:57:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if a plugin is loaded/enabled already. Returns the plugin if so, null otherwise
|
|
|
|
*/
|
|
|
|
private Plugin checkPlugin(String p) {
|
|
|
|
Plugin plugin = pm.getPlugin(p);
|
|
|
|
return checkPlugin(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Plugin checkPlugin(Plugin plugin) {
|
|
|
|
if (plugin != null && plugin.isEnabled()) {
|
|
|
|
log.info(Stargate.getString("prefix") + "Found " + plugin.getDescription().getName() + " (v" + plugin.getDescription().getVersion() + ")");
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:58:31 +01:00
|
|
|
/**
|
|
|
|
* Reloads all portals and files
|
2021-02-20 13:57:04 +01:00
|
|
|
*
|
2021-02-16 21:58:31 +01:00
|
|
|
* @param sender <p>The sender of the reload request</p>
|
|
|
|
*/
|
|
|
|
public void reload(CommandSender sender) {
|
|
|
|
// Deactivate portals
|
|
|
|
for (Portal p : activeList) {
|
|
|
|
p.deactivate();
|
|
|
|
}
|
|
|
|
// Close portals
|
|
|
|
closeAllPortals();
|
|
|
|
// Clear all lists
|
|
|
|
activeList.clear();
|
|
|
|
openList.clear();
|
|
|
|
managedWorlds.clear();
|
|
|
|
PortalHandler.clearGates();
|
2021-02-22 17:01:47 +01:00
|
|
|
GateHandler.clearGates();
|
2021-02-16 21:58:31 +01:00
|
|
|
|
|
|
|
// Store the old Bungee enabled value
|
|
|
|
boolean oldEnableBungee = enableBungee;
|
|
|
|
// Reload data
|
|
|
|
loadConfig();
|
|
|
|
loadGates();
|
|
|
|
loadAllPortals();
|
|
|
|
languageLoader.setChosenLanguage(langName);
|
|
|
|
languageLoader.reload();
|
|
|
|
|
|
|
|
// Load Economy support if enabled/clear if disabled
|
|
|
|
if (EconomyHandler.economyEnabled && EconomyHandler.economy == null) {
|
|
|
|
if (EconomyHandler.setupEconomy(pm)) {
|
|
|
|
if (EconomyHandler.economy != null) {
|
|
|
|
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
|
|
|
|
log.info(Stargate.getString("prefix") + Stargate.replaceVars(
|
|
|
|
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 21:58:31 +01:00
|
|
|
}
|
|
|
|
if (!EconomyHandler.economyEnabled) {
|
|
|
|
EconomyHandler.vault = null;
|
|
|
|
EconomyHandler.economy = null;
|
|
|
|
}
|
2021-02-07 03:37:25 +01:00
|
|
|
|
2021-02-16 21:58:31 +01:00
|
|
|
// Enable the required channels for Bungee support
|
|
|
|
if (oldEnableBungee != enableBungee) {
|
|
|
|
if (enableBungee) {
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordListener());
|
|
|
|
} else {
|
|
|
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
|
|
|
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 21:58:31 +01:00
|
|
|
|
|
|
|
sendMessage(sender, "stargate reloaded");
|
2021-02-07 03:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|