From 581dd69f38051e029ec13fd81ea9fe0a7911ad68 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 27 May 2016 19:31:05 +0200 Subject: [PATCH] Use Java 7 Language Level --- src/com/dre/brewery/BCauldron.java | 2 +- src/com/dre/brewery/BIngredients.java | 14 ++++++------ src/com/dre/brewery/BPlayer.java | 6 ++--- src/com/dre/brewery/BRecipe.java | 6 ++--- src/com/dre/brewery/Barrel.java | 8 +++---- src/com/dre/brewery/Brew.java | 13 +++++------ src/com/dre/brewery/P.java | 6 +++-- src/com/dre/brewery/Wakeup.java | 7 +++--- src/com/dre/brewery/Words.java | 22 ++++++------------- .../dre/brewery/filedata/ConfigUpdater.java | 2 +- src/com/dre/brewery/filedata/DataSave.java | 2 +- src/com/dre/brewery/filedata/DataUpdater.java | 4 ++-- .../dre/brewery/filedata/LanguageReader.java | 5 +++-- src/com/dre/brewery/filedata/ReadOldData.java | 1 + .../brewery/integration/LogBlockBarrel.java | 2 +- src/com/dre/brewery/integration/WGBarrel.java | 2 +- .../brewery/listeners/CommandListener.java | 2 +- .../brewery/listeners/InventoryListener.java | 4 ++-- 18 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 79c8781..03421ce 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -13,7 +13,7 @@ import org.bukkit.material.Cauldron; import org.bukkit.material.MaterialData; public class BCauldron { - public static CopyOnWriteArrayList bcauldrons = new CopyOnWriteArrayList(); + public static CopyOnWriteArrayList bcauldrons = new CopyOnWriteArrayList<>(); private BIngredients ingredients = new BIngredients(); private Block block; diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index a475a31..5320215 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -9,14 +9,14 @@ import org.bukkit.potion.PotionEffectType; import java.util.*; public class BIngredients { - public static Set possibleIngredients = new HashSet(); - public static ArrayList recipes = new ArrayList(); - public static Map cookedNames = new HashMap(); + public static Set possibleIngredients = new HashSet<>(); + public static ArrayList recipes = new ArrayList<>(); + public static Map cookedNames = new HashMap<>(); private static int lastId = 0; private int id; - private ArrayList ingredients = new ArrayList(); - private Map materials = new HashMap(); // Merged List Of ingredients that doesnt consider Durability + private ArrayList ingredients = new ArrayList<>(); + private Map materials = new HashMap<>(); // Merged List Of ingredients that doesnt consider Durability private int cookedTime; // Represents ingredients in Cauldron, Brew @@ -225,7 +225,7 @@ public class BIngredients { // when ingredients are not complete return -1; } - ArrayList mergedChecked = new ArrayList(); + ArrayList mergedChecked = new ArrayList<>(); for (ItemStack ingredient : ingredients) { if (mergedChecked.contains(ingredient.getType())) { // This ingredient type was already checked as part of a merged material @@ -334,7 +334,7 @@ public class BIngredients { //convert the ingredient Material to String public Map serializeIngredients() { - Map mats = new HashMap(); + Map mats = new HashMap<>(); for (ItemStack item : ingredients) { String mat = item.getType().name() + "," + item.getDurability(); mats.put(mat, item.getAmount()); diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 00934d8..8a7ffea 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -18,12 +18,12 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; public class BPlayer { - private static Map players = new HashMap();// Players name/uuid and BPlayer - private static Map pTasks = new HashMap();// Player and count + private static Map players = new HashMap<>();// Players name/uuid and BPlayer + private static Map pTasks = new HashMap<>();// Player and count private static int taskId; // Settings - public static Map drainItems = new HashMap();// DrainItem Material and Strength + public static Map drainItems = new HashMap<>();// DrainItem Material and Strength public static Material pukeItem; public static int hangoverTime; public static boolean overdrinkKick; diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index 09e26a0..d75f51c 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -12,7 +12,7 @@ import java.util.List; public class BRecipe { private String[] name; - private ArrayList ingredients = new ArrayList();// material and amount + private ArrayList ingredients = new ArrayList<>();// material and amount private int cookingTime;// time to cook in cauldron private int distillruns;// runs through the brewer private byte wood;// type of wood the barrel has to consist of @@ -20,7 +20,7 @@ public class BRecipe { private String color;// color of the destilled/finished potion private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed private int alcohol;// Alcohol in perfect potion - private ArrayList effects = new ArrayList(); // Special Effects when drinking + private ArrayList effects = new ArrayList<>(); // Special Effects when drinking public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) { String nameList = configSectionRecipes.getString(recipeId + ".name"); @@ -244,7 +244,7 @@ public class BRecipe { int uid = Brew.generateUID(); - ArrayList list = new ArrayList(ingredients.size()); + ArrayList list = new ArrayList<>(ingredients.size()); for (ItemStack item : ingredients) { if (item.getDurability() == -1) { list.add(new ItemStack(item.getType(), item.getAmount())); diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index a247ea6..3491cbb 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -29,7 +29,7 @@ import org.apache.commons.lang.ArrayUtils; public class Barrel implements InventoryHolder { - public static CopyOnWriteArrayList barrels = new CopyOnWriteArrayList(); + public static CopyOnWriteArrayList barrels = new CopyOnWriteArrayList<>(); private static int check = 0; private Block spigot; @@ -766,7 +766,7 @@ public class Barrel implements InventoryHolder { int endX; int endZ; - ArrayList stairs = new ArrayList(); + ArrayList stairs = new ArrayList<>(); if (direction == 1) { startX = 1; @@ -839,8 +839,8 @@ public class Barrel implements InventoryHolder { int endX; int endZ; - ArrayList stairs = new ArrayList(); - ArrayList woods = new ArrayList(); + ArrayList stairs = new ArrayList<>(); + ArrayList woods = new ArrayList<>(); if (direction == 1) { startX = 1; diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index daa4fae..403c4d1 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -20,7 +20,7 @@ public class Brew { // represents the liquid in the brewed Potions - public static Map potions = new HashMap(); + public static Map potions = new HashMap<>(); public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch public static Boolean colorInBarrels; // color the Lore while in Barrels public static Boolean colorInBrewer; // color the Lore while in Brewer @@ -150,10 +150,7 @@ public class Brew { } public boolean reloadRecipe() { - if (currentRecipe != null) { - return setRecipeFromString(currentRecipe.getName(5)); - } - return true; + return currentRecipe == null || setRecipeFromString(currentRecipe.getName(5)); } // Copy a Brew with a new unique ID and return its item @@ -573,7 +570,7 @@ public class Brew { meta.setLore(existingLore); return; } - List newLore = new ArrayList(); + List newLore = new ArrayList<>(); newLore.add(""); newLore.add(prefix + lore); meta.setLore(newLore); @@ -674,7 +671,7 @@ public class Brew { } } - public static enum PotionColor { + public enum PotionColor { PINK(1, PotionType.REGEN), CYAN(2, PotionType.SPEED), ORANGE(3, PotionType.FIRE_RESISTANCE), @@ -691,7 +688,7 @@ public class Brew { private final int colorId; private final PotionType type; - private PotionColor(int colorId, PotionType type) { + PotionColor(int colorId, PotionType type) { this.colorId = colorId; this.type = type; } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 4d6b51c..a6e1635 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -389,7 +389,7 @@ public class P extends JavaPlugin { } // loading Ingredients into ingMap - Map ingMap = new HashMap(); + Map ingMap = new HashMap<>(); ConfigurationSection section = data.getConfigurationSection("Ingredients"); if (section != null) { for (String id : section.getKeys(false)) { @@ -430,6 +430,7 @@ public class P extends JavaPlugin { // keys have players name for (String name : section.getKeys(false)) { try { + //noinspection ResultOfMethodCallIgnored UUID.fromString(name); if (!useUUID) { continue; @@ -462,7 +463,7 @@ public class P extends JavaPlugin { } public ArrayList deserializeIngredients(ConfigurationSection matSection) { - ArrayList ingredients = new ArrayList(); + ArrayList ingredients = new ArrayList<>(); for (String mat : matSection.getKeys(false)) { String[] matSplit = mat.split(","); ItemStack item = new ItemStack(Material.getMaterial(matSplit[0]), matSection.getInt(mat)); @@ -763,6 +764,7 @@ public class P extends JavaPlugin { return msg; } + @SuppressWarnings("ResultOfMethodCallIgnored") public static void saveFile(InputStream in, File dest, String name) throws IOException { if (in == null) return; if (!dest.exists()) { diff --git a/src/com/dre/brewery/Wakeup.java b/src/com/dre/brewery/Wakeup.java index af20fea..03c66b6 100644 --- a/src/com/dre/brewery/Wakeup.java +++ b/src/com/dre/brewery/Wakeup.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; public class Wakeup { - public static ArrayList wakeups = new ArrayList(); + public static ArrayList wakeups = new ArrayList<>(); public static P p = P.p; public static int checkId = -1; public static Player checkPlayer = null; @@ -28,7 +28,7 @@ public class Wakeup { return null; } - ArrayList worldWakes = new ArrayList(); + ArrayList worldWakes = new ArrayList<>(); for (Wakeup wakeup : wakeups) { if (wakeup.active) { @@ -44,6 +44,7 @@ public class Wakeup { Wakeup w1 = calcRandom(worldWakes); worldWakes.remove(w1); + if (w1 == null) return null; while (!w1.check()) { p.errorLog("Please Check Wakeup-Location with id: &6" + wakeups.indexOf(w1)); @@ -119,7 +120,7 @@ public class Wakeup { return; } - ArrayList locs = new ArrayList(); + ArrayList locs = new ArrayList<>(); for (int id = 0; id < wakeups.size(); id++) { Wakeup wakeup = wakeups.get(id); diff --git a/src/com/dre/brewery/Words.java b/src/com/dre/brewery/Words.java index 2e7c20b..d9e4610 100644 --- a/src/com/dre/brewery/Words.java +++ b/src/com/dre/brewery/Words.java @@ -15,13 +15,13 @@ public class Words { // represends Words and letters, that are replaced in drunk players messages - public static ArrayList words = new ArrayList(); + public static ArrayList words = new ArrayList<>(); public static List commands; - public static List ignoreText = new ArrayList(); + public static List ignoreText = new ArrayList<>(); public static FileConfiguration config; public static Boolean doSigns; public static Boolean log; - private static Map waitPlayers = new HashMap(); + private static Map waitPlayers = new HashMap<>(); private String from; private String to; @@ -270,18 +270,10 @@ public class Words { boolean isBefore = !match; if (pre != null) { for (String pr : pre) { - if (match) { - // if one is correct, it is enough - if (part.endsWith(pr) == match) { - isBefore = true; - break; - } - } else { - // if one is wrong, its over - if (part.endsWith(pr) != match) { - isBefore = false; - break; - } + if (part.endsWith(pr)) { + // If a match is wanted set isBefore to true, else to false + isBefore = match; + break; } } } else { diff --git a/src/com/dre/brewery/filedata/ConfigUpdater.java b/src/com/dre/brewery/filedata/ConfigUpdater.java index c5f37d8..7792bb6 100644 --- a/src/com/dre/brewery/filedata/ConfigUpdater.java +++ b/src/com/dre/brewery/filedata/ConfigUpdater.java @@ -13,7 +13,7 @@ import com.dre.brewery.P; public class ConfigUpdater { - private ArrayList config = new ArrayList(); + private ArrayList config = new ArrayList<>(); private File file; public ConfigUpdater(File file) { diff --git a/src/com/dre/brewery/filedata/DataSave.java b/src/com/dre/brewery/filedata/DataSave.java index ea7507f..f9d212c 100644 --- a/src/com/dre/brewery/filedata/DataSave.java +++ b/src/com/dre/brewery/filedata/DataSave.java @@ -54,7 +54,7 @@ public class DataSave extends BukkitRunnable { } try { cancel(); - } catch (IllegalStateException e) { + } catch (IllegalStateException ignored) { } FileConfiguration configFile = new YamlConfiguration(); diff --git a/src/com/dre/brewery/filedata/DataUpdater.java b/src/com/dre/brewery/filedata/DataUpdater.java index 52d4db7..b76de94 100644 --- a/src/com/dre/brewery/filedata/DataUpdater.java +++ b/src/com/dre/brewery/filedata/DataUpdater.java @@ -51,7 +51,7 @@ public class DataUpdater { ConfigurationSection matSection = section.getConfigurationSection(id + ".mats"); if (matSection != null) { // matSection has all the materials + amount as Integers - Map ingredients = new HashMap(); + Map ingredients = new HashMap<>(); for (String ingredient : matSection.getKeys(false)) { // convert to Material Material mat = Material.getMaterial(P.p.parseInt(ingredient)); @@ -81,7 +81,7 @@ public class DataUpdater { ConfigurationSection ingredientSection = cauldrons.getConfigurationSection(id + ".ingredients"); if (ingredientSection != null) { // has all the materials + amount as Integers - Map ingredients = new HashMap(); + Map ingredients = new HashMap<>(); for (String ingredient : ingredientSection.getKeys(false)) { // convert to Material Material mat = Material.getMaterial(P.p.parseInt(ingredient)); diff --git a/src/com/dre/brewery/filedata/LanguageReader.java b/src/com/dre/brewery/filedata/LanguageReader.java index f8b5d4a..69cfc12 100644 --- a/src/com/dre/brewery/filedata/LanguageReader.java +++ b/src/com/dre/brewery/filedata/LanguageReader.java @@ -10,8 +10,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; public class LanguageReader { - private Map entries = new TreeMap(); - private Map defaults = new TreeMap(); + private Map entries = new TreeMap<>(); + private Map defaults = new TreeMap<>(); private File file; private boolean changed; @@ -143,6 +143,7 @@ public class LanguageReader { } } + @SuppressWarnings("ResultOfMethodCallIgnored") public void save() { if (changed) { /* Copy old File */ diff --git a/src/com/dre/brewery/filedata/ReadOldData.java b/src/com/dre/brewery/filedata/ReadOldData.java index 2396ca2..ef04b7e 100644 --- a/src/com/dre/brewery/filedata/ReadOldData.java +++ b/src/com/dre/brewery/filedata/ReadOldData.java @@ -14,6 +14,7 @@ public class ReadOldData extends BukkitRunnable { public FileConfiguration data; public boolean done = false; + @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void run() { File datafile = new File(P.p.getDataFolder(), "data.yml"); diff --git a/src/com/dre/brewery/integration/LogBlockBarrel.java b/src/com/dre/brewery/integration/LogBlockBarrel.java index d604e0a..be0406d 100644 --- a/src/com/dre/brewery/integration/LogBlockBarrel.java +++ b/src/com/dre/brewery/integration/LogBlockBarrel.java @@ -17,7 +17,7 @@ import static de.diddiz.util.BukkitUtils.compressInventory; import static de.diddiz.util.BukkitUtils.rawData; public class LogBlockBarrel { - private static final List opened = new ArrayList(); + private static final List opened = new ArrayList<>(); public static Consumer consumer = LogBlock.getInstance().getConsumer(); private HumanEntity player; diff --git a/src/com/dre/brewery/integration/WGBarrel.java b/src/com/dre/brewery/integration/WGBarrel.java index eb282e4..25e29b9 100644 --- a/src/com/dre/brewery/integration/WGBarrel.java +++ b/src/com/dre/brewery/integration/WGBarrel.java @@ -5,5 +5,5 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public interface WGBarrel { - public abstract boolean checkAccess(Player player, Block spigot, Plugin plugin); + boolean checkAccess(Player player, Block spigot, Plugin plugin); } diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 12b7731..c6a240b 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -163,7 +163,7 @@ public class CommandListener implements CommandExecutor { public ArrayList getCommands(CommandSender sender) { - ArrayList cmds = new ArrayList(); + ArrayList cmds = new ArrayList<>(); cmds.add(p.languageReader.get("Help_Help")); if (sender.hasPermission("brewery.cmd.player")) { diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index f8ae8d2..bc56e5e 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -40,8 +40,8 @@ import java.util.UUID; public class InventoryListener implements Listener { /* === Recreating manually the prior BrewEvent behavior. === */ - private HashSet trackedBrewmen = new HashSet(); - private HashMap trackedBrewers = new HashMap(); + private HashSet trackedBrewmen = new HashSet<>(); + private HashMap trackedBrewers = new HashMap<>(); private static final int DISTILLTIME = 401; /**