From 624c9b52d716e90ac4e22b6d60ffdce3c60adc0a Mon Sep 17 00:00:00 2001 From: PseudoKnight Date: Wed, 23 May 2018 15:03:44 -0700 Subject: [PATCH] Code cleanup --- .gitignore | 2 + pom.xml | 2 +- src/net/TheDgtl/Stargate/EconomyHandler.java | 3 +- src/net/TheDgtl/Stargate/Gate.java | 36 +- src/net/TheDgtl/Stargate/LangLoader.java | 11 +- src/net/TheDgtl/Stargate/MetricsLite.java | 398 ------------------- src/net/TheDgtl/Stargate/Portal.java | 69 ++-- src/net/TheDgtl/Stargate/Stargate.java | 179 ++------- 8 files changed, 88 insertions(+), 612 deletions(-) create mode 100644 .gitignore delete mode 100644 src/net/TheDgtl/Stargate/MetricsLite.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef862 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +.idea/ diff --git a/pom.xml b/pom.xml index bfdf0a3..1de5ef5 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.spigotmc spigot-api - 1.12-R0.1-SNAPSHOT + 1.12.2-R0.1-SNAPSHOT net.milkbowl.vault diff --git a/src/net/TheDgtl/Stargate/EconomyHandler.java b/src/net/TheDgtl/Stargate/EconomyHandler.java index 64cb2d4..4faeaac 100644 --- a/src/net/TheDgtl/Stargate/EconomyHandler.java +++ b/src/net/TheDgtl/Stargate/EconomyHandler.java @@ -76,8 +76,7 @@ public class EconomyHandler { } public static boolean useEconomy() { - if(!economyEnabled || economy == null) return false; - return true; + return economyEnabled && economy != null; } } diff --git a/src/net/TheDgtl/Stargate/Gate.java b/src/net/TheDgtl/Stargate/Gate.java index 6269fa9..340ad29 100644 --- a/src/net/TheDgtl/Stargate/Gate.java +++ b/src/net/TheDgtl/Stargate/Gate.java @@ -39,9 +39,9 @@ public class Gate { public static final int ENTRANCE = -2; public static final int CONTROL = -3; public static final int EXIT = -4; - private static HashMap gates = new HashMap(); - private static HashMap> controlBlocks = new HashMap>(); - private static HashSet frameBlocks = new HashSet(); + private static HashMap gates = new HashMap<>(); + private static HashMap> controlBlocks = new HashMap<>(); + private static HashSet frameBlocks = new HashSet<>(); private String filename; private Character[][] layout; @@ -51,7 +51,7 @@ public class Gate { private RelativeBlockVector[] border = new RelativeBlockVector[0]; private RelativeBlockVector[] controls = new RelativeBlockVector[0]; private RelativeBlockVector exitBlock = null; - private HashMap exits = new HashMap(); + private HashMap exits = new HashMap<>(); private int portalBlockOpen = Material.PORTAL.getId(); private int portalBlockClosed = Material.AIR.getId(); @@ -71,9 +71,9 @@ public class Gate { } private void populateCoordinates() { - ArrayList entranceList = new ArrayList(); - ArrayList borderList = new ArrayList(); - ArrayList controlList = new ArrayList(); + ArrayList entranceList = new ArrayList<>(); + ArrayList borderList = new ArrayList<>(); + ArrayList controlList = new ArrayList<>(); RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length]; int[] exitDepths = new int[layout[0].length]; RelativeBlockVector lastExit = null; @@ -312,11 +312,11 @@ public class Gate { public static Gate loadGate(File file) { Scanner scanner = null; boolean designing = false; - ArrayList> design = new ArrayList>(); - HashMap types = new HashMap(); - HashMap metadata = new HashMap(); - HashMap config = new HashMap(); - HashSet frameTypes = new HashSet(); + ArrayList> design = new ArrayList<>(); + HashMap types = new HashMap<>(); + HashMap metadata = new HashMap<>(); + HashMap config = new HashMap<>(); + HashSet frameTypes = new HashSet<>(); int cols = 0; // Init types map @@ -331,7 +331,7 @@ public class Gate { String line = scanner.nextLine(); if (designing) { - ArrayList row = new ArrayList(); + ArrayList row = new ArrayList<>(); if (line.length() > cols) { cols = line.length(); @@ -460,13 +460,13 @@ public class Gate { {'X', '*', '.', 'X'}, {' ', 'X', 'X', ' '}, }; - HashMap types = new HashMap(); + HashMap types = new HashMap<>(); types.put('.', ENTRANCE); types.put('*', EXIT); types.put(' ', ANYTHING); types.put('X', Obsidian); types.put('-', Obsidian); - HashMap metadata = new HashMap(); + HashMap metadata = new HashMap<>(); Gate gate = new Gate("nethergate.gate", layout, types, metadata); gate.save(gateFolder); @@ -505,8 +505,8 @@ public class Gate { } public static void clearGates() { - gates.clear(); - controlBlocks.clear(); - frameBlocks.clear(); + gates.clear(); + controlBlocks.clear(); + frameBlocks.clear(); } } diff --git a/src/net/TheDgtl/Stargate/LangLoader.java b/src/net/TheDgtl/Stargate/LangLoader.java index db384b4..6325d84 100644 --- a/src/net/TheDgtl/Stargate/LangLoader.java +++ b/src/net/TheDgtl/Stargate/LangLoader.java @@ -81,8 +81,8 @@ public class LangLoader { // with missing lines from the in-JAR files private void updateLanguage(String lang) { // Load the current language file - ArrayList keyList = new ArrayList(); - ArrayList valList = new ArrayList(); + ArrayList keyList = new ArrayList<>(); + ArrayList valList = new ArrayList<>(); HashMap curLang = load(lang); @@ -160,7 +160,7 @@ public class LangLoader { } private HashMap load(String lang, InputStream is) { - HashMap strings = new HashMap(); + HashMap strings = new HashMap<>(); FileInputStream fis = null; InputStreamReader isr = null; try { @@ -192,8 +192,9 @@ public class LangLoader { return null; } finally { if (fis != null) { - try {fis.close();} - catch (Exception ex) {} + try { + fis.close(); + } catch (Exception ex) {} } } return strings; diff --git a/src/net/TheDgtl/Stargate/MetricsLite.java b/src/net/TheDgtl/Stargate/MetricsLite.java deleted file mode 100644 index e1f293a..0000000 --- a/src/net/TheDgtl/Stargate/MetricsLite.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright 2011 Tyler Blair. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ - -package net.TheDgtl.Stargate; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitTask; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.UUID; -import java.util.logging.Level; - -public class MetricsLite { - - /** - * The current revision number - */ - private final static int REVISION = 6; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/report/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private final static int PING_INTERVAL = 10; - - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - - /** - * The plugin configuration file - */ - private final File configurationFile; - - /** - * Unique server id - */ - private final String guid; - - /** - * Debug mode - */ - private final boolean debug; - - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - - /** - * Id of the scheduled task - */ - private volatile BukkitTask task = null; - - public MetricsLite(Plugin plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - configuration.addDefault("debug", false); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); - debug = configuration.getBoolean("debug", false); - } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send - * the initial data to the metrics backend, and then after that it will post in increments of - * PING_INTERVAL * 1200 ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; - } - - // Is metrics already running? - if (task != null) { - return true; - } - - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - - private boolean firstPost = true; - - public void run() { - try { - // This has to be synchronized or it can collide with the disable method. - synchronized (optOutLock) { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && task != null) { - task.cancel(); - task = null; - } - } - - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (IOException e) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } - } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() { - synchronized(optOutLock) { - try { - // Reload the metrics file - configuration.load(getConfigFile()); - } catch (IOException ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } catch (InvalidConfigurationException ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } - return configuration.getBoolean("opt-out", false); - } - } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { - configuration.set("opt-out", false); - configuration.save(configurationFile); - } - - // Enable Task, if it is not running - if (task == null) { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws IOException - */ - public void disable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) { - configuration.set("opt-out", true); - configuration.save(configurationFile); - } - - // Disable Task, if it is running - if (task != null) { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); - } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(boolean isPing) throws IOException { - // Server software specific section - PluginDescriptionFile description = plugin.getDescription(); - String pluginName = description.getName(); - boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled - String pluginVersion = description.getVersion(); - String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().size(); - - // END server software specific section -- all code below does not use any code outside of this class / Java - - // Construct the post data - final StringBuilder data = new StringBuilder(); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - data.append(encode("guid")).append('=').append(encode(guid)); - encodeDataPair(data, "version", pluginVersion); - encodeDataPair(data, "server", serverVersion); - encodeDataPair(data, "players", Integer.toString(playersOnline)); - encodeDataPair(data, "revision", String.valueOf(REVISION)); - - // New data as of R6 - String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - String osversion = System.getProperty("os.version"); - String java_version = System.getProperty("java.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) { - osarch = "x86_64"; - } - - encodeDataPair(data, "osname", osname); - encodeDataPair(data, "osarch", osarch); - encodeDataPair(data, "osversion", osversion); - encodeDataPair(data, "cores", Integer.toString(coreCount)); - encodeDataPair(data, "online-mode", Boolean.toString(onlineMode)); - encodeDataPair(data, "java_version", java_version); - - // If we're pinging, append it - if (isPing) { - encodeDataPair(data, "ping", "true"); - } - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(pluginName))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - connection.setDoOutput(true); - - // Write the data - final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); - writer.write(data.toString()); - writer.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - final String response = reader.readLine(); - - // close resources - writer.close(); - reader.close(); - - if (response == null || response.startsWith("ERR")) { - throw new IOException(response); //Throw the exception - } - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - return false; - } - } - - /** - *

Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first - * key/value pair MUST be included manually, e.g:

- * - * StringBuffer data = new StringBuffer(); - * data.append(encode("guid")).append('=').append(encode(guid)); - * encodeDataPair(data, "version", description.getVersion()); - * - * - * @param buffer the stringbuilder to append the data pair onto - * @param key the key value - * @param value the value - */ - private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException { - buffer.append('&').append(encode(key)).append('=').append(encode(value)); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String encode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } - -} \ No newline at end of file diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 7de051b..5c1d804 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Random; import java.util.Scanner; import java.util.logging.Level; @@ -26,12 +27,13 @@ import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.entity.StorageMinecart; +import org.bukkit.entity.minecart.StorageMinecart; import org.bukkit.entity.Vehicle; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.material.Button; import org.bukkit.material.MaterialData; +import org.bukkit.material.Step; import org.bukkit.util.Vector; /** @@ -56,15 +58,15 @@ import org.bukkit.util.Vector; public class Portal { // Static variables used to store portal lists - private static final HashMap lookupBlocks = new HashMap(); - private static final HashMap lookupEntrances = new HashMap(); - private static final HashMap lookupControls = new HashMap(); - private static final ArrayList allPortals = new ArrayList(); - private static final HashMap> allPortalsNet = new HashMap>(); - private static final HashMap> lookupNamesNet = new HashMap>(); + private static final HashMap lookupBlocks = new HashMap<>(); + private static final HashMap lookupEntrances = new HashMap<>(); + private static final HashMap lookupControls = new HashMap<>(); + private static final ArrayList allPortals = new ArrayList<>(); + private static final HashMap> allPortalsNet = new HashMap<>(); + private static final HashMap> lookupNamesNet = new HashMap<>(); // A list of Bungee gates - private static final HashMap bungeePortals = new HashMap(); + private static final HashMap bungeePortals = new HashMap<>(); // Gate location block info private Blox topLeft; @@ -103,7 +105,7 @@ public class Portal { // In-use information private Player player; private Player activePlayer; - private ArrayList destinations = new ArrayList(); + private ArrayList destinations = new ArrayList<>(); private boolean isOpen = false; private long openTime; @@ -496,19 +498,19 @@ public class Portal { // Get new velocity final Vector newVelocity = new Vector(); - switch ((int)id.getBlock().getData()) { - case 2: - newVelocity.setZ(-1); - break; - case 3: - newVelocity.setZ(1); - break; - case 4: - newVelocity.setX(-1); - break; - case 5: - newVelocity.setX(1); - break; + switch (id.getBlock().getData()) { + case 2: + newVelocity.setZ(-1); + break; + case 3: + newVelocity.setZ(1); + break; + case 4: + newVelocity.setX(-1); + break; + case 5: + newVelocity.setX(1); + break; } newVelocity.multiply(velocity); @@ -547,7 +549,7 @@ public class Portal { } if (loc != null) { - if (getWorld().getBlockTypeIdAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) == Material.STEP.getId()) { + if (getWorld().getBlockAt(loc).getState().getData() instanceof Step) { loc.setY(loc.getY() + 0.5); } @@ -581,9 +583,10 @@ public class Portal { } public ArrayList getDestinations(Player player, String network) { - ArrayList destinations = new ArrayList(); + ArrayList destinations = new ArrayList<>(); for (String dest : allPortalsNet.get(network.toLowerCase())) { Portal portal = getByName(dest, network); + if (portal == null) continue; // Check if dest is a random gate if (portal.isRandom()) continue; // Check if dest is always open (Don't show if so) @@ -1324,15 +1327,15 @@ public class Portal { String network = (split.length > 9) ? split[9] : Stargate.getDefaultNetwork(); if (network.isEmpty()) network = Stargate.getDefaultNetwork(); String owner = (split.length > 10) ? split[10] : ""; - boolean hidden = (split.length > 11) ? split[11].equalsIgnoreCase("true") : false; - boolean alwaysOn = (split.length > 12) ? split[12].equalsIgnoreCase("true") : false; - boolean priv = (split.length > 13) ? split[13].equalsIgnoreCase("true") : false; - boolean free = (split.length > 15) ? split[15].equalsIgnoreCase("true") : false; - boolean backwards = (split.length > 16) ? split[16].equalsIgnoreCase("true") : false; - boolean show = (split.length > 17) ? split[17].equalsIgnoreCase("true") : false; - boolean noNetwork = (split.length > 18) ? split[18].equalsIgnoreCase("true") : false; - boolean random = (split.length > 19) ? split[19].equalsIgnoreCase("true") : false; - boolean bungee = (split.length > 20) ? split[20].equalsIgnoreCase("true") : false; + boolean hidden = (split.length > 11) && split[11].equalsIgnoreCase("true"); + boolean alwaysOn = (split.length > 12) && split[12].equalsIgnoreCase("true"); + boolean priv = (split.length > 13) && split[13].equalsIgnoreCase("true"); + boolean free = (split.length > 15) && split[15].equalsIgnoreCase("true"); + boolean backwards = (split.length > 16) && split[16].equalsIgnoreCase("true"); + boolean show = (split.length > 17) && split[17].equalsIgnoreCase("true"); + boolean noNetwork = (split.length > 18) && split[18].equalsIgnoreCase("true"); + boolean random = (split.length > 19) && split[19].equalsIgnoreCase("true"); + boolean bungee = (split.length > 20) && split[20].equalsIgnoreCase("true"); Portal portal = new Portal(topLeft, modX, modZ, rotX, sign, button, dest, name, false, network, gate, owner, hidden, alwaysOn, priv, free, backwards, show, noNetwork, random, bungee); portal.register(); diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 57e7f69..b8e1e61 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -29,6 +29,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Entity; +import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; import org.bukkit.entity.Vehicle; import org.bukkit.event.Event.Result; @@ -109,14 +110,14 @@ public class Stargate extends JavaPlugin { public static boolean debug = false; public static boolean permDebug = false; - public static ConcurrentLinkedQueue openList = new ConcurrentLinkedQueue(); - public static ConcurrentLinkedQueue activeList = new ConcurrentLinkedQueue(); + public static ConcurrentLinkedQueue openList = new ConcurrentLinkedQueue<>(); + public static ConcurrentLinkedQueue activeList = new ConcurrentLinkedQueue<>(); // Used for populating gate open/closed material. - public static Queue blockPopulatorQueue = new LinkedList(); + public static Queue blockPopulatorQueue = new LinkedList<>(); // HashMap of player names for Bungee support - public static Map bungeeQueue = new HashMap(); + public static Map bungeeQueue = new HashMap<>(); public void onDisable() { Portal.closeAllGates(); @@ -170,19 +171,6 @@ public class Stargate extends JavaPlugin { getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); getServer().getScheduler().scheduleSyncRepeatingTask(this, new BlockPopulatorThread(), 0L, 1L); - - // Enable Plugin Metrics - try { - MetricsLite ml = new MetricsLite(this); - if (!ml.isOptOut()) { - ml.start(); - log.info("[Stargate] Plugin metrics enabled."); - } else { - log.info("[Stargate] Plugin metrics not enabled."); - } - } catch (IOException ex) { - log.warning("[Stargate] Error enabling plugin metrics: " + ex); - } } public void loadConfig() { @@ -253,23 +241,6 @@ public class Stargate extends JavaPlugin { File newFile = new File(portalFolder, getServer().getWorlds().get(0).getName() + ".db"); if (!newFile.exists()) { newFile.getParentFile().mkdirs(); - // Migrate not-so-old stargate db - File oldishFile = new File("plugins/Stargate/stargate.db"); - if (oldishFile.exists()) { - Stargate.log.info("[Stargate] Migrating existing stargate.db"); - oldishFile.renameTo(newFile); - } - } - - // Migrate old gates if applicaple - File oldDir = new File("stargates"); - if (oldDir.exists()) { - File newDir = new File(gateFolder); - if (!newDir.exists()) newDir.mkdirs(); - for (File file : oldDir.listFiles(new Gate.StargateFilenameFilter())) { - Stargate.log.info("[Stargate] Migrating existing gate " + file.getName()); - file.renameTo(new File(gateFolder, file.getName())); - } } } @@ -396,12 +367,10 @@ public class Stargate extends JavaPlugin { // Can use all Stargate player features or access all worlds if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.world")) { // Do a deep check to see if the player lacks this specific world node - if (!hasPermDeep(player, "stargate.world." + world)) return false; - return true; + return hasPermDeep(player, "stargate.world." + world); } // Can access dest world - if (hasPerm(player, "stargate.world." + world)) return true; - return false; + return hasPerm(player, "stargate.world." + world); } /* @@ -411,16 +380,14 @@ public class Stargate extends JavaPlugin { // Can user all Stargate player features, or access all networks if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.network")) { // Do a deep check to see if the player lacks this specific network node - if (!hasPermDeep(player, "stargate.network." + network)) return false; - return true; + return hasPermDeep(player, "stargate.network." + network); } // Can access this network if (hasPerm(player, "stargate.network." + network)) return true; // 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); - if (network.equals(playerName) && hasPerm(player, "stargate.create.personal")) return true; - return false; + return network.equals(playerName) && hasPerm(player, "stargate.create.personal"); } /* @@ -430,12 +397,10 @@ public class Stargate extends JavaPlugin { // Can user all Stargate player features, or access all servers if (hasPerm(player, "stargate.use") || hasPerm(player, "stargate.servers")) { // Do a deep check to see if the player lacks this specific server node - if (!hasPermDeep(player, "stargate.server." + server)) return false; - return true; + return hasPermDeep(player, "stargate.server." + server); } // Can access this server - if (hasPerm(player, "stargate.server." + server)) return true; - return false; + return hasPerm(player, "stargate.server." + server); } /* @@ -444,8 +409,7 @@ public class Stargate extends JavaPlugin { public static boolean canAccessPortal(Player player, Portal portal, boolean deny) { StargateAccessEvent event = new StargateAccessEvent(player, portal, deny); Stargate.server.getPluginManager().callEvent(event); - if (event.getDeny()) return false; - return true; + return !event.getDeny(); } /* @@ -457,8 +421,7 @@ public class Stargate extends JavaPlugin { // Player gets free use if (hasPerm(player, "stargate.free") || Stargate.hasPerm(player, "stargate.free.use")) return true; // Don't charge for free destination gates - if (dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree()) return true; - return false; + return dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree(); } /* @@ -470,8 +433,7 @@ public class Stargate extends JavaPlugin { // The player is an admin with the ability to see hidden gates if (hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.hidden")) return true; // The player is the owner of the gate - if (portal.getOwner().equalsIgnoreCase(player.getName())) return true; - return false; + return portal.getOwner().equalsIgnoreCase(player.getName()); } /* @@ -481,8 +443,7 @@ public class Stargate extends JavaPlugin { // Check if the player is the owner of the gate if (portal.getOwner().equalsIgnoreCase(player.getName())) return true; // The player is an admin with the ability to use private gates - if (hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.private")) return true; - return false; + return hasPerm(player, "stargate.admin") || hasPerm(player, "stargate.admin.private"); } /* @@ -492,8 +453,7 @@ public class Stargate extends JavaPlugin { // Check if the player can use all options if (hasPerm(player, "stargate.option")) return true; // Check if they can use this specific option - if (hasPerm(player, "stargate.option." + option)) return true; - return false; + return hasPerm(player, "stargate.option." + option); } /* @@ -505,13 +465,11 @@ public class Stargate extends JavaPlugin { // Check for all network create permission if (hasPerm(player, "stargate.create.network")) { // Do a deep check to see if the player lacks this specific network node - if (!hasPermDeep(player, "stargate.create.network." + network)) return false; - return true; + return hasPermDeep(player, "stargate.create.network." + network); } // Check for this specific network - if (hasPerm(player, "stargate.create.network." + network)) return true; - - return false; + return hasPerm(player, "stargate.create.network." + network); + } /* @@ -521,8 +479,7 @@ public class Stargate extends JavaPlugin { // Check for general create if (hasPerm(player, "stargate.create")) return true; // Check for personal - if (hasPerm(player, "stargate.create.personal")) return true; - return false; + return hasPerm(player, "stargate.create.personal"); } /* @@ -534,13 +491,10 @@ public class Stargate extends JavaPlugin { // Check for all gate create permissions if (hasPerm(player, "stargate.create.gate")) { // Do a deep check to see if the player lacks this specific gate node - if (!hasPermDeep(player, "stargate.create.gate." + gate)) return false; - return true; + return hasPermDeep(player, "stargate.create.gate." + gate); } // Check for this specific gate - if (hasPerm(player, "stargate.create.gate." + gate)) return true; - - return false; + return hasPerm(player, "stargate.create.gate." + gate); } /* @@ -553,14 +507,12 @@ public class Stargate extends JavaPlugin { // Check for all network destroy permission if (hasPerm(player, "stargate.destroy.network")) { // Do a deep check to see if the player lacks permission for this network node - if (!hasPermDeep(player, "stargate.destroy.network." + network)) return false; - return true; + return hasPermDeep(player, "stargate.destroy.network." + network); } // Check for this specific network if (hasPerm(player, "stargate.destroy.network." + network)) return true; // Check for personal gate - if (player.getName().equalsIgnoreCase(portal.getOwner()) && hasPerm(player, "stargate.destroy.personal")) return true; - return false; + return player.getName().equalsIgnoreCase(portal.getOwner()) && hasPerm(player, "stargate.destroy.personal"); } /* @@ -1148,89 +1100,6 @@ public class Stargate extends JavaPlugin { } } } - - // Going to leave this commented out until they fix EntityDamagebyBlock - /* - @Override - public void onEntityDamage(EntityDamageEvent event) { - if (!(event.getEntity() instanceof Player)) return; - if (!(event instanceof EntityDamageByBlockEvent)) return; - EntityDamageByBlockEvent bEvent = (EntityDamageByBlockEvent)event; - Player player = (Player)bEvent.getEntity(); - Block block = bEvent.getDamager(); - // Fucking null blocks, we'll do it live! This happens for lava only, as far as I know. - // So we're "borrowing" the code from World.java used to determine if we're intersecting a lava block - if (block == null) { - CraftEntity ce = (CraftEntity)event.getEntity(); - net.minecraft.server.Entity entity = ce.getHandle(); - AxisAlignedBB axisalignedbb = entity.boundingBox.b(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D); - int minx = MathHelper.floor(axisalignedbb.a); - int maxx = MathHelper.floor(axisalignedbb.d + 1.0D); - int miny = MathHelper.floor(axisalignedbb.b); - int maxy = MathHelper.floor(axisalignedbb.e + 1.0D); - int minz = MathHelper.floor(axisalignedbb.c); - int maxz = MathHelper.floor(axisalignedbb.f + 1.0D); - - for (int x = minx; x < maxx; ++x) { - for (int y = miny; y < maxy; ++y) { - for (int z = minz; z < maxz; ++z) { - int blockType = player.getWorld().getBlockTypeIdAt(x, y, z); - if (blockType == Material.LAVA.getId() || blockType == Material.STATIONARY_LAVA.getId()) { - block = player.getWorld().getBlockAt(x, y, z); - log.info("Found block! " + block); - break; - } - } - if (block != null) break; - } - if (block != null) break; - } - } - if (block == null) return; - Portal portal = Portal.getByEntrance(block); - if (portal == null) return; - log.info("Found portal"); - bEvent.setDamage(0); - bEvent.setCancelled(true); - } - - @Override - public void onEntityCombust(EntityCombustEvent event) { - if (!(event.getEntity() instanceof Player)) return; - Player player = (Player)event.getEntity(); - // WHY DOESN'T THIS CANCEL IF YOU CANCEL LAVA DAMAGE?! - Block block = null; - CraftEntity ce = (CraftEntity)event.getEntity(); - net.minecraft.server.Entity entity = ce.getHandle(); - AxisAlignedBB axisalignedbb = entity.boundingBox.b(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D); - int minx = MathHelper.floor(axisalignedbb.a); - int maxx = MathHelper.floor(axisalignedbb.d + 1.0D); - int miny = MathHelper.floor(axisalignedbb.b); - int maxy = MathHelper.floor(axisalignedbb.e + 1.0D); - int minz = MathHelper.floor(axisalignedbb.c); - int maxz = MathHelper.floor(axisalignedbb.f + 1.0D); - - for (int x = minx; x < maxx; ++x) { - for (int y = miny; y < maxy; ++y) { - for (int z = minz; z < maxz; ++z) { - int blockType = player.getWorld().getBlockTypeIdAt(x, y, z); - if (blockType == Material.LAVA.getId() || blockType == Material.STATIONARY_LAVA.getId()) { - block = player.getWorld().getBlockAt(x, y, z); - log.info("Found block! " + block); - break; - } - } - if (block != null) break; - } - if (block != null) break; - } - if (block == null) return; - log.info("What? " + block); - Portal portal = Portal.getByEntrance(block); - if (portal == null) return; - log.info("What2?"); - event.setCancelled(true); - }*/ } private class sListener implements Listener {