好的,我正在尝试将数据附加到 Minecraft Bukkit ItemStack。我想要它,所以它掉落的实体也有它,但这是可选的。如果我不能直接执行此操作,是否有其他方法可以在该项目通过玩家及其库存槽时保留一段数据(java int,java string)?谢谢!
编辑:这是一个代码示例。
package path.to.the.package;
import org.bukkit.event.*;
import org.bukkit.event.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
public ExamplePlugin extends JavaPlugin
{
public List<ItemStack> stacks = new ArrayList<ItemStack>();
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if(cmd.getName().equalsIgnoreCase("tester123"))
{
ItemStack stack = new ItemStack(272, 0, (byte)0);
Player p = (Player)sender;
stacks.add(stack);
p.getLocation().getWorld().dropItem(player.getLocation(), stack);
}
return true;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemStackRightClick(PlayerInteractEvent e)
{
Player player = e.getPlayer();
for(ItemStack item : items)
{
if(player.getItemInHand() == item)
{
//What I DO want is something like: if(item.getPluginData(this, "KEY") == "SPECIAL")
//And I would have set it like: item.setPluginData(this, "KEY", "SPECIAL");
player.sendMessage("You got one of our SPECIAL stone swords!!!!");
}
}
}
}
我启动了这个例子,但是当我用一把特殊的剑右键单击时它不起作用。