diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 7e800e7..223a57d 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index ea05d31..a239b38 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -3838,6 +3838,7 @@ public class GenericFunctions { public static boolean giveItem(Player p, ItemStack... items) { HashMap remaining = p.getInventory().addItem(items); if (remaining.isEmpty()) { + SoundUtils.playLocalSound(p, Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); return true; } else { for (Integer i : remaining.keySet()) { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/CubeType.java b/src/sig/plugin/TwosideKeeper/HelperStructures/CubeType.java index ead446a..4c4b669 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/CubeType.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/CubeType.java @@ -1,5 +1,34 @@ package sig.plugin.TwosideKeeper.HelperStructures; +import sig.plugin.TwosideKeeper.TwosideKeeper; + public enum CubeType { - NORMAL,LARGE,ENDER,VACUUM + NORMAL(0,9),LARGE(1,27),ENDER(2,27),VACUUM(3,54),FILTER(4,27); + + int id=0; + int size=9; + + private CubeType(int id, int size) { + this.id=id; + this.size=size; + } + + public int getID() { + return this.id; + } + + public int getSize() { + return this.size; + } + + public static CubeType getCubeTypeFromID(int id) { + for (CubeType ct : CubeType.values()) { + if (ct.getID()==id) { + return ct; + } + } + TwosideKeeper.log("INVALID CUBE ID SPECIFIED: "+id+". THIS SHOULD NOT BE HAPPENING!", 0); + return null; + } + } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/CustomItem.java b/src/sig/plugin/TwosideKeeper/HelperStructures/CustomItem.java index f87ff1b..674f93a 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/CustomItem.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/CustomItem.java @@ -50,6 +50,7 @@ public class CustomItem { TwosideKeeper.ENDER_ITEM_CUBE_RECIPE = EnderItemCubeRecipe(); TwosideKeeper.DUPLICATE_ENDER_ITEM_CUBE_RECIPE = DuplicateEnderItemCubeRecipe(); TwosideKeeper.VACUUM_CUBE_RECIPE = VacuumCubeRecipe(); + TwosideKeeper.FILTER_CUBE_RECIPE = FilterCubeRecipe(); TwosideKeeper.ARROW_QUIVER_RECIPE = ArrowQuiverRecipe(); TwosideKeeper.HARDENED_IRON_HELMET_RECIPE = HardenedRecipe(Material.IRON_HELMET,Material.IRON_BLOCK,"aaa","axa","xxx"); TwosideKeeper.HARDENED_IRON_CHESTPLATE_RECIPE = HardenedRecipe(Material.IRON_CHESTPLATE,Material.IRON_BLOCK,"axa","aaa","aaa"); @@ -142,6 +143,30 @@ public class CustomItem { ItemCube.addIngredient(Material.REDSTONE_BLOCK); return ItemCube; } + + private static ShapelessRecipe FilterCubeRecipe() { + ItemStack item_FilterCube = FilterCube(); + + ShapelessRecipe FilterCube = new ShapelessRecipe(item_FilterCube); + FilterCube.addIngredient(Material.CHEST); + FilterCube.addIngredient(Material.HOPPER); + FilterCube.addIngredient(4,Material.DIAMOND_BLOCK); + FilterCube.addIngredient(3,Material.IRON_BLOCK); + return FilterCube; + } + + private static ItemStack FilterCube() { + ItemStack item_FilterCube = new ItemStack(Material.HOPPER_MINECART); + List item_FilterCube_lore = new ArrayList(); + item_FilterCube_lore.add("A storage container that holds up"); + item_FilterCube_lore.add("to 27 items. Shift-Right click to"); + item_FilterCube_lore.add("open up a filtered item list."); + ItemMeta item_FilterCube_meta=item_FilterCube.getItemMeta(); + item_FilterCube_meta.setLore(item_FilterCube_lore); + item_FilterCube_meta.setDisplayName(ChatColor.GREEN+""+ChatColor.BOLD+"Filter Cube"); + item_FilterCube.setItemMeta(item_FilterCube_meta); + return item_FilterCube.clone(); + } private static ShapelessRecipe WorldShopRecipe() { ItemStack item_worldShop = WorldShop(); @@ -563,4 +588,11 @@ public class CustomItem { return false; } + public static boolean isFilterCube(ItemStack item) { + if (ItemUtils.isValidLoreItem(item) && ItemUtils.LoreContains(item, "open up a filtered item list.")) { + return true; + } + return false; + } + } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ArrayUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ArrayUtils.java index 5585673..95c6ca4 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ArrayUtils.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ArrayUtils.java @@ -1,5 +1,7 @@ package sig.plugin.TwosideKeeper.HelperStructures.Utils; +import java.util.HashMap; + import org.bukkit.inventory.ItemStack; public class ArrayUtils { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java index a994e99..7babe0b 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java @@ -55,4 +55,33 @@ public class InventoryUtils { } return remaining; } + public static boolean isCarryingFilterCube(Player p) { + for (ItemStack items : p.getInventory().getContents()) { + if (items!=null && CustomItem.isFilterCube(items)) { + return true; + } + } + return false; + } + public static ItemStack[] insertItemsInFilterCube(Player p,ItemStack...items) { + ItemStack[] remaining = items; + for (ItemStack itemStacks : p.getInventory().getContents()) { + if (itemStacks!=null && CustomItem.isFilterCube(itemStacks)) { + //Insert as many items as possible in here. + int id = Integer.parseInt(ItemUtils.GetLoreLineContainingString(itemStacks, ChatColor.DARK_PURPLE+"ID#").split("#")[1]); + List itemCubeContents = TwosideKeeper.itemCube_loadConfig(id); + Inventory virtualinventory = Bukkit.createInventory(p, 27); + for (int i=0;i remainingitems = ItemCubeUtils.AttemptingToAddItemToFilterCube(id,virtualinventory,remaining); + + remaining = remainingitems.values().toArray(new ItemStack[0]); + } + } + return remaining; + } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemCubeUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemCubeUtils.java new file mode 100644 index 0000000..6ea75e1 --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemCubeUtils.java @@ -0,0 +1,73 @@ +package sig.plugin.TwosideKeeper.HelperStructures.Utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Hopper; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import sig.plugin.TwosideKeeper.TwosideKeeper; +import sig.plugin.TwosideKeeper.HelperStructures.ItemCube; + +public class ItemCubeUtils { + public static int getItemCubeID(ItemStack item) { + return Integer.parseInt(ItemUtils.GetLoreLineContainingString(item, ChatColor.DARK_PURPLE+"ID#").split("#")[1]); + } + public static Location getFilterCubeLoc(int id) { + int posx = id % 960; + int posy = 64; + int posz = id / 960; + return new Location(Bukkit.getWorld("FilterCube"),posx,posy,posz); + } + public static Block getFilterCubeBlock(int id) { + Block b = Bukkit.getWorld("FilterCube").getBlockAt(getFilterCubeLoc(id)); + return b; + } + public static Hopper getFilterCubeHopper(int id) { + Hopper h = (Hopper)Bukkit.getWorld("FilterCube").getBlockAt(getFilterCubeLoc(id)).getState(); + return h; + } + public static void createNewFilterCube(int id) { + Block b = getFilterCubeBlock(id); + b.getWorld().getBlockAt(getFilterCubeLoc(id)).setType(Material.HOPPER); + } + public static HashMap AttemptingToAddItemToFilterCube(int id, Inventory cube_inv, ItemStack[] remaining) { + Hopper h = getFilterCubeHopper(id); + Inventory inv = h.getInventory(); + HashMap reject_items = new HashMap(); + for (ItemStack it : remaining) { + if (it!=null) { + if (inv.containsAtLeast(it, 1)) { + HashMap extras = cube_inv.addItem(it); + if (extras.size()==0) { + List itemslist = new ArrayList(); + for (int i=0;i itemslist = new ArrayList(); + for (int j=0;j=0) || @@ -5706,6 +5723,18 @@ public class TwosideKeeper extends JavaPlugin implements Listener { return; } + if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) { + ev.setCancelled(true); + ev.getItem().remove(); + SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); + AddToPlayerInventory(ev.getItem().getItemStack(), p); + return; + } + + /** + * MUST BE HANDLED AFTER EVERYTHING ELSE. + */ + if (ev.getItem().getItemStack().getType().isBlock() && InventoryUtils.isCarryingVacuumCube(p)) { //Try to insert it into the Vacuum cube. ItemStack[] remaining = InventoryUtils.insertItemsInVacuumCube(p, ev.getItem().getItemStack()); @@ -5714,16 +5743,28 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ev.getItem().remove(); SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); return; + } else { + ev.getItem().setItemStack(remaining[0]); } } - if (GenericFunctions.isValidArrow(ev.getItem().getItemStack())) { - ev.setCancelled(true); - ev.getItem().remove(); - SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); - AddToPlayerInventory(ev.getItem().getItemStack(), p); - return; + if (InventoryUtils.isCarryingFilterCube(p)) { + //Try to insert it into the Filter cube. + ItemStack[] remaining = InventoryUtils.insertItemsInFilterCube(p, ev.getItem().getItemStack()); + if (remaining.length==0) { + ev.setCancelled(true); + ev.getItem().remove(); + SoundUtils.playGlobalSound(ev.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); + return; + } else { + ev.getItem().setItemStack(remaining[0]); + } } + + ev.setCancelled(true); + ev.getItem().remove(); + GenericFunctions.giveItem(p, ev.getItem().getItemStack()); + return; } private boolean AutoConsumeItem(Player p, ItemStack item) { @@ -6827,42 +6868,35 @@ public class TwosideKeeper extends JavaPlugin implements Listener { File config; config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - - for (int i=0;i<54;i++) { + CubeType type = CubeType.getCubeTypeFromID(workable.getInt("cubetype")); + for (int i=0;i itemCube_loadFilterConfig(int id){ + List ItemCube_items = new ArrayList(); File config; config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - switch (workable.getInt("cubetype")) { - case 0:{return CubeType.NORMAL;} - case 1:{return CubeType.LARGE;} - case 2:{return CubeType.ENDER;} - case 3:{return CubeType.VACUUM;} - default:{return CubeType.NORMAL;} + for (int i=0;i<5;i++) { + ItemCube_items.add(workable.getItemStack("filter"+i, new ItemStack(Material.AIR))); } + return ItemCube_items; } - //Item Cube Saving. - public static void itemCube_saveConfig(int id, List items){ + public static CubeType itemCube_getCubeType(int id){ File config; config = new File(TwosideKeeper.filesave,"itemcubes/ItemCube"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - - for (int i=0;i items){ + itemCube_saveConfig(id,items,null); } public static void itemCube_saveConfig(int id, List items, CubeType cubetype){ @@ -6873,11 +6907,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { for (int i=0;i ents = p.getNearbyEntities(0.25, 0.25, 0.25); + for (Entity ent : ents) { + if (ent instanceof Item && GenericFunctions.itemCanBeSuckedUp((Item)ent)) { + Item it = (Item)ent; + ItemStack[] remaining = InventoryUtils.insertItemsInFilterCube(p, it.getItemStack()); + if (remaining.length==0) { + it.remove(); + SoundUtils.playGlobalSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); + return; + } + } + } + } + } + public static void runVacuumCubeSuckup(Player p) { if (InventoryUtils.isCarryingVacuumCube(p)) { //Suck up nearby item entities.