diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index 07e51cd..e1733f3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -21,7 +21,6 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import me.filoghost.chestcommands.SimpleUpdater.ResponseHandler; import me.filoghost.chestcommands.bridge.BarAPIBridge; import me.filoghost.chestcommands.bridge.EconomyBridge; import me.filoghost.chestcommands.bridge.PlaceholderAPIBridge; @@ -46,10 +45,10 @@ import me.filoghost.chestcommands.task.RefreshMenusTask; import me.filoghost.chestcommands.util.BukkitUtils; import me.filoghost.chestcommands.util.CaseInsensitiveMap; import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.Utils; - import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -80,7 +79,7 @@ public class ChestCommands extends JavaPlugin { instance = this; fileNameToMenuMap = CaseInsensitiveMap.create(); commandsToMenuMap = CaseInsensitiveMap.create(); - boundItems = Utils.newHashSet(); + boundItems = new HashSet<>(); settings = new Settings(new PluginConfig(this, "config.yml")); lang = new Lang(new PluginConfig(this, "lang.yml")); @@ -98,21 +97,17 @@ public class ChestCommands extends JavaPlugin { } if (settings.update_notifications) { - new SimpleUpdater(this, 56919).checkForUpdates(new ResponseHandler() { + new SimpleUpdater(this, 56919).checkForUpdates((String newVersion) -> { + ChestCommands.newVersion = newVersion; - @Override - public void onUpdateFound(String newVersion) { - ChestCommands.newVersion = newVersion; - - if (settings.use_console_colors) { - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); - Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands"); - } else { - getLogger().info("Found a new version available: " + newVersion); - getLogger().info("Download it on Bukkit Dev:"); - getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands"); - } + if (settings.use_console_colors) { + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + "Found a new version: " + newVersion + ChatColor.WHITE + " (yours: v" + getDescription().getVersion() + ")"); + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "Download it on Bukkit Dev:"); + Bukkit.getConsoleSender().sendMessage(CHAT_PREFIX + ChatColor.WHITE + "dev.bukkit.org/bukkit-plugins/chest-commands"); + } else { + getLogger().info("Found a new version available: " + newVersion); + getLogger().info("Download it on Bukkit Dev:"); + getLogger().info("dev.bukkit.org/bukkit-plugins/chest-commands"); } }); } @@ -256,7 +251,7 @@ public class ChestCommands extends JavaPlugin { * Loads all the configuration files recursively into a list. */ private List loadMenus(File file) { - List list = Utils.newArrayList(); + List list = new ArrayList<>(); if (file.isDirectory()) { for (File subFile : file.listFiles()) { list.addAll(loadMenus(subFile)); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java index a3273a3..1d8c60d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/SimpleUpdater.java @@ -59,44 +59,38 @@ public final class SimpleUpdater { * @param responseHandler the response handler */ public void checkForUpdates(final ResponseHandler responseHandler) { - Thread updaterThread = new Thread(new Runnable() { + Thread updaterThread = new Thread(() -> { + try { + JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); - @Override - public void run() { - - try { - JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId); - - if (filesArray.size() == 0) { - // The array cannot be empty, there must be at least one file. - // The project ID is not valid or curse returned a wrong response. - return; - } - - String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name"); - final PluginVersion remoteVersion = new PluginVersion(updateName); - PluginVersion localVersion = new PluginVersion(plugin.getDescription().getVersion()); - - if (remoteVersion.isNewerThan(localVersion)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - responseHandler.onUpdateFound(remoteVersion.toString()); - } - }); - } - - } catch (IOException e) { - plugin.getLogger().warning("Could not contact BukkitDev to check for updates."); - } catch (InvalidVersionException e) { - plugin.getLogger().warning("Could not check for updates because of a version format error: " + e.getMessage() + "."); - plugin.getLogger().warning("Please notify the author of this error."); - } catch (Exception e) { - e.printStackTrace(); - plugin.getLogger().warning("Unable to check for updates: unhandled exception."); + if (filesArray.size() == 0) { + // The array cannot be empty, there must be at least one file. + // The project ID is not valid or curse returned a wrong response. + return; } + String updateName = (String) ((JSONObject) filesArray.get(filesArray.size() - 1)).get("name"); + final PluginVersion remoteVersion = new PluginVersion(updateName); + PluginVersion localVersion = new PluginVersion(plugin.getDescription().getVersion()); + + if (remoteVersion.isNewerThan(localVersion)) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + + @Override + public void run() { + responseHandler.onUpdateFound(remoteVersion.toString()); + } + }); + } + + } catch (IOException e) { + plugin.getLogger().warning("Could not contact BukkitDev to check for updates."); + } catch (InvalidVersionException e) { + plugin.getLogger().warning("Could not check for updates because of a version format error: " + e.getMessage() + "."); + plugin.getLogger().warning("Please notify the author of this error."); + } catch (Exception e) { + e.printStackTrace(); + plugin.getLogger().warning("Unable to check for updates: unhandled exception."); } }); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java index 1ab26ef..590e8e8 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/Icon.java @@ -28,6 +28,7 @@ import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.internal.VariableManager; import me.filoghost.chestcommands.util.Utils; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -59,7 +60,7 @@ public class Icon { private ItemStack cachedItem; // When there are no variables, we don't recreate the item public Icon() { - enchantments = new HashMap(); + enchantments = new HashMap<>(); closeOnClick = true; amount = 1; } @@ -154,7 +155,7 @@ public class Icon { } public Map getEnchantments() { - return new HashMap(enchantments); + return new HashMap<>(enchantments); } public void addEnchantment(Enchantment ench) { @@ -244,7 +245,7 @@ public class Icon { if (hasLore()) { - output = Utils.newArrayList(); + output = new ArrayList<>(); if (pov != null && loreLinesWithVariables != null) { for (int i = 0; i < lore.size(); i++) { @@ -263,7 +264,7 @@ public class Icon { if (material == null) { if (output == null) { - output = Utils.newArrayList(); + output = new ArrayList<>(); } // Add an error message diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java index b9d6db0..fecbf82 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/AsciiPlaceholders.java @@ -24,6 +24,7 @@ import me.filoghost.chestcommands.util.Utils; import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,7 +34,7 @@ import java.util.Map.Entry; */ public class AsciiPlaceholders { - private static Map placeholders = Utils.newHashMap(); + private static Map placeholders = new HashMap<>(); public static void load(ErrorLogger errorLogger) throws IOException, Exception { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java index 9f2d214..7706f5d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/ConfigUtil.java @@ -14,14 +14,13 @@ */ package me.filoghost.chestcommands.config; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; import org.bukkit.configuration.ConfigurationSection; -import me.filoghost.chestcommands.util.Utils; - public class ConfigUtil { public static String getAnyString(ConfigurationSection config, String... paths) { @@ -75,7 +74,7 @@ public class ConfigUtil { } String[] splitValues = input.split(Pattern.quote(separator)); - List values = Utils.newArrayList(); + List values = new ArrayList<>(); for (String value : splitValues) { String trimmedValue = value.trim(); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java index 0e82145..80498a1 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/config/yaml/SpecialConfig.java @@ -47,7 +47,7 @@ public class SpecialConfig { // Check if the configuration was initialized if (defaultValuesMap == null) { - defaultValuesMap = new HashMap(); + defaultValuesMap = new HashMap<>(); // Put the values in the default values map for (Field field : getClass().getDeclaredFields()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java index d4204a6..fd9c31f 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/internal/icon/command/OpenIconCommand.java @@ -38,13 +38,11 @@ public class OpenIconCommand extends IconCommand { * Delay the task, since this command is executed in ClickInventoryEvent * and opening another inventory in the same moment is not a good idea. */ - Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), new Runnable() { - public void run() { - if (player.hasPermission(menu.getPermission())) { - menu.open(player); - } else { - menu.sendNoPermissionMessage(player); - } + Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), () -> { + if (player.hasPermission(menu.getPermission())) { + menu.open(player); + } else { + menu.sendNoPermissionMessage(player); } }); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java index ef65355..4ec8883 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/listener/InventoryListener.java @@ -30,13 +30,12 @@ import me.filoghost.chestcommands.api.IconMenu; import me.filoghost.chestcommands.internal.BoundItem; import me.filoghost.chestcommands.internal.MenuInventoryHolder; import me.filoghost.chestcommands.task.ExecuteCommandsTask; -import me.filoghost.chestcommands.util.Utils; - +import java.util.HashMap; import java.util.Map; public class InventoryListener implements Listener { - private static Map antiClickSpam = Utils.newHashMap(); + private static Map antiClickSpam = new HashMap<>(); @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onInteract(PlayerInteractEvent event) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java index 8aa808e..726d3bc 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/CommandSerializer.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.regex.Matcher; @@ -22,11 +23,10 @@ import java.util.regex.Pattern; import me.filoghost.chestcommands.internal.icon.IconCommand; import me.filoghost.chestcommands.internal.icon.command.*; import me.filoghost.chestcommands.util.ErrorLogger; -import me.filoghost.chestcommands.util.Utils; public class CommandSerializer { - private static Map> commandTypesMap = Utils.newHashMap(); + private static Map> commandTypesMap = new HashMap<>(); static { commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java index 4d26dd2..11ec9e0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/EnchantmentSerializer.java @@ -24,7 +24,7 @@ import java.util.Map; public class EnchantmentSerializer { - private static Map enchantmentsMap = new HashMap(); + private static Map enchantmentsMap = new HashMap<>(); static { enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java index 858da88..eea2661 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/IconSerializer.java @@ -14,6 +14,8 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,7 +36,6 @@ import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; import me.filoghost.chestcommands.util.ItemUtils; -import me.filoghost.chestcommands.util.Utils; import me.filoghost.chestcommands.util.Validate; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParseException; import me.filoghost.chestcommands.util.nbt.parser.MojangsonParser; @@ -137,7 +138,7 @@ public class IconSerializer { List serializedEnchantments = ConfigUtil.getStringListOrInlineList(section, ";", Nodes.ENCHANTMENTS); if (serializedEnchantments != null && !serializedEnchantments.isEmpty()) { - Map enchantments = Utils.newHashMap(); + Map enchantments = new HashMap<>(); for (String serializedEnchantment : serializedEnchantments) { if (serializedEnchantment != null && !serializedEnchantment.isEmpty()) { @@ -190,7 +191,7 @@ public class IconSerializer { List serializedCommands = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS); if (serializedCommands != null && !serializedCommands.isEmpty()) { - List commands = Utils.newArrayList(); + List commands = new ArrayList<>(); for (String serializedCommand : serializedCommands) { if (serializedCommand != null && !serializedCommand.isEmpty()) { @@ -220,7 +221,7 @@ public class IconSerializer { List serializedRequiredItems = ConfigUtil.getStringListOrSingle(section, Nodes.REQUIRED_ITEMS); if (serializedRequiredItems != null && !serializedRequiredItems.isEmpty()) { - List requiredItems = Utils.newArrayList(); + List requiredItems = new ArrayList<>(); for (String serializedItem : serializedRequiredItems) { try { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java index 340281f..cfd2ad0 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/serializer/MenuSerializer.java @@ -14,6 +14,7 @@ */ package me.filoghost.chestcommands.serializer; +import java.util.ArrayList; import java.util.List; import org.bukkit.ChatColor; @@ -32,7 +33,6 @@ import me.filoghost.chestcommands.util.ClickType; import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.FormatUtils; import me.filoghost.chestcommands.util.ItemStackReader; -import me.filoghost.chestcommands.util.Utils; public class MenuSerializer { @@ -119,7 +119,7 @@ public class MenuSerializer { List serializedOpenCommands = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS); if (serializedOpenCommands != null && !serializedOpenCommands.isEmpty()) { - List openCommands = Utils.newArrayList(); + List openCommands = new ArrayList<>(); for (String serializedCommand : serializedOpenCommands) { if (serializedCommand != null && !serializedCommand.isEmpty()) { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java index 6ef461d..ecea034 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/ErrorLoggerTask.java @@ -20,8 +20,7 @@ import org.bukkit.ChatColor; import me.filoghost.chestcommands.ChestCommands; import me.filoghost.chestcommands.util.ErrorLogger; import me.filoghost.chestcommands.util.StringUtils; -import me.filoghost.chestcommands.util.Utils; - +import java.util.ArrayList; import java.util.List; public class ErrorLoggerTask implements Runnable { @@ -35,7 +34,7 @@ public class ErrorLoggerTask implements Runnable { @Override public void run() { - List lines = Utils.newArrayList(); + List lines = new ArrayList<>(); lines.add(" "); lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java index a2ceec1..9dc5484 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/ErrorLogger.java @@ -22,14 +22,14 @@ import java.util.List; */ public class ErrorLogger { - private List errors = new ArrayList(); + private List errors = new ArrayList<>(); public void addError(String error) { errors.add(error); } public List getErrors() { - return new ArrayList(errors); + return new ArrayList<>(errors); } public boolean hasErrors() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java index a4d07eb..e64877d 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/MaterialsRegistry.java @@ -31,7 +31,7 @@ public final class MaterialsRegistry { private static final char[] IGNORE_CHARS = {'-', '_', ' '}; // Default material names are ugly - private static final Map MATERIALS_BY_ALIAS = new HashMap(); + private static final Map MATERIALS_BY_ALIAS = new HashMap<>(); // Materials that are considered air (with 1.13+ compatibility) private static final Collection AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR"); diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java index cc6d4b7..036639a 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/util/Utils.java @@ -64,7 +64,7 @@ public final class Utils { BufferedReader br = null; try { - List lines = newArrayList(); + List lines = new ArrayList<>(); if (!file.exists()) { throw new FileNotFoundException(); @@ -89,18 +89,6 @@ public final class Utils { } } - public static Set newHashSet() { - return new HashSet(); - } - - public static Map newHashMap() { - return new HashMap(); - } - - public static List newArrayList() { - return new ArrayList(); - } - public static boolean isClassLoaded(String name) { try { Class.forName(name); diff --git a/pom.xml b/pom.xml index cc6598d..b0df1f8 100644 --- a/pom.xml +++ b/pom.xml @@ -19,8 +19,8 @@ UTF-8 - 1.6 - 1.6 + 1.8 + 1.8 true 1.8.8-R0.1-SNAPSHOT