From 1bd79b35053bf0c5b889fb07ecef70feaf74427d Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Sun, 30 Sep 2018 13:28:27 -0400 Subject: [PATCH] Removed data loading message. Cached AutoCrafting data; --- .../levels/modules/ModuleAutoCrafting.java | 19 ++++++++++++++----- .../songoda/epichoppers/storage/Storage.java | 2 +- .../epichoppers/utils/SettingsManager.java | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java index ddec428..d589879 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java @@ -18,6 +18,8 @@ import java.util.Map; public class ModuleAutoCrafting implements Module { + private final Map cachedRecipes = new HashMap<>(); + @Override public String getName() { return "AutoCrafting"; @@ -47,13 +49,20 @@ public class ModuleAutoCrafting implements Module { public List getBlockedItems(Hopper hopper) { List materials = new ArrayList<>(); if (hopper.getAutoCrafting() != null) { - for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) { - if (!(recipe instanceof ShapedRecipe)) continue; - for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) { - if (itemStack == null) continue; - materials.add(itemStack.getType()); + + Material material = hopper.getAutoCrafting(); + + if (!cachedRecipes.containsKey(material)) { + for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(material))) { + if (!(recipe instanceof ShapedRecipe)) continue; + cachedRecipes.put(material, recipe); } } + + for (ItemStack itemStack : ((ShapedRecipe) cachedRecipes.get(material)).getIngredientMap().values()) { + if (itemStack == null) continue; + materials.add(itemStack.getType()); + } } return materials; } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java index dcaf4ec..2e61ba5 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java @@ -13,7 +13,7 @@ public abstract class Storage { public Storage(EpicHoppersPlugin instance) { this.instance = instance; this.dataFile = new ConfigWrapper(instance, "", "data.yml"); - this.dataFile.createNewFile("Loading Data File", "EpicHoppers Data File"); + this.dataFile.createNewFile(null, "EpicHoppers Data File"); this.dataFile.getConfig().options().copyDefaults(true); this.dataFile.saveConfig(); } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java index b459d8f..2eab732 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java @@ -194,6 +194,7 @@ public class SettingsManager implements Listener { } } } + public enum Setting { o1("Upgrading-enabled", "Main.Allow hopper Upgrading", true), o2("Upgrade-with-eco", "Main.Upgrade With Economy", true),