Update to Java 8

This commit is contained in:
filoghost 2020-06-05 18:59:19 +02:00
parent b90c431891
commit e303d6969c
17 changed files with 78 additions and 103 deletions

View File

@ -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,10 +97,7 @@ public class ChestCommands extends JavaPlugin {
}
if (settings.update_notifications) {
new SimpleUpdater(this, 56919).checkForUpdates(new ResponseHandler() {
@Override
public void onUpdateFound(String newVersion) {
new SimpleUpdater(this, 56919).checkForUpdates((String newVersion) -> {
ChestCommands.newVersion = newVersion;
if (settings.use_console_colors) {
@ -113,7 +109,6 @@ public class ChestCommands extends JavaPlugin {
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<PluginConfig> loadMenus(File file) {
List<PluginConfig> list = Utils.newArrayList();
List<PluginConfig> list = new ArrayList<>();
if (file.isDirectory()) {
for (File subFile : file.listFiles()) {
list.addAll(loadMenus(subFile));

View File

@ -59,11 +59,7 @@ public final class SimpleUpdater {
* @param responseHandler the response handler
*/
public void checkForUpdates(final ResponseHandler responseHandler) {
Thread updaterThread = new Thread(new Runnable() {
@Override
public void run() {
Thread updaterThread = new Thread(() -> {
try {
JSONArray filesArray = (JSONArray) readJson("https://api.curseforge.com/servermods/files?projectIds=" + projectId);
@ -96,8 +92,6 @@ public final class SimpleUpdater {
e.printStackTrace();
plugin.getLogger().warning("Unable to check for updates: unhandled exception.");
}
}
});
updaterThread.start();

View File

@ -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<Enchantment, Integer>();
enchantments = new HashMap<>();
closeOnClick = true;
amount = 1;
}
@ -154,7 +155,7 @@ public class Icon {
}
public Map<Enchantment, Integer> getEnchantments() {
return new HashMap<Enchantment, Integer>(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

View File

@ -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<String, String> placeholders = Utils.newHashMap();
private static Map<String, String> placeholders = new HashMap<>();
public static void load(ErrorLogger errorLogger) throws IOException, Exception {

View File

@ -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<String> values = Utils.newArrayList();
List<String> values = new ArrayList<>();
for (String value : splitValues) {
String trimmedValue = value.trim();

View File

@ -47,7 +47,7 @@ public class SpecialConfig {
// Check if the configuration was initialized
if (defaultValuesMap == null) {
defaultValuesMap = new HashMap<String, Object>();
defaultValuesMap = new HashMap<>();
// Put the values in the default values map
for (Field field : getClass().getDeclaredFields()) {

View File

@ -38,14 +38,12 @@ 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() {
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestCommands.getInstance(), () -> {
if (player.hasPermission(menu.getPermission())) {
menu.open(player);
} else {
menu.sendNoPermissionMessage(player);
}
}
});
} else {

View File

@ -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<Player, Long> antiClickSpam = Utils.newHashMap();
private static Map<Player, Long> antiClickSpam = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onInteract(PlayerInteractEvent event) {

View File

@ -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<Pattern, Class<? extends IconCommand>> commandTypesMap = Utils.newHashMap();
private static Map<Pattern, Class<? extends IconCommand>> commandTypesMap = new HashMap<>();
static {
commandTypesMap.put(commandPattern("console:"), ConsoleIconCommand.class);

View File

@ -24,7 +24,7 @@ import java.util.Map;
public class EnchantmentSerializer {
private static Map<String, Enchantment> enchantmentsMap = new HashMap<String, Enchantment>();
private static Map<String, Enchantment> enchantmentsMap = new HashMap<>();
static {
enchantmentsMap.put(formatLowercase("Protection"), Enchantment.PROTECTION_ENVIRONMENTAL);

View File

@ -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<String> serializedEnchantments = ConfigUtil.getStringListOrInlineList(section, ";", Nodes.ENCHANTMENTS);
if (serializedEnchantments != null && !serializedEnchantments.isEmpty()) {
Map<Enchantment, Integer> enchantments = Utils.newHashMap();
Map<Enchantment, Integer> enchantments = new HashMap<>();
for (String serializedEnchantment : serializedEnchantments) {
if (serializedEnchantment != null && !serializedEnchantment.isEmpty()) {
@ -190,7 +191,7 @@ public class IconSerializer {
List<String> serializedCommands = ConfigUtil.getStringListOrInlineList(section, ChestCommands.getSettings().multiple_commands_separator, Nodes.ACTIONS);
if (serializedCommands != null && !serializedCommands.isEmpty()) {
List<IconCommand> commands = Utils.newArrayList();
List<IconCommand> commands = new ArrayList<>();
for (String serializedCommand : serializedCommands) {
if (serializedCommand != null && !serializedCommand.isEmpty()) {
@ -220,7 +221,7 @@ public class IconSerializer {
List<String> serializedRequiredItems = ConfigUtil.getStringListOrSingle(section, Nodes.REQUIRED_ITEMS);
if (serializedRequiredItems != null && !serializedRequiredItems.isEmpty()) {
List<RequiredItem> requiredItems = Utils.newArrayList();
List<RequiredItem> requiredItems = new ArrayList<>();
for (String serializedItem : serializedRequiredItems) {
try {

View File

@ -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<String> serializedOpenCommands = ConfigUtil.getStringListOrInlineList(config, ChestCommands.getSettings().multiple_commands_separator, Nodes.OPEN_ACTIONS);
if (serializedOpenCommands != null && !serializedOpenCommands.isEmpty()) {
List<IconCommand> openCommands = Utils.newArrayList();
List<IconCommand> openCommands = new ArrayList<>();
for (String serializedCommand : serializedOpenCommands) {
if (serializedCommand != null && !serializedCommand.isEmpty()) {

View File

@ -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<String> lines = Utils.newArrayList();
List<String> lines = new ArrayList<>();
lines.add(" ");
lines.add(ChatColor.RED + "#------------------- Chest Commands Errors -------------------#");

View File

@ -22,14 +22,14 @@ import java.util.List;
*/
public class ErrorLogger {
private List<String> errors = new ArrayList<String>();
private List<String> errors = new ArrayList<>();
public void addError(String error) {
errors.add(error);
}
public List<String> getErrors() {
return new ArrayList<String>(errors);
return new ArrayList<>(errors);
}
public boolean hasErrors() {

View File

@ -31,7 +31,7 @@ public final class MaterialsRegistry {
private static final char[] IGNORE_CHARS = {'-', '_', ' '};
// Default material names are ugly
private static final Map<String, Material> MATERIALS_BY_ALIAS = new HashMap<String, Material>();
private static final Map<String, Material> MATERIALS_BY_ALIAS = new HashMap<>();
// Materials that are considered air (with 1.13+ compatibility)
private static final Collection<Material> AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR");

View File

@ -64,7 +64,7 @@ public final class Utils {
BufferedReader br = null;
try {
List<String> lines = newArrayList();
List<String> lines = new ArrayList<>();
if (!file.exists()) {
throw new FileNotFoundException();
@ -89,18 +89,6 @@ public final class Utils {
}
}
public static <T> Set<T> newHashSet() {
return new HashSet<T>();
}
public static <T, V> Map<T, V> newHashMap() {
return new HashMap<T, V>();
}
public static <T> List<T> newArrayList() {
return new ArrayList<T>();
}
public static boolean isClassLoaded(String name) {
try {
Class.forName(name);

View File

@ -19,8 +19,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.test.skip>true</maven.test.skip>
<spigot-api.version>1.8.8-R0.1-SNAPSHOT</spigot-api.version>
</properties>