Removed data loading message.

Cached AutoCrafting data;
This commit is contained in:
Brianna O'Keefe 2018-09-30 13:28:27 -04:00
parent bed3c0016b
commit 1bd79b3505
3 changed files with 16 additions and 6 deletions

View File

@ -18,6 +18,8 @@ import java.util.Map;
public class ModuleAutoCrafting implements Module { public class ModuleAutoCrafting implements Module {
private final Map<Material, Recipe> cachedRecipes = new HashMap<>();
@Override @Override
public String getName() { public String getName() {
return "AutoCrafting"; return "AutoCrafting";
@ -47,13 +49,20 @@ public class ModuleAutoCrafting implements Module {
public List<Material> getBlockedItems(Hopper hopper) { public List<Material> getBlockedItems(Hopper hopper) {
List<Material> materials = new ArrayList<>(); List<Material> materials = new ArrayList<>();
if (hopper.getAutoCrafting() != null) { if (hopper.getAutoCrafting() != null) {
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) {
if (!(recipe instanceof ShapedRecipe)) continue; Material material = hopper.getAutoCrafting();
for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) {
if (itemStack == null) continue; if (!cachedRecipes.containsKey(material)) {
materials.add(itemStack.getType()); 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; return materials;
} }

View File

@ -13,7 +13,7 @@ public abstract class Storage {
public Storage(EpicHoppersPlugin instance) { public Storage(EpicHoppersPlugin instance) {
this.instance = instance; this.instance = instance;
this.dataFile = new ConfigWrapper(instance, "", "data.yml"); 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.getConfig().options().copyDefaults(true);
this.dataFile.saveConfig(); this.dataFile.saveConfig();
} }

View File

@ -194,6 +194,7 @@ public class SettingsManager implements Listener {
} }
} }
} }
public enum Setting { public enum Setting {
o1("Upgrading-enabled", "Main.Allow hopper Upgrading", true), o1("Upgrading-enabled", "Main.Allow hopper Upgrading", true),
o2("Upgrade-with-eco", "Main.Upgrade With Economy", true), o2("Upgrade-with-eco", "Main.Upgrade With Economy", true),