Improves some variable names and adds some comments
This commit is contained in:
parent
d24f35375a
commit
1e29db58b9
@ -42,7 +42,7 @@ public class LanguageLoader {
|
||||
File tmp = new File(languageFolder, chosenLanguage + ".txt");
|
||||
if (!tmp.exists()) {
|
||||
if (tmp.getParentFile().mkdirs() && Stargate.debuggingEnabled) {
|
||||
Stargate.log.info("[stargate] Created language folder");
|
||||
Stargate.logger.info("[stargate] Created language folder");
|
||||
}
|
||||
}
|
||||
updateLanguage(chosenLanguage);
|
||||
@ -54,7 +54,7 @@ public class LanguageLoader {
|
||||
loadedBackupStrings = load("en", inputStream);
|
||||
} else {
|
||||
loadedBackupStrings = null;
|
||||
Stargate.log.severe("[stargate] Error loading backup language. There may be missing text in-game");
|
||||
Stargate.logger.severe("[stargate] Error loading backup language. There may be missing text in-game");
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,10 +110,10 @@ public class LanguageLoader {
|
||||
|
||||
InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt");
|
||||
if (inputStream == null) {
|
||||
Stargate.log.info("[stargate] The language " + language + " is not available. Falling back to " +
|
||||
Stargate.logger.info("[stargate] The language " + language + " is not available. Falling back to " +
|
||||
"english, You can add a custom language by creating a new text file in the lang directory.");
|
||||
if (Stargate.debuggingEnabled) {
|
||||
Stargate.log.info("[stargate] Unable to load /lang/" + language + ".txt");
|
||||
Stargate.logger.info("[stargate] Unable to load /lang/" + language + ".txt");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -157,7 +157,7 @@ public class LanguageLoader {
|
||||
}
|
||||
}
|
||||
if (updated) {
|
||||
Stargate.log.info("[stargate] Your language file (" + language + ".txt) has been updated");
|
||||
Stargate.logger.info("[stargate] Your language file (" + language + ".txt) has been updated");
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ public class LanguageLoader {
|
||||
readLanguageFile(inputStreamReader, strings);
|
||||
} catch (Exception e) {
|
||||
if (Stargate.debuggingEnabled) {
|
||||
Stargate.log.info("Unable to load chosen language");
|
||||
Stargate.logger.info("Unable to load chosen language");
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
|
@ -3,7 +3,6 @@ package net.knarcraft.stargate;
|
||||
import net.knarcraft.stargate.command.CommandStarGate;
|
||||
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.event.StargateAccessEvent;
|
||||
import net.knarcraft.stargate.listener.BlockEventListener;
|
||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||
import net.knarcraft.stargate.listener.EntityEventListener;
|
||||
@ -18,7 +17,6 @@ import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.thread.StarGateThread;
|
||||
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
@ -27,7 +25,6 @@ import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -47,47 +44,51 @@ import java.util.logging.Logger;
|
||||
@SuppressWarnings("unused")
|
||||
public class Stargate extends JavaPlugin {
|
||||
|
||||
public static final ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<>();
|
||||
//Used for changing gate open/closed material.
|
||||
public static final Queue<BlockChangeRequest> blockChangeRequestQueue = new LinkedList<>();
|
||||
public static final ConcurrentLinkedQueue<Portal> openPortalsQueue = new ConcurrentLinkedQueue<>();
|
||||
public static final ConcurrentLinkedQueue<Portal> activePortalsQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
//Amount of seconds before deactivating/closing portals
|
||||
private static final int activeTime = 10;
|
||||
private static final int openTime = 10;
|
||||
public static Logger log;
|
||||
|
||||
public static Logger logger;
|
||||
public static Server server;
|
||||
public static Stargate stargate;
|
||||
public static LanguageLoader languageLoader;
|
||||
public static int maxGates = 0;
|
||||
|
||||
public static int maxGatesEachNetwork = 0;
|
||||
public static boolean rememberDestination = false;
|
||||
public static boolean handleVehicles = true;
|
||||
public static boolean sortNetworkDestinations = 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
|
||||
private static boolean destroyExplosion = false;
|
||||
//Temp workaround for snowmen, don't check gate entrance
|
||||
public static boolean ignoreEntrance = false;
|
||||
|
||||
public static ChatColor signColor;
|
||||
// Used for debug
|
||||
public static boolean debuggingEnabled = false;
|
||||
public static boolean permissionDebuggingEnabled = false;
|
||||
public static final ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<>();
|
||||
// Used for populating gate open/closed material.
|
||||
public static final Queue<BlockChangeRequest> blockChangeRequestQueue = new LinkedList<>();
|
||||
|
||||
// HashMap of player names for Bungee support
|
||||
public static final Map<String, String> bungeeQueue = new HashMap<>();
|
||||
//World names that contain stargates
|
||||
public static final HashSet<String> managedWorlds = new HashSet<>();
|
||||
|
||||
private static String pluginVersion;
|
||||
private static String portalFolder;
|
||||
private static String gateFolder;
|
||||
|
||||
private static String defaultGateNetwork = "central";
|
||||
private static boolean destroyExplosion = false;
|
||||
private static String languageName = "en";
|
||||
|
||||
private FileConfiguration newConfig;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
public Stargate() {
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Special constructor used for MockBukkit
|
||||
*
|
||||
@ -100,152 +101,148 @@ public class Stargate extends JavaPlugin {
|
||||
super(loader, descriptionFile, dataFolder, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version of this plugin
|
||||
*
|
||||
* @return <p>This plugin's version</p>
|
||||
*/
|
||||
public static String getPluginVersion() {
|
||||
return pluginVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether portals should be destroyed by explosions
|
||||
*
|
||||
* @return <p>True if portals should be destroyed</p>
|
||||
*/
|
||||
public static boolean destroyedByExplosion() {
|
||||
return destroyExplosion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of seconds a portal should be open before automatically closing
|
||||
*
|
||||
* @return <p>The open time of a gate</p>
|
||||
*/
|
||||
public static int getOpenTime() {
|
||||
return openTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of seconds a portal should be active before automatically deactivating
|
||||
*
|
||||
* @return <p>The active time of a gate</p>
|
||||
*/
|
||||
public static int getActiveTime() {
|
||||
return activeTime;
|
||||
}
|
||||
|
||||
public static void debug(String rout, String msg) {
|
||||
/**
|
||||
* Sends a debug message
|
||||
*
|
||||
* @param route <p>The class name/route where something happened</p>
|
||||
* @param message <p>A message describing what happened</p>
|
||||
*/
|
||||
public static void debug(String route, String message) {
|
||||
if (Stargate.debuggingEnabled) {
|
||||
log.info("[stargate::" + rout + "] " + msg);
|
||||
logger.info("[stargate::" + route + "] " + message);
|
||||
} else {
|
||||
log.log(Level.FINEST, "[stargate::" + rout + "] " + msg);
|
||||
logger.log(Level.FINEST, "[stargate::" + route + "] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender player, String message) {
|
||||
/**
|
||||
* Sends an error message to a player
|
||||
*
|
||||
* @param player <p>The player to send the message to</p>
|
||||
* @param message <p>The message to send</p>
|
||||
*/
|
||||
public static void sendErrorMessage(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);
|
||||
/**
|
||||
* Sends a success message to a player
|
||||
*
|
||||
* @param player <p>The player to send the message to</p>
|
||||
* @param message <p>The message to send</p>
|
||||
*/
|
||||
public static void sendSuccessMessage(CommandSender player, String message) {
|
||||
sendMessage(player, message, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to a player
|
||||
*
|
||||
* @param player <p>The player to send the message to</p>
|
||||
* @param message <p>The message to send</p>
|
||||
* @param error <p>Whether the message sent is an error</p>
|
||||
*/
|
||||
private static void sendMessage(CommandSender player, String message, boolean error) {
|
||||
if (message.isEmpty()) return;
|
||||
//Replace color codes with green? What's the deal with the dollar sign?
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a line on a sign, adding the chosen sign color
|
||||
*
|
||||
* @param sign <p>The sign to update</p>
|
||||
* @param index <p>The index of the sign line to change</p>
|
||||
* @param text <p>The new text on the sign</p>
|
||||
*/
|
||||
public static void setLine(Sign sign, int index, String text) {
|
||||
sign.setLine(index, Stargate.signColor + text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder for saving created portals
|
||||
*
|
||||
* <p>The returned String path is the full path to the folder</p>
|
||||
*
|
||||
* @return <p>The folder for storing the portal database</p>
|
||||
*/
|
||||
public static String getSaveLocation() {
|
||||
return portalFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the folder storing gate files
|
||||
*
|
||||
* <p>The returned String path is the full path to the folder</p>
|
||||
*
|
||||
* @return <p>The folder storing gate files</p>
|
||||
*/
|
||||
public static String getGateFolder() {
|
||||
return gateFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default network for gates where a network is not specified
|
||||
*
|
||||
* @return <p>The default network</p>
|
||||
*/
|
||||
public static String getDefaultNetwork() {
|
||||
return defaultGateNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a translated string given its string key
|
||||
*
|
||||
* <p>The name/key is the string before the equals sign in the language files</p>
|
||||
*
|
||||
* @param name <p>The name/key of the string to get</p>
|
||||
* @return <p>The full translated string</p>
|
||||
*/
|
||||
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() && !PermissionHelper.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StargateAccessPortal 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) {
|
||||
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
||||
Stargate.server.getPluginManager().callEvent(event);
|
||||
return event.getDeny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given user cannot travel between two portals
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @param entrancePortal <p>The portal the user wants to enter</p>
|
||||
* @param destination <p>The portal the user wants to exit</p>
|
||||
* @return <p>False if the user is allowed to access the portal</p>
|
||||
*/
|
||||
public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) {
|
||||
boolean deny = false;
|
||||
// Check if player has access to this server for Bungee gates
|
||||
if (entrancePortal.isBungee() && !PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
||||
deny = true;
|
||||
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
||||
deny = true;
|
||||
} else if (!entrancePortal.isBungee() && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
||||
deny = true;
|
||||
}
|
||||
return Stargate.cannotAccessPortal(player, entrancePortal, deny);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a list of variables in a string in the order they are given
|
||||
*
|
||||
@ -289,7 +286,7 @@ public class Stargate extends JavaPlugin {
|
||||
PluginDescriptionFile pluginDescriptionFile = this.getDescription();
|
||||
pluginManager = getServer().getPluginManager();
|
||||
newConfig = this.getConfig();
|
||||
log = Logger.getLogger("Minecraft");
|
||||
logger = Logger.getLogger("Minecraft");
|
||||
Stargate.server = getServer();
|
||||
Stargate.stargate = this;
|
||||
|
||||
@ -301,7 +298,7 @@ public class Stargate extends JavaPlugin {
|
||||
|
||||
pluginVersion = pluginDescriptionFile.getVersion();
|
||||
|
||||
log.info(pluginDescriptionFile.getName() + " v." + pluginDescriptionFile.getVersion() + " is enabled.");
|
||||
logger.info(pluginDescriptionFile.getName() + " v." + pluginDescriptionFile.getVersion() + " is enabled.");
|
||||
|
||||
//Register events before loading gates to stop weird things happening.
|
||||
registerEventListeners();
|
||||
@ -390,7 +387,7 @@ public class Stargate extends JavaPlugin {
|
||||
private void loadGateConfig() {
|
||||
String defaultNetwork = newConfig.getString("gates.defaultGateNetwork");
|
||||
defaultGateNetwork = defaultNetwork != null ? defaultNetwork.trim() : null;
|
||||
maxGates = newConfig.getInt("gates.maxGatesEachNetwork");
|
||||
maxGatesEachNetwork = newConfig.getInt("gates.maxGatesEachNetwork");
|
||||
|
||||
//Functionality
|
||||
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
|
||||
@ -434,7 +431,7 @@ public class Stargate extends JavaPlugin {
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
log.warning(getString("prefix") + "You have specified an invalid color in your config.yml. Defaulting to BLACK");
|
||||
logger.warning(getString("prefix") + "You have specified an invalid color in your config.yml. Defaulting to BLACK");
|
||||
Stargate.signColor = ChatColor.BLACK;
|
||||
}
|
||||
|
||||
@ -443,7 +440,7 @@ public class Stargate extends JavaPlugin {
|
||||
*/
|
||||
public void closeAllPortals() {
|
||||
// Close all gates prior to reloading
|
||||
for (Portal openPortal : openList) {
|
||||
for (Portal openPortal : openPortalsQueue) {
|
||||
openPortal.close(true);
|
||||
}
|
||||
}
|
||||
@ -453,7 +450,7 @@ public class Stargate extends JavaPlugin {
|
||||
*/
|
||||
public void loadGates() {
|
||||
GateHandler.loadGates(gateFolder);
|
||||
log.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
|
||||
logger.info(Stargate.getString("prefix") + "Loaded " + GateHandler.getGateCount() + " gate layouts");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,13 +472,13 @@ public class Stargate extends JavaPlugin {
|
||||
File newPortalDir = new File(portalFolder);
|
||||
if (!newPortalDir.exists()) {
|
||||
if (!newPortalDir.mkdirs()) {
|
||||
log.severe("Unable to create portal directory");
|
||||
logger.severe("Unable to create portal directory");
|
||||
}
|
||||
}
|
||||
File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db");
|
||||
if (!newFile.exists() && !newFile.getParentFile().exists()) {
|
||||
if (!newFile.getParentFile().mkdirs()) {
|
||||
log.severe("Unable to create portal database folder: " + newFile.getParentFile().getPath());
|
||||
logger.severe("Unable to create portal database folder: " + newFile.getParentFile().getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -493,14 +490,14 @@ public class Stargate extends JavaPlugin {
|
||||
*/
|
||||
public void reload(CommandSender sender) {
|
||||
// Deactivate portals
|
||||
for (Portal activePortal : activeList) {
|
||||
for (Portal activePortal : activePortalsQueue) {
|
||||
activePortal.deactivate();
|
||||
}
|
||||
// Close portals
|
||||
closeAllPortals();
|
||||
// Clear all lists
|
||||
activeList.clear();
|
||||
openList.clear();
|
||||
activePortalsQueue.clear();
|
||||
openPortalsQueue.clear();
|
||||
managedWorlds.clear();
|
||||
PortalHandler.clearGates();
|
||||
GateHandler.clearGates();
|
||||
@ -522,7 +519,7 @@ public class Stargate extends JavaPlugin {
|
||||
startStopBungeeListener(enableBungee);
|
||||
}
|
||||
|
||||
sendMessage(sender, "stargate reloaded");
|
||||
sendErrorMessage(sender, "stargate reloaded");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -543,7 +540,7 @@ public class Stargate extends JavaPlugin {
|
||||
private void setupVaultEconomy() {
|
||||
if (EconomyHandler.setupEconomy(pluginManager) && EconomyHandler.economy != null) {
|
||||
String vaultVersion = EconomyHandler.vault.getDescription().getVersion();
|
||||
log.info(Stargate.getString("prefix") + Stargate.replaceVars(
|
||||
logger.info(Stargate.getString("prefix") + Stargate.replaceVars(
|
||||
Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class CommandReload implements CommandExecutor {
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (!player.hasPermission("stargate.reload")) {
|
||||
Stargate.sendMessage(commandSender, "Permission Denied");
|
||||
Stargate.sendErrorMessage(commandSender, "Permission Denied");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class BlockEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.sendMessage(player, Stargate.getString("createMsg"), false);
|
||||
Stargate.sendSuccessMessage(player, Stargate.getString("createMsg"));
|
||||
Stargate.debug("onSignChange", "Initialized stargate: " + portal.getName());
|
||||
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, portal::drawSign, 1);
|
||||
}
|
||||
@ -88,7 +88,7 @@ public class BlockEventListener implements Listener {
|
||||
if (!PermissionHelper.canDestroyPortal(player, portal)) {
|
||||
denyMsg = Stargate.getString("denyMsg");
|
||||
deny = true;
|
||||
Stargate.log.info(Stargate.getString("prefix") + player.getName() + " tried to destroy gate");
|
||||
Stargate.logger.info(Stargate.getString("prefix") + player.getName() + " tried to destroy gate");
|
||||
}
|
||||
|
||||
int cost = EconomyHandler.getDestroyCost(player, portal.getGate());
|
||||
@ -103,7 +103,7 @@ public class BlockEventListener implements Listener {
|
||||
|
||||
//Destroy denied
|
||||
if (destroyEvent.getDeny()) {
|
||||
Stargate.sendMessage(player, destroyEvent.getDenyReason());
|
||||
Stargate.sendErrorMessage(player, destroyEvent.getDenyReason());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class BlockEventListener implements Listener {
|
||||
}
|
||||
|
||||
PortalHandler.unregisterPortal(portal, true);
|
||||
Stargate.sendMessage(player, Stargate.getString("destroyMsg"), false);
|
||||
Stargate.sendSuccessMessage(player, Stargate.getString("destroyMsg"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +122,7 @@ public class PlayerEventListener implements Listener {
|
||||
} else {
|
||||
destination.teleport(player, entrancePortal, event);
|
||||
}
|
||||
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
||||
Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
entrancePortal.close(false);
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ public class PlayerEventListener implements Listener {
|
||||
//Decide if the user should be teleported to another bungee server
|
||||
if (entrancePortal.isBungee()) {
|
||||
if (bungeeTeleport(player, entrancePortal, event)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
||||
Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -236,8 +236,8 @@ public class PlayerEventListener implements Listener {
|
||||
private boolean cannotAccessPortal(Player player, Portal portal) {
|
||||
boolean deny = PermissionHelper.cannotAccessNetwork(player, portal.getNetwork());
|
||||
|
||||
if (Stargate.cannotAccessPortal(player, portal, deny)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
||||
if (PermissionHelper.cannotAccessPortal(player, portal, deny)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -277,7 +277,7 @@ public class PlayerEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.openPortal(player, portal);
|
||||
PermissionHelper.openPortal(player, portal);
|
||||
if (portal.isOpenFor(player)) {
|
||||
event.setUseInteractedBlock(Event.Result.ALLOW);
|
||||
}
|
||||
@ -319,7 +319,7 @@ public class PlayerEventListener implements Listener {
|
||||
private boolean bungeeTeleport(Player player, Portal entrancePortal, PlayerMoveEvent event) {
|
||||
//Check if bungee is actually enabled
|
||||
if (!Stargate.enableBungee) {
|
||||
player.sendMessage(Stargate.getString("bungeeDisabled"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
|
||||
entrancePortal.close(false);
|
||||
return false;
|
||||
}
|
||||
@ -362,7 +362,7 @@ public class PlayerEventListener implements Listener {
|
||||
|
||||
// Not open for this player
|
||||
if (!entrancePortal.isOpenFor(player)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
entrancePortal.teleport(player, entrancePortal, event);
|
||||
return false;
|
||||
}
|
||||
@ -373,8 +373,8 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
|
||||
//Player cannot access portal
|
||||
if (Stargate.cannotAccessPortal(player, entrancePortal, destination)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destination)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
entrancePortal.teleport(player, entrancePortal, event);
|
||||
entrancePortal.close(false);
|
||||
return false;
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.utility.EconomyHandler;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
@ -59,13 +60,13 @@ public class VehicleEventListener implements Listener {
|
||||
*/
|
||||
private static void teleportVehicle(List<Entity> passengers, Portal entrancePortal, Vehicle vehicle) {
|
||||
if (!passengers.isEmpty() && passengers.get(0) instanceof Player) {
|
||||
Stargate.log.info(Stargate.getString("prefox") + "Found passenger vehicle");
|
||||
Stargate.logger.info(Stargate.getString("prefox") + "Found passenger vehicle");
|
||||
teleportPlayerAndVehicle(entrancePortal, vehicle, passengers);
|
||||
} else {
|
||||
Stargate.log.info(Stargate.getString("prefox") + "Found empty vehicle");
|
||||
Stargate.logger.info(Stargate.getString("prefox") + "Found empty vehicle");
|
||||
Portal destinationPortal = entrancePortal.getDestination();
|
||||
if (destinationPortal == null) {
|
||||
Stargate.log.warning(Stargate.getString("prefox") + "Unable to find portal destination");
|
||||
Stargate.logger.warning(Stargate.getString("prefox") + "Unable to find portal destination");
|
||||
return;
|
||||
}
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " + destinationPortal.getId());
|
||||
@ -83,7 +84,7 @@ public class VehicleEventListener implements Listener {
|
||||
private static void teleportPlayerAndVehicle(Portal entrancePortal, Vehicle vehicle, List<Entity> passengers) {
|
||||
Player player = (Player) passengers.get(0);
|
||||
if (!entrancePortal.isOpenFor(player)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -93,8 +94,8 @@ public class VehicleEventListener implements Listener {
|
||||
}
|
||||
|
||||
//Make sure the user can access the portal
|
||||
if (Stargate.cannotAccessPortal(player, entrancePortal, destinationPortal)) {
|
||||
Stargate.sendMessage(player, Stargate.getString("denyMsg"));
|
||||
if (PermissionHelper.cannotAccessPortal(player, entrancePortal, destinationPortal)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
entrancePortal.close(false);
|
||||
return;
|
||||
}
|
||||
@ -107,7 +108,7 @@ public class VehicleEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
||||
Stargate.sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
destinationPortal.teleport(vehicle, entrancePortal);
|
||||
entrancePortal.close(false);
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ public class Gate {
|
||||
|
||||
bufferedWriter.close();
|
||||
} catch (IOException ex) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
|
||||
Stargate.logger.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class GateHandler {
|
||||
try (Scanner scanner = new Scanner(file)) {
|
||||
return loadGate(file.getName(), file.getParent(), scanner);
|
||||
} catch (Exception ex) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
|
||||
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -180,13 +180,13 @@ public class GateHandler {
|
||||
*/
|
||||
private static boolean validateGate(Gate gate, String fileName) {
|
||||
if (gate.getLayout().getControls().length != 2) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + fileName +
|
||||
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName +
|
||||
" - Gates must have exactly 2 control points.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + fileName +
|
||||
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName +
|
||||
" - Gate button must be a type of button.");
|
||||
return false;
|
||||
}
|
||||
@ -253,7 +253,7 @@ public class GateHandler {
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + fileName + " - " + ex.getMessage());
|
||||
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - " + ex.getMessage());
|
||||
return -1;
|
||||
} finally {
|
||||
if (scanner != null) {
|
||||
@ -283,7 +283,7 @@ public class GateHandler {
|
||||
|
||||
for (Character symbol : line.toCharArray()) {
|
||||
if ((symbol.equals('?')) || (!types.containsKey(symbol))) {
|
||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + fileName + " - Unknown symbol '" + symbol + "' in diagram");
|
||||
Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - Unknown symbol '" + symbol + "' in diagram");
|
||||
return -1;
|
||||
}
|
||||
row.add(symbol);
|
||||
@ -334,7 +334,7 @@ public class GateHandler {
|
||||
try {
|
||||
return Integer.parseInt(config.get(key));
|
||||
} catch (NumberFormatException ex) {
|
||||
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), fileName, key));
|
||||
Stargate.logger.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), fileName, key));
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ public class GateHandler {
|
||||
if (material != null) {
|
||||
return material;
|
||||
} else {
|
||||
Stargate.log.log(Level.WARNING, String.format("Error reading %s: %s is not a material", fileName, key));
|
||||
Stargate.logger.log(Level.WARNING, String.format("Error reading %s: %s is not a material", fileName, key));
|
||||
}
|
||||
}
|
||||
return defaultMaterial;
|
||||
|
@ -511,8 +511,8 @@ public class Portal {
|
||||
//Update the open state of this portal
|
||||
isOpen = true;
|
||||
openTime = System.currentTimeMillis() / 1000;
|
||||
Stargate.openList.add(this);
|
||||
Stargate.activeList.remove(this);
|
||||
Stargate.openPortalsQueue.add(this);
|
||||
Stargate.activePortalsQueue.remove(this);
|
||||
|
||||
//Open remote portal
|
||||
if (!isAlwaysOn()) {
|
||||
@ -561,8 +561,8 @@ public class Portal {
|
||||
//Update the closed state of this portal
|
||||
player = null;
|
||||
isOpen = false;
|
||||
Stargate.openList.remove(this);
|
||||
Stargate.activeList.remove(this);
|
||||
Stargate.openPortalsQueue.remove(this);
|
||||
Stargate.activePortalsQueue.remove(this);
|
||||
|
||||
//Close remote portal
|
||||
if (!isAlwaysOn()) {
|
||||
@ -714,7 +714,7 @@ public class Portal {
|
||||
if (vehicle instanceof RideableMinecart || vehicle instanceof Boat) {
|
||||
World vehicleWorld = exit.getWorld();
|
||||
if (vehicleWorld == null) {
|
||||
Stargate.log.warning(Stargate.getString("prefix") + "Unable to get the world to teleport the vehicle to");
|
||||
Stargate.logger.warning(Stargate.getString("prefix") + "Unable to get the world to teleport the vehicle to");
|
||||
return;
|
||||
}
|
||||
putPassengersInNewVehicle(vehicle, passengers, vehicleWorld, exit, newVelocity);
|
||||
@ -803,7 +803,7 @@ public class Portal {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Stargate.log.log(Level.WARNING, Stargate.getString("prefix") + "Missing destination point in .gate file " + gate.getFilename());
|
||||
Stargate.logger.log(Level.WARNING, Stargate.getString("prefix") + "Missing destination point in .gate file " + gate.getFilename());
|
||||
}
|
||||
|
||||
return adjustExitLocation(traveller, exitLocation);
|
||||
@ -895,7 +895,7 @@ public class Portal {
|
||||
exitLocation.setPitch(traveller.getPitch());
|
||||
return exitLocation;
|
||||
} else {
|
||||
Stargate.log.log(Level.WARNING, Stargate.getString("prefix") + "Unable to generate exit location");
|
||||
Stargate.logger.log(Level.WARNING, Stargate.getString("prefix") + "Unable to generate exit location");
|
||||
}
|
||||
return traveller;
|
||||
}
|
||||
@ -1026,7 +1026,7 @@ public class Portal {
|
||||
private boolean activate(Player player) {
|
||||
destinations.clear();
|
||||
destination = "";
|
||||
Stargate.activeList.add(this);
|
||||
Stargate.activePortalsQueue.add(this);
|
||||
activePlayer = player;
|
||||
String network = getNetwork();
|
||||
destinations = PortalHandler.getDestinations(this, player, network);
|
||||
@ -1040,7 +1040,7 @@ public class Portal {
|
||||
StargateActivateEvent event = new StargateActivateEvent(this, player, destinations, destination);
|
||||
Stargate.server.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
Stargate.activeList.remove(this);
|
||||
Stargate.activePortalsQueue.remove(this);
|
||||
return false;
|
||||
}
|
||||
destination = event.getDestination();
|
||||
@ -1059,7 +1059,7 @@ public class Portal {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.activeList.remove(this);
|
||||
Stargate.activePortalsQueue.remove(this);
|
||||
if (isFixed()) {
|
||||
return;
|
||||
}
|
||||
@ -1110,7 +1110,7 @@ public class Portal {
|
||||
}
|
||||
|
||||
if (destinations.size() == 0) {
|
||||
Stargate.sendMessage(player, Stargate.getString("destEmpty"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("destEmpty"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1147,7 +1147,7 @@ public class Portal {
|
||||
public final void drawSign() {
|
||||
BlockState state = id.getBlock().getState();
|
||||
if (!(state instanceof Sign)) {
|
||||
Stargate.log.warning(Stargate.getString("prefix") + "Sign block is not a Sign object");
|
||||
Stargate.logger.warning(Stargate.getString("prefix") + "Sign block is not a Sign object");
|
||||
Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation());
|
||||
return;
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Keeps track of all loaded portals, and handles portal creation
|
||||
*/
|
||||
public class PortalHandler {
|
||||
// Static variables used to store portal lists
|
||||
private static final Map<BlockLocation, Portal> lookupBlocks = new HashMap<>();
|
||||
@ -92,7 +95,7 @@ public class PortalHandler {
|
||||
}
|
||||
// Check if this player can access the dest world
|
||||
if (PermissionHelper.cannotAccessWorld(player, portal.getWorld().getName())) {
|
||||
Stargate.log.info("cannot access world");
|
||||
Stargate.logger.info("cannot access world");
|
||||
continue;
|
||||
}
|
||||
// Visible to this player.
|
||||
@ -316,16 +319,16 @@ public class PortalHandler {
|
||||
//If the player is trying to create a Bungee gate without permissions, drop out here
|
||||
if (options.indexOf(PortalOption.BUNGEE.getCharacterRepresentation()) != -1) {
|
||||
if (!PermissionHelper.hasPermission(player, "stargate.admin.bungee")) {
|
||||
Stargate.sendMessage(player, Stargate.getString("bungeeDeny"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDeny"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (portalOptions.get(PortalOption.BUNGEE)) {
|
||||
if (!Stargate.enableBungee) {
|
||||
Stargate.sendMessage(player, Stargate.getString("bungeeDisabled"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("bungeeDisabled"));
|
||||
return null;
|
||||
} else if (destinationName.isEmpty() || network.isEmpty()) {
|
||||
Stargate.sendMessage(player, Stargate.getString("bungeeEmpty"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("bungeeEmpty"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -351,7 +354,7 @@ public class PortalHandler {
|
||||
network = player.getName();
|
||||
if (network.length() > 11) network = network.substring(0, 11);
|
||||
Stargate.debug("createPortal", "Creating personal portal");
|
||||
Stargate.sendMessage(player, Stargate.getString("createPersonal"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createPersonal"));
|
||||
} else {
|
||||
Stargate.debug("createPortal", "Player does not have access to network");
|
||||
deny = true;
|
||||
@ -387,7 +390,7 @@ public class PortalHandler {
|
||||
BlockLocation b = topLeft.modRelative(v.getRight(), v.getDepth(), v.getDistance(), modX, 1, modZ);
|
||||
if (getByBlock(b.getBlock()) != null) {
|
||||
Stargate.debug("createPortal", "Gate conflicts with existing gate");
|
||||
Stargate.sendMessage(player, Stargate.getString("createConflict"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createConflict"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -406,7 +409,7 @@ public class PortalHandler {
|
||||
return null;
|
||||
}
|
||||
if (cEvent.getDeny()) {
|
||||
Stargate.sendMessage(player, cEvent.getDenyReason());
|
||||
Stargate.sendErrorMessage(player, cEvent.getDenyReason());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -415,7 +418,7 @@ public class PortalHandler {
|
||||
// Name & Network can be changed in the event, so do these checks here.
|
||||
if (portal.getName().length() < 1 || portal.getName().length() > 11) {
|
||||
Stargate.debug("createPortal", "Name length error");
|
||||
Stargate.sendMessage(player, Stargate.getString("createNameLength"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createNameLength"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -423,20 +426,20 @@ public class PortalHandler {
|
||||
if (portal.isBungee()) {
|
||||
if (bungeePortals.get(portal.getName().toLowerCase()) != null) {
|
||||
Stargate.debug("createPortal::Bungee", "Gate Exists");
|
||||
Stargate.sendMessage(player, Stargate.getString("createExists"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createExists"));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (getByName(portal.getName(), portal.getNetwork()) != null) {
|
||||
Stargate.debug("createPortal", "Name Error");
|
||||
Stargate.sendMessage(player, Stargate.getString("createExists"));
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createExists"));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if there are too many gates in this network
|
||||
List<String> netList = allPortalNetworks.get(portal.getNetwork().toLowerCase());
|
||||
if (Stargate.maxGates > 0 && netList != null && netList.size() >= Stargate.maxGates) {
|
||||
Stargate.sendMessage(player, Stargate.getString("createFull"));
|
||||
if (Stargate.maxGatesEachNetwork > 0 && netList != null && netList.size() >= Stargate.maxGatesEachNetwork) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("createFull"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -715,7 +718,7 @@ public class PortalHandler {
|
||||
|
||||
bw.close();
|
||||
} catch (Exception e) {
|
||||
Stargate.log.log(Level.SEVERE, "Exception while writing stargates to " + loc + ": " + e);
|
||||
Stargate.logger.log(Level.SEVERE, "Exception while writing stargates to " + loc + ": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -783,7 +786,7 @@ public class PortalHandler {
|
||||
if (database.exists()) {
|
||||
return loadGates(world, database);
|
||||
} else {
|
||||
Stargate.log.info(Stargate.getString("prefix") + "{" + world.getName() + "} No stargates for world ");
|
||||
Stargate.logger.info(Stargate.getString("prefix") + "{" + world.getName() + "} No stargates for world ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -811,7 +814,7 @@ public class PortalHandler {
|
||||
//Check if the min. required portal data is present
|
||||
String[] portalData = line.split(":");
|
||||
if (portalData.length < 8) {
|
||||
Stargate.log.info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
|
||||
Stargate.logger.info(Stargate.getString("prefix") + "Invalid line - " + lineIndex);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -822,12 +825,12 @@ public class PortalHandler {
|
||||
// Open any always-on gates. Do this here as it should be more efficient than in the loop.
|
||||
TwoTuple<Integer, Integer> portalCounts = openAlwaysOpenGates();
|
||||
|
||||
Stargate.log.info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
|
||||
Stargate.logger.info(String.format("%s{%s} Loaded %d stargates with %d set as always-on",
|
||||
Stargate.getString("prefix"), world.getName(), portalCounts.getSecondValue(),
|
||||
portalCounts.getFirstValue()));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Stargate.log.log(Level.SEVERE, "Exception while reading stargates from " + database.getName() + ": " + lineIndex);
|
||||
Stargate.logger.log(Level.SEVERE, "Exception while reading stargates from " + database.getName() + ": " + lineIndex);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -851,7 +854,7 @@ public class PortalHandler {
|
||||
BlockLocation topLeft = new BlockLocation(world, portalData[6]);
|
||||
Gate gate = GateHandler.getGateByName(portalData[7]);
|
||||
if (gate == null) {
|
||||
Stargate.log.info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex +
|
||||
Stargate.logger.info(Stargate.getString("prefix") + "Gate layout on line " + lineIndex +
|
||||
" does not exist [" + portalData[7] + "]");
|
||||
return;
|
||||
}
|
||||
@ -949,14 +952,14 @@ public class PortalHandler {
|
||||
}
|
||||
}
|
||||
PortalHandler.unregisterPortal(portal, false);
|
||||
Stargate.log.info(Stargate.getString("prefix") + "Destroying stargate at " + portal);
|
||||
Stargate.logger.info(Stargate.getString("prefix") + "Destroying stargate at " + portal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all star gate portals
|
||||
*/
|
||||
public static void closeAllGates() {
|
||||
Stargate.log.info("Closing all stargates.");
|
||||
Stargate.logger.info("Closing all stargates.");
|
||||
for (Portal portal : allPortals) {
|
||||
if (portal != null) {
|
||||
portal.close(true);
|
||||
|
@ -14,7 +14,7 @@ public class StarGateThread implements Runnable {
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
// Close open portals
|
||||
for (Iterator<Portal> iterator = Stargate.openList.iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<Portal> iterator = Stargate.openPortalsQueue.iterator(); iterator.hasNext(); ) {
|
||||
Portal portal = iterator.next();
|
||||
// Skip always open and non-open gates
|
||||
if (portal.isAlwaysOn() || !portal.isOpen()) {
|
||||
@ -26,7 +26,7 @@ public class StarGateThread implements Runnable {
|
||||
}
|
||||
}
|
||||
// Deactivate active portals
|
||||
for (Iterator<Portal> iterator = Stargate.activeList.iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<Portal> iterator = Stargate.activePortalsQueue.iterator(); iterator.hasNext(); ) {
|
||||
Portal portal = iterator.next();
|
||||
if (!portal.isActive()) {
|
||||
continue;
|
||||
|
@ -48,7 +48,7 @@ public final class BungeeHelper {
|
||||
dataOutputStream.writeBytes(message);
|
||||
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
|
||||
} catch (IOException ex) {
|
||||
Stargate.log.severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet");
|
||||
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord teleport packet");
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@ -72,7 +72,7 @@ public final class BungeeHelper {
|
||||
player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray());
|
||||
byteArrayOutputStream.reset();
|
||||
} catch (IOException ex) {
|
||||
Stargate.log.severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet");
|
||||
Stargate.logger.severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet");
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@ -99,7 +99,7 @@ public final class BungeeHelper {
|
||||
data = new byte[dataLength];
|
||||
dataInputStream.readFully(data);
|
||||
} catch (IOException ex) {
|
||||
Stargate.log.severe(Stargate.getString("prefix") + "Error receiving BungeeCord message");
|
||||
Stargate.logger.severe(Stargate.getString("prefix") + "Error receiving BungeeCord message");
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -127,7 +127,7 @@ public final class BungeeHelper {
|
||||
Portal destinationPortal = PortalHandler.getBungeeGate(destination);
|
||||
// Specified an invalid gate. For now we'll just let them connect at their current location
|
||||
if (destinationPortal == null) {
|
||||
Stargate.log.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist");
|
||||
Stargate.logger.info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist");
|
||||
return;
|
||||
}
|
||||
destinationPortal.teleport(player, destinationPortal, null);
|
||||
|
@ -152,10 +152,10 @@ public final class EconomyHandler {
|
||||
EconomyHandler.vault = vault;
|
||||
return true;
|
||||
} else {
|
||||
Stargate.log.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError"));
|
||||
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("ecoLoadError"));
|
||||
}
|
||||
} else {
|
||||
Stargate.log.info(Stargate.getString("prefix") + Stargate.getString("vaultLoadError"));
|
||||
Stargate.logger.info(Stargate.getString("prefix") + Stargate.getString("vaultLoadError"));
|
||||
}
|
||||
economyEnabled = false;
|
||||
return false;
|
||||
|
@ -68,7 +68,7 @@ public final class EconomyHelper {
|
||||
public static void sendObtainMessage(String portalName, Player portalOwner, int earnings) {
|
||||
String obtainedMsg = Stargate.getString("ecoObtain");
|
||||
obtainedMsg = replaceVars(obtainedMsg, portalName, earnings);
|
||||
Stargate.sendMessage(portalOwner, obtainedMsg, false);
|
||||
Stargate.sendSuccessMessage(portalOwner, obtainedMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ public final class EconomyHelper {
|
||||
public static void sendDeductMessage(String portalName, Player player, int cost) {
|
||||
String deductMsg = Stargate.getString("ecoDeduct");
|
||||
deductMsg = replaceVars(deductMsg, portalName, cost);
|
||||
Stargate.sendMessage(player, deductMsg, false);
|
||||
Stargate.sendSuccessMessage(player, deductMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ public final class EconomyHelper {
|
||||
public static void sendInsufficientFundsMessage(String portalName, Player player, int cost) {
|
||||
String inFundMsg = Stargate.getString("ecoInFunds");
|
||||
inFundMsg = replaceVars(inFundMsg, portalName, cost);
|
||||
Stargate.sendMessage(player, inFundMsg);
|
||||
Stargate.sendErrorMessage(player, inFundMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +107,7 @@ public final class EconomyHelper {
|
||||
public static void sendRefundMessage(String portalName, Player player, int cost) {
|
||||
String refundMsg = Stargate.getString("ecoRefund");
|
||||
refundMsg = replaceVars(refundMsg, portalName, -cost);
|
||||
Stargate.sendMessage(player, refundMsg, false);
|
||||
Stargate.sendSuccessMessage(player, refundMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.event.StargateAccessEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalOption;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,6 +15,102 @@ public final class PermissionHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a portal if the given player is allowed to, and if the portal is not already open
|
||||
*
|
||||
* @param player <p>The player opening the portal</p>
|
||||
* @param portal <p>The portal to open</p>
|
||||
*/
|
||||
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.sendErrorMessage(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.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if the player can use the private gate
|
||||
if (portal.isPrivate() && !PermissionHelper.canPrivate(player, portal)) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("denyMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Destination blocked
|
||||
if ((destination.isOpen()) && (!destination.isAlwaysOn())) {
|
||||
Stargate.sendErrorMessage(player, Stargate.getString("blockMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Open gate
|
||||
portal.open(player, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StargateAccessPortal 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) {
|
||||
StargateAccessEvent event = new StargateAccessEvent(player, portal, deny);
|
||||
Stargate.server.getPluginManager().callEvent(event);
|
||||
return event.getDeny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given user cannot travel between two portals
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @param entrancePortal <p>The portal the user wants to enter</p>
|
||||
* @param destination <p>The portal the user wants to exit</p>
|
||||
* @return <p>False if the user is allowed to access the portal</p>
|
||||
*/
|
||||
public static boolean cannotAccessPortal(Player player, Portal entrancePortal, Portal destination) {
|
||||
boolean deny = false;
|
||||
// Check if player has access to this server for Bungee gates
|
||||
if (entrancePortal.isBungee() && !PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
||||
deny = true;
|
||||
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
||||
deny = true;
|
||||
} else if (!entrancePortal.isBungee() && PermissionHelper.cannotAccessWorld(player, destination.getWorld().getName())) {
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access world");
|
||||
deny = true;
|
||||
}
|
||||
return cannotAccessPortal(player, entrancePortal, deny);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has the given permission
|
||||
*
|
||||
@ -55,8 +152,9 @@ public final class PermissionHelper {
|
||||
|
||||
/**
|
||||
* Checks whether a player can access the given world
|
||||
*
|
||||
* @param player <p>The player trying to access the world</p>
|
||||
* @param world <p>The world the player is trying to access</p>
|
||||
* @param world <p>The world the player is trying to access</p>
|
||||
* @return <p>False if the player should be allowed to access the world</p>
|
||||
*/
|
||||
public static boolean cannotAccessWorld(Player player, String world) {
|
||||
@ -96,6 +194,7 @@ public final class PermissionHelper {
|
||||
|
||||
/**
|
||||
* Checks whether a player can access the given bungee server
|
||||
*
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @param server <p>The server the player is trying to connect to</p>
|
||||
* @return <p>True if the player is allowed to access the given server</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user