Java 组合项堆栈阵列
我在开发我的插件时遇到了麻烦,我对阵列不是很在行,所以我想知道是否有人对我的工艺很在行,可以帮我:) 因此,我遇到的问题是添加项目堆栈或合并它们。 我希望pot将temp的内容添加到其ItemStack[]Java 组合项堆栈阵列,java,arrays,minecraft,bukkit,Java,Arrays,Minecraft,Bukkit,我在开发我的插件时遇到了麻烦,我对阵列不是很在行,所以我想知道是否有人对我的工艺很在行,可以帮我:) 因此,我遇到的问题是添加项目堆栈或合并它们。 我希望pot将temp的内容添加到其ItemStack[] ItemStack[] temp; ItemStack[] pot; public void openPot(Player player) { player.openInventory(inve()); } public Inventory in
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在每次调用后重置。pot不要将temp的所有元素添加到pot中,请使用:
this.pot.addAll(this.temp);
你想用哪种方法来做这件事?我想用inve()来做,我想用ItemStack[]pot+=ItemStack[]temp我只是不知道该怎么做,或者如果我不需要添加,我只想知道在添加更多的东西时如何将这些东西放在箱子里可能是重复的。无法在数组类型ItemStack[]上调用addall(ItemStack[])当我尝试它的时候,我得到了那个错误,我非常确定这个罐子是一个对象。idk混乱。请尝试不将其作为对象引用。罐加全部(温度);调用此函数的类是静态的还是对象?根据函数声明,它需要是对象,并且在引用类之前需要“this”objects@LucianFarsky你没有道理。在自己对Java语言没有很好的了解的情况下,不要回答Java问题。