我的插件即时开发时遇到问题,我对阵列的表现并不是很好,所以我想知道是否有人对我的工艺有好处,并且可以帮助我:)。
所以我遇到麻烦的是添加ItemStacks或组合它们。 我想让pot在其ItemStack []中添加temp的内容。
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;
}
}
最终发生的事情是当我设置胸部内容时,它会摆脱那里的旧数据。
我只想知道如何添加两个ItemStack数组 Pot + = temp // temp在每次调用后重置。锅没有
答案 0 :(得分:-1)
将所有temp元素添加到pot使用中:
this.pot.addAll(this.temp);