diff --git a/src/main/java/net/knarcraft/stargate/Stargate.java b/src/main/java/net/knarcraft/stargate/Stargate.java index c9e2b60..0c3b72c 100644 --- a/src/main/java/net/knarcraft/stargate/Stargate.java +++ b/src/main/java/net/knarcraft/stargate/Stargate.java @@ -55,7 +55,7 @@ public class Stargate extends JavaPlugin { public static final Queue blockChangeRequestQueue = new LinkedList<>(); public static final ConcurrentLinkedQueue openPortalsQueue = new ConcurrentLinkedQueue<>(); public static final ConcurrentLinkedQueue activePortalsQueue = new ConcurrentLinkedQueue<>(); - public static final Queue chunkUnloadQueue = new PriorityQueue<>(); + private static final Queue chunkUnloadQueue = new PriorityQueue<>(); //Amount of seconds before deactivating/closing portals private static final int activeTime = 10; @@ -482,9 +482,9 @@ public class Stargate extends JavaPlugin { */ private void loadEconomyConfig() { EconomyHandler.economyEnabled = newConfig.getBoolean("economy.useEconomy"); - EconomyHandler.setCreateCost(newConfig.getInt("economy.createCost")); - EconomyHandler.setDestroyCost(newConfig.getInt("economy.destroyCost")); - EconomyHandler.setUseCost(newConfig.getInt("economy.useCost")); + EconomyHandler.setDefaultCreateCost(newConfig.getInt("economy.createCost")); + EconomyHandler.setDefaultDestroyCost(newConfig.getInt("economy.destroyCost")); + EconomyHandler.setDefaultUseCost(newConfig.getInt("economy.useCost")); EconomyHandler.toOwner = newConfig.getBoolean("economy.toOwner"); EconomyHandler.chargeFreeDestination = newConfig.getBoolean("economy.chargeFreeDestination"); EconomyHandler.freeGatesGreen = newConfig.getBoolean("economy.freeGatesGreen"); diff --git a/src/main/java/net/knarcraft/stargate/portal/GateHandler.java b/src/main/java/net/knarcraft/stargate/portal/GateHandler.java index 8993150..fa20d6a 100644 --- a/src/main/java/net/knarcraft/stargate/portal/GateHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/GateHandler.java @@ -117,24 +117,24 @@ public class GateHandler { */ private static Gate loadGate(String fileName, String parentFolder, Scanner scanner) { List> design = new ArrayList<>(); - Map types = new HashMap<>(); + Map characterMaterialMap = new HashMap<>(); Map config = new HashMap<>(); Set frameTypes = new HashSet<>(); //Initialize types map - types.put(ENTRANCE, Material.AIR); - types.put(EXIT, Material.AIR); - types.put(ANYTHING, Material.AIR); + characterMaterialMap.put(ENTRANCE, Material.AIR); + characterMaterialMap.put(EXIT, Material.AIR); + characterMaterialMap.put(ANYTHING, Material.AIR); //Read the file into appropriate lists and maps - int cols = readGateFile(scanner, types, fileName, design, frameTypes, config); + int cols = readGateFile(scanner, characterMaterialMap, fileName, design, frameTypes, config); if (cols < 0) { return null; } Character[][] layout = generateLayoutMatrix(design, cols); //Create and validate the new gate - Gate gate = createGate(config, fileName, layout, types); + Gate gate = createGate(config, fileName, layout, characterMaterialMap); if (gate == null) { return null; } @@ -146,23 +146,25 @@ public class GateHandler { /** * Creates a new gate * - * @param config

The config map to get configuration values from

- * @param fileName

The name of the saved gate config file

- * @param layout

The layout matrix of the new gate

- * @param types

The mapping for used gate material types

+ * @param config

The config map to get configuration values from

+ * @param fileName

The name of the saved gate config file

+ * @param layout

The layout matrix of the new gate

+ * @param characterMaterialMap

The mapping for used gate material types

* @return

A new gate or null if the config is invalid

*/ private static Gate createGate(Map config, String fileName, Character[][] layout, - Map types) { + Map characterMaterialMap) { Material portalOpenBlock = readConfig(config, fileName, "portal-open", defaultPortalBlockOpen); Material portalClosedBlock = readConfig(config, fileName, "portal-closed", defaultPortalBlockClosed); Material portalButton = readConfig(config, fileName, "button", defaultButton); int useCost = readConfig(config, fileName, "usecost"); int createCost = readConfig(config, fileName, "createcost"); int destroyCost = readConfig(config, fileName, "destroycost"); - boolean toOwner = (config.containsKey("toowner") ? Boolean.parseBoolean(config.get("toowner")) : EconomyHandler.toOwner); + boolean toOwner = (config.containsKey("toowner") ? Boolean.parseBoolean(config.get("toowner")) : + EconomyHandler.toOwner); - Gate gate = new Gate(fileName, new GateLayout(layout), types, portalOpenBlock, portalClosedBlock, portalButton, useCost, + Gate gate = new Gate(fileName, new GateLayout(layout), characterMaterialMap, portalOpenBlock, portalClosedBlock, + portalButton, useCost, createCost, destroyCost, toOwner); if (!validateGate(gate, fileName)) { @@ -223,15 +225,15 @@ public class GateHandler { /** * Reads the gate file * - * @param scanner

The scanner to read from

- * @param types

The map of characters to store valid symbols in

- * @param fileName

The filename of the loaded gate config file

- * @param design

The list to store the loaded design to

- * @param frameTypes

The set of gate frame types to store to

- * @param config

The map of config values to store to

+ * @param scanner

The scanner to read from

+ * @param characterMaterialMap

The map of characters to store valid symbols in

+ * @param fileName

The filename of the loaded gate config file

+ * @param design

The list to store the loaded design to

+ * @param frameTypes

The set of gate frame types to store to

+ * @param config

The map of config values to store to

* @return

The column count/width of the loaded gate

*/ - private static int readGateFile(Scanner scanner, Map types, String fileName, + private static int readGateFile(Scanner scanner, Map characterMaterialMap, String fileName, List> design, Set frameTypes, Map config) { boolean designing = false; int cols = 0; @@ -240,13 +242,13 @@ public class GateHandler { String line = scanner.nextLine(); if (designing) { - cols = readGateDesignLine(line, cols, types, fileName, design); + cols = readGateDesignLine(line, cols, characterMaterialMap, fileName, design); if (cols < 0) { return -1; } } else { if (!line.isEmpty() && !line.startsWith("#")) { - readGateConfigValue(line, types, frameTypes, config); + readGateConfigValue(line, characterMaterialMap, frameTypes, config); } else if ((line.isEmpty()) || (!line.contains("=") && !line.startsWith("#"))) { designing = true; } @@ -268,13 +270,13 @@ public class GateHandler { * * @param line

The line to read

* @param cols

The current max columns value of the design

- * @param types

The map of characters to check for valid symbols

+ * @param characterMaterialMap

The map of characters to check for valid symbols

* @param fileName

The filename of the loaded gate config file

* @param design

The list to store the loaded design to

* @return

The new max columns value of the design

*/ - private static int readGateDesignLine(String line, int cols, Map types, String fileName, - List> design) { + private static int readGateDesignLine(String line, int cols, Map characterMaterialMap, + String fileName, List> design) { List row = new ArrayList<>(); if (line.length() > cols) { @@ -282,8 +284,9 @@ public class GateHandler { } for (Character symbol : line.toCharArray()) { - if ((symbol.equals('?')) || (!types.containsKey(symbol))) { - Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - Unknown symbol '" + symbol + "' in diagram"); + if ((symbol.equals('?')) || (!characterMaterialMap.containsKey(symbol))) { + Stargate.logger.log(Level.SEVERE, "Could not load Gate " + fileName + " - Unknown symbol '" + + symbol + "' in diagram"); return -1; } row.add(symbol); @@ -297,13 +300,13 @@ public class GateHandler { * Reads one config value from the gate layout file * * @param line

The line to read

- * @param types

The map of characters to materials to store to

+ * @param characterMaterialMap

The map of characters to materials to store to

* @param frameTypes

The set of gate frame types to store to

* @param config

The map of config values to store to

* @throws Exception

If an invalid material is encountered

*/ - private static void readGateConfigValue(String line, Map types, Set frameTypes, - Map config) throws Exception { + private static void readGateConfigValue(String line, Map characterMaterialMap, + Set frameTypes, Map config) throws Exception { String[] split = line.split("="); String key = split[0].trim(); String value = split[1].trim(); @@ -314,7 +317,7 @@ public class GateHandler { if (id == null) { throw new Exception("Invalid material in line: " + line); } - types.put(symbol, id); + characterMaterialMap.put(symbol, id); frameTypes.add(id); } else { config.put(key, value); @@ -334,7 +337,8 @@ public class GateHandler { try { return Integer.parseInt(config.get(key)); } catch (NumberFormatException ex) { - Stargate.logger.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)); } }