From f020975edb2271fc562cb10c6fe9a9844764804c Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Tue, 28 Aug 2018 00:49:55 -0400 Subject: [PATCH] Added a feature for AutoCrafting items --- .../epichoppers/api/hopper/Hopper.java | 15 ++++ .../songoda/epichoppers/api/hopper/Level.java | 9 +++ .../epichoppers/api/hopper/LevelManager.java | 3 +- .../api/hopper/TeleportTrigger.java | 2 +- .../epichoppers/EpicHoppersPlugin.java | 19 ++++- .../epichoppers/handlers/HopHandler.java | 81 +++++++++++++++++-- .../songoda/epichoppers/hopper/EHopper.java | 78 +++++++++++++++++- .../epichoppers/hopper/EHopperManager.java | 2 +- .../songoda/epichoppers/hopper/ELevel.java | 13 ++- .../epichoppers/hopper/ELevelManager.java | 4 +- .../epichoppers/listeners/BlockListeners.java | 2 +- .../listeners/InventoryListeners.java | 24 ++++-- .../songoda/epichoppers/player/MenuType.java | 3 +- .../src/main/resources/en_US.lang | 5 ++ 14 files changed, 231 insertions(+), 29 deletions(-) diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java index 8c963d9..b6066cf 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java @@ -1,6 +1,7 @@ package com.songoda.epichoppers.api.hopper; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -76,6 +77,20 @@ public interface Hopper { */ void setLastPlayer(UUID uuid); + /** + * Get the item being automatically crafted. + * + * @return item being crafted + */ + Material getAutoCrafting(); + + /** + * Set the Item being automatically crafted. + * + * @param autoCrafting item to craft + */ + void setAutoCrafting(Material autoCrafting); + /** * Get the teleport trigger is currently enabled. * diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Level.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Level.java index 022095d..a1126a1 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Level.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Level.java @@ -66,6 +66,15 @@ public interface Level { */ boolean isTeleport(); + /** + * Whether or not hopper crafting is enabled with + * this level. + * + * @return true if crafting is enabled false + * otherwise + */ + boolean isCrafting(); + /** * Get the distance in which a hopper with this * level will suck items into them. diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/LevelManager.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/LevelManager.java index d42552c..39ab05d 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/LevelManager.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/LevelManager.java @@ -18,8 +18,9 @@ public interface LevelManager { * @param blockBreak The tick frequency in which this hopper will break blocks placed directly above it. * @param filter Whether or not access to the filter is allowed. * @param teleport Whether or not teleporting through hoppers is allowed. + * @param crafting Whether or not crafting with hoppers is allowed. */ - void addLevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport); + void addLevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting); /** * Get {@link Level} by corresponding integer value. diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java index dfd7d4f..60b48cf 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java @@ -3,5 +3,5 @@ package com.songoda.epichoppers.api.hopper; public enum TeleportTrigger { DISABLED, WALK_ON, - SNEAK; + SNEAK } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java index 10f6250..ed6bd77 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java @@ -120,6 +120,8 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { List blackList = (ArrayList) dataFile.getConfig().getList("data.sync." + locationStr + ".blacklist"); List voidList = (ArrayList) dataFile.getConfig().getList("data.sync." + locationStr + ".void"); + Material autoCrafting = Material.valueOf(dataFile.getConfig().getString("data.sync." + locationStr + ".autoCrafting", "AIR")); + String blackLoc = dataFile.getConfig().getString("data.sync." + locationStr + ".black"); Block black = blackLoc == null ? null : Arconix.pl().getApi().serialize().unserializeLocation(dataFile.getConfig().getString("data.sync." + locationStr + ".black")).getBlock(); @@ -130,7 +132,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { filter.setVoidList(voidList); filter.setEndPoint(black); - EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, block, filter, teleportTrigger); + EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, block, filter, teleportTrigger, autoCrafting); hopperManager.addHopper(location, hopper); } @@ -216,6 +218,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { dataFile.getConfig().set("data.sync." + locationStr + ".player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString()); dataFile.getConfig().set("data.sync." + locationStr + ".placedBy", hopper.getPlacedBy() == null ? null : hopper.getPlacedBy().toString()); dataFile.getConfig().set("data.sync." + locationStr + ".teleportTrigger", hopper.getTeleportTrigger().toString()); + dataFile.getConfig().set("data.sync." + locationStr + ".autoCrafting", hopper.getAutoCrafting() == Material.AIR ? null : hopper.getAutoCrafting().name()); dataFile.getConfig().set("data.sync." + locationStr + ".whitelist", hopper.getFilter().getWhiteList()); dataFile.getConfig().set("data.sync." + locationStr + ".blacklist", hopper.getFilter().getBlackList()); dataFile.getConfig().set("data.sync." + locationStr + ".void", hopper.getFilter().getVoidList()); @@ -250,9 +253,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { int blockBreak = getConfig().getInt("settings.levels." + levelName + ".BlockBreak"); boolean filter = getConfig().getBoolean("settings.levels." + levelName + ".Filter"); boolean teleport = getConfig().getBoolean("settings.levels." + levelName + ".Teleport"); + boolean crafting = getConfig().getBoolean("settings.levels." + levelName + ".AutoCrafting"); int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp"); int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco"); - levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, suction, blockBreak, filter, teleport); + levelManager.addLevel(level, costExperiance, costEconomy, radius, amount, suction, blockBreak, filter, teleport, crafting); } } @@ -298,6 +302,17 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { getConfig().addDefault("settings.levels.Level-6.Teleport", true); getConfig().addDefault("settings.levels.Level-6.Cost-xp", 45); getConfig().addDefault("settings.levels.Level-6.Cost-eco", 20000); + + getConfig().addDefault("settings.levels.Level-7.Range", 70); + getConfig().addDefault("settings.levels.Level-7.Amount", 5); + getConfig().addDefault("settings.levels.Level-7.Suction", 3); + getConfig().addDefault("settings.levels.Level-7.BlockBreak", 2); + getConfig().addDefault("settings.levels.Level-7.Filter", true); + getConfig().addDefault("settings.levels.Level-7.Teleport", true); + getConfig().addDefault("settings.levels.Level-7.AutoCrafting", true); + getConfig().addDefault("settings.levels.Level-7.Cost-xp", 50); + getConfig().addDefault("settings.levels.Level-7.Cost-eco", 30000); + } getConfig().options().copyDefaults(true); diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/HopHandler.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/HopHandler.java index 1ed5afc..86436d2 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/HopHandler.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/HopHandler.java @@ -11,10 +11,7 @@ import org.bukkit.block.Hopper; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; -import org.bukkit.inventory.FurnaceInventory; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.*; import org.bukkit.metadata.FixedMetadataValue; import java.util.*; @@ -24,6 +21,7 @@ import java.util.*; */ public class HopHandler { + public Map blockTick = new HashMap<>(); private EpicHoppersPlugin instance; public HopHandler(EpicHoppersPlugin instance) { @@ -57,8 +55,6 @@ public class HopHandler { } } - public Map blockTick = new HashMap<>(); - private void hopperRunner() { try { Set metaItems = new HashSet<>(); @@ -87,6 +83,26 @@ public class HopHandler { org.bukkit.block.Hopper hopperBlock = (org.bukkit.block.Hopper) (block != null ? block.getState() : null); + ItemStack[] is = hopperBlock.getInventory().getContents(); + + if (hopper.getAutoCrafting() != null && canMove(hopperBlock.getInventory(), new ItemStack(hopper.getAutoCrafting()))) { + main: + for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) { + if (!(recipe instanceof ShapedRecipe)) continue; + Map ingredientMap = ((ShapedRecipe) recipe).getIngredientMap(); + if (hopperBlock.getInventory().getSize() == 0) continue; + List needed = stackItems(new ArrayList<>(ingredientMap.values())); + + for (ItemStack item : needed) { + if (!hopperBlock.getInventory().contains(item.getType(), item.getAmount())) continue main; + } + for (ItemStack item : needed) { + hopperBlock.getInventory().removeItem(item); + } + hopperBlock.getInventory().addItem(new ItemStack(hopper.getAutoCrafting())); + } + } + if (hopper.getLevel().getBlockBreak() != 0) { int amt = hopper.getLevel().getBlockBreak(); if (!blockTick.containsKey(block)) { @@ -171,12 +187,22 @@ public class HopHandler { int amt = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier()); - ItemStack[] is = hopperBlock.getInventory().getContents(); - List whiteList = hopper.getFilter().getWhiteList(); List blackList = hopper.getFilter().getBlackList(); + List materials = new ArrayList<>(); + if (hopper.getAutoCrafting() != null) { + for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(hopper.getAutoCrafting()))) { + if (recipe instanceof ShapedRecipe) { + for (ItemStack itemStack : ((ShapedRecipe) recipe).getIngredientMap().values()) { + if (itemStack == null) continue; + materials.add(itemStack.getType()); + } + } + } + } + int num = 0; while (num != 5) { ItemStack it = null; @@ -184,6 +210,13 @@ public class HopHandler { it = is[num].clone(); it.setAmount(1); } + + if (is[num] != null + && materials.contains(is[num].getType())) { + num++; + continue; + } + if (is[num] != null && !whiteList.isEmpty() && !whiteList.contains(it)) { @@ -206,6 +239,23 @@ public class HopHandler { } } + private List stackItems(List items) { + Map materials = new HashMap<>(); + for (ItemStack itemStack : items) { + if (itemStack == null) continue; + if (materials.containsKey(itemStack.getType())) { + materials.put(itemStack.getType(), materials.get(itemStack.getType()) + itemStack.getAmount()); + continue; + } + materials.put(itemStack.getType(), itemStack.getAmount()); + } + List stacked = new ArrayList<>(); + for (Map.Entry entry : materials.entrySet()) { + stacked.add(new ItemStack(entry.getKey(), entry.getValue())); + } + return stacked; + } + private void doBlacklist(Hopper hopperBlock, com.songoda.epichoppers.api.hopper.Hopper hopper, ItemStack item, ItemStack[] isS, int amt, int place) { try { Location loc = hopperBlock.getLocation(); @@ -318,6 +368,21 @@ public class HopHandler { return 0; } + private boolean canMove(Inventory inventory, ItemStack item) { + try { + if (inventory.firstEmpty() != -1) return true; + + for (ItemStack stack : inventory.getContents()) { + if (stack.isSimilar(item) && stack.getAmount() < stack.getMaxStackSize()) { + return true; + } + } + } catch (Exception e) { + Debugger.runReport(e); + } + return false; + } + public boolean canHop(Inventory i, ItemStack item, int hop) { try { if (i.firstEmpty() != -1) { diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java index 962574d..b330dbe 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java @@ -38,9 +38,10 @@ public class EHopper implements Hopper { private Block syncedBlock; private Filter filter; private TeleportTrigger teleportTrigger; + private Material autoCrafting; - public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger) { + public EHopper(Location location, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) { this.location = location; this.level = level; this.syncedBlock = syncedBlock; @@ -48,10 +49,11 @@ public class EHopper implements Hopper { this.lastPlayer = lastPlayer; this.placedBy = placedBy; this.teleportTrigger = teleportTrigger; + this.autoCrafting = autoCrafting; } - public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger) { - this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, teleportTrigger); + public EHopper(Block block, com.songoda.epichoppers.api.hopper.Level level, UUID lastPlayer, UUID placedBy, Block syncedBlock, Filter filter, TeleportTrigger teleportTrigger, Material autoCrafting) { + this(block.getLocation(), level, lastPlayer, placedBy, syncedBlock, filter, teleportTrigger, autoCrafting); } public void overview(Player player) { @@ -91,6 +93,17 @@ public class EHopper implements Hopper { filtermeta.setLore(lorefilter); filter.setItemMeta(filtermeta); + ItemStack crafting = new ItemStack(Material.CRAFTING_TABLE, 1); + ItemMeta craftingmeta = crafting.getItemMeta(); + craftingmeta.setDisplayName(instance.getLocale().getMessage("interface.hopper.craftingtitle")); + ArrayList lorecrafting = new ArrayList<>(); + parts = instance.getLocale().getMessage("interface.hopper.craftinglore").split("\\|"); + for (String line : parts) { + lorecrafting.add(Arconix.pl().getApi().format().formatText(line)); + } + craftingmeta.setLore(lorecrafting); + crafting.setItemMeta(craftingmeta); + ItemStack item = new ItemStack(Material.HOPPER, 1); ItemMeta itemmeta = item.getItemMeta(); @@ -164,12 +177,19 @@ public class EHopper implements Hopper { i.setItem(5, filter); } + boolean canCraft = level.isCrafting() || player.hasPermission("EpicHoppers.Crafting"); + if (!canCraft) + i.setItem(22, hook); + else if (canFilter) { + i.setItem(23, hook); + i.setItem(21, crafting); + } + if (instance.getConfig().getBoolean("Main.Upgrade With XP") && player.hasPermission("EpicHoppers.Upgrade.XP")) { i.setItem(11, itemXP); } i.setItem(13, item); - i.setItem(22, hook); if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && player.hasPermission("EpicHoppers.Upgrade.ECO")) { i.setItem(15, itemECO); @@ -200,6 +220,46 @@ public class EHopper implements Hopper { } } + public void crafting(Player player) { + try { + EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); + instance.getPlayerDataManager().getPlayerData(player).setLastHopper(this); + + Inventory i = Bukkit.createInventory(null, 27, Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), false) + " &8-&f Crafting")); + + int nu = 0; + while (nu != 27) { + i.setItem(nu, Methods.getGlass()); + nu++; + } + + i.setItem(0, Methods.getBackgroundGlass(true)); + i.setItem(1, Methods.getBackgroundGlass(true)); + i.setItem(2, Methods.getBackgroundGlass(false)); + i.setItem(6, Methods.getBackgroundGlass(false)); + i.setItem(7, Methods.getBackgroundGlass(true)); + i.setItem(8, Methods.getBackgroundGlass(true)); + i.setItem(9, Methods.getBackgroundGlass(true)); + i.setItem(10, Methods.getBackgroundGlass(false)); + i.setItem(16, Methods.getBackgroundGlass(false)); + i.setItem(17, Methods.getBackgroundGlass(true)); + i.setItem(18, Methods.getBackgroundGlass(true)); + i.setItem(19, Methods.getBackgroundGlass(true)); + i.setItem(20, Methods.getBackgroundGlass(false)); + i.setItem(24, Methods.getBackgroundGlass(false)); + i.setItem(25, Methods.getBackgroundGlass(true)); + i.setItem(26, Methods.getBackgroundGlass(true)); + + i.setItem(13, new ItemStack(autoCrafting == null ? Material.AIR : autoCrafting)); + + player.openInventory(i); + instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.CRAFTING); + lastPlayer = player.getUniqueId(); + } catch (Exception e) { + Debugger.runReport(e); + } + } + public void filter(Player player) { try { EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); @@ -520,6 +580,16 @@ public class EHopper implements Hopper { lastPlayer = uuid; } + @Override + public Material getAutoCrafting() { + return autoCrafting; + } + + @Override + public void setAutoCrafting(Material autoCrafting) { + this.autoCrafting = autoCrafting; + } + @Override public TeleportTrigger getTeleportTrigger() { return teleportTrigger; diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java index ccbbea1..ecf1900 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java @@ -29,7 +29,7 @@ public class EHopperManager implements HopperManager { @Override public Hopper getHopper(Location location) { if (!registeredHoppers.containsKey(roundLocation(location))) { - addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, null, new EFilter(), TeleportTrigger.DISABLED)); + addHopper(location, new EHopper(location, EpicHoppersPlugin.getInstance().getLevelManager().getLowestLevel(), null, null, null, new EFilter(), TeleportTrigger.DISABLED, null)); } return registeredHoppers.get(roundLocation(location)); } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevel.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevel.java index b09742c..ec8afe3 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevel.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevel.java @@ -10,11 +10,11 @@ public class ELevel implements Level { private int level, costExperience, costEconomy, range, amount, blockBreak, suction; - private boolean filter, teleport; + private boolean filter, teleport, crafting; private List description = new ArrayList<>(); - public ELevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport) { + public ELevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting) { this.level = level; this.costExperience = costExperience; this.costEconomy = costEconomy; @@ -24,6 +24,7 @@ public class ELevel implements Level { this.suction = suction; this.filter = filter; this.teleport = teleport; + this.crafting = crafting; EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); @@ -32,7 +33,8 @@ public class ELevel implements Level { if (suction != 0) description.add(instance.getLocale().getMessage("interface.hopper.suction", suction)); if (blockBreak != 0) description.add(instance.getLocale().getMessage("interface.hopper.blockbreak", blockBreak)); if (filter) description.add(instance.getLocale().getMessage("interface.hopper.filter", true)); - if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.filter", true)); + if (teleport) description.add(instance.getLocale().getMessage("interface.hopper.teleport", true)); + if (crafting) description.add(instance.getLocale().getMessage("interface.hopper.crafting", true)); } @Override @@ -70,6 +72,11 @@ public class ELevel implements Level { return teleport; } + @Override + public boolean isCrafting() { + return crafting; + } + @Override public int getSuction() { return suction; diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevelManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevelManager.java index 62012e6..0e6ed0f 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevelManager.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/ELevelManager.java @@ -13,8 +13,8 @@ public class ELevelManager implements LevelManager { private final NavigableMap registeredLevels = new TreeMap<>(); @Override - public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport) { - registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, suction, blockBreak, filter, teleport)); + public void addLevel(int level, int costExperience, int costEconomy, int range, int amount, int suction, int blockBreak, boolean filter, boolean teleport, boolean crafting) { + registeredLevels.put(level, new ELevel(level, costExperience, costEconomy, range, amount, suction, blockBreak, filter, teleport, crafting)); } @Override diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java index 0fa1195..ecdadd0 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java @@ -56,7 +56,7 @@ public class BlockListeners implements Listener { ItemStack item = e.getItemInHand().clone(); - instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), e.getPlayer().getUniqueId(),null, new EFilter(), TeleportTrigger.DISABLED)); + instance.getHopperManager().addHopper(e.getBlock().getLocation(), new EHopper(e.getBlock(), instance.getLevelFromItem(item), e.getPlayer().getUniqueId(), e.getPlayer().getUniqueId(),null, new EFilter(), TeleportTrigger.DISABLED, null)); } catch (Exception ee) { Debugger.runReport(ee); diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java index d76b13e..68ac74b 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java @@ -24,7 +24,7 @@ import org.bukkit.inventory.ItemStack; public class InventoryListeners implements Listener { private EpicHoppersPlugin instance; - + public InventoryListeners(EpicHoppersPlugin instance) { this.instance = instance; } @@ -32,7 +32,6 @@ public class InventoryListeners implements Listener { @EventHandler public void onInventoryClick(InventoryClickEvent event) { try { - Inventory inv = event.getInventory(); Player player = (Player) event.getWhoClicked(); if (inv == null || event.getCurrentItem() == null) return; @@ -71,6 +70,14 @@ public class InventoryListeners implements Listener { PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player); + if (playerData.getInMenu() == MenuType.CRAFTING) { + if (event.getSlot() == 13) { + return; + } + event.setCancelled(true); + return; + } + if (playerData.getInMenu() != MenuType.OVERVIEW) return; event.setCancelled(true); @@ -94,8 +101,6 @@ public class InventoryListeners implements Listener { return; } player.closeInventory(); - - } else if (event.getCurrentItem().getItemMeta().hasDisplayName() && event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.filtertitle")) && (hopper.getLevel().isFilter() || player.hasPermission("EpicHoppers.Filter"))) { if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) { ((EHopper)hopper).filter(player); @@ -110,7 +115,9 @@ public class InventoryListeners implements Listener { ((EHopper)hopper).upgrade("ECO", player); player.closeInventory(); } - } else if (event.getSlot() == 22) { + } else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.craftingtitle"))) { + ((EHopper)hopper).crafting(player); + } else if (event.getCurrentItem().getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.hopper.synchopper"))) { if (event.isRightClick()) { player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("event.hopper.desync")); hopper.setSyncedBlock(null); @@ -135,6 +142,7 @@ public class InventoryListeners implements Listener { } } + private boolean doFilter(InventoryClickEvent e) { Player player = (Player) e.getWhoClicked(); PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player); @@ -212,8 +220,14 @@ public class InventoryListeners implements Listener { try { Player player = (Player)event.getPlayer(); PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player); + if (playerData.getInMenu() == MenuType.CRAFTING) { + Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player); + ItemStack item = event.getInventory().getItem(13); + hopper.setAutoCrafting(item == null ? Material.AIR : item.getType()); + } if (playerData.getInMenu() != MenuType.NOT_IN) { Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player); + if (hopper != null) hopper.setLastPlayer(null); } if (playerData.getInMenu() == MenuType.FILTER) { diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/MenuType.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/MenuType.java index 4f76ae1..88a1015 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/MenuType.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/MenuType.java @@ -4,6 +4,7 @@ public enum MenuType { NOT_IN, OVERVIEW, - FILTER + FILTER, + CRAFTING } diff --git a/EpicHoppers-Plugin/src/main/resources/en_US.lang b/EpicHoppers-Plugin/src/main/resources/en_US.lang index 11915c3..113f695 100644 --- a/EpicHoppers-Plugin/src/main/resources/en_US.lang +++ b/EpicHoppers-Plugin/src/main/resources/en_US.lang @@ -16,6 +16,9 @@ interface.hopper.currentlevel = "&6Hopper Level &7%level%" interface.hopper.nextlevel = "&6Next Level &7%level%" interface.hopper.range = "&7Range: &6%range%" interface.hopper.amount = "&7Amount: &6%amount%" +interface.hopper.teleport = "&7Teleport: &6%enabled%" +interface.hopper.filter = "&7Filter: &6%enabled%" +interface.hopper.crafting = "&7AutoCrafting: &6%enabled%" interface.hopper.suction = "&7Suction: &6%suction%" interface.hopper.blockbreak = "&7Block Break: &6Every %ticks% ticks" interface.hopper.alreadymaxed = "&7This hopper is already maxed out!" @@ -24,6 +27,8 @@ interface.hopper.perltitle = "&6Click to Teleport" interface.hopper.perllore2 = "|&7Left-Click to teleport to|&7the end of the chain.||&7Right-Click to switch the|&7teleport trigger mode.|&7Currently set to: &a%type%&7." interface.hopper.filtertitle = "&cClick to Filter" interface.hopper.filterlore = "|&7This allows you to choose|&7which items go where." +interface.hopper.craftingtitle = "&cClick to setup AutoCrafting" +interface.hopper.craftinglore = "|&7This allows you to choose|&7which item this hopper|&7will automaticly craft." interface.hopper.synchopper = "&6Click to Sync This hopper" interface.hopper.rejectsync = "&6Click to Sync Rejected Items" interface.filter.infotitle = "&aFilter Guide"