From c916bbf82729fcbcd502de74c271a526fde3adb9 Mon Sep 17 00:00:00 2001 From: Tastybento Date: Thu, 8 Feb 2018 20:08:46 -0800 Subject: [PATCH] Automated code cleanup. Removes spaces, adds {} to if statements, etc. --- .../us/tastybento/bskyblock/BSkyBlock.java | 8 +- .../us/tastybento/bskyblock/Constants.java | 2 +- .../java/us/tastybento/bskyblock/Metrics.java | 34 ++-- .../us/tastybento/bskyblock/Settings.java | 26 +-- .../bskyblock/api/addons/Addon.java | 66 ++++--- .../api/addons/AddonClassLoader.java | 94 ++++----- .../api/addons/AddonDescription.java | 26 +-- .../api/addons/exception/AddonException.java | 16 +- .../InvalidAddonFormatException.java | 38 ++-- .../InvalidAddonInheritException.java | 14 +- .../api/commands/CompositeCommand.java | 66 ++++--- .../api/commands/DefaultHelpCommand.java | 4 +- .../bskyblock/api/commands/User.java | 38 ++-- .../api/configuration/ConfigEntry.java | 2 +- .../api/configuration/ISettings.java | 6 +- .../bskyblock/api/events/IslandBaseEvent.java | 16 +- .../bskyblock/api/events/PremadeEvent.java | 2 +- .../api/events/addon/AddonEvent.java | 16 +- .../api/events/command/CommandEvent.java | 10 +- .../api/events/island/FlagChangeEvent.java | 4 +- .../api/events/island/IslandEvent.java | 6 +- .../api/events/purge/PurgeStartEvent.java | 18 +- .../bskyblock/api/events/team/TeamEvent.java | 4 +- .../tastybento/bskyblock/api/flags/Flag.java | 6 +- .../bskyblock/api/flags/FlagBuilder.java | 10 +- .../bskyblock/api/localization/BSBLocale.java | 12 +- .../bskyblock/api/panels/Panel.java | 2 +- .../bskyblock/api/panels/PanelItem.java | 13 +- .../bskyblock/api/panels/PanelListener.java | 2 +- .../api/panels/builders/PanelBuilder.java | 16 +- .../api/panels/builders/PanelItemBuilder.java | 9 +- .../bskyblock/commands/AdminCommand.java | 6 +- .../bskyblock/commands/IslandCommand.java | 14 +- .../commands/admin/AdminReloadCommand.java | 2 +- .../commands/admin/AdminTeleportCommand.java | 16 +- .../commands/admin/AdminVersionCommand.java | 2 +- .../island/CustomIslandMultiHomeHelp.java | 18 +- .../commands/island/IslandAboutCommand.java | 6 +- .../commands/island/IslandCreateCommand.java | 12 +- .../commands/island/IslandGoCommand.java | 8 +- .../commands/island/IslandResetCommand.java | 19 +- .../island/IslandResetnameCommand.java | 10 +- .../commands/island/IslandSethomeCommand.java | 8 +- .../commands/island/IslandSetnameCommand.java | 18 +- .../teams/AbstractIslandTeamCommand.java | 10 +- .../island/teams/IslandTeamCommand.java | 21 +- .../teams/IslandTeamInviteAcceptCommand.java | 32 +-- .../island/teams/IslandTeamInviteCommand.java | 14 +- .../teams/IslandTeamInviteRejectCommand.java | 14 +- .../island/teams/IslandTeamKickCommand.java | 12 +- .../island/teams/IslandTeamLeaveCommand.java | 6 +- .../teams/IslandTeamPromoteCommand.java | 10 +- .../teams/IslandTeamSetownerCommand.java | 14 +- .../bskyblock/database/BSBDatabase.java | 4 +- .../flatfile/FlatFileDatabaseConnecter.java | 5 +- .../flatfile/FlatFileDatabaseHandler.java | 97 +++++---- .../database/managers/PlayersManager.java | 49 +++-- .../database/managers/island/IslandCache.java | 84 +++++--- .../managers/island/IslandsManager.java | 114 +++++++---- .../database/managers/island/NewIsland.java | 34 ++-- .../database/mysql/MySQLDatabaseHandler.java | 187 +++++++++++------- .../mysql/MySQLDatabaseResourceCloser.java | 9 +- .../database/objects/DataObject.java | 6 +- .../bskyblock/database/objects/Island.java | 58 +++--- .../bskyblock/database/objects/Players.java | 31 +-- .../database/objects/adapters/Adapter.java | 2 +- .../objects/adapters/AdapterInterface.java | 6 +- .../objects/adapters/FlagSerializer.java | 8 +- .../adapters/PotionEffectListAdapter.java | 14 +- .../generators/ChunkGeneratorWorld.java | 2 +- .../bskyblock/generators/IslandWorld.java | 4 +- .../bskyblock/generators/NetherPopulator.java | 22 +-- .../island/builders/IslandBuilder.java | 22 +-- .../listeners/JoinLeaveListener.java | 26 ++- .../listeners/PanelListenerManager.java | 10 +- .../listeners/flags/AbstractFlagListener.java | 30 +-- .../flags/BlockInteractionListener.java | 10 +- .../listeners/flags/BreakBlocksListener.java | 10 +- .../listeners/flags/BreedingListener.java | 2 +- .../listeners/flags/BucketListener.java | 14 +- .../listeners/flags/EggListener.java | 2 +- .../flags/EntityInteractListener.java | 6 +- .../listeners/flags/FireListener.java | 38 +++- .../listeners/flags/HurtingListener.java | 11 +- .../listeners/flags/InventoryListener.java | 6 +- .../flags/ItemDropPickUpListener.java | 2 +- .../listeners/flags/LeashListener.java | 2 +- .../listeners/flags/MobSpawnListener.java | 6 +- .../listeners/flags/PVPListener.java | 36 ++-- .../flags/PhysicalInteractionListener.java | 2 +- .../listeners/flags/PlaceBlocksListener.java | 6 +- .../listeners/flags/PortalListener.java | 2 +- .../listeners/flags/ShearingListener.java | 2 +- .../flags/TeleportationListener.java | 4 +- .../listeners/protection/FlyingMobEvents.java | 2 +- .../us/tastybento/bskyblock/lists/Flags.java | 8 +- .../bskyblock/managers/AddonsManager.java | 29 +-- .../bskyblock/managers/CommandsManager.java | 7 +- .../bskyblock/managers/FlagsManager.java | 4 +- .../bskyblock/managers/LocalesManager.java | 41 ++-- .../bskyblock/managers/RanksManager.java | 16 +- .../bskyblock/util/DeleteIslandChunks.java | 6 +- .../tastybento/bskyblock/util/FileLister.java | 6 +- .../bskyblock/util/SafeSpotTeleport.java | 6 +- .../us/tastybento/bskyblock/util/Util.java | 41 ++-- .../bskyblock/util/YmlCommentParser.java | 4 +- .../util/placeholders/PlaceholderHandler.java | 6 +- .../placeholders/PlaceholderInterface.java | 10 +- .../util/placeholders/Placeholders.java | 4 +- .../hooks/InternalPlaceholderImpl.java | 6 +- src/test/java/bskyblock/TestBSkyBlock.java | 107 +++++----- 111 files changed, 1223 insertions(+), 923 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 966641d99..ce4595bae 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -50,9 +50,9 @@ public class BSkyBlock extends JavaPlugin { // Save the default config from config.yml saveDefaultConfig(); setInstance(this); - + settings = new Settings(); - // Load settings from config.yml. This will check if there are any issues with it too. + // Load settings from config.yml. This will check if there are any issues with it too. try { //settings.saveSettings(); settings = settings.loadSettings(); @@ -88,7 +88,7 @@ public class BSkyBlock extends JavaPlugin { islandWorldManager = new IslandWorld(plugin); getServer().getScheduler().runTask(plugin, () -> { - + // Load Flags flagsManager = new FlagsManager(plugin); @@ -187,7 +187,7 @@ public class BSkyBlock extends JavaPlugin { private static void setInstance(BSkyBlock plugin) { BSkyBlock.plugin = plugin; } - + public static BSkyBlock getInstance() { return plugin; } diff --git a/src/main/java/us/tastybento/bskyblock/Constants.java b/src/main/java/us/tastybento/bskyblock/Constants.java index 902cb5dfd..f2b12cc68 100644 --- a/src/main/java/us/tastybento/bskyblock/Constants.java +++ b/src/main/java/us/tastybento/bskyblock/Constants.java @@ -20,7 +20,7 @@ public class Constants { public static final String ISLANDCOMMAND = "ai"; // Admin command public static final String ADMINCOMMAND = "acid"; - */ + */ public static final GameType GAMETYPE = GameType.BSKYBLOCK; // Permission prefix public static final String PERMPREFIX = "bskyblock."; diff --git a/src/main/java/us/tastybento/bskyblock/Metrics.java b/src/main/java/us/tastybento/bskyblock/Metrics.java index 25be8f7ed..670c6182f 100755 --- a/src/main/java/us/tastybento/bskyblock/Metrics.java +++ b/src/main/java/us/tastybento/bskyblock/Metrics.java @@ -30,7 +30,7 @@ import org.json.simple.JSONObject; * bStats collects some data for plugin authors. * * Check out https://bStats.org/ to learn more about bStats! - * + * * @author BtoBastian */ @SuppressWarnings("unchecked") @@ -96,7 +96,7 @@ public class Metrics { "To honor their work, you should not disable it.\n" + "This has nearly no effect on the server performance!\n" + "Check out https://bStats.org/ to learn more :)" - ).copyDefaults(true); + ).copyDefaults(true); try { config.save(configFile); } catch (IOException ignored) { } @@ -150,12 +150,7 @@ public class Metrics { } // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - submitData(); - } - }); + Bukkit.getScheduler().runTask(plugin, () -> submitData()); } }, 1000*60*5L, 1000*60*30L); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start @@ -250,17 +245,14 @@ public class Metrics { data.put("plugins", pluginData); // Create a new thread for the connection to the bStats server - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } + new Thread(() -> { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); } } }).start(); @@ -283,7 +275,9 @@ public class Metrics { // Compress the data to save bandwidth byte[] compressedData = compress(data.toString()); - if (compressedData == null) throw new Exception(); + if (compressedData == null) { + throw new Exception(); + } // Add headers connection.setRequestMethod("POST"); connection.addRequestProperty("Accept", "application/json"); diff --git a/src/main/java/us/tastybento/bskyblock/Settings.java b/src/main/java/us/tastybento/bskyblock/Settings.java index f9b587eb7..fdf568b61 100644 --- a/src/main/java/us/tastybento/bskyblock/Settings.java +++ b/src/main/java/us/tastybento/bskyblock/Settings.java @@ -155,7 +155,7 @@ public class Settings implements ISettings { // Reset @ConfigEntry(path = "island.reset.reset-limit") private int resetLimit = -1; - + @ConfigEntry(path = "island.require-confirmation.reset") private boolean resetConfirmation = true; @@ -164,7 +164,7 @@ public class Settings implements ISettings { @ConfigEntry(path = "island.reset.leavers-lose-reset") private boolean leaversLoseReset = false; - + @ConfigEntry(path = "island.reset.kicked-keep-inventory") private boolean kickedKeepInventory = false; @@ -173,16 +173,16 @@ public class Settings implements ISettings { private boolean removeMobsOnLogin = false; @ConfigEntry(path = "island.remove-mobs.on-island") private boolean removeMobsOnIsland = false; - + @ConfigEntry(path = "island.remove-mobs.whitelist") private List removeMobsWhitelist = new ArrayList<>(); @ConfigEntry(path = "island.make-island-if-none") private boolean makeIslandIfNone = false; - + @ConfigEntry(path = "island.immediate-teleport-on-island") private boolean immediateTeleportOnIsland = false; - + private boolean respawnOnIsland = true; // Deaths @@ -191,7 +191,7 @@ public class Settings implements ISettings { @ConfigEntry(path = "island.deaths.sum-team") private boolean deathsSumTeam = false; - + // Ranks @ConfigEntry(path = "island.customranks") private Map customRanks = new HashMap<>(); @@ -250,10 +250,10 @@ public class Settings implements ISettings { /* SCHEMATICS */ private List companionNames = new ArrayList<>(); - + @ConfigEntry(path = "island.chest-items") private List chestItems = new ArrayList<>(); - + private EntityType companionType = EntityType.COW; private boolean useOwnGenerator; @@ -267,13 +267,13 @@ public class Settings implements ISettings { @ConfigEntry(path = "island.require-confirmation.kick-wait") private long kickWait = 300; - + @ConfigEntry(path = "island.require-confirmation.leave") private boolean leaveConfirmation = true; @ConfigEntry(path = "island.require-confirmation.leave-wait") private long leaveWait = 300; - + /** * @return the acidDamage @@ -540,6 +540,7 @@ public class Settings implements ISettings { /** * @return the uniqueId */ + @Override public String getUniqueId() { return uniqueId; } @@ -1137,7 +1138,7 @@ public class Settings implements ISettings { public void setRemoveMobsOnIsland(boolean removeMobsOnIsland) { this.removeMobsOnIsland = removeMobsOnIsland; } - + /** * @param removeMobsOnLogin the removeMobsOnLogin to set */ @@ -1207,6 +1208,7 @@ public class Settings implements ISettings { /** * @param uniqueId the uniqueId to set */ + @Override public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } @@ -1240,6 +1242,6 @@ public class Settings implements ISettings { public void setFakePlayers(Set fakePlayers) { this.fakePlayers = fakePlayers; } - + } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java b/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java index 105e0c354..41e345520 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java @@ -16,8 +16,8 @@ import org.bukkit.event.Listener; import us.tastybento.bskyblock.BSkyBlock; /** - * Add-on class for BSkyBlock. Extend this to create an add-on. - * The operation and methods are very similar to Bukkit's JavaPlugin. + * Add-on class for BSkyBlock. Extend this to create an add-on. The operation + * and methods are very similar to Bukkit's JavaPlugin. * * @author tastybento, ComminQ_Q */ @@ -32,10 +32,10 @@ public abstract class Addon implements AddonInterface { private File file; public Addon() { - this.enabled = false; + enabled = false; } - public BSkyBlock getBSkyBlock(){ + public BSkyBlock getBSkyBlock() { return BSkyBlock.getInstance(); } @@ -77,6 +77,7 @@ public abstract class Addon implements AddonInterface { /** * Convenience method to obtain the server + * * @return the server object */ public Server getServer() { @@ -89,6 +90,7 @@ public abstract class Addon implements AddonInterface { /** * Load a YAML file + * * @param file * @return Yaml File configuration */ @@ -109,9 +111,10 @@ public abstract class Addon implements AddonInterface { /** * Register a listener for this addon + * * @param listener */ - public void registerListener(Listener listener){ + public void registerListener(Listener listener) { BSkyBlock.getInstance().getServer().getPluginManager().registerEvents(listener, BSkyBlock.getInstance()); } @@ -120,15 +123,15 @@ public abstract class Addon implements AddonInterface { */ public void saveConfig() { try { - this.config.save(new File(dataFolder, ADDON_CONFIG_FILENAME)); + config.save(new File(dataFolder, ADDON_CONFIG_FILENAME)); } catch (IOException e) { Bukkit.getLogger().severe("Could not save config!"); } } /** - * Saves the addon's config.yml file to the addon's data folder and loads it. - * If the file exists already, it will not be replaced. + * Saves the addon's config.yml file to the addon's data folder and loads it. If + * the file exists already, it will not be replaced. */ public void saveDefaultConfig() { saveResource(ADDON_CONFIG_FILENAME, false); @@ -136,20 +139,30 @@ public abstract class Addon implements AddonInterface { } /** - * Saves a resource contained in this add-on's jar file to the addon's data folder. - * @param resourcePath in jar file - * @param replace - if true, will overwrite previous file + * Saves a resource contained in this add-on's jar file to the addon's data + * folder. + * + * @param resourcePath + * in jar file + * @param replace + * - if true, will overwrite previous file */ public void saveResource(String resourcePath, boolean replace) { saveResource(resourcePath, dataFolder, replace, false); } /** - * Saves a resource contained in this add-on's jar file to the destination folder. - * @param jarResource in jar file - * @param destinationFolder on file system - * @param replace - if true, will overwrite previous file - * @param noPath - if true, the resource's path will be ignored when saving + * Saves a resource contained in this add-on's jar file to the destination + * folder. + * + * @param jarResource + * in jar file + * @param destinationFolder + * on file system + * @param replace + * - if true, will overwrite previous file + * @param noPath + * - if true, the resource's path will be ignored when saving */ public void saveResource(String jarResource, File destinationFolder, boolean replace, boolean noPath) { if (jarResource == null || jarResource.equals("")) { @@ -162,7 +175,8 @@ public abstract class Addon implements AddonInterface { if (jarConfig != null) { try (InputStream in = jar.getInputStream(jarConfig)) { if (in == null) { - throw new IllegalArgumentException("The embedded resource '" + jarResource + "' cannot be found in " + jar.getName()); + throw new IllegalArgumentException( + "The embedded resource '" + jarResource + "' cannot be found in " + jar.getName()); } // There are two options, use the path of the resource or not File outFile = new File(destinationFolder, jarResource); @@ -181,36 +195,42 @@ public abstract class Addon implements AddonInterface { } } } catch (IOException e) { - Bukkit.getLogger().severe("Could not save from jar file. From " + jarResource + " to " + destinationFolder.getAbsolutePath()); + Bukkit.getLogger().severe( + "Could not save from jar file. From " + jarResource + " to " + destinationFolder.getAbsolutePath()); } } /** * Set the file that contains this addon - * @param f the file to set + * + * @param f + * the file to set */ public void setAddonFile(File f) { - this.file = f; + file = f; } /** * Set this addon's data folder + * * @param file */ public void setDataFolder(File file) { - this.dataFolder = file; + dataFolder = file; } /** * Set this addons description + * * @param desc */ - public void setDescription(AddonDescription desc){ - this.description = desc; + public void setDescription(AddonDescription desc) { + description = desc; } /** * Set whether this addon is enabled or not + * * @param enabled */ public void setEnabled(boolean enabled) { diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java b/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java index aff49e67c..1c8bbc247 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java @@ -20,57 +20,57 @@ import us.tastybento.bskyblock.managers.AddonsManager; */ public class AddonClassLoader extends URLClassLoader { - private final Map> classes = new HashMap>(); - private Addon addon; + private final Map> classes = new HashMap<>(); + private Addon addon; private AddonsManager loader; - - public AddonClassLoader(AddonsManager addonsManager, Mapdata, File path, ClassLoader parent) - throws InvalidAddonInheritException, - MalformedURLException, - InvalidAddonFormatException, - InvalidDescriptionException, - InstantiationException, - IllegalAccessException { - super(new URL[]{path.toURI().toURL()}, parent); - - this.loader = addonsManager; - - Class javaClass = null; - try { - //Bukkit.getLogger().info("data " + data.get("main")); - /* + + public AddonClassLoader(AddonsManager addonsManager, Mapdata, File path, ClassLoader parent) + throws InvalidAddonInheritException, + MalformedURLException, + InvalidAddonFormatException, + InvalidDescriptionException, + InstantiationException, + IllegalAccessException { + super(new URL[]{path.toURI().toURL()}, parent); + + loader = addonsManager; + + Class javaClass = null; + try { + //Bukkit.getLogger().info("data " + data.get("main")); + /* for (Entry en : data.entrySet()) { Bukkit.getLogger().info(en.getKey() + " => " + en.getValue()); }*/ - javaClass = Class.forName(data.get("main"), true, this); - if(data.get("main").contains("us.tastybento")){ - throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'"); - } - } catch (ClassNotFoundException e) { - BSkyBlock.getInstance().getLogger().severe("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "'"); - throw new InvalidDescriptionException("Invalid addon.yml"); - } - - Class addonClass; - try{ - addonClass = javaClass.asSubclass(Addon.class); - } catch(ClassCastException e){ - throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'"); - } - - this.addon = addonClass.newInstance(); - addon.setDescription(this.asDescription(data)); - } - - private AddonDescription asDescription(Map data){ - String[] authors = data.get("authors").split("\\,"); - - return new AddonDescriptionBuilder(data.get("name")) - .withVersion(data.get("version")) - .withAuthor(authors).build(); - } + javaClass = Class.forName(data.get("main"), true, this); + if(data.get("main").contains("us.tastybento")){ + throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'"); + } + } catch (ClassNotFoundException e) { + BSkyBlock.getInstance().getLogger().severe("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "'"); + throw new InvalidDescriptionException("Invalid addon.yml"); + } + + Class addonClass; + try{ + addonClass = javaClass.asSubclass(Addon.class); + } catch(ClassCastException e){ + throw new InvalidAddonInheritException("Main class doesn't not extends super class 'Addon'"); + } + + addon = addonClass.newInstance(); + addon.setDescription(asDescription(data)); + } + + private AddonDescription asDescription(Map data){ + String[] authors = data.get("authors").split("\\,"); + + return new AddonDescriptionBuilder(data.get("name")) + .withVersion(data.get("version")) + .withAuthor(authors).build(); + } + - /* (non-Javadoc) * @see java.net.URLClassLoader#findClass(java.lang.String) */ @@ -118,5 +118,5 @@ public class AddonClassLoader extends URLClassLoader { public Addon getAddon() { return addon; } - + } diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/AddonDescription.java b/src/main/java/us/tastybento/bskyblock/api/addons/AddonDescription.java index b778f8233..22372fa45 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/AddonDescription.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/AddonDescription.java @@ -15,7 +15,7 @@ public final class AddonDescription { private List authors; public AddonDescription() {} - + public AddonDescription(String main, String name, String version, String description, List authors) { this.main = main; this.name = name; @@ -78,34 +78,34 @@ public final class AddonDescription { public List getAuthors() { return authors; } - + public static class AddonDescriptionBuilder{ - + private AddonDescription description; - + public AddonDescriptionBuilder(String name){ description = new AddonDescription(); description.setName(name); } - + public AddonDescriptionBuilder withAuthor(String... authors){ - this.description.setAuthors(Arrays.asList(authors)); + description.setAuthors(Arrays.asList(authors)); return this; } - + public AddonDescriptionBuilder withDescription(String desc){ - this.description.setDescription(desc); + description.setDescription(desc); return this; } - + public AddonDescriptionBuilder withVersion(String version){ - this.description.setVersion(version); + description.setVersion(version); return this; } - + public AddonDescription build(){ - return this.description; + return description; } - + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/exception/AddonException.java b/src/main/java/us/tastybento/bskyblock/api/addons/exception/AddonException.java index a0960e33e..0c15d3988 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/exception/AddonException.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/exception/AddonException.java @@ -2,13 +2,13 @@ package us.tastybento.bskyblock.api.addons.exception; public abstract class AddonException extends Exception { - /** - * - */ - private static final long serialVersionUID = 4203162022348693854L; + /** + * + */ + private static final long serialVersionUID = 4203162022348693854L; + + public AddonException(String errorMessage){ + super("AddonException : " + errorMessage); + } - public AddonException(String errorMessage){ - super("AddonException : " + errorMessage); - } - } diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonFormatException.java b/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonFormatException.java index 8f683b18b..dfcc0b86a 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonFormatException.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonFormatException.java @@ -6,25 +6,25 @@ import org.bukkit.Bukkit; public class InvalidAddonFormatException extends AddonException { - /** - * - */ - private static final long serialVersionUID = 7741502900847049986L; + /** + * + */ + private static final long serialVersionUID = 7741502900847049986L; - public InvalidAddonFormatException(String errorMessage) { - super(errorMessage); - } + public InvalidAddonFormatException(String errorMessage) { + super(errorMessage); + } - @Override - public void printStackTrace(){ - super.printStackTrace(); - - System.out.println(""); - - Bukkit.getLogger().log(Level.WARNING, " Basic format : (addon.yml)"); - Bukkit.getLogger().log(Level.WARNING, " main: path.to.your.MainClass"); - Bukkit.getLogger().log(Level.WARNING, " name: "); - Bukkit.getLogger().log(Level.WARNING, " authors: | "); - Bukkit.getLogger().log(Level.WARNING, " version: YourVersion"); - } + @Override + public void printStackTrace(){ + super.printStackTrace(); + + System.out.println(""); + + Bukkit.getLogger().log(Level.WARNING, " Basic format : (addon.yml)"); + Bukkit.getLogger().log(Level.WARNING, " main: path.to.your.MainClass"); + Bukkit.getLogger().log(Level.WARNING, " name: "); + Bukkit.getLogger().log(Level.WARNING, " authors: | "); + Bukkit.getLogger().log(Level.WARNING, " version: YourVersion"); + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonInheritException.java b/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonInheritException.java index 00ee7cb2c..42b56c27b 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonInheritException.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/exception/InvalidAddonInheritException.java @@ -2,13 +2,13 @@ package us.tastybento.bskyblock.api.addons.exception; public class InvalidAddonInheritException extends AddonException { - /** - * - */ - private static final long serialVersionUID = -5847358994397613244L; + /** + * + */ + private static final long serialVersionUID = -5847358994397613244L; - public InvalidAddonInheritException(String errorMessage) { - super(errorMessage); - } + public InvalidAddonInheritException(String errorMessage) { + super(errorMessage); + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java index dea2130df..8ea9f4cd8 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java @@ -71,14 +71,14 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi */ public CompositeCommand(BSkyBlock plugin, String label, String... string) { super(label); - this.setAliases(new ArrayList<>(Arrays.asList(string))); - this.parent = null; + setAliases(new ArrayList<>(Arrays.asList(string))); + parent = null; setUsage(""); - this.subCommandLevel = 0; // Top level - this.subCommands = new LinkedHashMap<>(); - this.subCommandAliases = new LinkedHashMap<>(); - this.setup(); - if (!this.getSubCommand("help").isPresent() && !label.equals("help")) { + subCommandLevel = 0; // Top level + subCommands = new LinkedHashMap<>(); + subCommandAliases = new LinkedHashMap<>(); + setup(); + if (!getSubCommand("help").isPresent() && !label.equals("help")) { new DefaultHelpCommand(this); } } @@ -93,20 +93,20 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi public CompositeCommand(CompositeCommand parent, String label, String... aliases) { super(label); this.parent = parent; - this.subCommandLevel = parent.getLevel() + 1; + subCommandLevel = parent.getLevel() + 1; // Add this sub-command to the parent parent.getSubCommands().put(label, this); - this.setAliases(new ArrayList<>(Arrays.asList(aliases))); - this.subCommands = new LinkedHashMap<>(); - this.subCommandAliases = new LinkedHashMap<>(); + setAliases(new ArrayList<>(Arrays.asList(aliases))); + subCommands = new LinkedHashMap<>(); + subCommandAliases = new LinkedHashMap<>(); // Add aliases to the parent for this command for (String alias : aliases) { parent.subCommandAliases.put(alias, this); } setUsage(""); - this.setup(); + setup(); // If this command does not define its own help class, then use the default help command - if (!this.getSubCommand("help").isPresent() && !label.equals("help")) { + if (!getSubCommand("help").isPresent() && !label.equals("help")) { new DefaultHelpCommand(this); } if (DEBUG) { @@ -124,25 +124,25 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi if (DEBUG) { Bukkit.getLogger().info("DEBUG: top level command registering..." + label); } - this.setAliases(new ArrayList<>(Arrays.asList(aliases))); - this.parent = null; + setAliases(new ArrayList<>(Arrays.asList(aliases))); + parent = null; setUsage(""); - this.subCommandLevel = 0; // Top level - this.subCommands = new LinkedHashMap<>(); - this.subCommandAliases = new LinkedHashMap<>(); + subCommandLevel = 0; // Top level + subCommands = new LinkedHashMap<>(); + subCommandAliases = new LinkedHashMap<>(); // Register command if it is not already registered if (getPlugin().getCommand(label) == null) { getPlugin().getCommandsManager().registerCommand(this); } - this.setup(); - if (!this.getSubCommand("help").isPresent() && !label.equals("help")) { + setup(); + if (!getSubCommand("help").isPresent() && !label.equals("help")) { new DefaultHelpCommand(this); } } - /* - * This method deals with the command execution. It traverses the tree of + /* + * This method deals with the command execution. It traverses the tree of * subcommands until it finds the right object and then runs execute on it. */ @Override @@ -189,17 +189,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi private CompositeCommand getCommandFromArgs(String[] args) { CompositeCommand subCommand = this; // Run through any arguments - for (int i = 0; i < args.length; i++) { + for (String arg : args) { // get the subcommand corresponding to the arg if (subCommand.hasSubCommmands()) { - Optional sub = subCommand.getSubCommand(args[i]); + Optional sub = subCommand.getSubCommand(arg); if (!sub.isPresent()) { return subCommand; } // Step down one subCommand = sub.orElse(subCommand); // Set the label - subCommand.setLabel(args[i]); + subCommand.setLabel(arg); } else { // We are at the end of the walk return subCommand; @@ -254,7 +254,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi @Override public String getPermission() { - return this.permission; + return permission; } /** @@ -292,14 +292,18 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi if (DEBUG) { Bukkit.getLogger().info("DEBUG: " + entry.getKey()); } - if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommands.get(label)); + if (entry.getKey().equalsIgnoreCase(label)) { + return Optional.of(subCommands.get(label)); + } } // Try aliases for (Map.Entry entry : subCommandAliases.entrySet()) { if (DEBUG) { Bukkit.getLogger().info("DEBUG: alias " + entry.getKey()); } - if (entry.getKey().equalsIgnoreCase(label)) return Optional.of(subCommandAliases.get(label)); + if (entry.getKey().equalsIgnoreCase(label)) { + return Optional.of(subCommandAliases.get(label)); + } } return Optional.empty(); } @@ -396,8 +400,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi @Override public Command setUsage(String usage) { // Go up the chain - CompositeCommand parent = this.getParent(); - this.usage = this.getLabel() + " " + usage; + CompositeCommand parent = getParent(); + this.usage = getLabel() + " " + usage; while (parent != null) { this.usage = parent.getLabel() + " " + this.usage; parent = parent.getParent(); @@ -428,7 +432,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return options; } // Add any tab completion from the subcommand - options.addAll(cmd.tabComplete(User.getInstance(sender), alias, new LinkedList(Arrays.asList(args))).orElse(new ArrayList<>())); + options.addAll(cmd.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElse(new ArrayList<>())); // Add any sub-commands automatically if (cmd.hasSubCommmands()) { // Check if subcommands are visible to this sender diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java index 5fc53a412..a03910ff4 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/DefaultHelpCommand.java @@ -28,8 +28,8 @@ public class DefaultHelpCommand extends CompositeCommand { @Override public void setup() { // Set the usage to what the parent's command is - this.setParameters(parent.getParameters()); - this.setDescription(parent.getDescription()); + setParameters(parent.getParameters()); + setDescription(parent.getDescription()); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/User.java b/src/main/java/us/tastybento/bskyblock/api/commands/User.java index ce59e3556..ac072b57e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/User.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/User.java @@ -44,8 +44,9 @@ public class User { * @return user */ public static User getInstance(Player player) { - if (player == null) + if (player == null) { return null; + } if (users.containsKey(player.getUniqueId())) { return users.get(player.getUniqueId()); } @@ -80,22 +81,22 @@ public class User { private final CommandSender sender; private User(CommandSender sender) { - this.player = null; - this.playerUUID = null; + player = null; + playerUUID = null; this.sender = sender; } private User(Player player) { this.player = player; - this.sender = player; - this.playerUUID = player.getUniqueId(); + sender = player; + playerUUID = player.getUniqueId(); users.put(player.getUniqueId(), this); } private User(UUID playerUUID) { - this.player = Bukkit.getPlayer(playerUUID); + player = Bukkit.getPlayer(playerUUID); this.playerUUID = playerUUID; - this.sender = null; + sender = null; } public Set getEffectivePermissions() { @@ -160,7 +161,9 @@ public class User { String translation = plugin.getLocalesManager().get(this, reference); // If no translation has been found, return the reference for debug purposes. - if (translation == null) return reference; + if (translation == null) { + return reference; + } // Then replace variables if (variables.length > 1) { @@ -168,7 +171,7 @@ public class User { translation = translation.replace(variables[i], variables[i+1]); } } - + return ChatColor.translateAlternateColorCodes('&', translation); } @@ -182,7 +185,7 @@ public class User { String translation = getTranslation(reference, variables); return translation.equals(reference) ? "" : translation; } - + /** * Send a message to sender if message is not empty. Does not include color codes or spaces. * @param reference - language file reference @@ -199,7 +202,7 @@ public class User { } } } - + /** * Sends a message to sender without any modification (colors, multi-lines, placeholders). * Should only be used for debug purposes. @@ -244,23 +247,24 @@ public class User { public void closeInventory() { player.closeInventory(); } - + /** * Get the user's locale * @return Locale */ public Locale getLocale() { if (sender instanceof Player) { - if (!plugin.getPlayers().getLocale(this.playerUUID).isEmpty()) - return Locale.forLanguageTag(plugin.getPlayers().getLocale(this.playerUUID)); - } + if (!plugin.getPlayers().getLocale(playerUUID).isEmpty()) { + return Locale.forLanguageTag(plugin.getPlayers().getLocale(playerUUID)); + } + } return Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage()); } - + @SuppressWarnings("deprecation") public void updateInventory() { player.updateInventory(); - + } } diff --git a/src/main/java/us/tastybento/bskyblock/api/configuration/ConfigEntry.java b/src/main/java/us/tastybento/bskyblock/api/configuration/ConfigEntry.java index 4f814a20a..b81c5a15c 100644 --- a/src/main/java/us/tastybento/bskyblock/api/configuration/ConfigEntry.java +++ b/src/main/java/us/tastybento/bskyblock/api/configuration/ConfigEntry.java @@ -22,5 +22,5 @@ public @interface ConfigEntry { boolean experimental() default false; boolean needsReset() default false; GameType specificTo() default GameType.BOTH; - + } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java b/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java index 08e4269bb..d8970e58e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java +++ b/src/main/java/us/tastybento/bskyblock/api/configuration/ISettings.java @@ -31,7 +31,7 @@ public interface ISettings { } default void saveBackup() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IntrospectionException, SQLException { - // Save backup + // Save backup @SuppressWarnings("unchecked") AbstractDatabaseHandler backupHandler = (AbstractDatabaseHandler) new FlatFileDatabase().getHandler(getInstance().getClass()); backupHandler.saveObject(getInstance()); @@ -41,11 +41,11 @@ public interface ISettings { @SuppressWarnings("unchecked") default T loadSettings() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, ClassNotFoundException, IntrospectionException, SQLException { // See if this settings object already exists in the database - AbstractDatabaseHandler dbhandler = (AbstractDatabaseHandler) BSBDatabase.getDatabase().getHandler(this.getClass()); + AbstractDatabaseHandler dbhandler = (AbstractDatabaseHandler) BSBDatabase.getDatabase().getHandler(getClass()); T dbConfig = null; if (dbhandler.objectExits(this.getUniqueId())) { // Load it - dbConfig = dbhandler.loadObject(getUniqueId()); + dbConfig = dbhandler.loadObject(getUniqueId()); } // Get the handler AbstractDatabaseHandler configHandler = (AbstractDatabaseHandler) new FlatFileDatabase().getHandler(getInstance().getClass()); diff --git a/src/main/java/us/tastybento/bskyblock/api/events/IslandBaseEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/IslandBaseEvent.java index 71524cb97..3c44b9c79 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/IslandBaseEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/IslandBaseEvent.java @@ -23,11 +23,11 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable { public IslandBaseEvent(Island island) { super(); this.island = island; - this.playerUUID = island == null ? null : island.getOwner(); - this.admin = false; - this.location = island == null ? null : island.getCenter(); + playerUUID = island == null ? null : island.getOwner(); + admin = false; + location = island == null ? null : island.getCenter(); } - + /** * @param island * @param playerUUID @@ -46,14 +46,14 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable { * @return the island involved in this event */ public Island getIsland(){ - return this.island; + return island; } - + /** * @return the owner of the island */ public UUID getOwner() { - return this.getOwner(); + return getOwner(); } /** @@ -84,6 +84,6 @@ public class IslandBaseEvent extends PremadeEvent implements Cancellable { @Override public void setCancelled(boolean cancel) { - this.cancelled = cancel; + cancelled = cancel; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/PremadeEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/PremadeEvent.java index 9a5fa3fe6..ab2f46a2e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/PremadeEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/PremadeEvent.java @@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList; public abstract class PremadeEvent extends Event { private static final HandlerList handlers = new HandlerList(); - + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/us/tastybento/bskyblock/api/events/addon/AddonEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/addon/AddonEvent.java index 0b6318a41..9a71f1b55 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/addon/AddonEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/addon/AddonEvent.java @@ -57,14 +57,14 @@ public class AddonEvent { public AddonBaseEvent build() { switch (reason) { - case ENABLE: - return new AddonEnableEvent(addon); - case DISABLE: - return new AddonDisableEvent(addon); - case LOAD: - return new AddonLoadEvent(addon); - default: - return new AddonGeneralEvent(addon); + case ENABLE: + return new AddonEnableEvent(addon); + case DISABLE: + return new AddonDisableEvent(addon); + case LOAD: + return new AddonLoadEvent(addon); + default: + return new AddonGeneralEvent(addon); } } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java index 829119696..119ad869e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/command/CommandEvent.java @@ -20,7 +20,7 @@ public class CommandEvent extends PremadeEvent implements Cancellable { private final Command command; private final String label; private final String[] args; - + private CommandEvent(CommandSender sender, Command command, String label, String[] args) { super(); this.sender = sender; @@ -32,14 +32,14 @@ public class CommandEvent extends PremadeEvent implements Cancellable { public static CommandEventBuilder builder() { return new CommandEventBuilder(); } - + public static class CommandEventBuilder { // Here field are NOT final. They are just used for the building. private CommandSender sender; private Command command; private String label; private String[] args; - + public CommandEventBuilder setSender(CommandSender sender) { this.sender = sender; return this; @@ -63,7 +63,7 @@ public class CommandEvent extends PremadeEvent implements Cancellable { public CommandEvent build() { return new CommandEvent(sender, command, label, args); } - + } public CommandSender getSender() { @@ -89,6 +89,6 @@ public class CommandEvent extends PremadeEvent implements Cancellable { @Override public void setCancelled(boolean arg0) { - cancelled = arg0; + cancelled = arg0; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/FlagChangeEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/FlagChangeEvent.java index 3dbf6a610..3ec957989 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/FlagChangeEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/FlagChangeEvent.java @@ -43,13 +43,13 @@ public class FlagChangeEvent extends IslandBaseEvent { * @return the edited flag */ public Flag getFlag() { - return this.editedFlag; + return editedFlag; } /** * @return enabled/disabled */ public boolean getSetTo() { - return this.setTo; + return setTo; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEvent.java index 2d8cd423e..a6427ecbc 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/island/IslandEvent.java @@ -143,10 +143,10 @@ public class IslandEvent { } public IslandEventBuilder location(Location center) { - this.location = center; + location = center; return this; } - + public IslandBaseEvent build() { switch (reason) { case CREATE: @@ -194,7 +194,7 @@ public class IslandEvent { BSkyBlock.getInstance().getServer().getPluginManager().callEvent(general); return general; } - + } } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java index 3b6722530..4205e8a61 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/purge/PurgeStartEvent.java @@ -24,7 +24,7 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable { /** * Called to create the event * @param user - the UUID of the player who launched the purge, may be null if purge is launched using the console. - * @param islandsList - the list of islands to remove, based on their leader's UUID + * @param islandsList - the list of islands to remove, based on their leader's UUID */ public PurgeStartEvent(UUID user, List islandsList) { this.user = user; @@ -35,14 +35,14 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable { * @return the user who launched the purge, may be null if purge is launched using the console. */ public UUID getUser( ){ - return this.user; + return user; } /** - * @return the list of islands to remove, based on their leader's UUID + * @return the list of islands to remove, based on their leader's UUID */ public List getIslandsList() { - return this.islandsList; + return islandsList; } /** @@ -50,7 +50,9 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable { * @param - the owner's UUID from the island to remove */ public void add(UUID islandOwner) { - if(!this.islandsList.contains(islandOwner)) islandsList.add(islandOwner); + if(!islandsList.contains(islandOwner)) { + islandsList.add(islandOwner); + } } /** @@ -58,7 +60,9 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable { * @param - the owner's UUID from the island to remove */ public void remove(UUID islandOwner) { - if(this.islandsList.contains(islandOwner)) islandsList.remove(islandOwner); + if(islandsList.contains(islandOwner)) { + islandsList.remove(islandOwner); + } } /** @@ -76,6 +80,6 @@ public class PurgeStartEvent extends PremadeEvent implements Cancellable { @Override public void setCancelled(boolean cancel) { - this.cancelled = cancel; + cancelled = cancel; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/events/team/TeamEvent.java b/src/main/java/us/tastybento/bskyblock/api/events/team/TeamEvent.java index 2998a9f13..e6d28e84e 100644 --- a/src/main/java/us/tastybento/bskyblock/api/events/team/TeamEvent.java +++ b/src/main/java/us/tastybento/bskyblock/api/events/team/TeamEvent.java @@ -134,10 +134,10 @@ public class TeamEvent { } public TeamEventBuilder location(Location center) { - this.location = center; + location = center; return this; } - + public IslandBaseEvent build() { switch (reason) { case JOIN: diff --git a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java index 63870174f..b1dc7b7d1 100644 --- a/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java +++ b/src/main/java/us/tastybento/bskyblock/api/flags/Flag.java @@ -12,15 +12,15 @@ public class Flag implements Comparable { PROTECTION, SETTING } - + private final String id; private final PanelItem icon; private final Listener listener; private final FlagType type; private boolean defaultSetting; - + public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) { - this.id = id2; + id = id2; this.icon = icon; this.listener = listener; this.type = type; diff --git a/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java b/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java index 7d676a83e..40e02deac 100644 --- a/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/api/flags/FlagBuilder.java @@ -17,7 +17,7 @@ public class FlagBuilder { private FlagType type = FlagType.PROTECTION; public FlagBuilder id(String string) { - this.id = string; + id = string; return this; } @@ -42,17 +42,17 @@ public class FlagBuilder { public Flag build() { return new Flag(id, icon, listener, defaultSetting, type); } - + /** * Sets the default setting for this flag in the world * @param setting * @return */ public FlagBuilder allowedByDefault(boolean setting) { - this.defaultSetting = setting; + defaultSetting = setting; return this; } - + /** * Set the type of this flag * @param type {@link FlagType} @@ -69,7 +69,7 @@ public class FlagBuilder { * @return */ public FlagBuilder id(Enum flag) { - this.id = flag.name(); + id = flag.name(); return this; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java b/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java index f48472ff6..1b0660c0c 100644 --- a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java +++ b/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java @@ -15,7 +15,7 @@ public class BSBLocale { public BSBLocale(Locale locale, File file) { this.locale = locale; - this.config = YamlConfiguration.loadConfiguration(file); + config = YamlConfiguration.loadConfiguration(file); } /** @@ -35,7 +35,9 @@ public class BSBLocale { * @return the locale language */ public String getLanguage(){ - if(locale == null) return "unknown"; + if(locale == null) { + return "unknown"; + } return locale.getDisplayLanguage(); } @@ -45,7 +47,9 @@ public class BSBLocale { * @return the locale country */ public String getCountry(){ - if(locale == null) return "unknown"; + if(locale == null) { + return "unknown"; + } return locale.getDisplayCountry(); } @@ -55,7 +59,7 @@ public class BSBLocale { * @return the locale language tag */ public String toLanguageTag(){ - return this.locale.toLanguageTag(); + return locale.toLanguageTag(); } /** diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java b/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java index ac834fe96..485d4fad3 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java @@ -22,7 +22,7 @@ public class Panel { // If size is undefined (0) then use the number of items if (size == 0) { size = items.keySet().size(); - } + } // Create panel if (size > 0) { // Make sure size is a multiple of 9 diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/PanelItem.java b/src/main/java/us/tastybento/bskyblock/api/panels/PanelItem.java index ba1c7ea94..e89d16484 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/PanelItem.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/PanelItem.java @@ -30,11 +30,11 @@ public class PanelItem { meta = icon.getItemMeta(); this.clickHandler = clickHandler; - + // Create the final item - this.setName(name); - this.setDescription(description); - this.setGlow(glow); + setName(name); + setDescription(description); + setGlow(glow); // Set flags to neaten up the view meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); @@ -78,10 +78,11 @@ public class PanelItem { public void setGlow(boolean glow) { this.glow = glow; - if (glow) + if (glow) { meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, true); - else + } else { meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, false); + } } /** diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/PanelListener.java b/src/main/java/us/tastybento/bskyblock/api/panels/PanelListener.java index 4250b8b72..bd83ad09c 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/PanelListener.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/PanelListener.java @@ -11,7 +11,7 @@ public interface PanelListener { * This is called when the panel is first setup */ void setup(); - + /** * Called when the panel is clicked * @param user diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java index beac3b6fb..378be65e9 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelBuilder.java @@ -27,27 +27,27 @@ public class PanelBuilder { * @return PanelBuilder */ public PanelBuilder addItem(int slot, PanelItem item) { - this.items.put(slot, item); + items.put(slot, item); return this; } public int nextSlot() { - if (this.items.isEmpty()) { + if (items.isEmpty()) { return 0; } else { return items.lastEntry().getKey() + 1; - } + } } - + /** * Checks if a slot is occupied in the panel or not * @param slot to check * @return true or false */ public boolean slotOccupied(int slot) { - return this.items.containsKey(slot); + return items.containsKey(slot); } - + /** * Build the panel * @return Panel @@ -63,9 +63,9 @@ public class PanelBuilder { */ public PanelBuilder addItem(PanelItem item) { if (items.isEmpty()) { - this.items.put(0, item); + items.put(0, item); } else { - this.items.put(items.lastEntry().getKey() + 1, item); + items.put(items.lastEntry().getKey() + 1, item); } return this; } diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelItemBuilder.java b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelItemBuilder.java index cf86fec50..8b2be6ce0 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelItemBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/builders/PanelItemBuilder.java @@ -29,8 +29,8 @@ public class PanelItemBuilder { } public PanelItemBuilder name(String name) { - this.name = name; - return this; + this.name = name; + return this; } public PanelItemBuilder description(List description) { @@ -47,7 +47,7 @@ public class PanelItemBuilder { this.description.add(description); return this; } - + public PanelItemBuilder glow(boolean glow) { this.glow = glow; return this; @@ -59,8 +59,9 @@ public class PanelItemBuilder { } public PanelItem build() { - if (icon == null) + if (icon == null) { Bukkit.getLogger().info("DEBUG: icon is null"); + } return new PanelItem(icon, name, description, glow, clickHandler); } diff --git a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java index 64b0baba0..d1ac7d079 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/AdminCommand.java @@ -17,9 +17,9 @@ public class AdminCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "admin.*"); - this.setOnlyPlayer(false); - this.setDescription("admin.help.description"); + setPermission(Constants.PERMPREFIX + "admin.*"); + setOnlyPlayer(false); + setDescription("admin.help.description"); new AdminVersionCommand(this); new AdminReloadCommand(this); new AdminTeleportCommand(this); diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 2fb7d6cf3..3efb75961 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -27,10 +27,10 @@ public class IslandCommand extends CompositeCommand { */ @Override public void setup() { - this.setDescription("commands.island.help.description"); - this.setOnlyPlayer(true); + setDescription("commands.island.help.description"); + setOnlyPlayer(true); // Permission - this.setPermission(Constants.PERMPREFIX + "island"); + setPermission(Constants.PERMPREFIX + "island"); // Set up subcommands new IslandAboutCommand(this); new IslandCreateCommand(this); @@ -47,19 +47,19 @@ public class IslandCommand extends CompositeCommand { public boolean execute(User user, List args) { // If this player does not have an island, create one if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) { - Optional subCreate = this.getSubCommand("create"); + Optional subCreate = getSubCommand("create"); if (subCreate.isPresent()) { subCreate.get().execute(user, new ArrayList<>()); } } - Optional go = this.getSubCommand("go"); + Optional go = getSubCommand("go"); // Otherwise, currently, just go home if (go.isPresent()) { go.get().execute(user, new ArrayList<>()); } - + return true; } - + } diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java index c3c9c31ad..31f0d30ae 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminReloadCommand.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.commands.admin; diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminTeleportCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminTeleportCommand.java index baf5069fa..7d9fb3046 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminTeleportCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminTeleportCommand.java @@ -18,9 +18,9 @@ public class AdminTeleportCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "admin.tp"); - this.setOnlyPlayer(true); - this.setDescription("commands.admin.tp.description"); + setPermission(Constants.PERMPREFIX + "admin.tp"); + setOnlyPlayer(true); + setDescription("commands.admin.tp.description"); } @Override @@ -29,7 +29,7 @@ public class AdminTeleportCommand extends CompositeCommand { user.sendMessage("commands.admin.tp.help"); return true; } - + // Convert name to a UUID final UUID targetUUID = getPlayers().getUUID(args.get(0)); if (targetUUID == null) { @@ -38,10 +38,10 @@ public class AdminTeleportCommand extends CompositeCommand { } else { if (getPlayers().hasIsland(targetUUID) || getPlayers().inTeam(targetUUID)) { Location warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getIslandWorld()); - if (this.getLabel().equals("tpnether")) { - warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld()); - } else if (this.getLabel().equals("tpend")) { - warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getEndWorld()); + if (getLabel().equals("tpnether")) { + warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld()); + } else if (getLabel().equals("tpend")) { + warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getEndWorld()); } // Other wise, go to a safe spot String failureMessage = user.getTranslation("commands.admin.tp.manual", "[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " diff --git a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java index 577d7eb37..6eee377de 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/admin/AdminVersionCommand.java @@ -15,7 +15,7 @@ public class AdminVersionCommand extends CompositeCommand { @Override public void setup() { // Permission - this.setPermission(Constants.PERMPREFIX + "admin.version"); + setPermission(Constants.PERMPREFIX + "admin.version"); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java b/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java index a7ec5f3e6..408b16495 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/CustomIslandMultiHomeHelp.java @@ -11,25 +11,25 @@ import us.tastybento.bskyblock.util.Util; * This is a custom help for the /island go and /island sethome commands. It overrides the default help sub command. * The number of homes can change depending on the player's permissions and config.yml settings. * This is an example of a custom help as much as anything. - * + * * @author tastybento * */ public class CustomIslandMultiHomeHelp extends CompositeCommand { public CustomIslandMultiHomeHelp(CompositeCommand parent) { - super(parent, "help"); + super(parent, "help"); } - + @Override public void setup() { - this.setOnlyPlayer(true); + setOnlyPlayer(true); // Inherit parameters from the respective parent class - in this case, only /island go and /island sethome - this.setParameters(parent.getParameters()); - this.setDescription(parent.getDescription()); - this.setPermission(parent.getPermission()); + setParameters(parent.getParameters()); + setDescription(parent.getDescription()); + setPermission(parent.getPermission()); } - + @Override public boolean execute(User user, List args) { // This will only be shown if it is for a player @@ -56,6 +56,6 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand { } return false; } - + } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandAboutCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandAboutCommand.java index 4b40b6e8a..2e999e26b 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandAboutCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandAboutCommand.java @@ -15,12 +15,12 @@ public class IslandAboutCommand extends CompositeCommand { public IslandAboutCommand(CompositeCommand islandCommand) { super(islandCommand, "about", "ab"); } - + @Override public void setup() { - this.setDescription("commands.island.about.description"); + setDescription("commands.island.about.description"); } - + @Override public boolean execute(User user, List args) { user.sendRawMessage("About " + BSkyBlock.getInstance().getDescription().getName() + " v" + BSkyBlock.getInstance().getDescription().getVersion() + ":"); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java index 4cfc976c6..8516dae65 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandCreateCommand.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.commands.island; @@ -23,12 +23,12 @@ public class IslandCreateCommand extends CompositeCommand { public IslandCreateCommand(IslandCommand islandCommand) { super(islandCommand, "create", "auto"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.create"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.create.description"); + setPermission(Constants.PERMPREFIX + "island.create"); + setOnlyPlayer(true); + setDescription("commands.island.create.description"); } /* (non-Javadoc) @@ -41,7 +41,7 @@ public class IslandCreateCommand extends CompositeCommand { return false; } if (getPlayers().inTeam(user.getUniqueId())) { - return false; + return false; } user.sendMessage("commands.island.create.creating-island"); createIsland(user); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java index afe4090fa..85837bbfb 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandGoCommand.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.commands.island; @@ -26,9 +26,9 @@ public class IslandGoCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.home"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.go.description"); + setPermission(Constants.PERMPREFIX + "island.home"); + setOnlyPlayer(true); + setDescription("commands.island.go.description"); new CustomIslandMultiHomeHelp(this); } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java index 227e007af..572840faa 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetCommand.java @@ -20,12 +20,12 @@ public class IslandResetCommand extends CompositeCommand { public IslandResetCommand(CompositeCommand islandCommand) { super(islandCommand, "reset", "restart"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.create"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.reset.description"); + setPermission(Constants.PERMPREFIX + "island.create"); + setOnlyPlayer(true); + setDescription("commands.island.reset.description"); } @Override @@ -36,7 +36,7 @@ public class IslandResetCommand extends CompositeCommand { } if (!getIslands().isOwner(user.getUniqueId())) { user.sendMessage("general.errors.not-leader"); - return false; + return false; } if (getPlugin().getPlayers().inTeam(user.getUniqueId())) { user.sendMessage("commands.island.reset.must-remove-members"); @@ -46,15 +46,18 @@ public class IslandResetCommand extends CompositeCommand { player.setGameMode(GameMode.SPECTATOR); // Get the player's old island Island oldIsland = getIslands().getIsland(player.getUniqueId()); - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ()); + } // Remove them from this island (it still exists and will be deleted later) getIslands().removePlayer(player.getUniqueId()); - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner()); + } // Create new island and then delete the old one - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: making new island "); + } try { NewIsland.builder(getPlugin()) .player(player) diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java index d3b298e0c..559fbc687 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandResetnameCommand.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.commands.island; @@ -19,12 +19,12 @@ public class IslandResetnameCommand extends CompositeCommand { public IslandResetnameCommand(CompositeCommand islandCommand) { super(islandCommand, "resetname"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.name"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.resetname.description"); + setPermission(Constants.PERMPREFIX + "island.name"); + setOnlyPlayer(true); + setDescription("commands.island.resetname.description"); } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java index 08fb0c471..8bfa3410d 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSethomeCommand.java @@ -16,9 +16,9 @@ public class IslandSethomeCommand extends CompositeCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.sethome"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.sethome.description"); + setPermission(Constants.PERMPREFIX + "island.sethome"); + setOnlyPlayer(true); + setDescription("commands.island.sethome.description"); new CustomIslandMultiHomeHelp(this); } @@ -32,7 +32,7 @@ public class IslandSethomeCommand extends CompositeCommand { } if (!getPlugin().getIslands().playerIsOnIsland(user)) { user.sendMessage("commands.island.sethome.must-be-on-your-island"); - return false; + return false; } if (args.isEmpty()) { // island sethome diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java index 30cb3e686..571f898ec 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/IslandSetnameCommand.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.commands.island; @@ -23,13 +23,13 @@ public class IslandSetnameCommand extends CompositeCommand { public IslandSetnameCommand(CompositeCommand islandCommand) { super(islandCommand, "setname"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.name"); - this.setOnlyPlayer(true); - this.setParameters("commands.island.setname.parameters"); - this.setDescription("commands.island.setname.description"); + setPermission(Constants.PERMPREFIX + "island.name"); + setOnlyPlayer(true); + setParameters("commands.island.setname.parameters"); + setDescription("commands.island.setname.description"); } /* (non-Javadoc) @@ -69,9 +69,11 @@ public class IslandSetnameCommand extends CompositeCommand { } // Set the name - if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format")) + if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format")) { getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name)); - else getIslands().getIsland(playerUUID).setName(name); + } else { + getIslands().getIsland(playerUUID).setName(name); + } user.sendMessage("general.success"); return true; diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java index 6de0c3972..be9840364 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/AbstractIslandTeamCommand.java @@ -20,21 +20,21 @@ import us.tastybento.bskyblock.api.commands.User; * */ public abstract class AbstractIslandTeamCommand extends CompositeCommand { - + protected final static boolean DEBUG = false; - protected static BiMap inviteList = HashBiMap.create(); + protected static BiMap inviteList = HashBiMap.create(); // The time a player has to wait until they can reset their island again protected static HashMap resetWaitTime = new HashMap<>(); protected static Set leavingPlayers = new HashSet<>(); protected static Set kickingPlayers = new HashSet<>(); - + // TODO: It would be good if these could be auto-provided protected User user; - + public AbstractIslandTeamCommand(CompositeCommand command, String label, String... aliases) { super(command, label,aliases); } - + /** * Sets a timeout for player into the Hashmap resetWaitTime * diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java index bb9304553..328de6081 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamCommand.java @@ -23,9 +23,9 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.team.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setDescription("commands.island.team.description"); new IslandTeamInviteCommand(this); new IslandTeamLeaveCommand(this); @@ -36,17 +36,20 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand { @Override public boolean execute(User user, List args) { UUID playerUUID = user.getUniqueId(); - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: executing team command for " + playerUUID); + } // Fire event so add-ons can run commands, etc. IslandBaseEvent event = TeamEvent.builder() .island(getIslands() - .getIsland(playerUUID)) + .getIsland(playerUUID)) .reason(TeamEvent.Reason.INFO) .involvedPlayer(playerUUID) .build(); getPlugin().getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return true; + if (event.isCancelled()) { + return true; + } UUID teamLeaderUUID = getTeamLeader(user); Set teamMembers = getMembers(user); if (teamLeaderUUID.equals(playerUUID)) { @@ -69,9 +72,11 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand { } } // Do some sanity checking - if (maxSize < 1) maxSize = 1; + if (maxSize < 1) { + maxSize = 1; + } } - + if (teamMembers.size() < maxSize) { user.sendMessage("commands.island.team.invite.you-can-invite", "[number]", String.valueOf(maxSize - teamMembers.size())); } else { diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java index 023cefda7..147c27954 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteAcceptCommand.java @@ -18,22 +18,23 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { public IslandTeamInviteAcceptCommand(IslandTeamInviteCommand islandTeamInviteCommand) { super(islandTeamInviteCommand, "accept"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.team.invite.accept.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setDescription("commands.island.team.invite.accept.description"); } @Override public boolean execute(User user, List args) { - + Bukkit.getLogger().info("DEBUG: accept - " + inviteList.toString()); - + UUID playerUUID = user.getUniqueId(); - if(!inviteList.containsKey(playerUUID)) - return false; + if(!inviteList.containsKey(playerUUID)) { + return false; + } // Check if player has been invited if (!inviteList.containsKey(playerUUID)) { user.sendMessage("commands.island.team.invite.errors.none-invited-you"); @@ -51,20 +52,24 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { inviteList.remove(playerUUID); return false; } - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: Invite is valid"); + } // Fire event so add-ons can run commands, etc. IslandBaseEvent event = TeamEvent.builder() .island(getIslands() - .getIsland(prospectiveTeamLeaderUUID)) + .getIsland(prospectiveTeamLeaderUUID)) .reason(TeamEvent.Reason.JOIN) .involvedPlayer(playerUUID) .build(); getPlugin().getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return true; + if (event.isCancelled()) { + return true; + } // Remove the invite - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: Removing player from invite list"); + } inviteList.remove(playerUUID); // Put player into Spectator mode user.setGameMode(GameMode.SPECTATOR); @@ -100,8 +105,9 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); } getIslands().save(false); - if (DEBUG) + if (DEBUG) { getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMemberSet().toString()); + } return true; } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java index 138eef747..54da32b0d 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteCommand.java @@ -27,9 +27,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.team.invite.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setDescription("commands.island.team.invite.description"); new IslandTeamInviteAcceptCommand(this); new IslandTeamInviteRejectCommand(this); @@ -106,7 +106,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { } } // Do some sanity checking - if (maxSize < 1) maxSize = 1; + if (maxSize < 1) { + maxSize = 1; + } } if (teamMembers.size() < maxSize) { // If that player already has an invite out then retract it. @@ -122,7 +124,9 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { .involvedPlayer(invitedPlayerUUID) .build(); getPlugin().getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return true; + if (event.isCancelled()) { + return true; + } // Put the invited player (key) onto the list with inviter (value) // If someone else has invited a player, then this invite will overwrite the previous invite! inviteList.put(invitedPlayerUUID, playerUUID); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java index 60e33fd63..2410b8c64 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamInviteRejectCommand.java @@ -13,12 +13,12 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { public IslandTeamInviteRejectCommand(IslandTeamInviteCommand islandTeamInviteCommand) { super(islandTeamInviteCommand, "reject"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.team.invite.reject.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setDescription("commands.island.team.invite.reject.description"); } @Override @@ -29,12 +29,14 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { // Fire event so add-ons can run commands, etc. IslandBaseEvent event = TeamEvent.builder() .island(getIslands() - .getIsland(inviteList.get(playerUUID))) + .getIsland(inviteList.get(playerUUID))) .reason(TeamEvent.Reason.REJECT) .involvedPlayer(playerUUID) .build(); getPlugin().getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return false; + if (event.isCancelled()) { + return false; + } // Remove this player from the global invite list inviteList.remove(user.getUniqueId()); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommand.java index 324917074..a2db50a99 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamKickCommand.java @@ -20,10 +20,10 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setParameters("commands.island.team.kick.parameters"); - this.setDescription("commands.island.team.kick.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setParameters("commands.island.team.kick.parameters"); + setDescription("commands.island.team.kick.description"); kickSet = new HashSet<>(); } @@ -46,11 +46,11 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand { UUID targetUUID = getPlayers().getUUID(args.get(0)); if (targetUUID == null) { user.sendMessage("general.errors.unknown-player"); - return true; + return true; } if (!getIslands().getMembers(user.getUniqueId()).contains(targetUUID)) { user.sendMessage("general.errors.not-in-team"); - return true; + return true; } if (!getSettings().isKickConfirmation() || kickSet.contains(targetUUID)) { kickSet.remove(targetUUID); diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java index dfb8c7cae..d5272734d 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamLeaveCommand.java @@ -20,9 +20,9 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand { @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setDescription("commands.island.team.leave.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setDescription("commands.island.team.leave.description"); leaveSet = new HashSet<>(); } diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java index 48f29c256..419b7ca6d 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamPromoteCommand.java @@ -10,13 +10,13 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand { public IslandTeamPromoteCommand(IslandTeamCommand islandTeamCommand) { super(islandTeamCommand, "promote"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setParameters("commands.island.team.promote.parameters"); - this.setDescription("commands.island.team.promote.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setParameters("commands.island.team.promote.parameters"); + setDescription("commands.island.team.promote.description"); } @Override diff --git a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java index d0c02ee4e..657fdbbed 100644 --- a/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/island/teams/IslandTeamSetownerCommand.java @@ -21,13 +21,13 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { public IslandTeamSetownerCommand(IslandTeamCommand islandTeamCommand) { super(islandTeamCommand, "setleader"); } - + @Override public void setup() { - this.setPermission(Constants.PERMPREFIX + "island.team"); - this.setOnlyPlayer(true); - this.setParameters("commands.island.team.setowner.parameters"); - this.setDescription("commands.island.team.setowner.description"); + setPermission(Constants.PERMPREFIX + "island.team"); + setOnlyPlayer(true); + setParameters("commands.island.team.setowner.parameters"); + setDescription("commands.island.team.setowner.description"); } @Override @@ -75,7 +75,9 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { .involvedPlayer(targetUUID) .build(); getPlugin().getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return false; + if (event.isCancelled()) { + return false; + } // target is the new leader getIslands().getIsland(playerUUID).setOwner(targetUUID); diff --git a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java index c0bc456b8..eac83c72f 100755 --- a/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java +++ b/src/main/java/us/tastybento/bskyblock/database/BSBDatabase.java @@ -14,7 +14,9 @@ public abstract class BSBDatabase { */ public static BSBDatabase getDatabase(){ for(DatabaseType type : DatabaseType.values()){ - if(type == BSkyBlock.getInstance().getSettings().getDatabaseType()) return type.database; + if(type == BSkyBlock.getInstance().getSettings().getDatabaseType()) { + return type.database; + } } return DatabaseType.FLATFILE.database; } diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java index b3d8c3017..c078e6542 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseConnecter.java @@ -37,10 +37,11 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter { /** * Loads a YAML file and if it does not exist it is looked for in the JAR - * + * * @param fileName * @return */ + @Override public YamlConfiguration loadYamlFile(String tableName, String fileName) { if (!fileName.endsWith(".yml")) { fileName = fileName + ".yml"; @@ -77,7 +78,7 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter { /** * Saves a YAML file - * + * * @param yamlConfig * @param fileName */ diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java index 04552239a..4d20fa619 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseHandler.java @@ -109,16 +109,13 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { */ @Override public List loadObjects() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException, ClassNotFoundException { - List list = new ArrayList(); - FilenameFilter ymlFilter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - String lowercaseName = name.toLowerCase(); - if (lowercaseName.endsWith(".yml")) { - return true; - } else { - return false; - } + List list = new ArrayList<>(); + FilenameFilter ymlFilter = (dir, name) -> { + String lowercaseName = name.toLowerCase(); + if (lowercaseName.endsWith(".yml")) { + return true; + } else { + return false; } }; String path = dataObject.getSimpleName(); @@ -166,27 +163,30 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject); // Get the write method Method method = propertyDescriptor.getWriteMethod(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: " + field.getName() + ": " + propertyDescriptor.getPropertyType().getTypeName()); + } String storageLocation = field.getName(); // Check if there is an annotation on the field ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); // If there is a config annotation then do something - if (configEntry != null) { + if (configEntry != null) { if (!configEntry.path().isEmpty()) { storageLocation = configEntry.path(); } if (!configEntry.specificTo().equals(GameType.BOTH) && !configEntry.specificTo().equals(Constants.GAMETYPE)) { - if (DEBUG) + if (DEBUG) { Bukkit.getLogger().info(field.getName() + " not applicable to this game type"); + } continue; } // TODO: Add handling of other ConfigEntry elements } Adapter adapterNotation = field.getAnnotation(Adapter.class); if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: there is an adapter"); + } // A conversion adapter has been defined Object value = config.get(storageLocation); method.invoke(instance, ((AdapterInterface)adapterNotation.value().newInstance()).serialize(value)); @@ -199,7 +199,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType())); } // We are done here - continue; + continue; } // Look in the YAML Config to see if this field exists (it should) @@ -216,10 +216,11 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { // collectionTypes should be 2 long Type keyType = collectionTypes.get(0); Type valueType = collectionTypes.get(1); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: is Map or HashMap<" + keyType.getTypeName() + ", " + valueType.getTypeName() + ">"); + } // TODO: this may not work with all keys. Further serialization may be required. - Map value = new HashMap(); + Map value = new HashMap<>(); for (String key : config.getConfigurationSection(storageLocation).getKeys(false)) { // Keys cannot be null - skip if they exist Object mapKey = deserialize(key,Class.forName(keyType.getTypeName())); @@ -240,49 +241,52 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName()); plugin.getLogger().info("DEBUG: adding a set"); } - // Loop through the collection resultset + // Loop through the collection resultset // Note that we have no idea what type this is List collectionTypes = Util.getCollectionParameterTypes(method); // collectionTypes should be only 1 long Type setType = collectionTypes.get(0); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: is HashSet<" + setType.getTypeName() + ">"); - Set value = new HashSet(); + } + Set value = new HashSet<>(); if (DEBUG) { plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName()); } for (Object listValue: config.getList(storageLocation)) { //plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize()); - ((Set) value).add(deserialize(listValue,Class.forName(setType.getTypeName()))); + value.add(deserialize(listValue,Class.forName(setType.getTypeName()))); } // TODO: this may not work with all keys. Further serialization may be required. - //Set value = new HashSet((List) config.getList(storageLocation)); + //Set value = new HashSet((List) config.getList(storageLocation)); method.invoke(instance, value); } else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { //plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName()); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding a set"); - // Loop through the collection resultset + } + // Loop through the collection resultset // Note that we have no idea what type this is List collectionTypes = Util.getCollectionParameterTypes(method); // collectionTypes should be only 1 long Type setType = collectionTypes.get(0); - List value = new ArrayList(); + List value = new ArrayList<>(); //plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); //plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName()); for (Object listValue: config.getList(storageLocation)) { //plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize()); - ((List) value).add(deserialize(listValue,Class.forName(setType.getTypeName()))); + value.add(deserialize(listValue,Class.forName(setType.getTypeName()))); } // TODO: this may not work with all keys. Further serialization may be required. - //Set value = new HashSet((List) config.getList(storageLocation)); + //Set value = new HashSet((List) config.getList(storageLocation)); method.invoke(instance, value); } else { // Not a collection - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: not a collection"); + } Object value = config.get(storageLocation); if (DEBUG) { plugin.getLogger().info("DEBUG: name = " + field.getName()); @@ -303,6 +307,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { /* (non-Javadoc) * @see us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler#saveConfig(java.lang.Object) */ + @Override public void saveSettings(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException { configFlag = true; saveObject(instance); @@ -337,7 +342,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { } // Run through all the fields in the class that is being stored. EVERY field must have a get and set method - fields: + fields: for (Field field : dataObject.getDeclaredFields()) { // Get the property descriptor for this field @@ -361,16 +366,17 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { } if (!configEntry.path().isEmpty()) { storageLocation = configEntry.path(); - } + } // TODO: add in game-specific saving } Adapter adapterNotation = field.getAnnotation(Adapter.class); if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: there is an adapter"); - // A conversion adapter has been defined + } + // A conversion adapter has been defined try { config.set(storageLocation, ((AdapterInterface)adapterNotation.value().newInstance()).deserialize(value)); } catch (InstantiationException e) { @@ -384,7 +390,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { // Depending on the vale type, it'll need serializing differenty // Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class if (method.getName().equals("getUniqueId")) { - // If the object does not have a unique name assigned to it already, one is created at random + // If the object does not have a unique name assigned to it already, one is created at random //plugin.getLogger().info("DEBUG: uniqueId = " + value); String id = (String)value; if (value == null || id.isEmpty()) { @@ -393,15 +399,16 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { propertyDescriptor.getWriteMethod().invoke(instance, id); } // Save the name for when the file is saved - if (filename.isEmpty()) + if (filename.isEmpty()) { filename = id; + } } // Collections need special serialization if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { // Maps need to have keys serialized //plugin.getLogger().info("DEBUG: Map for " + storageLocation); if (value != null) { - Map result = new HashMap(); + Map result = new HashMap<>(); for (Entry object : ((Map)value).entrySet()) { // Serialize all key types // TODO: also need to serialize values? @@ -412,10 +419,11 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { } } else if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { // Sets need to be serialized as string lists - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Set for " + storageLocation); + } if (value != null) { - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object object : (Set)value) { list.add(serialize(object)); } @@ -430,7 +438,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { if (filename.isEmpty()) { throw new IllegalArgumentException("No uniqueId in class"); } - databaseConnecter.saveYamlFile(config, path, filename); + databaseConnecter.saveYamlFile(config, path, filename); } /** @@ -463,15 +471,16 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { if (DEBUG) { plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getCanonicalName()); plugin.getLogger().info("DEBUG: value is " + value); - if (value != null) + if (value != null) { plugin.getLogger().info("DEBUG: value class is " + value.getClass().getCanonicalName()); + } } // If value is already null, then it can be nothing else if (value == null) { return null; } if (value instanceof String && value.equals("null")) { - // If the value is null as a string, return null + // If the value is null as a string, return null return null; } // Bukkit may have deserialized the object already @@ -480,7 +489,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { } // Types that need to be deserialized if (clazz.equals(Long.class) && value.getClass().equals(Integer.class)) { - return new Long((Integer)value); + return new Long((Integer)value); } if (clazz.equals(UUID.class)) { value = UUID.fromString((String)value); @@ -522,7 +531,7 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { File dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME); File tableFolder = new File(dataFolder, dataObject.getSimpleName()); if (tableFolder.exists()) { - + File file = new File(tableFolder, fileName); try { Files.delete(file.toPath()); @@ -537,7 +546,9 @@ public class FlatFileDatabaseHandler extends AbstractDatabaseHandler { */ @Override public T loadSettings(String uniqueId, T dbConfig) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IntrospectionException { - if (dbConfig == null) return loadObject(uniqueId); + if (dbConfig == null) { + return loadObject(uniqueId); + } // TODO: compare the loaded with the database copy diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java index 2f81a2dac..6e9fa3cf3 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/PlayersManager.java @@ -70,14 +70,16 @@ public class PlayersManager{ * @param async - if true, save async */ public void save(boolean async){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving " + async); + } Collection set = Collections.unmodifiableCollection(playerCache.values()); if(async){ Runnable save = () -> { for(Players player : set){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId()); + } try { handler.saveObject(player); } catch (Exception e) { @@ -88,8 +90,9 @@ public class PlayersManager{ plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save); } else { for(Players player : set){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId()); + } try { handler.saveObject(player); } catch (Exception e) { @@ -121,33 +124,39 @@ public class PlayersManager{ * @return the players object */ public Players addPlayer(final UUID playerUUID) { - if (playerUUID == null) + if (playerUUID == null) { return null; - if (DEBUG) + } + if (DEBUG) { plugin.getLogger().info("DEBUG: adding player " + playerUUID); + } if (!playerCache.containsKey(playerUUID)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: player not in cache"); + } Players player = null; // If the player is in the database, load it, otherwise create a new player if (handler.objectExits(playerUUID.toString())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: player in database"); + } try { player = handler.loadObject(playerUUID.toString()); } catch (Exception e) { plugin.getLogger().severe("Could not load player " + playerUUID + " " + e.getMessage()); } } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: new player"); + } player = new Players(plugin, playerUUID); } playerCache.put(playerUUID, player); return player; } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: known player"); + } return playerCache.get(playerUUID); } } @@ -331,8 +340,9 @@ public class PlayersManager{ * @param name */ public void setPlayerName(User user) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Setting player name to " + user.getName() + " for " + user.getUniqueId()); + } addPlayer(user.getUniqueId()); playerCache.get(user.getUniqueId()).setPlayerName(user.getName()); } @@ -345,14 +355,16 @@ public class PlayersManager{ * @return String - playerName */ public String getName(UUID playerUUID) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Geting player name"); + } if (playerUUID == null) { return ""; } addPlayer(playerUUID); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: name is " + playerCache.get(playerUUID).getPlayerName()); + } return playerCache.get(playerUUID).getPlayerName(); } @@ -363,8 +375,9 @@ public class PlayersManager{ * @return UUID of owner of island */ public UUID getPlayerFromIslandLocation(Location loc) { - if (loc == null) + if (loc == null) { return null; + } // Look in the grid Optional island = plugin.getIslands().getIslandAt(loc); return island.map(x->x.getOwner()).orElse(null); @@ -425,7 +438,9 @@ public class PlayersManager{ */ public String getLocale(UUID playerUUID) { addPlayer(playerUUID); - if (playerUUID == null) return ""; + if (playerUUID == null) { + return ""; + } return playerCache.get(playerUUID).getLocale(); } @@ -578,8 +593,9 @@ public class PlayersManager{ if (playerCache.containsKey(playerUUID)) { final Players player = playerCache.get(playerUUID); try { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving player by uuid " + player.getPlayerName() + " " + playerUUID + " saved"); + } handler.saveObject(player); } catch (IllegalAccessException | IllegalArgumentException @@ -589,8 +605,9 @@ public class PlayersManager{ plugin.getLogger().severe("Could not save player to database: " + playerUUID + " " + e.getMessage()); } } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: " + playerUUID + " is not in the cache to save"); + } } } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java index a50217191..76e44029c 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandCache.java @@ -43,14 +43,17 @@ public class IslandCache { */ public void addIsland(Island island) { islandsByLocation.put(island.getCenter(), island); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: owner = " + island.getOwner()); + } islandsByUUID.put(island.getOwner(), island); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members"); + } for (UUID member: island.getMemberSet()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: " + member); + } islandsByUUID.put(member, island); } addToGrid(island); @@ -66,12 +69,14 @@ public class IslandCache { */ private void addToGrid(Island newIsland) { if (islandGrid.containsKey(newIsland.getMinX())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: min x is in the grid :" + newIsland.getMinX()); + } TreeMap zEntry = islandGrid.get(newIsland.getMinX()); if (zEntry.containsKey(newIsland.getMinZ())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: min z is in the grid :" + newIsland.getMinZ()); + } // Island already exists Island conflict = islandGrid.get(newIsland.getMinX()).get(newIsland.getMinZ()); plugin.getLogger().warning("*** Duplicate or overlapping islands! ***"); @@ -94,17 +99,19 @@ public class IslandCache { return; } else { // Add island - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ()); + } zEntry.put(newIsland.getMinZ(), newIsland); islandGrid.put(newIsland.getMinX(), zEntry); // plugin.getLogger().info("Debug: " + newIsland.toString()); } } else { // Add island - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: added island to grid at " + newIsland.getMinX() + "," + newIsland.getMinZ()); - TreeMap zEntry = new TreeMap(); + } + TreeMap zEntry = new TreeMap<>(); zEntry.put(newIsland.getMinZ(), newIsland); islandGrid.put(newIsland.getMinX(), zEntry); } @@ -117,8 +124,9 @@ public class IslandCache { public Island createIsland(Island island) { islandsByLocation.put(island.getCenter(), island); - if (island.getOwner() != null) + if (island.getOwner() != null) { islandsByUUID.put(island.getOwner(), island); + } addToGrid(island); return island; } @@ -137,12 +145,14 @@ public class IslandCache { * @param owner UUID */ public Island createIsland(Location location, UUID owner){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); + } Island island = new Island(location, owner, plugin.getSettings().getIslandProtectionRange()); islandsByLocation.put(location, island); - if (owner != null) + if (owner != null) { islandsByUUID.put(owner, island); + } addToGrid(island); return island; } @@ -163,26 +173,31 @@ public class IslandCache { } } // Remove from grid - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: deleting island at " + island.getCenter()); + } if (island != null) { int x = island.getMinX(); int z = island.getMinZ(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: x = " + x + " z = " + z); + } if (islandGrid.containsKey(x)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: x found"); + } TreeMap zEntry = islandGrid.get(x); if (zEntry.containsKey(z)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: z found - deleting the island"); + } // Island exists - delete it zEntry.remove(z); islandGrid.put(x, zEntry); } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: could not find z"); + } } } } @@ -225,12 +240,14 @@ public class IslandCache { // Check if in the island range Island island = ent.getValue(); if (island.inIslandSpace(x, z)) { - if (DEBUG2) + if (DEBUG2) { plugin.getLogger().info("DEBUG: In island space"); + } return island; } - if (DEBUG2) + if (DEBUG2) { plugin.getLogger().info("DEBUG: not in island space"); + } } } return null; @@ -264,8 +281,9 @@ public class IslandCache { * @return Location of player's island or null if one does not exist */ public Location getIslandLocation(UUID playerUUID) { - if (hasIsland(playerUUID)) + if (hasIsland(playerUUID)) { return getIsland(playerUUID).getCenter(); + } return null; } @@ -291,14 +309,16 @@ public class IslandCache { public Set getMembers(UUID playerUUID) { Island island = islandsByUUID.get(playerUUID); - if (island != null) - return new HashSet(island.getMemberSet()); - return new HashSet(0); + if (island != null) { + return new HashSet<>(island.getMemberSet()); + } + return new HashSet<>(0); } public UUID getTeamLeader(UUID playerUUID) { - if (islandsByUUID.containsKey(playerUUID)) + if (islandsByUUID.containsKey(playerUUID)) { return islandsByUUID.get(playerUUID).getOwner(); + } return null; } @@ -318,35 +338,41 @@ public class IslandCache { } } if (islandsByUUID.containsKey(playerUUID) && islandsByUUID.get(playerUUID).getOwner() != null) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: checking for equals"); + } if (islandsByUUID.get(playerUUID).getOwner().equals(playerUUID)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: has island"); + } return true; } } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: doesn't have island"); + } return false; } public void removePlayer(UUID playerUUID) { Island island = islandsByUUID.get(playerUUID); if (island != null) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: island found"); + } if (island.getOwner() != null && island.getOwner().equals(playerUUID)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: player is the owner of this island"); + } // Clear ownership and members island.getMemberSet().clear(); island.setOwner(null); } island.getMemberSet().remove(playerUUID); } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: removing reference to island by UUID"); + } islandsByUUID.remove(playerUUID); } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java index 7416d317d..a4cae85d6 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java @@ -224,7 +224,7 @@ public class IslandsManager { if (maxYradius < height) { maxYradius++; } - //plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius + + //plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius + // "," + maxXradius + "," + maxYradius + "," + maxZradius); } while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth || maxYradius < height); @@ -246,8 +246,9 @@ public class IslandsManager { * @param owner UUID */ public Island createIsland(Location location, UUID owner){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding island for " + owner + " at " + location); + } return islandCache.createIsland(new Island(location, owner, plugin.getSettings().getIslandProtectionRange())); } @@ -257,8 +258,9 @@ public class IslandsManager { * @param removeBlocks - if the island blocks should be removed or not */ public void deleteIsland(Island island, boolean removeBlocks) { - if (island == null) + if (island == null) { return; + } // Set the owner of the island to no one. island.setOwner(null); island.setLocked(false); @@ -291,8 +293,9 @@ public class IslandsManager { */ public void deleteIsland(final UUID player, boolean removeBlocks) { // Removes the island - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: deleting player island"); + } //CoopPlay.getInstance().clearAllIslandCoops(player); //getWarpSignsListener().removeWarp(player); final Island island = getIsland(player); @@ -377,8 +380,9 @@ public class IslandsManager { * @return Location of player's island or null if one does not exist */ public Location getIslandLocation(UUID playerUUID) { - if (hasIsland(playerUUID)) + if (hasIsland(playerUUID)) { return getIsland(playerUUID).getCenter(); + } return null; } @@ -439,8 +443,9 @@ public class IslandsManager { l = plugin.getPlayers().getHomeLocation(playerUUID, number); } // Check if it is safe - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Home location " + l); + } if (l != null) { if (isSafeLocation(l)) { return l; @@ -456,38 +461,45 @@ public class IslandsManager { } } } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Home location either isn't safe, or does not exist so try the island"); + } // Home location either isn't safe, or does not exist so try the island // location if (plugin.getPlayers().inTeam(playerUUID)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG:player is in team"); + } l = plugin.getIslands().getIslandLocation(playerUUID); if (isSafeLocation(l)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG:island loc is safe"); + } plugin.getPlayers().setHomeLocation(playerUUID, l, number); return l; } else { // try team leader's home - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: trying leader's home"); + } Location tlh = plugin.getPlayers().getHomeLocation(plugin.getIslands().getTeamLeader(playerUUID)); if (tlh != null) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: leader has a home"); + } if (isSafeLocation(tlh)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: team leader's home is safe"); + } plugin.getPlayers().setHomeLocation(playerUUID, tlh, number); return tlh; } } } } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: player is not in team - trying island location"); + } l = plugin.getIslands().getIslandLocation(playerUUID); if (isSafeLocation(l)) { plugin.getPlayers().setHomeLocation(playerUUID, l, number); @@ -498,28 +510,32 @@ public class IslandsManager { plugin.getLogger().warning(plugin.getPlayers().getName(playerUUID) + " player has no island!"); return null; } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: If these island locations are not safe, then we need to get creative"); + } // If these island locations are not safe, then we need to get creative // Try the default location - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: try default location"); + } Location dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 2.5D, 0F, 30F); if (isSafeLocation(dl)) { plugin.getPlayers().setHomeLocation(playerUUID, dl, number); return dl; } // Try just above the bedrock - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: above bedrock"); + } dl = new Location(l.getWorld(), l.getX() + 0.5D, l.getY() + 5D, l.getZ() + 0.5D, 0F, 30F); if (isSafeLocation(dl)) { plugin.getPlayers().setHomeLocation(playerUUID, dl, number); return dl; } // Try all the way up to the sky - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: try all the way to the sky"); + } for (int y = l.getBlockY(); y < 255; y++) { final Location n = new Location(l.getWorld(), l.getX() + 0.5D, y, l.getZ() + 0.5D); if (isSafeLocation(n)) { @@ -527,8 +543,9 @@ public class IslandsManager { return n; } } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: unsuccessful"); + } // Unsuccessful return null; } @@ -542,8 +559,9 @@ public class IslandsManager { */ public Location getSpawnPoint() { //plugin.getLogger().info("DEBUG: getting spawn point : " + spawn.getSpawnPoint()); - if (spawn == null) + if (spawn == null) { return null; + } return spawn.getSpawnPoint(); } @@ -584,11 +602,13 @@ public class IslandsManager { @SuppressWarnings("deprecation") public void homeTeleport(final Player player, int number) { Location home; - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("home teleport called for #" + number); + } home = getSafeHomeLocation(player.getUniqueId(), number); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("home get safe loc = " + home); + } // Check if the player is a passenger in a boat if (player.isInsideVehicle()) { Entity boat = player.getVehicle(); @@ -601,14 +621,16 @@ public class IslandsManager { } } if (home == null) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("Fixing home location using safe spot teleport"); + } // Try to fix this teleport location and teleport the player if possible new SafeSpotTeleport(plugin, player, plugin.getPlayers().getHomeLocation(player.getUniqueId(), number), number); return; } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting"); + } //home.getChunk().load(); player.teleport(home); //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0); @@ -644,11 +666,13 @@ public class IslandsManager { * @return */ public boolean isIsland(Location location){ - if (location == null) + if (location == null) { return true; + } location = getClosestIsland(location); - if (islandCache.contains(location)) + if (islandCache.contains(location)) { return true; + } if (!plugin.getSettings().isUseOwnGenerator()) { // Block check @@ -662,7 +686,7 @@ public class IslandsManager { for (int x = -5; x <= 5; x++) { for (int y = 10; y <= 255; y++) { for (int z = -5; z <= 5; z++) { - if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty() + if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty() && !location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isLiquid()) { plugin.getLogger().info("Solid block found during long search - adding "); createIsland(location); @@ -677,14 +701,14 @@ public class IslandsManager { /** * This returns the coordinate of where an island should be on the grid. - * + * * @param location location to query * @return Location of closest island */ public Location getClosestIsland(Location location) { - long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance()) + long x = Math.round((double) location.getBlockX() / plugin.getSettings().getIslandDistance()) * plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandXOffset(); - long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance()) + long z = Math.round((double) location.getBlockZ() / plugin.getSettings().getIslandDistance()) * plugin.getSettings().getIslandDistance() + plugin.getSettings().getIslandZOffset(); long y = plugin.getSettings().getIslandHeight(); return new Location(location.getWorld(), x, y, z); @@ -708,18 +732,21 @@ public class IslandsManager { islandCache.clear(); spawn = null; try { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: loading grid"); + } for (Island island : handler.loadObjects()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding island at "+ island.getCenter()); + } islandCache.addIsland(island); } } catch (Exception e) { plugin.getLogger().severe("Could not load islands to cache! " + e.getMessage()); } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: islands loaded"); + } } /** @@ -731,7 +758,7 @@ public class IslandsManager { */ public boolean locationIsAtHome(UUID uuid, boolean coop, Location loc) { // Make a list of test locations and test them - Set islandTestLocations = new HashSet(); + Set islandTestLocations = new HashSet<>(); if (plugin.getPlayers().hasIsland(uuid) || plugin.getPlayers().inTeam(uuid)) { islandTestLocations.add(plugin.getIslands().getIslandLocation(uuid)); // If new Nether @@ -800,7 +827,7 @@ public class IslandsManager { } // Not in the grid, so do it the old way // Make a list of test locations and test them - Set islandTestLocations = new HashSet(); + Set islandTestLocations = new HashSet<>(); if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) { islandTestLocations.add(getIslandLocation(player.getUniqueId())); } @@ -829,7 +856,7 @@ public class IslandsManager { } public void metrics_setCreatedCount(int count){ - this.metrics_createdcount = count; + metrics_createdcount = count; } /** @@ -877,8 +904,9 @@ public class IslandsManager { * @param playerUUID */ public void removePlayer(UUID playerUUID) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: removing player"); + } islandCache.removePlayer(playerUUID); } @@ -920,13 +948,14 @@ public class IslandsManager { * @param async - if true, saving will be done async */ public void save(boolean async){ - Collection collection = islandCache.getIslands(); + Collection collection = islandCache.getIslands(); if(async){ Runnable save = () -> { int index = 1; for(Island island : collection){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving island async " + index++); + } try { handler.saveObject(island); } catch (Exception e) { @@ -938,8 +967,9 @@ public class IslandsManager { } else { int index = 1; for(Island island : collection){ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saving island " + index++); + } try { handler.saveObject(island); } catch (Exception e) { @@ -967,8 +997,9 @@ public class IslandsManager { */ public boolean setJoinTeam(Island teamIsland, UUID playerUUID) { // Add player to new island - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Adding player to new island"); + } teamIsland.addMember(playerUUID); islandCache.addPlayer(playerUUID, teamIsland); if (DEBUG) { @@ -990,8 +1021,9 @@ public class IslandsManager { * @param playerUUID */ public void setLeaveTeam(UUID playerUUID) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: leaving team"); + } plugin.getPlayers().clearPlayerHomes(playerUUID); removePlayer(playerUUID); } diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java index 35e7b9f87..8210ba144 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/NewIsland.java @@ -28,7 +28,7 @@ public class NewIsland { private NewIsland(Island oldIsland, Player player, Reason reason) { super(); - this.plugin = BSkyBlock.getInstance(); + plugin = BSkyBlock.getInstance(); this.player = player; this.reason = reason; newIsland(); @@ -47,7 +47,7 @@ public class NewIsland { /** * Start building a new island - * @param plugin + * @param plugin * @return New island builder object */ public static Builder builder(BSkyBlock plugin) { @@ -93,8 +93,9 @@ public class NewIsland { * Makes an island. */ public void newIsland() { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: new island"); + } //long time = System.nanoTime(); final UUID playerUUID = player.getUniqueId(); /* @@ -102,11 +103,13 @@ public class NewIsland { if (!plugin.getPlayers().hasIsland(playerUUID)) { firstTime = true; }*/ - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: finding island location"); + } Location next = getNextIsland(player.getUniqueId()); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: found " + next); + } // Add to the grid island = plugin.getIslands().createIsland(next, playerUUID); @@ -123,16 +126,18 @@ public class NewIsland { plugin.getPlayers().setHomeLocation(playerUUID, next, 1); // Fire event - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: firing event"); + } IslandBaseEvent event = IslandEvent.builder() .involvedPlayer(player.getUniqueId()) .reason(reason) .island(island) .location(island.getCenter()) .build(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: event cancelled status = " + event.isCancelled()); + } if (!event.isCancelled()) { // Create island new IslandBuilder(plugin, island) @@ -153,7 +158,7 @@ public class NewIsland { .setChestItems(plugin.getSettings().getChestItems()) .setType(IslandType.END) .build(); - } + } // Teleport player to their island plugin.getIslands().homeTeleport(player); // Fire exit event @@ -186,25 +191,30 @@ public class NewIsland { Location last = plugin.getIslands().getLast(); if (DEBUG) + { plugin.getLogger().info("DEBUG: last = " + last); - // Find the next free spot + // Find the next free spot + } if (last == null) { last = new Location(plugin.getIslandWorldManager().getIslandWorld(), plugin.getSettings().getIslandXOffset() + plugin.getSettings().getIslandStartX(), plugin.getSettings().getIslandHeight(), plugin.getSettings().getIslandZOffset() + plugin.getSettings().getIslandStartZ()); } Location next = last.clone(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: last 2 = " + last); + } while (plugin.getIslands().isIsland(next)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: getting next loc"); + } next = nextGridLocation(next); }; // Make the last next, last last = next.clone(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: last 3 = " + last); + } return next; } diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java index b6db74227..c08ec4d54 100644 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseHandler.java @@ -83,7 +83,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { mySQLmapping.put(Location.class.getTypeName(), "VARCHAR(254)"); mySQLmapping.put(World.class.getTypeName(), "VARCHAR(254)"); - // Collections are stored as additional tables. The boolean indicates whether there + // Collections are stored as additional tables. The boolean indicates whether there // is any data in it or not (maybe) mySQLmapping.put(Set.class.getTypeName(), "BOOL"); mySQLmapping.put(Map.class.getTypeName(), "BOOL"); @@ -97,7 +97,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { /** * Handles the connection to the database and creation of the initial database schema (tables) for - * the class that will be stored. + * the class that will be stored. * @param plugin * @param type - the type of class to be stored in the database. Must inherit DataObject * @param databaseConnecter - authentication details for the database @@ -163,8 +163,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { //plugin.getLogger().info(setSql); // Execute the statement try (PreparedStatement collections = connection.prepareStatement(setSql)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collections prepared statement = " + collections.toString()); + } collections.executeUpdate(); } } @@ -182,8 +183,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { //plugin.getLogger().info("DEBUG: SQL string = " + sql); // Prepare and execute the database statements pstmt = connection.prepareStatement(sql); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: pstmt = " + pstmt.toString()); + } pstmt.executeUpdate(); } catch (Exception e) { plugin.getLogger().severe("Could not create database schema! " + e.getMessage()); @@ -209,15 +211,17 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { boolean first = true; /* Iterate the column-names */ for (Field f : dataObject.getDeclaredFields()) { - if (first) + if (first) { first = false; - else + } else { sb.append(", "); + } - if (usePlaceHolders) + if (usePlaceHolders) { sb.append("?"); - else + } else { sb.append("`" + f.getName() + "`"); + } } return sb.toString(); @@ -240,18 +244,21 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { boolean first = true; for (String col : cols) { // Add commas - if (first) + if (first) { first = false; - else + } else { sb.append(", "); + } // this is used if the string is going to be used to insert something so the value will replace the ? - if (usePlaceHolders) + if (usePlaceHolders) { sb.append("?"); - else + } else { sb.append(col); + } } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collection column string = " + sb.toString()); + } return sb.toString(); } @@ -269,8 +276,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { col += " " + en.getValue(); } columns.add(col); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collection columns = " + col); + } } return columns; @@ -288,11 +296,11 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // In this way, we can deduce what type needs to be written at runtime. Type[] genericParameterTypes = method.getGenericParameterTypes(); // There could be more than one argument, so step through them - for (int i = 0; i < genericParameterTypes.length; i++) { + for (Type genericParameterType : genericParameterTypes) { // If the argument is a parameter, then do something - this should always be true if the parameter is a collection - if (genericParameterTypes[i] instanceof ParameterizedType) { - // Get the actual type arguments of the parameter - Type[] parameters = ((ParameterizedType)genericParameterTypes[i]).getActualTypeArguments(); + if (genericParameterType instanceof ParameterizedType) { + // Get the actual type arguments of the parameter + Type[] parameters = ((ParameterizedType)genericParameterType).getActualTypeArguments(); //parameters[0] contains java.lang.String for method like "method(List value)" // Run through them one by one and create a SQL string int index = 0; @@ -300,8 +308,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // This is a request for column names. String setMapping = mySQLmapping.get(type.getTypeName()); columns.put("`" + type.getTypeName() + "_" + index + "`", setMapping != null ? setMapping : "VARCHAR(254)"); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collection column = " + "`" + type.getTypeName() + "_" + index + "`" + setMapping); + } } // Increment the index so each column has a unique name index++; @@ -381,8 +390,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { Connection connection = null; PreparedStatement preparedStatement = null; - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: saveObject "); + } try { // Try to connect to the database connection = databaseConnecter.createConnection(); @@ -400,37 +410,43 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { } // Create the insertion int i = 0; - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: insert Query " + insertQuery); + } // Run through the fields in the class using introspection for (Field field : dataObject.getDeclaredFields()) { // Get the field's property descriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject); // Get the read method for this field Method method = propertyDescriptor.getReadMethod(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Field = " + field.getName() + "(" + propertyDescriptor.getPropertyType().getTypeName() + ")"); + } //sql += "`" + field.getName() + "` " + mapping + ","; // Invoke the read method to obtain the value from the class - this is the value we need to store in the database Object value = method.invoke(instance); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: value = " + value); + } // Adapter // Check if there is an annotation on the field ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); // If there is a config annotation then do something - if (configEntry != null) { - if (DEBUG) + if (configEntry != null) { + if (DEBUG) { plugin.getLogger().info("DEBUG: there is a configEntry"); + } } Adapter adapterNotation = field.getAnnotation(Adapter.class); if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: there is an adapter"); - // A conversion adapter has been defined + } + // A conversion adapter has been defined value = ((AdapterInterface)adapterNotation.value().newInstance()).deserialize(value); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: value now after deserialization = " + value); + } } // Create set and map table inserts if this is a Collection if (propertyDescriptor.getPropertyType().equals(Set.class) || @@ -443,8 +459,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { try (PreparedStatement collStatement = connection.prepareStatement(clearTableSql)) { collStatement.setString(1, uniqueId); collStatement.execute(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString()); + } } // Insert into the table String setSql = "INSERT INTO `" + dataObject.getCanonicalName() + "." + field.getName() + "` (uniqueId, "; @@ -456,8 +473,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { try (PreparedStatement collStatement = connection.prepareStatement(setSql)) { // Set the uniqueId collStatement.setString(1, uniqueId); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collection insert =" + setSql); + } // Do single dimension types (set and list) if (propertyDescriptor.getPropertyType().equals(Set.class) || propertyDescriptor.getPropertyType().equals(ArrayList.class)) { @@ -474,8 +492,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { //} // Set the value from ? to whatever it is collStatement.setObject(2, setValue); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: " + collStatement.toString()); + } // Execute the SQL in the database collStatement.execute(); } @@ -486,22 +505,26 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { Iterator it = collection.entrySet().iterator(); while (it.hasNext()) { Entry en = (Entry) it.next(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: entry ket = " + en.getKey()); + } // Get the key and serialize it Object key = serialize(en.getKey(), en.getKey().getClass()); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: key class = " + en.getKey().getClass().getTypeName()); + } // Get the value and serialize it Object mapValue = serialize(en.getValue(), en.getValue().getClass()); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: mapValue = " + mapValue); + } // Write the objects into prepared statement collStatement.setObject(1, key); collStatement.setObject(2, mapValue); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: " + collStatement.toString()); + } // Write to database collStatement.execute(); } @@ -521,8 +544,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // Add the statements to a batch preparedStatement.addBatch(); // Execute - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: prepared statement = " + preparedStatement.toString()); + } preparedStatement.executeBatch(); } finally { @@ -600,8 +624,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { try { connection = databaseConnecter.createConnection(); statement = connection.createStatement(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: selectQuery = " + selectQuery); + } resultSet = statement.executeQuery(selectQuery); return createObjects(resultSet); @@ -623,15 +648,17 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { Connection connection = null; Statement statement = null; ResultSet resultSet = null; - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: loading object for " + uniqueId); + } try { connection = databaseConnecter.createConnection(); String query = "SELECT " + getColumns(false) + " FROM `" + dataObject.getCanonicalName() + "` WHERE uniqueId = ? LIMIT 1"; try (PreparedStatement preparedStatement = connection.prepareStatement(query)) { preparedStatement.setString(1, uniqueId); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: load Object query = " + preparedStatement.toString()); + } resultSet = preparedStatement.executeQuery(); List result = createObjects(resultSet); @@ -673,7 +700,7 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { IllegalAccessException, IntrospectionException, InvocationTargetException, ClassNotFoundException { - List list = new ArrayList(); + List list = new ArrayList<>(); // The database can return multiple results in one go, e.g., all the islands in the database // Run through them one by one while (resultSet.next()) { @@ -693,14 +720,16 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // Get the write method for this field, because we are going to use it to write the value // once we get the value from the database Method method = propertyDescriptor.getWriteMethod(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: propertyDescriptor.getPropertyType() = " + propertyDescriptor.getPropertyType()); - // If the type is a Collection, then we need to deal with set and map tables + } + // If the type is a Collection, then we need to deal with set and map tables if (Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType()) || Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { // Collection - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Collection or Map"); + } // TODO Get the values from the subsidiary tables. // value is just of type boolean right now String setSql = "SELECT "; @@ -713,21 +742,23 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { try (PreparedStatement collStatement = connection.prepareStatement(setSql)) { // Set the unique ID collStatement.setObject(1, uniqueId); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString()); + } try (ResultSet collectionResultSet = collStatement.executeQuery()) { //plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString()); // Do single dimension types (set and list) if (Set.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding a set"); - // Loop through the collection resultset + } + // Loop through the collection resultset // Note that we have no idea what type this is List collectionTypes = Util.getCollectionParameterTypes(method); // collectionTypes should be only 1 long Type setType = collectionTypes.get(0); - value = new HashSet(); + value = new HashSet<>(); if (DEBUG) { plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName()); @@ -736,14 +767,15 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { ((Set) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName()))); } } else if (List.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Adding a list "); - // Loop through the collection resultset + } + // Loop through the collection resultset // Note that we have no idea what type this is List collectionTypes = Util.getCollectionParameterTypes(method); // collectionTypes should be only 1 long Type setType = collectionTypes.get(0); - value = new ArrayList(); + value = new ArrayList<>(); //plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); while (collectionResultSet.next()) { //plugin.getLogger().info("DEBUG: adding to the list"); @@ -752,29 +784,34 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { } } else if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType()) || HashMap.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Adding a map "); - // Loop through the collection resultset + } + // Loop through the collection resultset // Note that we have no idea what type this is List collectionTypes = Util.getCollectionParameterTypes(method); // collectionTypes should be 2 long Type keyType = collectionTypes.get(0); Type valueType = collectionTypes.get(1); - value = new HashMap(); - if (DEBUG) + value = new HashMap<>(); + if (DEBUG) { plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); + } while (collectionResultSet.next()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: adding to the map"); + } //plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize()); // Work through the columns // Key Object key = deserialize(collectionResultSet.getObject(1),Class.forName(keyType.getTypeName())); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: key = " + key); + } Object mapValue = deserialize(collectionResultSet.getObject(2),Class.forName(valueType.getTypeName())); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: value = " + mapValue); + } ((Map) value).put(key,mapValue); } } else { @@ -785,27 +822,32 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { } } } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: regular type"); + } value = deserialize(value, propertyDescriptor.getPropertyType()); } // Adapter // Check if there is an annotation on the field ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); // If there is a config annotation then do something - if (configEntry != null) { - if (DEBUG) + if (configEntry != null) { + if (DEBUG) + { plugin.getLogger().info("DEBUG: there is a configEntry"); - // TODO: add config entry handling + // TODO: add config entry handling + } } Adapter adapterNotation = field.getAnnotation(Adapter.class); if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: there is an adapter"); - // A conversion adapter has been defined + } + // A conversion adapter has been defined value = ((AdapterInterface)adapterNotation.value().newInstance()).serialize(value); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: value now after deserialization = " + value); + } } if (DEBUG) { plugin.getLogger().info("DEBUG: invoking method " + method.getName()); @@ -833,10 +875,11 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { */ @SuppressWarnings({ "unchecked", "rawtypes" }) private Object deserialize(Object value, Class clazz) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName()); + } if (value instanceof String && value.equals("null")) { - // If the value is null as a string, return null + // If the value is null as a string, return null return null; } // Types that need to be deserialized @@ -894,8 +937,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { // Second is the unique ID preparedStatement.setString(1, uniqueId); preparedStatement.addBatch(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: DELETE Query " + preparedStatement.toString()); + } preparedStatement.executeBatch(); // Delete from any sub tables created from the object // Run through the fields in the class using introspection @@ -933,8 +977,9 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { */ @Override public boolean objectExits(String key) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: checking if " + key + " exists in the database"); + } Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; @@ -945,11 +990,13 @@ public class MySQLDatabaseHandler extends AbstractDatabaseHandler { preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, key); resultSet = preparedStatement.executeQuery(); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: object exists sql " + preparedStatement.toString()); + } if (resultSet.next()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: result is " + resultSet.getBoolean(1)); + } return resultSet.getBoolean(1); } } catch (SQLException e) { diff --git a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java index 68bd7d217..8be1706d6 100644 --- a/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java +++ b/src/main/java/us/tastybento/bskyblock/database/mysql/MySQLDatabaseResourceCloser.java @@ -17,8 +17,9 @@ public class MySQLDatabaseResourceCloser { */ public static void close(ResultSet... resultSets) { - if (resultSets == null) + if (resultSets == null) { return; + } for (ResultSet resultSet : resultSets) { if (resultSet != null) { @@ -43,8 +44,9 @@ public class MySQLDatabaseResourceCloser { * CallableStatement, because they extend Statement. */ - if (statements == null) + if (statements == null) { return; + } for (Statement statement : statements) { if (statement != null) { @@ -64,8 +66,9 @@ public class MySQLDatabaseResourceCloser { * Connections that should be closed */ public static void close(Connection... connections) { - if (connections == null) + if (connections == null) { return; + } for (Connection connection : connections) { if (connection != null) { diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java b/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java index 30903bd4e..3a25eba2a 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/DataObject.java @@ -8,11 +8,11 @@ import us.tastybento.bskyblock.BSkyBlock; * */ public interface DataObject { - + default BSkyBlock getPlugin() { return BSkyBlock.getInstance(); } - + /** * @return the uniqueId */ @@ -22,5 +22,5 @@ public interface DataObject { * @param uniqueId the uniqueId to set */ void setUniqueId(String uniqueId); - + } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java index 6cc474298..7baff9195 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java @@ -39,7 +39,7 @@ public class Island implements DataObject { private String uniqueId = ""; - //// Island //// + //// Island //// // The center of the island itself private Location center; @@ -77,13 +77,13 @@ public class Island implements DataObject { //// State //// private boolean locked = false; private boolean spawn = false; - + private boolean purgeProtected = false; - + //// Protection flags //// @Adapter(FlagSerializer.class) private HashMap flags = new HashMap<>(); - + private int levelHandicap; private Location spawnPoint; @@ -91,16 +91,16 @@ public class Island implements DataObject { public Island(Location location, UUID owner, int protectionRange) { setOwner(owner); - this.createdDate = System.currentTimeMillis(); - this.updatedDate = System.currentTimeMillis(); - this.world = location.getWorld(); - this.center = location; - this.range = BSkyBlock.getInstance().getSettings().getIslandDistance(); - this.minX = center.getBlockX() - range; - this.minZ = center.getBlockZ() - range; + createdDate = System.currentTimeMillis(); + updatedDate = System.currentTimeMillis(); + world = location.getWorld(); + center = location; + range = BSkyBlock.getInstance().getSettings().getIslandDistance(); + minX = center.getBlockX() - range; + minZ = center.getBlockZ() - range; this.protectionRange = protectionRange; - this.minProtectedX = center.getBlockX() - protectionRange; - this.minProtectedZ = center.getBlockZ() - protectionRange; + minProtectedX = center.getBlockX() - protectionRange; + minProtectedZ = center.getBlockZ() - protectionRange; } /** @@ -108,10 +108,11 @@ public class Island implements DataObject { * @param playerUUID */ public void addMember(UUID playerUUID) { - if (playerUUID != null) + if (playerUUID != null) { members.put(playerUUID, RanksManager.MEMBER_RANK); + } } - + /** * Adds target to a list of banned players for this island. May be blocked by the event being cancelled. * If the player is a member, coop or trustee, they will be removed from those lists. @@ -120,8 +121,9 @@ public class Island implements DataObject { */ public boolean addToBanList(UUID targetUUID) { // TODO fire ban event - if (targetUUID != null) + if (targetUUID != null) { members.put(targetUUID, RanksManager.BANNED_RANK); + } return true; } @@ -350,6 +352,7 @@ public class Island implements DataObject { return result; } + @Override public String getUniqueId() { // Island's have UUID's that are randomly assigned if they do not exist if (uniqueId.isEmpty()) { @@ -418,7 +421,7 @@ public class Island implements DataObject { * @return true if allowed, false if not */ public boolean isAllowed(Flag flag) { - return this.getFlag(flag) >= 0; + return getFlag(flag) >= 0; } /** @@ -429,7 +432,7 @@ public class Island implements DataObject { */ public boolean isAllowed(User user, Flag flag) { //Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag)); - return this.getRank(user) >= this.getFlag(flag); + return getRank(user) >= getFlag(flag); } /** @@ -547,7 +550,7 @@ public class Island implements DataObject { } } else { // Unlock the island - IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build(); + IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build(); if(!event.isCancelled()){ this.locked = locked; } @@ -603,14 +606,16 @@ public class Island implements DataObject { */ public void setOwner(UUID owner){ this.owner = owner; - if (owner == null) return; + if (owner == null) { + return; + } // Defensive code: demote any previous owner for (Entry en : members.entrySet()) { if (en.getValue().equals(RanksManager.OWNER_RANK)) { en.setValue(RanksManager.MEMBER_RANK); } } - this.members.put(owner, RanksManager.OWNER_RANK); + members.put(owner, RanksManager.OWNER_RANK); } /** @@ -640,23 +645,25 @@ public class Island implements DataObject { * @param rank */ public void setRank(User user, int rank) { - if (user.getUniqueId() != null) members.put(user.getUniqueId(), rank); + if (user.getUniqueId() != null) { + members.put(user.getUniqueId(), rank); + } } /** * @param ranks the ranks to set */ public void setRanks(HashMap ranks) { - this.members = ranks; + members = ranks; } /** * @param isSpawn - if the island is the spawn */ public void setSpawn(boolean isSpawn){ - this.spawn = isSpawn; + spawn = isSpawn; } - + /** * Resets the flags to their default as set in config.yml for the spawn */ @@ -671,6 +678,7 @@ public class Island implements DataObject { } + @Override public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java index 119cf2462..e69fa6579 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java @@ -31,21 +31,22 @@ public class Players implements DataObject { public Players() {} /** - * @param plugin + * @param plugin * @param uniqueId * Constructor - initializes the state variables * */ public Players(BSkyBlock plugin, final UUID uniqueId) { this.uniqueId = uniqueId.toString(); - this.homeLocations = new HashMap<>(); - this.playerName = ""; - this.resetsLeft = plugin.getSettings().getResetLimit(); - this.locale = ""; - this.kickedList = new HashMap<>(); - this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName(); - if (this.playerName == null) - this.playerName = uniqueId.toString(); + homeLocations = new HashMap<>(); + playerName = ""; + resetsLeft = plugin.getSettings().getResetLimit(); + locale = ""; + kickedList = new HashMap<>(); + playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName(); + if (playerName == null) { + playerName = uniqueId.toString(); + } } /** @@ -64,7 +65,7 @@ public class Players implements DataObject { public Location getHomeLocation(int number) { /* Bukkit.getLogger().info("DEBUG: getting home location " + number); - + Bukkit.getLogger().info("DEBUG: " + homeLocations.toString()); for (Entry en : homeLocations.entrySet()) { Bukkit.getLogger().info("DEBUG: " + en.getKey() + " ==> " + en.getValue()); @@ -148,7 +149,7 @@ public class Players implements DataObject { } /** - * Stores the numbered home location of the player. Numbering starts at 1. + * Stores the numbered home location of the player. Numbering starts at 1. * @param location * @param number */ @@ -165,7 +166,7 @@ public class Players implements DataObject { * @param uuid */ public void setPlayerUUID(final UUID uuid) { - this.uniqueId = uuid.toString(); + uniqueId = uuid.toString(); } /** @@ -210,9 +211,9 @@ public class Players implements DataObject { * Add death */ public void addDeath() { - this.deaths++; - if (this.deaths > getPlugin().getSettings().getDeathsMax()) { - this.deaths = getPlugin().getSettings().getDeathsMax(); + deaths++; + if (deaths > getPlugin().getSettings().getDeathsMax()) { + deaths = getPlugin().getSettings().getDeathsMax(); } } diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/Adapter.java b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/Adapter.java index da5ec607d..666ca5bb4 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/Adapter.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/Adapter.java @@ -15,5 +15,5 @@ import java.lang.annotation.Target; public @interface Adapter { Class value(); - + } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/AdapterInterface.java b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/AdapterInterface.java index ac1187081..021503675 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/AdapterInterface.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/AdapterInterface.java @@ -16,9 +16,9 @@ public interface AdapterInterface { * @return serialized object */ S serialize(Object object); - - /** - * Deserialize object + + /** + * Deserialize object * @param object * @return deserialized object */ diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/FlagSerializer.java b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/FlagSerializer.java index e4ddb3d48..81334490e 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/FlagSerializer.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/FlagSerializer.java @@ -10,7 +10,7 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.flags.Flag; /** - * Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and + * Serializes the {@link us.tastybento.bskyblock.database.objects.Island#getFlags() getFlags()} and * {@link us.tastybento.bskyblock.database.objects.Island#setFlags() setFlags()} * in {@link us.tastybento.bskyblock.database.objects.Island} * @author tastybento @@ -21,8 +21,9 @@ public class FlagSerializer implements AdapterInterface, @Override public HashMap serialize(Object object) { HashMap result = new HashMap<>(); - if (object == null) + if (object == null) { return result; + } // For YAML if (object instanceof MemorySection) { MemorySection section = (MemorySection) object; @@ -42,8 +43,9 @@ public class FlagSerializer implements AdapterInterface, @Override public HashMap deserialize(Object object) { HashMap result = new HashMap<>(); - if (object == null) + if (object == null) { return result; + } HashMap flags = (HashMap)object; for (Entry en: flags.entrySet()) { result.put(en.getKey().getID(), en.getValue()); diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/PotionEffectListAdapter.java b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/PotionEffectListAdapter.java index c1a2d3f3a..225c9439b 100644 --- a/src/main/java/us/tastybento/bskyblock/database/objects/adapters/PotionEffectListAdapter.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/adapters/PotionEffectListAdapter.java @@ -22,13 +22,13 @@ public class PotionEffectListAdapter implements AdapterInterface deserialize(Object to) { - List result = new ArrayList<>(); - if (to instanceof ArrayList) { - for (PotionEffectType type: (ArrayList)to) { - result.add(type.getName()); - } - } - return result; + List result = new ArrayList<>(); + if (to instanceof ArrayList) { + for (PotionEffectType type: (ArrayList)to) { + result.add(type.getName()); + } + } + return result; } } diff --git a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java index 7369d523c..092f82dd9 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/ChunkGeneratorWorld.java @@ -22,7 +22,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator { BSkyBlock plugin; Random rand = new Random(); PerlinOctaveGenerator gen; - + /** * @param plugin */ diff --git a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java index 307c5936e..580196ac0 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java +++ b/src/main/java/us/tastybento/bskyblock/generators/IslandWorld.java @@ -14,7 +14,7 @@ public class IslandWorld { private static final String NETHER = "_nether"; private static final String THE_END = "_the_end"; private static final String CREATING = "Creating "; - + private BSkyBlock plugin; private static World islandWorld; private static World netherWorld; @@ -91,7 +91,7 @@ public class IslandWorld { } } - + } /** diff --git a/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java b/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java index 3841795e3..2d0006895 100644 --- a/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java +++ b/src/main/java/us/tastybento/bskyblock/generators/NetherPopulator.java @@ -32,17 +32,17 @@ public class NetherPopulator extends BlockPopulator { if (b.getType().equals(Material.MOB_SPAWNER)) { CreatureSpawner cs = (CreatureSpawner) b.getState(); switch (random.nextInt(3)) { - case 0: - cs.setSpawnedType(EntityType.BLAZE); - break; - case 1: - cs.setSpawnedType(EntityType.SKELETON); - break; - case 2: - cs.setSpawnedType(EntityType.MAGMA_CUBE); - break; - default: - cs.setSpawnedType(EntityType.BLAZE); + case 0: + cs.setSpawnedType(EntityType.BLAZE); + break; + case 1: + cs.setSpawnedType(EntityType.SKELETON); + break; + case 2: + cs.setSpawnedType(EntityType.MAGMA_CUBE); + break; + default: + cs.setSpawnedType(EntityType.BLAZE); } } else if (b.getType().equals(Material.OBSIDIAN)) { b.setType(Material.CHEST); diff --git a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java index a52ccf090..16f0193a9 100644 --- a/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java +++ b/src/main/java/us/tastybento/bskyblock/island/builders/IslandBuilder.java @@ -50,7 +50,7 @@ public class IslandBuilder { public IslandBuilder(BSkyBlock plugin, Island island) { this.plugin = plugin; this.island = island; - this.world = island.getWorld(); + world = island.getWorld(); } @@ -61,16 +61,16 @@ public class IslandBuilder { this.type = type; switch(type) { case END: - this.world = plugin.getIslandWorldManager().getEndWorld(); + world = plugin.getIslandWorldManager().getEndWorld(); break; case ISLAND: - this.world = plugin.getIslandWorldManager().getIslandWorld(); + world = plugin.getIslandWorldManager().getIslandWorld(); break; case NETHER: - this.world = plugin.getIslandWorldManager().getNetherWorld(); + world = plugin.getIslandWorldManager().getNetherWorld(); break; default: - this.world = island.getWorld(); + world = island.getWorld(); break; } @@ -82,8 +82,8 @@ public class IslandBuilder { * @param player the player to set */ public IslandBuilder setPlayer(Player player) { - this.playerUUID = player.getUniqueId(); - this.playerName = player.getName(); + playerUUID = player.getUniqueId(); + playerName = player.getName(); return this; } @@ -92,7 +92,7 @@ public class IslandBuilder { * @param list the default chestItems to set */ public IslandBuilder setChestItems(List list) { - this.chestItems = list; + chestItems = list; return this; } @@ -109,7 +109,7 @@ public class IslandBuilder { generateNetherBlocks(); } else if (type == IslandType.END){ generateEndBlocks(); - } + } // Do other stuff } @@ -477,12 +477,12 @@ public class IslandBuilder { private void placeSign(int x, int y, int z) { Block blockToChange = world.getBlockAt(x, y, z); blockToChange.setType(Material.SIGN_POST); - if (this.playerUUID != null) { + if (playerUUID != null) { Sign sign = (Sign) blockToChange.getState(); User user = User.getInstance(playerUUID); for (int i = 0; i < 4; i++) { sign.setLine(i, user.getTranslation("new-island.sign.line" + i, "[player]", playerName)); - } + } ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH); sign.update(); } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java index 0d83aab2a..66f88d7bf 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java @@ -25,7 +25,7 @@ public class JoinLeaveListener implements Listener { */ public JoinLeaveListener(BSkyBlock plugin) { this.plugin = plugin; - this.players = plugin.getPlayers(); + players = plugin.getPlayers(); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -39,48 +39,56 @@ public class JoinLeaveListener implements Listener { } UUID playerUUID = user.getUniqueId(); if (plugin.getPlayers().isKnown(playerUUID)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: known player"); + } // Load player players.addPlayer(playerUUID); // Reset resets if the admin changes it to or from unlimited if (plugin.getSettings().getResetLimit() < players.getResetsLeft(playerUUID) || (plugin.getSettings().getResetLimit() >= 0 && players.getResetsLeft(playerUUID) < 0)) { players.setResetsLeft(playerUUID, plugin.getSettings().getResetLimit()); } - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Setting player's name"); + } // Set the player's name (it may have changed), but only if it isn't empty if (!user.getName().isEmpty()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Player name is " + user.getName()); + } players.setPlayerName(user); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Saving player"); + } players.save(playerUUID); } else { plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString()); } if (plugin.getSettings().isRemoveMobsOnLogin()) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Removing mobs"); + } plugin.getIslands().removeMobs(user.getLocation()); } // Check if they logged in to a locked island and expel them or if they are banned Island currentIsland = plugin.getIslands().getIslandAt(user.getLocation()).orElse(null); if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: Current island is locked, or player is banned"); + } if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: No bypass - teleporting"); + } user.sendMessage("locked.islandlocked"); plugin.getIslands().homeTeleport(user.getPlayer()); } } } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: not a known player"); + } } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java index 1cd1ad51d..752d9128f 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java @@ -55,12 +55,16 @@ public class PanelListenerManager implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onInventoryClose(InventoryCloseEvent event) { - if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) getOpenPanels().remove(event.getPlayer().getUniqueId()); + if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) { + getOpenPanels().remove(event.getPlayer().getUniqueId()); + } } @EventHandler(priority = EventPriority.NORMAL) public void onLogOut(PlayerQuitEvent event) { - if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) getOpenPanels().remove(event.getPlayer().getUniqueId()); + if (getOpenPanels().containsKey(event.getPlayer().getUniqueId())) { + getOpenPanels().remove(event.getPlayer().getUniqueId()); + } } /** @@ -69,5 +73,5 @@ public class PanelListenerManager implements Listener { public static HashMap getOpenPanels() { return openPanels; } - + } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java index cde565123..66d08400c 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/AbstractFlagListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -30,7 +30,7 @@ public abstract class AbstractFlagListener implements Listener { private BSkyBlock plugin = BSkyBlock.getInstance(); private User user = null; - + /** * @return the plugin */ @@ -45,7 +45,7 @@ public abstract class AbstractFlagListener implements Listener { public void setPlugin(BSkyBlock plugin) { this.plugin = plugin; } - + /** * Sets the player associated with this event. * If the user is a fake player, they are not counted. @@ -60,7 +60,7 @@ public abstract class AbstractFlagListener implements Listener { setUser(User.getInstance((Player)getPlayer.invoke(e))); return true; } - } catch (Exception e1) { // Do nothing + } catch (Exception e1) { // Do nothing } return false; } @@ -70,7 +70,9 @@ public abstract class AbstractFlagListener implements Listener { * @param user */ public AbstractFlagListener setUser(User user) { - if (!plugin.getSettings().getFakePlayers().contains(user.getName())) this.user = user; + if (!plugin.getSettings().getFakePlayers().contains(user.getName())) { + this.user = user; + } return this; } @@ -92,11 +94,13 @@ public abstract class AbstractFlagListener implements Listener { * @param silent - if true, message is not sent */ public void noGo(Event e, boolean silent) { - if (e instanceof Cancellable) + if (e instanceof Cancellable) { ((Cancellable)e).setCancelled(true); + } if (user != null) { - if (!silent) + if (!silent) { user.sendMessage("protection.protected"); + } user.updateInventory(); } } @@ -137,7 +141,7 @@ public abstract class AbstractFlagListener implements Listener { * @param breakBlocks * @return true if the check is okay, false if it was disallowed */ - public boolean checkIsland(Event e, Location loc, Flag breakBlocks) { + public boolean checkIsland(Event e, Location loc, Flag breakBlocks) { return checkIsland(e, loc, breakBlocks, false); } @@ -152,7 +156,9 @@ public abstract class AbstractFlagListener implements Listener { */ public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) { // If this is not an Island World, skip - if (!inWorld(loc)) return true; + if (!inWorld(loc)) { + return true; + } // Get the island and if present Optional island = getIslands().getIslandAt(loc); @@ -161,10 +167,10 @@ public abstract class AbstractFlagListener implements Listener { if (flag.getType().equals(FlagType.SETTING)) { // If the island exists, return the setting, otherwise return the default setting for this flag return island.map(x -> x.isAllowed(flag)).orElse(flag.isDefaultSetting()); - } - + } + // Protection flag - + // If the user is not set already, try to get it from the event if (user == null) { // Set the user associated with this event diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/BlockInteractionListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/BlockInteractionListener.java index 13e508080..76a3f2425 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/BlockInteractionListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/BlockInteractionListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -65,7 +65,7 @@ public class BlockInteractionListener extends AbstractFlagListener { checkIsland(e, e.getClickedBlock().getLocation(), Flags.CHEST); break; - + case ACACIA_DOOR: case BIRCH_DOOR: case DARK_OAK_DOOR: @@ -87,7 +87,7 @@ public class BlockInteractionListener extends AbstractFlagListener { case SPRUCE_FENCE_GATE: checkIsland(e, e.getClickedBlock().getLocation(), Flags.GATE); break; - + case BURNING_FURNACE: case FURNACE: checkIsland(e, e.getClickedBlock().getLocation(), Flags.FURNACE); @@ -121,7 +121,7 @@ public class BlockInteractionListener extends AbstractFlagListener { default: break; } - // Now check for in-hand items + // Now check for in-hand items if (e.getItem() != null) { switch (e.getItem().getType()) { case ENDER_PEARL: @@ -132,7 +132,7 @@ public class BlockInteractionListener extends AbstractFlagListener { break; default: break; - + } } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/BreakBlocksListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/BreakBlocksListener.java index a4fc3d858..6067c5519 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/BreakBlocksListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/BreakBlocksListener.java @@ -52,7 +52,9 @@ public class BreakBlocksListener extends AbstractFlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerInteract(final PlayerInteractEvent e) { // Only handle hitting things - if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK)) return; + if (!e.getAction().equals(Action.LEFT_CLICK_BLOCK)) { + return; + } // Look along player's sight line to see if any blocks are skulls try { @@ -94,7 +96,7 @@ public class BreakBlocksListener extends AbstractFlagListener { if (inWorld(e.getVehicle()) && e.getAttacker() instanceof Player) { User user = User.getInstance((Player) e.getAttacker()); // Get the island and if present, check the flag, react if required and return - getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> { + getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> { if (!x.isAllowed(user, Flags.BREAK_BLOCKS)) { e.setCancelled(true); user.sendMessage("protection.protected"); @@ -117,7 +119,9 @@ public class BreakBlocksListener extends AbstractFlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityDamage(EntityDamageByEntityEvent e) { // Only handle item frames and armor stands - if (!(e.getEntity() instanceof ItemFrame) && !(e.getEntity() instanceof ArmorStand)) return; + if (!(e.getEntity() instanceof ItemFrame) && !(e.getEntity() instanceof ArmorStand)) { + return; + } // Get the attacker if (e.getDamager() instanceof Player) { diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/BreedingListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/BreedingListener.java index c26b4d997..64f63503e 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/BreedingListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/BreedingListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/BucketListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/BucketListener.java index a6accff38..73c36bb7e 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/BucketListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/BucketListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -41,13 +41,19 @@ public class BucketListener extends AbstractFlagListener { public void onBucketFill(final PlayerBucketFillEvent e) { // Check filling of various liquids if (e.getItemStack().getType().equals(Material.LAVA_BUCKET)) { - if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA)) return; + if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA)) { + return; + } } if (e.getItemStack().getType().equals(Material.WATER_BUCKET)) { - if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER)) return; + if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER)) { + return; + } } if (e.getItemStack().getType().equals(Material.MILK_BUCKET)) { - if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING)) return; + if (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING)) { + return; + } } // Check general bucket use checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/EggListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/EggListener.java index ceb297d27..cd43e0a16 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/EggListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/EggListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/EntityInteractListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/EntityInteractListener.java index 382958aab..6f19b601d 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/EntityInteractListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/EntityInteractListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -21,14 +21,14 @@ import us.tastybento.bskyblock.lists.Flags; * */ public class EntityInteractListener extends AbstractFlagListener { - + @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onPlayerInteract(final PlayerInteractAtEntityEvent e) { if (e.getRightClicked() instanceof ArmorStand) { checkIsland(e, e.getRightClicked().getLocation(), Flags.ARMOR_STAND); } } - + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerHitEntity(PlayerInteractEntityEvent e) { // Animal riding diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java index 8be3c7d02..b521dbb92 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -42,10 +42,14 @@ public class FireListener extends AbstractFlagListener { // Check if the island exists and if fire is allowed Optional island = getIslands().getIslandAt(e.getBlock().getLocation()); island.ifPresent(x -> { - if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true); + if (!x.isAllowed(Flags.FIRE_SPREAD)) { + e.setCancelled(true); + } }); // If not on an island, check the default setting - if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true); + if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) { + e.setCancelled(true); + } } /** @@ -61,10 +65,14 @@ public class FireListener extends AbstractFlagListener { // Check if the island exists and if fire is allowed Optional island = getIslands().getIslandAt(e.getBlock().getLocation()); island.ifPresent(x -> { - if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true); + if (!x.isAllowed(Flags.FIRE_SPREAD)) { + e.setCancelled(true); + } }); // If not on an island, check the default setting - if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true); + if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) { + e.setCancelled(true); + } } } @@ -84,10 +92,14 @@ public class FireListener extends AbstractFlagListener { // Check if the island exists and if fire is allowed Optional island = getIslands().getIslandAt(e.getBlock().getLocation()); island.ifPresent(x -> { - if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true); + if (!x.isAllowed(Flags.FIRE)) { + e.setCancelled(true); + } }); // If not on an island, check the default setting - if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true); + if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) { + e.setCancelled(true); + } } @@ -137,13 +149,19 @@ public class FireListener extends AbstractFlagListener { // Check if the island exists and if fire is allowed Optional island = getIslands().getIslandAt(e.getBlock().getLocation()); island.ifPresent(x -> { - if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true); + if (!x.isAllowed(Flags.FIRE)) { + e.setCancelled(true); + } }); // If not on an island, check the default setting - if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true); + if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) { + e.setCancelled(true); + } // If either of these canceled the event, return - if (e.isCancelled()) return; + if (e.isCancelled()) { + return; + } // Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow if (e.getEntity() instanceof Projectile) { diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/HurtingListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/HurtingListener.java index 44d8590b7..75d0f5cd7 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/HurtingListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/HurtingListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -89,8 +89,9 @@ public class HurtingListener extends AbstractFlagListener { */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onFishing(PlayerFishEvent e) { - if (e.getCaught() == null) + if (e.getCaught() == null) { return; + } if ((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman || e.getCaught() instanceof Villager) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) { @@ -98,7 +99,7 @@ public class HurtingListener extends AbstractFlagListener { return; } - if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) + if ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS)) { e.getHook().remove(); return; @@ -126,7 +127,7 @@ public class HurtingListener extends AbstractFlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onSplashPotionSplash(final PotionSplashEvent e) { // Try to get the shooter - Projectile projectile = (Projectile) e.getEntity(); + Projectile projectile = e.getEntity(); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); // Run through all the affected entities @@ -164,7 +165,7 @@ public class HurtingListener extends AbstractFlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) { // Try to get the shooter - Projectile projectile = (Projectile) e.getEntity(); + Projectile projectile = e.getEntity(); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { UUID uuid = ((Player)projectile.getShooter()).getUniqueId(); // Store it and remove it when the effect is gone diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/InventoryListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/InventoryListener.java index 3c1ee775f..c8da8eef5 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/InventoryListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/InventoryListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -34,11 +34,11 @@ public class InventoryListener extends AbstractFlagListener { public void onMountInventoryClick(InventoryClickEvent e) { if (e.getInventory().getHolder() == null) { return; - } + } if (e.getInventory().getHolder() instanceof Animals) { checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY); } - else if (e.getInventory().getHolder() instanceof Chest + else if (e.getInventory().getHolder() instanceof Chest || e.getInventory().getHolder() instanceof Dispenser || e.getInventory().getHolder() instanceof Hopper || e.getInventory().getHolder() instanceof Dropper diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/ItemDropPickUpListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/ItemDropPickUpListener.java index e0f8bc848..a2b01d73d 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/ItemDropPickUpListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/ItemDropPickUpListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/LeashListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/LeashListener.java index 0899842b1..ba8fb7a1a 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/LeashListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/LeashListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java index 3fab1f489..680160455 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -43,7 +43,7 @@ public class MobSpawnListener extends AbstractFlagListener { || e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) { Optional island = getIslands().getIslandAt(e.getLocation()); if (island.isPresent()) { - if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { + if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!island.get().isAllowed(Flags.MOB_SPAWN)) { // Mobs not allowed to spawn e.setCancelled(true); @@ -58,7 +58,7 @@ public class MobSpawnListener extends AbstractFlagListener { } } else { // Outside of the island - if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { + if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!Flags.MOB_SPAWN.isDefaultSetting()) { // Mobs not allowed to spawn e.setCancelled(true); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java index 2d5a61761..c62bcde0f 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -45,8 +45,11 @@ public class PVPListener extends AbstractFlagListener { public void onEntityDamage(final EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Player) { Flag flag = Flags.PVP_OVERWORLD; - if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER; - else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END; + if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { + flag = Flags.PVP_NETHER; + } else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { + flag = Flags.PVP_END; + } respond(e, e.getDamager(), flag); } } @@ -73,8 +76,11 @@ public class PVPListener extends AbstractFlagListener { public void onFishing(PlayerFishEvent e) { if (e.getCaught() != null && e.getCaught() instanceof Player) { Flag flag = Flags.PVP_OVERWORLD; - if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER; - else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END; + if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { + flag = Flags.PVP_NETHER; + } else if (e.getCaught().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { + flag = Flags.PVP_END; + } if (checkIsland(e, e.getCaught().getLocation(), flag)) { e.getHook().remove(); return; @@ -90,11 +96,14 @@ public class PVPListener extends AbstractFlagListener { public void onSplashPotionSplash(final PotionSplashEvent e) { // Deduce the world Flag flag = Flags.PVP_OVERWORLD; - if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER; - else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END; + if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { + flag = Flags.PVP_NETHER; + } else if (e.getPotion().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { + flag = Flags.PVP_END; + } // Try to get the thrower - Projectile projectile = (Projectile) e.getEntity(); + Projectile projectile = e.getEntity(); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); // Run through all the affected entities @@ -118,7 +127,7 @@ public class PVPListener extends AbstractFlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) { // Try to get the shooter - Projectile projectile = (Projectile) e.getEntity(); + Projectile projectile = e.getEntity(); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { UUID uuid = ((Player)projectile.getShooter()).getUniqueId(); // Store it and remove it when the effect is gone @@ -133,13 +142,16 @@ public class PVPListener extends AbstractFlagListener { public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) { if (e.getEntity() == null || e.getEntity().getUniqueId() == null) { return; - } + } if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) { // Deduce the world Flag flag = Flags.PVP_OVERWORLD; - if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER; - else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END; + if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getNetherWorld())) { + flag = Flags.PVP_NETHER; + } else if (e.getEntity().getWorld().equals(getPlugin().getIslandWorldManager().getEndWorld())) { + flag = Flags.PVP_END; + } UUID attacker = thrownPotions.get(e.getDamager().getEntityId()); // Self damage diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/PhysicalInteractionListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/PhysicalInteractionListener.java index 77a594f74..3b019b2d6 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/PhysicalInteractionListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/PhysicalInteractionListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/PlaceBlocksListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/PlaceBlocksListener.java index 83c4d0413..6a5f5c5f4 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/PlaceBlocksListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/PlaceBlocksListener.java @@ -59,7 +59,7 @@ public class PlaceBlocksListener extends AbstractFlagListener { } return; default: - // Check in-hand items + // Check in-hand items if (e.getMaterial() != null) { // This check protects against an exploit in 1.7.9 against cactus // and sugar cane and placing boats on non-liquids @@ -71,7 +71,7 @@ public class PlaceBlocksListener extends AbstractFlagListener { } } } - + /** * Handles Frost Walking on visitor's islands. This creates ice blocks, which is like placing blocks * @param e @@ -80,7 +80,7 @@ public class PlaceBlocksListener extends AbstractFlagListener { public void onBlockForm(EntityBlockFormEvent e) { if (e.getNewState().getType().equals(Material.FROSTED_ICE)) { // Silently check - checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS, true); + checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS, true); } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/PortalListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/PortalListener.java index e32d870c6..fc649a1b5 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/PortalListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/PortalListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/ShearingListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/ShearingListener.java index 2b404a5cc..c2330ce78 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/ShearingListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/ShearingListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/TeleportationListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/TeleportationListener.java index f9c30e145..21f44f864 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/TeleportationListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/TeleportationListener.java @@ -1,5 +1,5 @@ /** - * + * */ package us.tastybento.bskyblock.listeners.flags; @@ -19,7 +19,7 @@ public class TeleportationListener extends AbstractFlagListener { /** * Ender pearl and chorus fruit teleport checks - * + * * @param e */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java index 883e633eb..2e8adb571 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java @@ -38,7 +38,7 @@ public class FlyingMobEvents implements Listener { */ public FlyingMobEvents(BSkyBlock plugin) { this.plugin = plugin; - this.mobSpawnInfo = new WeakHashMap<>(); + mobSpawnInfo = new WeakHashMap<>(); plugin.getServer().getScheduler().runTaskTimer(plugin, () -> { //Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size()); diff --git a/src/main/java/us/tastybento/bskyblock/lists/Flags.java b/src/main/java/us/tastybento/bskyblock/lists/Flags.java index dc910c2a0..acc2fbbe2 100644 --- a/src/main/java/us/tastybento/bskyblock/lists/Flags.java +++ b/src/main/java/us/tastybento/bskyblock/lists/Flags.java @@ -29,7 +29,7 @@ import us.tastybento.bskyblock.listeners.flags.ShearingListener; import us.tastybento.bskyblock.listeners.flags.TeleportationListener; public class Flags { - + public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build(); public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build(); @@ -61,7 +61,7 @@ public class Flags { public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build(); public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build(); public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build(); - public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build(); + public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build(); // Chorus Fruit and Enderpearls public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build(); @@ -79,7 +79,7 @@ public class Flags { * I'll take you to burn. * Fire * I'll take you to learn. - * You gonna burn, burn, burn + * You gonna burn, burn, burn * Fire * I'll take you to burn * - The Crazy World of Arthur Brown @@ -127,7 +127,7 @@ public class Flags { return Arrays.asList(Flags.class.getFields()).stream().map(field -> { try { return (Flag)field.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage()); } return null; diff --git a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java index 46ea6ce92..352b31096 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java @@ -34,13 +34,13 @@ public final class AddonsManager { private static final String LOCALE_FOLDER = "locales"; private List addons; private List loader; - private final Map> classes = new HashMap>(); + private final Map> classes = new HashMap<>(); private BSkyBlock plugin; public AddonsManager(BSkyBlock plugin) { this.plugin = plugin; - this.addons = new ArrayList<>(); - this.loader = new ArrayList<>(); + addons = new ArrayList<>(); + loader = new ArrayList<>(); } /** @@ -53,7 +53,7 @@ public final class AddonsManager { for (File file : f.listFiles()) { if (!file.isDirectory()) { try { - this.loadAddon(file); + loadAddon(file); } catch (InvalidAddonFormatException | InvalidAddonInheritException | InvalidDescriptionException e) { plugin.getLogger().severe("Could not load addon " + file.getName() + " : " + e.getMessage()); } @@ -68,7 +68,7 @@ public final class AddonsManager { } } - this.addons.forEach(addon -> { + addons.forEach(addon -> { addon.onEnable(); Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build()); addon.setEnabled(true); @@ -83,10 +83,14 @@ public final class AddonsManager { * @return */ public Optional getAddonByName(String name){ - if(name.equals("")) return Optional.empty(); + if(name.equals("")) { + return Optional.empty(); + } - for(Addon addon : this.addons){ - if(addon.getDescription().getName().contains(name)) return Optional.of(addon); + for(Addon addon : addons){ + if(addon.getDescription().getName().contains(name)) { + return Optional.of(addon); + } } return Optional.empty(); } @@ -109,7 +113,7 @@ public final class AddonsManager { // Open a reader to the jar BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry))); // Grab the description in the addon.yml file - Map data = this.data(reader); + Map data = data(reader); // Load the addon AddonClassLoader loader = new AddonClassLoader(this, data, f, this.getClass().getClassLoader()); @@ -133,7 +137,7 @@ public final class AddonsManager { Bukkit.getPluginManager().callEvent(AddonEvent.builder().addon(addon).reason(AddonEvent.Reason.LOAD).build()); // Add it to the list of addons - this.addons.add(addon); + addons.add(addon); // Run the onLoad() method addon.onLoad(); @@ -153,8 +157,9 @@ public final class AddonsManager { private Map data(BufferedReader reader) { Map map = new HashMap<>(); reader.lines().forEach(string -> { - if (DEBUG) + if (DEBUG) { Bukkit.getLogger().info("DEBUG: " + string); + } String[] data = string.split("\\: "); if (data.length > 1) { map.put(data[0], data[1].substring(0, data[1].length())); @@ -223,7 +228,7 @@ public final class AddonsManager { /** * Sets a class that this loader should know about * Code copied from Bukkit JavaPluginLoader - * + * * @param name * @param clazz */ diff --git a/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java b/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java index 546264e11..4c5e45fa8 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/CommandsManager.java @@ -13,9 +13,10 @@ public final class CommandsManager { private HashMap commands = new HashMap<>(); public void registerCommand(Command command) { - if (DEBUG) + if (DEBUG) { Bukkit.getLogger().info("DEBUG: registering command - " + command.getLabel()); - commands.put(command.getLabel(), command); + } + commands.put(command.getLabel(), command); // Use reflection to obtain the commandMap method in Bukkit's server. It used to be visible, but isn't anymore. try{ Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap"); @@ -25,7 +26,7 @@ public final class CommandsManager { } catch(Exception exception){ Bukkit.getLogger().severe("Bukkit server commandMap method is not there! This means no commands can be registered!"); - } + } } public Command getCommand(String command) { diff --git a/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java b/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java index 71984d2e9..972b27df8 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java @@ -66,7 +66,9 @@ public class FlagsManager { public Flag getFlagByIcon(PanelItem item) { for (Flag flag : flags.values()) { - if (flag.getIcon().equals(item)) return flag; + if (flag.getIcon().equals(item)) { + return flag; + } } return null; } diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 9d14ece75..65788007b 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -24,7 +24,7 @@ public final class LocalesManager { public LocalesManager(BSkyBlock plugin) { this.plugin = plugin; - this.loadLocales("BSkyBlock"); // Default + loadLocales("BSkyBlock"); // Default } /** @@ -35,8 +35,9 @@ public final class LocalesManager { */ public String get(User user, String reference) { BSBLocale locale = languages.get(user.getLocale()); - if (locale != null && locale.contains(reference)) + if (locale != null && locale.contains(reference)) { return locale.get(reference); + } // Return the default if (languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).contains(reference)) { return languages.get(Locale.forLanguageTag(plugin.getSettings().getDefaultLanguage())).get(reference); @@ -54,23 +55,22 @@ public final class LocalesManager { plugin.getLogger().info("DEBUG: loading locale for " + parent); } // Describe the filter - we only want files that are correctly named - FilenameFilter ymlFilter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - // Files must be 9 chars long - if (name.toLowerCase().endsWith(".yml") && name.length() == 9) { - if (DEBUG) - plugin.getLogger().info("DEBUG: bsb locale filename = " + name); - return true; - } - return false; + FilenameFilter ymlFilter = (dir, name) -> { + // Files must be 9 chars long + if (name.toLowerCase().endsWith(".yml") && name.length() == 9) { + if (DEBUG) { + plugin.getLogger().info("DEBUG: bsb locale filename = " + name); + } + return true; } + return false; }; // Run through the files and store the locales File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: localeDir = " + localeDir.getAbsolutePath()); + } // If the folder does not exist, then make it and fill with the locale files from the jar // If it does exist, then new files will NOT be written! if (!localeDir.exists()) { @@ -83,8 +83,9 @@ public final class LocalesManager { // Get the last part of the name int lastIndex = name.lastIndexOf('/'); File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0, name.length())); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: targetFile = " + targetFile.getAbsolutePath()); + } if (!targetFile.exists()) { java.nio.file.Files.copy(initialStream, targetFile.toPath()); } @@ -101,19 +102,23 @@ public final class LocalesManager { // Store all the locales available for (File language : localeDir.listFiles(ymlFilter)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: parent = " + parent + " language = " + language.getName().substring(0, language.getName().length() - 4)); + } Locale localeObject = Locale.forLanguageTag(language.getName().substring(0, language.getName().length() - 4)); - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: locale country found = " + localeObject.getCountry()); + } if (languages.containsKey(localeObject)) { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: this locale is known"); + } // Merge into current language languages.get(localeObject).merge(language); } else { - if (DEBUG) + if (DEBUG) { plugin.getLogger().info("DEBUG: this locale is not known - new language"); + } // New language languages.put(localeObject, new BSBLocale(localeObject, language)); } diff --git a/src/main/java/us/tastybento/bskyblock/managers/RanksManager.java b/src/main/java/us/tastybento/bskyblock/managers/RanksManager.java index 3c2aba087..5cc395148 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/RanksManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/RanksManager.java @@ -49,7 +49,7 @@ public class RanksManager { plugin.getLogger().severe("Error loading custom rank: " + en.getKey() + " " + en.getValue() + " skipping..."); } } - } + } /** * Try to add a new rank. Owner, member, visitor and banned ranks cannot be changed. @@ -67,12 +67,12 @@ public class RanksManager { ranks.put(reference, value); // Sort ranks = ranks.entrySet().stream() - .sorted(Map.Entry.comparingByValue()) - .collect(Collectors.toMap( - Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + .sorted(Map.Entry.comparingByValue()) + .collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); return true; } - + /** * Try to remove a rank. Owner, member, visitor and banned ranks cannot be removed. * @param reference @@ -85,10 +85,10 @@ public class RanksManager { || reference.equalsIgnoreCase(BANNED_RANK_REF)) { return false; } - + return ranks.remove(reference) == null ? false : true; } - + /** * Get the rank value for this reference * @param reference - locale reference to the name of this rank @@ -97,7 +97,7 @@ public class RanksManager { public int getRankValue(String reference) { return ranks.getOrDefault(reference, VISITOR_RANK); } - + /** * Get the ranks. Ranks are listed in ascending order * @return immutable map of ranks diff --git a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java index 6eb7f0580..77dc3de73 100644 --- a/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java +++ b/src/main/java/us/tastybento/bskyblock/util/DeleteIslandChunks.java @@ -27,11 +27,13 @@ public class DeleteIslandChunks { //plugin.getLogger().info("DEBUG: deleting the island"); // Fire event IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build(); - if (event.isCancelled()) + if (event.isCancelled()) { return; + } final World world = island.getCenter().getWorld(); - if (world == null) + if (world == null) { return; + } int minXChunk = island.getMinX() / 16; int maxXChunk = (island.getRange() * 2 + island.getMinX() - 1) /16; int minZChunk = island.getMinZ() / 16; diff --git a/src/main/java/us/tastybento/bskyblock/util/FileLister.java b/src/main/java/us/tastybento/bskyblock/util/FileLister.java index 790ff2d7d..de04ed0ce 100755 --- a/src/main/java/us/tastybento/bskyblock/util/FileLister.java +++ b/src/main/java/us/tastybento/bskyblock/util/FileLister.java @@ -22,7 +22,7 @@ public class FileLister{ private Plugin plugin; public FileLister(Plugin level){ - this.plugin = level; + plugin = level; } /** @@ -52,7 +52,7 @@ public class FileLister{ Method method = JavaPlugin.class.getDeclaredMethod("getFile"); method.setAccessible(true); - jarfile = (File) method.invoke(this.plugin); + jarfile = (File) method.invoke(plugin); } catch (Exception e) { throw new IOException(e); } @@ -97,7 +97,7 @@ public class FileLister{ Method method = JavaPlugin.class.getDeclaredMethod("getFile"); method.setAccessible(true); - jarfile = (File) method.invoke(this.plugin); + jarfile = (File) method.invoke(plugin); } catch (Exception e) { throw new IOException(e); } diff --git a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java index a745d7ece..dd4d536ab 100644 --- a/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java +++ b/src/main/java/us/tastybento/bskyblock/util/SafeSpotTeleport.java @@ -17,7 +17,7 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.database.objects.Island; /** - * A class that calculates finds a safe spot asynchronously and then teleports the player there. + * A class that calculates finds a safe spot asynchronously and then teleports the player there. * @author tastybento * */ @@ -56,7 +56,7 @@ public class SafeSpotTeleport { } /** * Teleport to a safe spot on an island - * + * * TODO: REFACTOR THIS! * @param plugin @@ -71,7 +71,7 @@ public class SafeSpotTeleport { if (island != null) { final World world = islandLoc.getWorld(); // Get the chunks - List chunkSnapshot = new ArrayList(); + List chunkSnapshot = new ArrayList<>(); // Add the center chunk chunkSnapshot.add(island.getCenter().toVector().toLocation(world).getChunk().getChunkSnapshot()); // Add immediately adjacent chunks diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index 9783cca77..80b048cbe 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -110,11 +110,11 @@ public class Util { // In this way, we can deduce what type needs to be written at runtime. Type[] genericParameterTypes = writeMethod.getGenericParameterTypes(); // There could be more than one argument, so step through them - for (int i = 0; i < genericParameterTypes.length; i++) { + for (Type genericParameterType : genericParameterTypes) { // If the argument is a parameter, then do something - this should always be true if the parameter is a collection - if( genericParameterTypes[i] instanceof ParameterizedType ) { - // Get the actual type arguments of the parameter - Type[] parameters = ((ParameterizedType)genericParameterTypes[i]).getActualTypeArguments(); + if( genericParameterType instanceof ParameterizedType ) { + // Get the actual type arguments of the parameter + Type[] parameters = ((ParameterizedType)genericParameterType).getActualTypeArguments(); result.addAll(Arrays.asList(parameters)); } } @@ -128,17 +128,20 @@ public class Util { */ @SuppressWarnings("deprecation") public static List getPlayerInHandItems(Player player) { - List result = new ArrayList(2); + List result = new ArrayList<>(2); if (plugin.getServer().getVersion().contains("(MC: 1.7") || plugin.getServer().getVersion().contains("(MC: 1.8")) { - if (player.getItemInHand() != null) + if (player.getItemInHand() != null) { result.add(player.getItemInHand()); + } return result; } - if (player.getInventory().getItemInMainHand() != null) + if (player.getInventory().getItemInMainHand() != null) { result.add(player.getInventory().getItemInMainHand()); - if (player.getInventory().getItemInOffHand() != null) + } + if (player.getInventory().getItemInOffHand() != null) { result.add(player.getInventory().getItemInOffHand()); + } return result; } @@ -152,8 +155,9 @@ public class Util { * Credits to mikenon on GitHub! */ public static String prettifyText(String ugly) { - if (!ugly.contains("_") && (!ugly.equals(ugly.toUpperCase()))) + if (!ugly.contains("_") && (!ugly.equals(ugly.toUpperCase()))) { return ugly; + } String fin = ""; ugly = ugly.toLowerCase(); if (ugly.contains("_")) { @@ -162,8 +166,9 @@ public class Util { for (String s : splt) { i += 1; fin += Character.toUpperCase(s.charAt(0)) + s.substring(1); - if (i < splt.length) + if (i < splt.length) { fin += " "; + } } } else { fin += Character.toUpperCase(ugly.charAt(0)) + ugly.substring(1); @@ -251,8 +256,8 @@ public class Util { } /** - * Returns all of the items that begin with the given start, - * ignoring case. Intended for tabcompletion. + * Returns all of the items that begin with the given start, + * ignoring case. Intended for tabcompletion. * * @param list * @param start @@ -261,8 +266,9 @@ public class Util { public static List tabLimit(final List list, final String start) { final List returned = new ArrayList<>(); for (String s : list) { - if (s == null) + if (s == null) { continue; + } if (s.toLowerCase().startsWith(start.toLowerCase())) { returned.add(s); } @@ -273,7 +279,7 @@ public class Util { /** * Loads a YAML file and if it does not exist it is looked for in the JAR - * + * * @param file * @return */ @@ -312,12 +318,7 @@ public class Util { } public static void runCommand(final Player player, final String string) { - plugin.getServer().getScheduler().runTask(plugin, new Runnable() { - - @Override - public void run() { - player.performCommand(string); - }}); + plugin.getServer().getScheduler().runTask(plugin, () -> player.performCommand(string)); } diff --git a/src/main/java/us/tastybento/bskyblock/util/YmlCommentParser.java b/src/main/java/us/tastybento/bskyblock/util/YmlCommentParser.java index 1f15f0c52..faa9e4518 100644 --- a/src/main/java/us/tastybento/bskyblock/util/YmlCommentParser.java +++ b/src/main/java/us/tastybento/bskyblock/util/YmlCommentParser.java @@ -160,7 +160,7 @@ public class YmlCommentParser { if (comment != null) { sb.append((lineNum > 1 ? "\n" : "") + comment .replaceAll("^#", Matcher.quoteReplacement(indent + "#")) - .replaceAll("\n#", Matcher.quoteReplacement("\n" + indent + "#"))); + .replaceAll("\n#", Matcher.quoteReplacement("\n" + indent + "#"))); } if (value != null && !value.trim().isEmpty()) { // Scalar with value @@ -197,7 +197,7 @@ public class YmlCommentParser { private Section(String name, int indentation) { this.indentation = indentation; - this.path = name; + path = name; } public int getIndentation() { diff --git a/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderHandler.java b/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderHandler.java index 332f069c1..96dab7161 100644 --- a/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderHandler.java +++ b/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderHandler.java @@ -10,7 +10,7 @@ import us.tastybento.bskyblock.BSkyBlock; /** * Handles hooks with other Placeholder APIs. - * + * * @author Poslovitch, Tastybento */ public class PlaceholderHandler { @@ -82,7 +82,9 @@ public class PlaceholderHandler { * @return updated message */ public static String replacePlaceholders(CommandSender receiver, String message){ - if(message == null || message.isEmpty()) return ""; + if(message == null || message.isEmpty()) { + return ""; + } for(PlaceholderInterface api : apis){ message = api.replacePlaceholders(receiver, message); diff --git a/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderInterface.java b/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderInterface.java index 59c8a7c74..a3911b814 100644 --- a/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderInterface.java +++ b/src/main/java/us/tastybento/bskyblock/util/placeholders/PlaceholderInterface.java @@ -6,30 +6,30 @@ import us.tastybento.bskyblock.BSkyBlock; /** * Simple interface for every Placeholder API. - * + * * @author Poslovitch */ public interface PlaceholderInterface { - + /** * Get the name of the Placeholder API * @return name of the placeholder plugin */ String getName(); - + /** * Register the placeholder API * @param plugin * @return true if registered */ boolean register(BSkyBlock plugin); - + /** * Unregister the placeholder API * @param plugin */ void unregister(BSkyBlock plugin); - + /** * Replace placeholders in the message according to the receiver * @param sender diff --git a/src/main/java/us/tastybento/bskyblock/util/placeholders/Placeholders.java b/src/main/java/us/tastybento/bskyblock/util/placeholders/Placeholders.java index 37d3c08ed..8e3ab2d37 100644 --- a/src/main/java/us/tastybento/bskyblock/util/placeholders/Placeholders.java +++ b/src/main/java/us/tastybento/bskyblock/util/placeholders/Placeholders.java @@ -9,11 +9,11 @@ import us.tastybento.bskyblock.BSkyBlock; /** * Register placeholders - * + * * @author Poslovitch */ public class Placeholders { - private static Set placeholders = new HashSet(); + private static Set placeholders = new HashSet<>(); private BSkyBlock plugin; diff --git a/src/main/java/us/tastybento/bskyblock/util/placeholders/hooks/InternalPlaceholderImpl.java b/src/main/java/us/tastybento/bskyblock/util/placeholders/hooks/InternalPlaceholderImpl.java index 7d6069061..4bb25e04f 100644 --- a/src/main/java/us/tastybento/bskyblock/util/placeholders/hooks/InternalPlaceholderImpl.java +++ b/src/main/java/us/tastybento/bskyblock/util/placeholders/hooks/InternalPlaceholderImpl.java @@ -11,7 +11,7 @@ import us.tastybento.bskyblock.util.placeholders.Placeholders.Placeholder; /** * Built-in placeholder API - * + * * @author Poslovitch */ public class InternalPlaceholderImpl implements PlaceholderInterface{ @@ -33,7 +33,9 @@ public class InternalPlaceholderImpl implements PlaceholderInterface{ @Override public String replacePlaceholders(CommandSender receiver, String message) { - if(message == null || message.isEmpty()) return ""; + if(message == null || message.isEmpty()) { + return ""; + } for(Placeholder placeholder : Placeholders.getPlaceholders()){ String identifier = "{" + placeholder.getIdentifier() + "}"; diff --git a/src/test/java/bskyblock/TestBSkyBlock.java b/src/test/java/bskyblock/TestBSkyBlock.java index 826850731..2ac5f1784 100644 --- a/src/test/java/bskyblock/TestBSkyBlock.java +++ b/src/test/java/bskyblock/TestBSkyBlock.java @@ -38,6 +38,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -98,14 +99,14 @@ public class TestBSkyBlock { Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); PluginManager pluginManager = mock(PluginManager.class); Mockito.when(server.getPluginManager()).thenReturn(pluginManager); - + sender = mock(CommandSender.class); player = mock(Player.class); ownerOfIsland = mock(Player.class); visitorToIsland = mock(Player.class); Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true); - + //Mockito.when(plugin.getServer()).thenReturn(server); location = mock(Location.class); @@ -113,40 +114,40 @@ public class TestBSkyBlock { Mockito.when(location.getBlockX()).thenReturn(0); Mockito.when(location.getBlockY()).thenReturn(0); Mockito.when(location.getBlockZ()).thenReturn(0); - + Mockito.when(player.getLocation()).thenReturn(location); Mockito.when(ownerOfIsland.getLocation()).thenReturn(location); Mockito.when(visitorToIsland.getLocation()).thenReturn(location); - + Mockito.when(player.getUniqueId()).thenReturn(MEMBER_UUID); Mockito.when(ownerOfIsland.getUniqueId()).thenReturn(OWNER_UUID); Mockito.when(visitorToIsland.getUniqueId()).thenReturn(VISITOR_UUID); - // Mock itemFactory for ItemStack + // Mock itemFactory for ItemStack ItemFactory itemFactory = PowerMockito.mock(ItemFactory.class); PowerMockito.when(Bukkit.getItemFactory()).thenReturn(itemFactory); ItemMeta itemMeta = PowerMockito.mock(ItemMeta.class); - PowerMockito.when(itemFactory.getItemMeta(Mockito.any())).thenReturn(itemMeta); - + PowerMockito.when(itemFactory.getItemMeta(Matchers.any())).thenReturn(itemMeta); + PowerMockito.mockStatic(Flags.class); - + plugin = Mockito.mock(BSkyBlock.class); flagsManager = new FlagsManager(plugin); Mockito.when(plugin.getFlagsManager()).thenReturn(flagsManager); - + block = Mockito.mock(Block.class); - + // Worlds IslandWorld iwm = mock(IslandWorld.class); Mockito.when(plugin.getIslandWorldManager()).thenReturn(iwm); Mockito.when(iwm.getIslandWorld()).thenReturn(world); Mockito.when(iwm.getNetherWorld()).thenReturn(world); Mockito.when(iwm.getEndWorld()).thenReturn(world); - + // User //User user = Mockito.mock(User.class); //Mockito.when(user.getName()).thenReturn("tastybento"); - + // Islands IslandsManager im = mock(IslandsManager.class); Mockito.when(plugin.getIslands()).thenReturn(im); @@ -162,12 +163,12 @@ public class TestBSkyBlock { Bukkit.getLogger().info("SETUP: owner UUID = " + OWNER_UUID); Bukkit.getLogger().info("SETUP: member UUID = " + MEMBER_UUID); Bukkit.getLogger().info("SETUP: visitor UUID = " + VISITOR_UUID); - Mockito.when(im.getIslandAt(Mockito.any())).thenReturn(Optional.of(island)); + Mockito.when(im.getIslandAt(Matchers.any())).thenReturn(Optional.of(island)); Settings settings = mock(Settings.class); Mockito.when(plugin.getSettings()).thenReturn(settings); Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet()); - + } @Test @@ -181,7 +182,7 @@ public class TestBSkyBlock { .build(); assertEquals(playerUUID, event.getPlayerUUID()); } - + @Test public void testCommandAPI() { // Test command @@ -203,7 +204,7 @@ public class TestBSkyBlock { // Check aliases for (String alias : command.getValue().getAliases()) { assertEquals(testCommand.getSubCommand(alias), Optional.of(command.getValue())); - } + } } String[] args = {""}; assertEquals(Arrays.asList("sub1","sub2", "help"), testCommand.tabComplete(player, "test", args)); @@ -224,23 +225,23 @@ public class TestBSkyBlock { assertEquals(Arrays.asList(new String[] {"Florian", "Ben", "Bill", "Ted", "help"}), testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", ""})); // Test for partial word - assertEquals(Arrays.asList(new String[] {"Ben", "Bill"}), + assertEquals(Arrays.asList(new String[] {"Ben", "Bill"}), testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", "b"})); // Test command arguments CompositeCommand argCmd = new Test3ArgsCommand(); argCmd.setOnlyPlayer(true); argCmd.setPermission(Constants.PERMPREFIX + "default.permission"); - assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"})); + assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100"})); assertTrue(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100", "today"})); - + // Usage tests assertEquals("/test", testCommand.getUsage()); assertEquals("test.params", testCommand.getParameters()); - + // Test help //assertTrue(testCommand.execute(player, "test", new String[] {"help"})); } @@ -249,7 +250,7 @@ public class TestBSkyBlock { public TestCommand() { super(plugin, "test", "t", "tt"); - this.setParameters("test.params"); + setParameters("test.params"); } @Override @@ -271,10 +272,10 @@ public class TestBSkyBlock { public TestSubCommand(CompositeCommand parent) { super(parent, "sub1", "subone"); } - + @Override public void setup() { - this.setParameters("sub.params"); + setParameters("sub.params"); } @Override @@ -328,14 +329,16 @@ public class TestBSkyBlock { public TestSubSubSubCommand(CompositeCommand parent) { super(parent, "subsubsub", "level3", "subsubsubby"); } - + @Override public void setup() {} @Override public boolean execute(User user, List args) { Bukkit.getLogger().info("args are " + args.toString()); - if (args.size() == 3) return true; + if (args.size() == 3) { + return true; + } return false; } @@ -347,13 +350,13 @@ public class TestBSkyBlock { return Optional.of(Util.tabLimit(options, lastArg)); } } - + private class Test3ArgsCommand extends CompositeCommand { public Test3ArgsCommand() { super(plugin, "args", ""); } - + @Override public void setup() {} @@ -363,8 +366,8 @@ public class TestBSkyBlock { return args.size() == 3 ? true : false; } - } - + } + // Protection tests @Test public void TestProtection() { @@ -373,29 +376,29 @@ public class TestBSkyBlock { island.setOwner(playerUUID); island.setCenter(location); island.setProtectionRange(100); - + assertNotNull(island); - + User visitor = User.getInstance(UUID.randomUUID()); assertEquals(RanksManager.OWNER_RANK, island.getRank(owner)); assertEquals(RanksManager.VISITOR_RANK, island.getRank(visitor)); - + // Make members UUID member1 = UUID.randomUUID(); UUID member2 = UUID.randomUUID(); UUID member3 = UUID.randomUUID(); - + // Add members island.addMember(member1); island.addMember(member2); island.addMember(member3); - + Set members = island.getMemberSet(); assertTrue(members.contains(playerUUID)); assertTrue(members.contains(member1)); assertTrue(members.contains(member2)); assertTrue(members.contains(member3)); - + // Remove members island.removeMember(member3); members = island.getMemberSet(); @@ -403,7 +406,7 @@ public class TestBSkyBlock { assertTrue(members.contains(member1)); assertTrue(members.contains(member2)); assertFalse(members.contains(member3)); - + // Ban member island.addToBanList(member1); members = island.getMemberSet(); @@ -411,16 +414,16 @@ public class TestBSkyBlock { assertFalse(members.contains(member1)); assertTrue(members.contains(member2)); assertFalse(members.contains(member3)); - + Set banned = island.getBanned(); assertTrue(banned.contains(member1)); - + // Unban island.removeFromBanList(member1); assertFalse(island.getBanned().contains(member1)); - + // Protection - + // Check default settings // Owner should be able to do anything assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS)); @@ -429,11 +432,11 @@ public class TestBSkyBlock { // Visitor can do nothing assertFalse(island.isAllowed(visitor, Flags.PLACE_BLOCKS)); assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS)); - - // Set up protection settings - members can break blocks, visitors and place blocks + + // Set up protection settings - members can break blocks, visitors and place blocks island.setFlag(Flags.BREAK_BLOCKS, RanksManager.MEMBER_RANK); assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS)); - + island.setFlag(Flags.PLACE_BLOCKS, RanksManager.VISITOR_RANK); assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS)); @@ -463,16 +466,16 @@ public class TestBSkyBlock { assertFalse(island.isAllowed(mem3, Flags.PLACE_BLOCKS)); assertFalse(island.isAllowed(mem3, Flags.BREAK_BLOCKS)); } - + @Test public void TestEventProtection() { // Test events - + FlagListener fl = new FlagListener(plugin); Bukkit.getLogger().info("SETUP: owner UUID = " + ownerOfIsland.getUniqueId()); Bukkit.getLogger().info("SETUP: member UUID = " + player.getUniqueId()); Bukkit.getLogger().info("SETUP: visitor UUID = " + visitorToIsland.getUniqueId()); - + Bukkit.getLogger().info("DEBUG: checking events - vistor"); Event e3 = new BlockBreakEvent(block, visitorToIsland); Assert.assertFalse(fl.checkIsland(e3, location, Flags.BREAK_BLOCKS, true)); @@ -480,14 +483,14 @@ public class TestBSkyBlock { Bukkit.getLogger().info("DEBUG: checking events - owner"); Event e = new BlockBreakEvent(block, ownerOfIsland); Assert.assertTrue(fl.checkIsland(e, location, Flags.BREAK_BLOCKS, true)); - + Bukkit.getLogger().info("DEBUG: checking events - member"); Event e2 = new BlockBreakEvent(block, player); Assert.assertTrue(fl.checkIsland(e2, location, Flags.BREAK_BLOCKS, true)); - + } - + @Test public void TestDefaultFlags() { // Check all the default flags @@ -501,7 +504,7 @@ public class TestBSkyBlock { assertTrue(flag.getID(), defaultFlags.contains(flag)); } } - + @Test public void TestCustomFlags() { // Custom @@ -510,12 +513,12 @@ public class TestBSkyBlock { assertEquals("CUSTOM_FLAG", customFlag.getID()); assertEquals(Material.DIAMOND, customFlag.getIcon().getItem().getType()); assertEquals(fl, customFlag.getListener().get()); - // Add it to the Flag Manager + // Add it to the Flag Manager flagsManager.registerFlag(customFlag); assertEquals(customFlag, flagsManager.getFlagByID("CUSTOM_FLAG")); assertEquals(customFlag, flagsManager.getFlagByIcon(customFlag.getIcon())); } - + /** * Dummy flag listener *