From 4c77944eb8e8803fe772295b629fff86c5419680 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 8 Nov 2019 16:22:58 +0100 Subject: [PATCH] Find more suitable Data Structures --- src/com/dre/brewery/BCauldron.java | 50 ++--- src/com/dre/brewery/BIngredients.java | 33 ++- src/com/dre/brewery/BPlayer.java | 26 +-- src/com/dre/brewery/Barrel.java | 9 +- src/com/dre/brewery/Brew.java | 4 +- src/com/dre/brewery/DistortChat.java | 4 +- src/com/dre/brewery/P.java | 10 +- src/com/dre/brewery/Wakeup.java | 3 +- src/com/dre/brewery/filedata/BConfig.java | 4 +- .../dre/brewery/filedata/LanguageReader.java | 208 +++++++++--------- .../dre/brewery/listeners/EntityListener.java | 6 +- src/com/dre/brewery/lore/BrewLore.java | 2 +- .../dre/brewery/recipe/BCauldronRecipe.java | 1 - src/com/dre/brewery/recipe/BRecipe.java | 5 +- .../{utility => recipe}/PotionColor.java | 2 +- src/com/dre/brewery/utility/BoundingBox.java | 7 +- src/com/dre/brewery/utility/LegacyUtil.java | 14 +- 17 files changed, 191 insertions(+), 197 deletions(-) rename src/com/dre/brewery/{utility => recipe}/PotionColor.java (99%) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index b8558f2..148589c 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -16,16 +16,18 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.CopyOnWriteArrayList; public class BCauldron { public static final byte EMPTY = 0, SOME = 1, FULL = 2; private static Set plInteracted = new HashSet<>(); - public static CopyOnWriteArrayList bcauldrons = new CopyOnWriteArrayList<>(); // TODO find best Collection + public static Map bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve private BIngredients ingredients = new BIngredients(); private final Block block; @@ -34,7 +36,7 @@ public class BCauldron { public BCauldron(Block block) { this.block = block; - bcauldrons.add(this); + bcauldrons.put(block, this); } // loading from file @@ -42,7 +44,7 @@ public class BCauldron { this.block = block; this.state = state; this.ingredients = ingredients; - bcauldrons.add(this); + bcauldrons.put(block, this); } public void onUpdate() { @@ -73,13 +75,9 @@ public class BCauldron { } // get cauldron by Block + @Nullable public static BCauldron get(Block block) { - for (BCauldron bcauldron : bcauldrons) { - if (bcauldron.block.equals(block)) { - return bcauldron; - } - } - return null; + return bcauldrons.get(block); } // get cauldron from block and add given ingredient @@ -87,10 +85,6 @@ public class BCauldron { public static boolean ingredientAdd(Block block, ItemStack ingredient, Player player) { // if not empty if (LegacyUtil.getFillLevel(block) != EMPTY) { - BCauldron bcauldron = get(block); - if (bcauldron == null) { - bcauldron = new BCauldron(block); - } if (!BCauldronRecipe.acceptedMaterials.contains(ingredient.getType()) && !ingredient.hasItemMeta()) { // Extremely fast way to check for most items @@ -102,10 +96,16 @@ public class BCauldron { return false; } + BCauldron bcauldron = get(block); + if (bcauldron == null) { + bcauldron = new BCauldron(block); + } + IngedientAddEvent event = new IngedientAddEvent(player, block, bcauldron, ingredient.clone(), rItem); P.p.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { bcauldron.add(event.getIngredient(), event.getRecipeItem()); + //P.p.debugLog("Cauldron add: t2 " + ((t2 - t1) / 1000) + " t3: " + ((t3 - t2) / 1000) + " t4: " + ((t4 - t3) / 1000) + " t5: " + ((t5 - t4) / 1000) + "µs"); return event.willTakeItem(); } else { return false; @@ -127,7 +127,7 @@ public class BCauldron { BlockData data = block.getBlockData(); Levelled cauldron = ((Levelled) data); if (cauldron.getLevel() <= 0) { - bcauldrons.remove(this); + bcauldrons.remove(block); return false; } cauldron.setLevel(cauldron.getLevel() - 1); @@ -137,7 +137,7 @@ public class BCauldron { block.setBlockData(data); if (cauldron.getLevel() <= 0) { - bcauldrons.remove(this); + bcauldrons.remove(block); } else { changed = true; } @@ -147,14 +147,14 @@ public class BCauldron { if (data > 3) { data = 3; } else if (data <= 0) { - bcauldrons.remove(this); + bcauldrons.remove(block); return false; } data -= 1; LegacyUtil.setData(block, data); if (data == 0) { - bcauldrons.remove(this); + bcauldrons.remove(block); } else { changed = true; } @@ -303,11 +303,7 @@ public class BCauldron { // reset to normal cauldron public static boolean remove(Block block) { if (LegacyUtil.getFillLevel(block) != EMPTY) { - BCauldron bcauldron = get(block); - if (bcauldron != null) { - bcauldrons.remove(bcauldron); - return true; - } + return bcauldrons.remove(block) != null; } return false; } @@ -315,11 +311,7 @@ public class BCauldron { // unloads cauldrons that are in a unloading world // as they were written to file just before, this is safe to do public static void onUnload(String name) { - for (BCauldron bcauldron : bcauldrons) { - if (bcauldron.block.getWorld().getName().equals(name)) { - bcauldrons.remove(bcauldron); - } - } + bcauldrons.keySet().removeIf(block -> block.getWorld().getName().equals(name)); } public static void save(ConfigurationSection config, ConfigurationSection oldData) { @@ -327,7 +319,7 @@ public class BCauldron { if (!bcauldrons.isEmpty()) { int id = 0; - for (BCauldron cauldron : bcauldrons) { + for (BCauldron cauldron : bcauldrons.values()) { String worldName = cauldron.block.getWorld().getName(); String prefix; diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index e301a52..721cb37 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -8,7 +8,7 @@ import com.dre.brewery.recipe.BRecipe; import com.dre.brewery.recipe.Ingredient; import com.dre.brewery.recipe.ItemLoader; import com.dre.brewery.recipe.RecipeItem; -import com.dre.brewery.utility.PotionColor; +import com.dre.brewery.recipe.PotionColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; @@ -22,6 +22,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +/** + * Represents ingredients in Cauldron, Brew + */ public class BIngredients { private static int lastId = 0; // Legacy @@ -29,14 +32,17 @@ public class BIngredients { private List ingredients = new ArrayList<>(); private int cookedTime; - // Represents ingredients in Cauldron, Brew - // Init a new BIngredients + /** + * Init a new BIngredients + */ public BIngredients() { //this.id = lastId; //lastId++; } - // Load from File + /** + * Load from File + */ public BIngredients(List ingredients, int cookedTime) { this.ingredients = ingredients; this.cookedTime = cookedTime; @@ -44,7 +50,9 @@ public class BIngredients { //lastId++; } - // Load from legacy Brew section + /** + * Load from legacy Brew section + */ public BIngredients(List ingredients, int cookedTime, boolean legacy) { this(ingredients, cookedTime); if (legacy) { @@ -53,8 +61,12 @@ public class BIngredients { } } - // Force add an ingredient to this - // Will not check if item is acceptable + /** + * Force add an ingredient to this + * Will not check if item is acceptable + * + * @param ingredient the item to add + */ public void add(ItemStack ingredient) { for (Ingredient existing : ingredients) { if (existing.matches(ingredient)) { @@ -68,7 +80,12 @@ public class BIngredients { ingredients.add(ing); } - // Add an ingredient to this with corresponding RecipeItem + /** + * Add an ingredient to this with corresponding RecipeItem + * + * @param ingredient the item to add + * @param rItem the RecipeItem that matches the ingredient + */ public void add(ItemStack ingredient, RecipeItem rItem) { Ingredient ingredientItem = rItem.toIngredient(ingredient); for (Ingredient existing : ingredients) { diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index cecfcc5..0e8a338 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -35,7 +35,7 @@ public class BPlayer { private static int taskId; private static boolean modAge = true; private static Random pukeRand; - private static Method gh; + private static Method itemHandle; private static Field age; private int quality = 0;// = quality of drunkeness * drunkeness @@ -326,11 +326,7 @@ public class BPlayer { return; } // delayed login event as the player is not fully accessible pre login - P.p.getServer().getScheduler().runTaskLater(P.p, new Runnable() { - public void run() { - login(player); - } - }, 1L); + P.p.getServer().getScheduler().runTaskLater(P.p, () -> login(player), 1L); } // he may be having a hangover @@ -390,11 +386,11 @@ public class BPlayer { public void drunkPuke(Player player) { if (drunkeness >= 80) { if (drunkeness >= 90) { - if (Math.random() < 0.15 - (getQuality() / 100)) { + if (Math.random() < 0.15f - (getQuality() / 100f)) { addPuke(player, 20 + (int) (Math.random() * 40)); } } else { - if (Math.random() < 0.08 - (getQuality() / 100)) { + if (Math.random() < 0.08f - (getQuality() / 100f)) { addPuke(player, 10 + (int) (Math.random() * 30)); } } @@ -414,11 +410,7 @@ public class BPlayer { } if (pTasks.isEmpty()) { - taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, new Runnable() { - public void run() { - pukeTask(); - } - }, 1L, 1L); + taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, BPlayer::pukeTask, 1L, 1L); } pTasks.put(player, new MutableInt(event.getCount())); } @@ -466,10 +458,10 @@ public class BPlayer { return; } try { - if (gh == null) { - gh = Class.forName(P.p.getServer().getClass().getPackage().getName() + ".entity.CraftItem").getMethod("getHandle", (Class[]) null); + if (itemHandle == null) { + itemHandle = Class.forName(P.p.getServer().getClass().getPackage().getName() + ".entity.CraftItem").getMethod("getHandle", (Class[]) null); } - Object entityItem = gh.invoke(item, (Object[]) null); + Object entityItem = itemHandle.invoke(item, (Object[]) null); if (age == null) { age = entityItem.getClass().getDeclaredField("age"); age.setAccessible(true); @@ -592,7 +584,7 @@ public class BPlayer { } public static void addBrewEffects(Brew brew, Player player) { - ArrayList effects = brew.getEffects(); + List effects = brew.getEffects(); if (effects != null) { for (BEffect effect : effects) { effect.apply(brew.getQuality(), player); diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 7f06861..3178f3d 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -30,11 +30,10 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; public class Barrel implements InventoryHolder { - public static CopyOnWriteArrayList barrels = new CopyOnWriteArrayList<>(); // TODO find best collection + public static List barrels = new ArrayList<>(); private static int check = 0; private final Block spigot; @@ -407,11 +406,7 @@ public class Barrel implements InventoryHolder { //unloads barrels that are in a unloading world public static void onUnload(String name) { - for (Barrel barrel : barrels) { - if (barrel.spigot.getWorld().getName().equals(name)) { - barrels.remove(barrel); - } - } + barrels.removeIf(barrel -> barrel.spigot.getWorld().getName().equals(name)); } // Saves all data diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index b882c63..45c383a 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -6,7 +6,7 @@ import com.dre.brewery.filedata.ConfigUpdater; import com.dre.brewery.lore.*; import com.dre.brewery.recipe.BEffect; import com.dre.brewery.recipe.BRecipe; -import com.dre.brewery.utility.PotionColor; +import com.dre.brewery.recipe.PotionColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.BrewerInventory; @@ -360,7 +360,7 @@ public class Brew { } // return special effect - public ArrayList getEffects() { + public List getEffects() { if (currentRecipe != null && quality > 0) { return currentRecipe.getEffects(); } diff --git a/src/com/dre/brewery/DistortChat.java b/src/com/dre/brewery/DistortChat.java index eb0f2c9..9fb091e 100644 --- a/src/com/dre/brewery/DistortChat.java +++ b/src/com/dre/brewery/DistortChat.java @@ -13,7 +13,7 @@ public class DistortChat { // represends Words and letters, that are replaced in drunk players messages - public static ArrayList words = new ArrayList<>(); + public static List words = new ArrayList<>(); public static List commands; public static List ignoreText = new ArrayList<>(); public static Boolean doSigns; @@ -164,6 +164,8 @@ public class DistortChat { // distorts a message without checking ignoreText letters private static String distortString(String message, int drunkeness) { if (message.length() > 1) { + // Create our own reference to the words list, in case of config reload + List words = DistortChat.words; for (DistortChat word : words) { if (word.alcohol <= drunkeness) { message = word.distort(message); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index ca744a9..f7715b8 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -436,9 +436,6 @@ public class P extends JavaPlugin { // save Data to Disk DataSave.save(true); - // save LanguageReader - languageReader.save(); - // delete Data from Ram Barrel.barrels.clear(); BCauldron.bcauldrons.clear(); @@ -473,8 +470,6 @@ public class P extends JavaPlugin { BConfig.customItems.clear(); BConfig.hasSlimefun = null; BConfig.hasMMOItems = null; - DistortChat.words.clear(); - DistortChat.ignoreText.clear(); DistortChat.commands = null; BConfig.drainItems.clear(); if (BConfig.useLB) { @@ -499,8 +494,7 @@ public class P extends JavaPlugin { return; } - // save and load LanguageReader - languageReader.save(); + // load LanguageReader languageReader = new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml")); // Reload Recipes @@ -563,7 +557,7 @@ public class P extends JavaPlugin { @Override public void run() { BConfig.reloader = null; - for (BCauldron cauldron : BCauldron.bcauldrons) { + for (BCauldron cauldron : BCauldron.bcauldrons.values()) { cauldron.onUpdate();// runs every min to update cooking time } Barrel.onUpdate();// runs every min to check and update ageing time diff --git a/src/com/dre/brewery/Wakeup.java b/src/com/dre/brewery/Wakeup.java index 371d169..46e2906 100644 --- a/src/com/dre/brewery/Wakeup.java +++ b/src/com/dre/brewery/Wakeup.java @@ -8,10 +8,11 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; public class Wakeup { - public static ArrayList wakeups = new ArrayList<>(); + public static List wakeups = new ArrayList<>(); public static P p = P.p; public static int checkId = -1; public static Player checkPlayer = null; diff --git a/src/com/dre/brewery/filedata/BConfig.java b/src/com/dre/brewery/filedata/BConfig.java index 8d6e60a..c38349e 100644 --- a/src/com/dre/brewery/filedata/BConfig.java +++ b/src/com/dre/brewery/filedata/BConfig.java @@ -22,8 +22,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -274,6 +272,8 @@ public class BConfig { } // Loading Words + DistortChat.words = new ArrayList<>(); + DistortChat.ignoreText = new ArrayList<>(); if (config.getBoolean("enableChatDistortion", false)) { for (Map map : config.getMapList("words")) { new DistortChat(map); diff --git a/src/com/dre/brewery/filedata/LanguageReader.java b/src/com/dre/brewery/filedata/LanguageReader.java index b523be9..bd44779 100644 --- a/src/com/dre/brewery/filedata/LanguageReader.java +++ b/src/com/dre/brewery/filedata/LanguageReader.java @@ -2,22 +2,24 @@ package com.dre.brewery.filedata; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; +import com.dre.brewery.utility.Tuple; 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 HashMap<>(128); private File file; private boolean changed; public LanguageReader(File file) { - this.setDefaults(); + List> defaults = getDefaults(); /* Load */ this.file = file; @@ -30,126 +32,132 @@ public class LanguageReader { } /* Check */ - this.check(); + check(defaults); + if (changed) { + save(); + } } - private void setDefaults() { + private List> getDefaults() { + List> defaults = new ArrayList<>(128); /* Player */ - defaults.put("Player_BarrelCreated", "Barrel created"); - defaults.put("Player_BarrelFull", "&cThis barrel can''t hold any more drinks"); - defaults.put("Player_CauldronInfo1", "This cauldron has been boiling for &v1 minutes."); - defaults.put("Player_CauldronInfo2", "This cauldron has just started boiling."); - defaults.put("Player_CantDrink", "You can't drink any more."); - defaults.put("Player_DrunkPassOut", "You drank too much and passed out."); - defaults.put("Player_LoginDeny", "Your character tries to log in, but is too drunk to find the server. Try again!"); - defaults.put("Player_LoginDenyLong", "Your character is really drunk and has passed out. Try again in 10 minutes!"); - defaults.put("Player_Wake", "Ohh no! I cannot remember how I got here..."); - defaults.put("Player_WakeCreated", "&aWakeup Point with id: &6&v1 &awas created successfully!"); - defaults.put("Player_WakeNotExist", "&cThe Wakeup Point with the id: &6&v1 &cdoesn't exist!"); - defaults.put("Player_WakeDeleted", "&aThe Wakeup Point with the id: &6&v1 &awas successfully deleted!"); - defaults.put("Player_WakeAlreadyDeleted", "&cThe Wakeup Point with the id: &6&v1 &chas already been deleted!"); - defaults.put("Player_WakeFilled", "&cThe Wakeup Point with the id: &6&v1&c at position &6&v2 &v3, &v4, &v5&c is filled with Blocks!"); - defaults.put("Player_WakeNoPoints", "&cThere are no Wakeup Points!"); - defaults.put("Player_WakeLast", "&aThis was the last Wakeup Point"); - defaults.put("Player_WakeTeleport", "Teleport to Wakeup Point with the id: &6&v1&f At position: &6&v2 &v3, &v4, &v5"); - defaults.put("Player_WakeHint1", "To Next Wakeup Point: Punch your fist in the air"); - defaults.put("Player_WakeHint2", "To Cancel: &9/br wakeup cancel"); - defaults.put("Player_WakeCancel", "&6Wakeup Point Check was cancelled"); - defaults.put("Player_WakeNoCheck", "&cNo Wakeup Point Check is currently active"); - defaults.put("Player_TriedToSay", "&v1 tried to say: &0&v2"); + defaults.add(new Tuple<>("Player_BarrelCreated", "Barrel created")); + defaults.add(new Tuple<>("Player_BarrelFull", "&cThis barrel can''t hold any more drinks")); + defaults.add(new Tuple<>("Player_CauldronInfo1", "This cauldron has been boiling for &v1 minutes.")); + defaults.add(new Tuple<>("Player_CauldronInfo2", "This cauldron has just started boiling.")); + defaults.add(new Tuple<>("Player_CantDrink", "You can't drink any more.")); + defaults.add(new Tuple<>("Player_DrunkPassOut", "You drank too much and passed out.")); + defaults.add(new Tuple<>("Player_LoginDeny", "Your character tries to log in, but is too drunk to find the server. Try again!")); + defaults.add(new Tuple<>("Player_LoginDenyLong", "Your character is really drunk and has passed out. Try again in 10 minutes!")); + defaults.add(new Tuple<>("Player_Wake", "Ohh no! I cannot remember how I got here...")); + defaults.add(new Tuple<>("Player_WakeCreated", "&aWakeup Point with id: &6&v1 &awas created successfully!")); + defaults.add(new Tuple<>("Player_WakeNotExist", "&cThe Wakeup Point with the id: &6&v1 &cdoesn't exist!")); + defaults.add(new Tuple<>("Player_WakeDeleted", "&aThe Wakeup Point with the id: &6&v1 &awas successfully deleted!")); + defaults.add(new Tuple<>("Player_WakeAlreadyDeleted", "&cThe Wakeup Point with the id: &6&v1 &chas already been deleted!")); + defaults.add(new Tuple<>("Player_WakeFilled", "&cThe Wakeup Point with the id: &6&v1&c at position &6&v2 &v3, &v4, &v5&c is filled with Blocks!")); + defaults.add(new Tuple<>("Player_WakeNoPoints", "&cThere are no Wakeup Points!")); + defaults.add(new Tuple<>("Player_WakeLast", "&aThis was the last Wakeup Point")); + defaults.add(new Tuple<>("Player_WakeTeleport", "Teleport to Wakeup Point with the id: &6&v1&f At position: &6&v2 &v3, &v4, &v5")); + defaults.add(new Tuple<>("Player_WakeHint1", "To Next Wakeup Point: Punch your fist in the air")); + defaults.add(new Tuple<>("Player_WakeHint2", "To Cancel: &9/br wakeup cancel")); + defaults.add(new Tuple<>("Player_WakeCancel", "&6Wakeup Point Check was cancelled")); + defaults.add(new Tuple<>("Player_WakeNoCheck", "&cNo Wakeup Point Check is currently active")); + defaults.add(new Tuple<>("Player_TriedToSay", "&v1 tried to say: &0&v2")); /* Brew */ - defaults.put("Brew_Distilled", "Distilled"); - defaults.put("Brew_BarrelRiped", "Barrel aged"); - defaults.put("Brew_Undefined", "Indefinable Brew"); - defaults.put("Brew_DistillUndefined", "Indefinable Distillate"); - defaults.put("Brew_BadPotion", "Ruined Potion"); - defaults.put("Brew_Ingredients", "Ingredients"); - defaults.put("Brew_minute", "minute"); - defaults.put("Brew_MinutePluralPostfix", "s"); - defaults.put("Brew_fermented", "fermented"); - defaults.put("Brew_-times", "-times"); - defaults.put("Brew_OneYear", "One Year"); - defaults.put("Brew_Years", "Years"); - defaults.put("Brew_HundredsOfYears", "Hundreds of Years"); - defaults.put("Brew_Woodtype", "Woodtype"); - defaults.put("Brew_ThickBrew", "Muddy Brew"); - defaults.put("Brew_Alc", "Alc &v1ml"); + defaults.add(new Tuple<>("Brew_Distilled", "Distilled")); + defaults.add(new Tuple<>("Brew_BarrelRiped", "Barrel aged")); + defaults.add(new Tuple<>("Brew_Undefined", "Indefinable Brew")); + defaults.add(new Tuple<>("Brew_DistillUndefined", "Indefinable Distillate")); + defaults.add(new Tuple<>("Brew_BadPotion", "Ruined Potion")); + defaults.add(new Tuple<>("Brew_Ingredients", "Ingredients")); + defaults.add(new Tuple<>("Brew_minute", "minute")); + defaults.add(new Tuple<>("Brew_MinutePluralPostfix", "s")); + defaults.add(new Tuple<>("Brew_fermented", "fermented")); + defaults.add(new Tuple<>("Brew_-times", "-times")); + defaults.add(new Tuple<>("Brew_OneYear", "One Year")); + defaults.add(new Tuple<>("Brew_Years", "Years")); + defaults.add(new Tuple<>("Brew_HundredsOfYears", "Hundreds of Years")); + defaults.add(new Tuple<>("Brew_Woodtype", "Woodtype")); + defaults.add(new Tuple<>("Brew_ThickBrew", "Muddy Brew")); + defaults.add(new Tuple<>("Brew_Alc", "Alc &v1ml")); /* Commands */ - defaults.put("CMD_Reload", "&aConfig was successfully reloaded"); - defaults.put("CMD_Configname", "&aName for the Config is: &f&v1"); - defaults.put("CMD_Configname_Error", "&cCould not find item in your hand"); - defaults.put("CMD_Player", "&a&v1 is now &6&v2% &adrunk, with a quality of &6&v3"); - defaults.put("CMD_Player_Error", "&cThe quality has to be between 1 and 10!"); - defaults.put("CMD_Info_NotDrunk", "&v1 is not drunk"); - defaults.put("CMD_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3"); - defaults.put("CMD_UnLabel", "&aLabel removed!"); - defaults.put("CMD_Persistent", "&aPotion is now Persistent and Static and may now be copied like any other item. You can remove the persistence with the same command."); - defaults.put("CMD_PersistRemove", "&cPersistent Brews cannot be removed from the Database. It would render any copies of them useless!"); - defaults.put("CMD_UnPersist", "&aPersistence and static Removed. &eEvery Potential copy NOT made with '/brew copy' could become useless now!"); - defaults.put("CMD_Copy_Error", "&6&v1 &cPotions did not fit into your inventory"); - defaults.put("CMD_CopyNotPersistent", "&eThese copies of this Brew will not be persistent or static!"); - defaults.put("CMD_Static", "&aPotion is now static and will not change in barrels or brewing stands."); - defaults.put("CMD_NonStatic", "&ePotion is not static anymore and will normally age in barrels."); + defaults.add(new Tuple<>("CMD_Reload", "&aConfig was successfully reloaded")); + defaults.add(new Tuple<>("CMD_Configname", "&aName for the Config is: &f&v1")); + defaults.add(new Tuple<>("CMD_Configname_Error", "&cCould not find item in your hand")); + defaults.add(new Tuple<>("CMD_Player", "&a&v1 is now &6&v2% &adrunk, with a quality of &6&v3")); + defaults.add(new Tuple<>("CMD_Player_Error", "&cThe quality has to be between 1 and 10!")); + defaults.add(new Tuple<>("CMD_Info_NotDrunk", "&v1 is not drunk")); + defaults.add(new Tuple<>("CMD_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3")); + defaults.add(new Tuple<>("CMD_UnLabel", "&aLabel removed!")); + defaults.add(new Tuple<>("CMD_Persistent", "&aPotion is now Persistent and Static and may now be copied like any other item. You can remove the persistence with the same command.")); + defaults.add(new Tuple<>("CMD_PersistRemove", "&cPersistent Brews cannot be removed from the Database. It would render any copies of them useless!")); + defaults.add(new Tuple<>("CMD_UnPersist", "&aPersistence and static Removed. &eEvery Potential copy NOT made with '/brew copy' could become useless now!")); + defaults.add(new Tuple<>("CMD_Copy_Error", "&6&v1 &cPotions did not fit into your inventory")); + defaults.add(new Tuple<>("CMD_CopyNotPersistent", "&eThese copies of this Brew will not be persistent or static!")); + defaults.add(new Tuple<>("CMD_Static", "&aPotion is now static and will not change in barrels or brewing stands.")); + defaults.add(new Tuple<>("CMD_NonStatic", "&ePotion is not static anymore and will normally age in barrels.")); /* Error */ - defaults.put("Error_UnknownCommand", "Unknown Command"); - defaults.put("Error_ShowHelp", "Use &6/brew help &fto display the help"); - defaults.put("Error_PlayerCommand", "&cThis command can only be executed as a player!"); - defaults.put("Error_ItemNotPotion", "&cThe item in your hand could not be identified as a potion!"); - defaults.put("Error_NoBrewName", "&cNo Recipe with Name: '&v1&c' found!"); - defaults.put("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!"); - defaults.put("Error_ConfigUpdate", "Unknown Brewery config version: v&v1, config was not updated!"); - defaults.put("Error_PersistStatic", "&cPersistent potions are always static!"); + defaults.add(new Tuple<>("Error_UnknownCommand", "Unknown Command")); + defaults.add(new Tuple<>("Error_ShowHelp", "Use &6/brew help &fto display the help")); + defaults.add(new Tuple<>("Error_PlayerCommand", "&cThis command can only be executed as a player!")); + defaults.add(new Tuple<>("Error_ItemNotPotion", "&cThe item in your hand could not be identified as a potion!")); + defaults.add(new Tuple<>("Error_NoBrewName", "&cNo Recipe with Name: '&v1&c' found!")); + defaults.add(new Tuple<>("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!")); + defaults.add(new Tuple<>("Error_ConfigUpdate", "Unknown Brewery config version: v&v1, config was not updated!")); + defaults.add(new Tuple<>("Error_PersistStatic", "&cPersistent potions are always static!")); /* Permissions */ - defaults.put("Error_NoPermissions", "&cYou don't have permissions to do this!"); - defaults.put("Error_NoBarrelAccess", "&cYou don't have permissions to access this barrel!"); - defaults.put("Perms_NoBarrelCreate", "&cYou don't have permissions to create barrels!"); - defaults.put("Perms_NoSmallBarrelCreate", "&cYou don't have permissions to create small barrels!"); - defaults.put("Perms_NoBigBarrelCreate", "&cYou don't have permissions to create big barrels!"); - defaults.put("Perms_NoCauldronInsert", "&cYou don't have permissions to put ingredients into cauldrons!"); - defaults.put("Perms_NoCauldronFill", "&cYou don't have permissions to fill bottles from this cauldron!"); + defaults.add(new Tuple<>("Error_NoPermissions", "&cYou don't have permissions to do this!")); + defaults.add(new Tuple<>("Error_NoBarrelAccess", "&cYou don't have permissions to access this barrel!")); + defaults.add(new Tuple<>("Perms_NoBarrelCreate", "&cYou don't have permissions to create barrels!")); + defaults.add(new Tuple<>("Perms_NoSmallBarrelCreate", "&cYou don't have permissions to create small barrels!")); + defaults.add(new Tuple<>("Perms_NoBigBarrelCreate", "&cYou don't have permissions to create big barrels!")); + defaults.add(new Tuple<>("Perms_NoCauldronInsert", "&cYou don't have permissions to put ingredients into cauldrons!")); + defaults.add(new Tuple<>("Perms_NoCauldronFill", "&cYou don't have permissions to fill bottles from this cauldron!")); /* Help */ - defaults.put("Help_Help", "&6/brew help [Page] &9Shows a specific help-page"); - defaults.put("Help_Player", "&6/brew <%Drunkeness> [Quality]&9 Sets Drunkeness (and Quality) of a Player"); - defaults.put("Help_Info", "&6/brew info&9 Displays your current Drunkeness and Quality"); - defaults.put("Help_UnLabel", "&6/brew unlabel &9Removes the detailled label of a potion"); - defaults.put("Help_Copy", "&6/brew copy [Quantity]>&9 Copies the potion in your hand"); - defaults.put("Help_Delete", "&6/brew delete &9Deletes the potion in your hand"); - defaults.put("Help_InfoOther", "&6/brew info [Player]&9 Displays the current Drunkeness and Quality of [Player]"); - defaults.put("Help_Wakeup", "&6/brew wakeup list &9 Lists all wakeup points"); - defaults.put("Help_WakeupList", "&6/brew wakeup list [World]&9 Lists all wakeup points of [world]"); - defaults.put("Help_WakeupCheck", "&6/brew wakeup check &9Teleports to all wakeup points"); - defaults.put("Help_WakeupCheckSpecific", "&6/brew wakeup check &9Teleports to the wakeup point with "); - defaults.put("Help_WakeupAdd", "&6/brew wakeup add &9Adds a wakeup point at your current position"); - defaults.put("Help_WakeupRemove", "&6/brew wakeup remove &9Removes the wakeup point with "); - defaults.put("Help_Reload", "&6/brew reload &9Reload config"); - defaults.put("Help_Configname", "&6/brew ItemName &9Display name of item in hand for the config"); - defaults.put("Help_Persist", "&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique"); - defaults.put("Help_Static", "&6/brew static &9Make Brew static -> No further ageing or distilling"); - defaults.put("Help_Create", "&6/brew create [Quality] [Player] &9Create a Brew with optional quality (1-10)"); + defaults.add(new Tuple<>("Help_Help", "&6/brew help [Page] &9Shows a specific help-page")); + defaults.add(new Tuple<>("Help_Player", "&6/brew <%Drunkeness> [Quality]&9 Sets Drunkeness (and Quality) of a Player")); + defaults.add(new Tuple<>("Help_Info", "&6/brew info&9 Displays your current Drunkeness and Quality")); + defaults.add(new Tuple<>("Help_UnLabel", "&6/brew unlabel &9Removes the detailled label of a potion")); + defaults.add(new Tuple<>("Help_Copy", "&6/brew copy [Quantity]>&9 Copies the potion in your hand")); + defaults.add(new Tuple<>("Help_Delete", "&6/brew delete &9Deletes the potion in your hand")); + defaults.add(new Tuple<>("Help_InfoOther", "&6/brew info [Player]&9 Displays the current Drunkeness and Quality of [Player]")); + defaults.add(new Tuple<>("Help_Wakeup", "&6/brew wakeup list &9 Lists all wakeup points")); + defaults.add(new Tuple<>("Help_WakeupList", "&6/brew wakeup list [World]&9 Lists all wakeup points of [world]")); + defaults.add(new Tuple<>("Help_WakeupCheck", "&6/brew wakeup check &9Teleports to all wakeup points")); + defaults.add(new Tuple<>("Help_WakeupCheckSpecific", "&6/brew wakeup check &9Teleports to the wakeup point with ")); + defaults.add(new Tuple<>("Help_WakeupAdd", "&6/brew wakeup add &9Adds a wakeup point at your current position")); + defaults.add(new Tuple<>("Help_WakeupRemove", "&6/brew wakeup remove &9Removes the wakeup point with ")); + defaults.add(new Tuple<>("Help_Reload", "&6/brew reload &9Reload config")); + defaults.add(new Tuple<>("Help_Configname", "&6/brew ItemName &9Display name of item in hand for the config")); + defaults.add(new Tuple<>("Help_Persist", "&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique")); + defaults.add(new Tuple<>("Help_Static", "&6/brew static &9Make Brew static -> No further ageing or distilling")); + defaults.add(new Tuple<>("Help_Create", "&6/brew create [Quality] [Player] &9Create a Brew with optional quality (1-10)")); /* Etc. */ - defaults.put("Etc_Usage", "Usage:"); - defaults.put("Etc_Page", "Page"); - defaults.put("Etc_Barrel", "Barrel"); + defaults.add(new Tuple<>("Etc_Usage", "Usage:")); + defaults.add(new Tuple<>("Etc_Page", "Page")); + defaults.add(new Tuple<>("Etc_Barrel", "Barrel")); + + return defaults; } - private void check() { - for (String defaultEntry : defaults.keySet()) { - if (!entries.containsKey(defaultEntry)) { - entries.put(defaultEntry, defaults.get(defaultEntry)); + private void check(List> defaults) { + for (Tuple def : defaults) { + if (!entries.containsKey(def.a())) { + entries.put(def.a(), def.b()); changed = true; } } } @SuppressWarnings("ResultOfMethodCallIgnored") - public void save() { + private void save() { if (changed) { /* Copy old File */ File source = new File(file.getPath()); diff --git a/src/com/dre/brewery/listeners/EntityListener.java b/src/com/dre/brewery/listeners/EntityListener.java index 43fde74..ff1c3cb 100644 --- a/src/com/dre/brewery/listeners/EntityListener.java +++ b/src/com/dre/brewery/listeners/EntityListener.java @@ -18,9 +18,9 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.List; import java.util.ListIterator; -import java.util.Set; public class EntityListener implements Listener { @@ -54,7 +54,7 @@ public class EntityListener implements Listener { public void onExplode(EntityExplodeEvent event) { ListIterator iter = event.blockList().listIterator(); if (!iter.hasNext()) return; - Set breakEvents = new HashSet<>(6); + List breakEvents = new ArrayList<>(6); Block block; blocks: while (iter.hasNext()) { block = iter.next(); diff --git a/src/com/dre/brewery/lore/BrewLore.java b/src/com/dre/brewery/lore/BrewLore.java index a7bf2eb..91d76b5 100644 --- a/src/com/dre/brewery/lore/BrewLore.java +++ b/src/com/dre/brewery/lore/BrewLore.java @@ -375,7 +375,7 @@ public class BrewLore { /** * Adds the Effect names to the Items description */ - public void addOrReplaceEffects(ArrayList effects, int quality) { + public void addOrReplaceEffects(List effects, int quality) { if (!P.use1_9 && effects != null) { for (BEffect effect : effects) { if (!effect.isHidden()) { diff --git a/src/com/dre/brewery/recipe/BCauldronRecipe.java b/src/com/dre/brewery/recipe/BCauldronRecipe.java index de8cc6b..534b6e5 100644 --- a/src/com/dre/brewery/recipe/BCauldronRecipe.java +++ b/src/com/dre/brewery/recipe/BCauldronRecipe.java @@ -1,7 +1,6 @@ package com.dre.brewery.recipe; import com.dre.brewery.P; -import com.dre.brewery.utility.PotionColor; import com.dre.brewery.utility.Tuple; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; diff --git a/src/com/dre/brewery/recipe/BRecipe.java b/src/com/dre/brewery/recipe/BRecipe.java index 8d99f42..e35d87d 100644 --- a/src/com/dre/brewery/recipe/BRecipe.java +++ b/src/com/dre/brewery/recipe/BRecipe.java @@ -4,7 +4,6 @@ import com.dre.brewery.BIngredients; import com.dre.brewery.Brew; import com.dre.brewery.P; import com.dre.brewery.filedata.BConfig; -import com.dre.brewery.utility.PotionColor; import com.dre.brewery.utility.Tuple; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -30,7 +29,7 @@ public class BRecipe { private int difficulty; // difficulty to brew the potion, how exact the instruction has to be followed private int alcohol; // Alcohol in perfect potion private List> lore; // Custom Lore on the Potion. The int is for Quality Lore, 0 = any, 1,2,3 = Bad,Middle,Good - private ArrayList effects = new ArrayList<>(); // Special Effects when drinking + private List effects = new ArrayList<>(); // Special Effects when drinking public BRecipe() { } @@ -497,7 +496,7 @@ public class BRecipe { return list; } - public ArrayList getEffects() { + public List getEffects() { return effects; } diff --git a/src/com/dre/brewery/utility/PotionColor.java b/src/com/dre/brewery/recipe/PotionColor.java similarity index 99% rename from src/com/dre/brewery/utility/PotionColor.java rename to src/com/dre/brewery/recipe/PotionColor.java index 2218061..8561ea4 100644 --- a/src/com/dre/brewery/utility/PotionColor.java +++ b/src/com/dre/brewery/recipe/PotionColor.java @@ -1,4 +1,4 @@ -package com.dre.brewery.utility; +package com.dre.brewery.recipe; import com.dre.brewery.P; import org.bukkit.Color; diff --git a/src/com/dre/brewery/utility/BoundingBox.java b/src/com/dre/brewery/utility/BoundingBox.java index e5fe831..a9160b7 100644 --- a/src/com/dre/brewery/utility/BoundingBox.java +++ b/src/com/dre/brewery/utility/BoundingBox.java @@ -5,12 +5,7 @@ import org.bukkit.block.Block; public class BoundingBox { - private final int x1; - private final int y1; - private final int z1; - private final int x2; - private final int y2; - private final int z2; + private final int x1, y1, z1, x2, y2, z2; public BoundingBox(int x1, int y1, int z1, int x2, int y2, int z2) { this.x1 = Math.min(x1, x2); diff --git a/src/com/dre/brewery/utility/LegacyUtil.java b/src/com/dre/brewery/utility/LegacyUtil.java index d981883..8e3c862 100644 --- a/src/com/dre/brewery/utility/LegacyUtil.java +++ b/src/com/dre/brewery/utility/LegacyUtil.java @@ -13,12 +13,12 @@ import org.bukkit.material.Wood; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; +import java.util.EnumSet; +import java.util.Set; import static com.dre.brewery.BCauldron.EMPTY; -import static com.dre.brewery.BCauldron.SOME; import static com.dre.brewery.BCauldron.FULL; +import static com.dre.brewery.BCauldron.SOME; @SuppressWarnings("JavaReflectionMemberAccess") public class LegacyUtil { @@ -42,7 +42,7 @@ public class LegacyUtil { } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ignored) { } - List planks = new ArrayList<>(6); + Set planks = EnumSet.noneOf(Material.class); for (Material m : Material.values()) { if (m.name().endsWith("PLANKS")) { planks.add(m); @@ -50,7 +50,7 @@ public class LegacyUtil { } PLANKS = planks; - List fences = new ArrayList<>(7); + Set fences = EnumSet.noneOf(Material.class); for (Material m : Material.values()) { if (m.name().endsWith("FENCE")) { fences.add(m); @@ -68,8 +68,8 @@ public class LegacyUtil { public static final Material JUNGLE_STAIRS = get("JUNGLE_STAIRS", "JUNGLE_WOOD_STAIRS"); public static final Material ACACIA_STAIRS = get("ACACIA_STAIRS"); public static final Material DARK_OAK_STAIRS = get("DARK_OAK_STAIRS"); - public static final List PLANKS; - public static final List FENCES; + public static final Set PLANKS; + public static final Set FENCES; // Materials removed in 1.13 public static final Material STATIONARY_LAVA = get("STATIONARY_LAVA");