1

im having trouble with my plugin im developing, im not really good with arrays so im wondering if anyone is good with mine-craft and can help me with this :).

so what im having trouble with is adding ItemStacks or combining them. I i want pot to add contents of temp to its ItemStack[].

 ItemStack[] temp;
 ItemStack[] pot;

public void openPot(Player player)
    {   
        player.openInventory(inve());
    }

public Inventory inve()
    {


        Inventory inv = Bukkit.createInventory(null, 45, ChatColor.DARK_GREEN + "Pot");//second parameter is how many slots, divisibile by 9

        inv.setContents(temp);
        pot = inv.getStorageContents();
        inv.setContents(pot);
        temp = null;
        //inv.addItem(items);
        return inv;
    }

public Inventory joinPot()
    {
        Inventory inv = Bukkit.createInventory(null, 45, ChatColor.DARK_GREEN + "Gamble");//second parameter is how many slots, divisibile by 9


        ItemStack cancel = new ItemStack(Material.REDSTONE_BLOCK);
        ItemStack Accept = new ItemStack(Material.EMERALD_BLOCK);

        ItemMeta cancelMeta = cancel.getItemMeta();
        ItemMeta AcceptMeta = Accept.getItemMeta();

        cancelMeta.setDisplayName(ChatColor.RED + "Cancel");
        AcceptMeta.setDisplayName(ChatColor.GREEN + "Accept");


        cancel.setItemMeta(cancelMeta);
        Accept.setItemMeta(AcceptMeta);

        inv.setItem(44,Accept);//setItem(slot location,item);
        inv.setItem(36, cancel);

        return inv;
    }
    //Player chooses item to join current pot
    public void openJoin(Player player)
    {
        player.openInventory(joinPot());
    }

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event)
    {
        if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Gamble"))
            return;
        Player player = (Player) event.getWhoClicked();
        //event.setCancelled(true);
        if(event.getCurrentItem().getType() == Material.REDSTONE_BLOCK){
            player.closeInventory();
            player.sendMessage(ChatColor.RED + "Canceld Joining pot");
            return;
        }
        else if(event.getCurrentItem().getType() == Material.EMERALD_BLOCK){


**here we setting temps itemstack to whatever i placed in the chest this works**
            temp = event.getInventory().getContents();

            player.closeInventory();
            player.sendMessage(ChatColor.GREEN + "Accepting your request to join");

            //return;
        }

    }

what ends up happening is when i set the chest contents it gets rid of the old data that was there.

i just want to know how to add two ItemStack arrays Pot += temp//temp resets after every call. pot doesnt

  • in which method are you trying to do that? – Anoop Kanyan May 15 '16 at 02:51
  • i wanna do it in inve(), i want ItemStack[] pot += ItemStack[] temp i just dont know how to go about that, or maybe if i dont have to add, just want to know how to keep the stuff in the chest when i add more stuff –  May 15 '16 at 03:02
  • Possible duplicate of [How can I concatenate two arrays in Java?](http://stackoverflow.com/questions/80476/how-can-i-concatenate-two-arrays-in-java). – bcsb1001 May 20 '16 at 15:50

1 Answers1

-1

to add all the elements of temp to pot use:

this.pot.addAll(this.temp);