Fix Item Cube functionality when first inserting an item to a newly

unactivated Item Cube. Made a new helper function to check it the item
is an Item Cube.
master_event
sigonasr2 11 years ago
parent c4108da16d
commit 3b8d4195e4
  1. 35
      BankEconomyMod/src/me/kaZep/Base/PlayerListener.java

@ -9685,12 +9685,15 @@ implements Listener
} }
if (event.getInventory().getType()==InventoryType.CRAFTING /*|| event.getInventory().getType()==InventoryType.CHEST*//*Buggy for some reason. We can't open chests in chests.*/) { if (event.getInventory().getType()==InventoryType.CRAFTING /*|| event.getInventory().getType()==InventoryType.CHEST*//*Buggy for some reason. We can't open chests in chests.*/) {
if (event.getCurrentItem()!=null) { if (event.getCurrentItem()!=null) {
if ((event.getCurrentItem().getType()==Material.CHEST || event.getCurrentItem().getType()==Material.TRAPPED_CHEST || event.getCurrentItem().getType()==Material.ENDER_CHEST) && event.getClick()==ClickType.RIGHT) { if ((event.getCurrentItem().getType()==Material.CHEST || event.getCurrentItem().getType()==Material.TRAPPED_CHEST || event.getCurrentItem().getType()==Material.ENDER_CHEST) && event.getClick()==ClickType.RIGHT && event.getCurrentItem().hasItemMeta()) {
if (isItemCube(event.getCurrentItem())) {
//Only cancel the event and view the Item Cube if it actually is one.
viewItemCube(p, event.getCurrentItem()); viewItemCube(p, event.getCurrentItem());
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
}
}else }else
if (event.getInventory().getType()==InventoryType.CHEST && event.getInventory().getName().contains("Item Cube")) { if (event.getInventory().getType()==InventoryType.CHEST && event.getInventory().getName().contains("Item Cube")) {
//If we click a chest, make sure it's not the same ID chest. //If we click a chest, make sure it's not the same ID chest.
@ -11832,27 +11835,29 @@ implements Listener
} }
} }
public void viewItemCube(Player p, ItemStack item_cube) { public boolean isItemCube(ItemStack item_cube) {
//This function will figure out what type of Item Cube this item is and then display the correct inventory on-screen, also setting up the identifier. if (item_cube.hasItemMeta() && item_cube.getItemMeta().getLore()!=null) {
//Note that this function does not check if the item *is* an item cube. It assumes it is.
Cube cube_type = null;
int identifier=-1;
if (item_cube.getItemMeta().getLore()!=null) {
//Check to see if the Lore contains anything. //Check to see if the Lore contains anything.
for (int i=0;i<item_cube.getItemMeta().getLore().size();i++) { for (int i=0;i<item_cube.getItemMeta().getLore().size();i++) {
if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 9 item slots.")) { if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 9 item slots.")) {
cube_type = Cube.SMALL; return true;
} }
if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 54 item slots.")) { if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 54 item slots.")) {
cube_type = Cube.LARGE; return true;
} }
if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 27 item slots.")) { if (item_cube.getItemMeta().getLore().get(i).equalsIgnoreCase(ChatColor.AQUA+"Contains 27 item slots.")) {
cube_type = Cube.ENDER; return true;
}
} }
if (item_cube.getItemMeta().getLore().get(i).contains("ID#")) {
identifier=Integer.valueOf(item_cube.getItemMeta().getLore().get(i).replace("ID#", ""));
} }
return false;
} }
public void viewItemCube(Player p, ItemStack item_cube) {
//This function will figure out what type of Item Cube this item is and then display the correct inventory on-screen, also setting up the identifier.
Cube cube_type = null;
int identifier=-1;
if (isItemCube(item_cube)) {
if (identifier==-1) { if (identifier==-1) {
//This doesn't have an identifier yet. Create a new one. //This doesn't have an identifier yet. Create a new one.
identifier=this.plugin.getConfig().getInt("item-cube-numb"); identifier=this.plugin.getConfig().getInt("item-cube-numb");
@ -12024,10 +12029,9 @@ implements Listener
f.set("item-"+i, new ItemStack(Material.AIR)); f.set("item-"+i, new ItemStack(Material.AIR));
} }
f.set("item-0", insert_item); f.set("item-0", insert_item);
insert_item.setType(Material.AIR);
f.set("created", Boolean.valueOf(true)); f.set("created", Boolean.valueOf(true));
return insert_item; //return insert_item;
} else { }
//We need to see if we have the inventory opened already...If so we have to add it to THAT one. //We need to see if we have the inventory opened already...If so we have to add it to THAT one.
Inventory thisinven=Bukkit.createInventory(p, slots, heading+"Item Cube #"+identifier); Inventory thisinven=Bukkit.createInventory(p, slots, heading+"Item Cube #"+identifier);
boolean changeinven=false; boolean changeinven=false;
@ -12086,7 +12090,6 @@ implements Listener
return new ItemStack(insert_item); return new ItemStack(insert_item);
} }
} }
}
public ItemStack insertIntoItemCube(Player p, ItemStack item_cube, ItemStack insert_item) { public ItemStack insertIntoItemCube(Player p, ItemStack item_cube, ItemStack insert_item) {
//This function will attmempt to insert an item into an item cube. It actually returns whatever cannot fit into the //This function will attmempt to insert an item into an item cube. It actually returns whatever cannot fit into the

Loading…
Cancel
Save