我正在开发一个插件,当你打破一个块,比如石头,取决于你的镐上有多少财富,取决于它会在你的库存中投入多少。
插件详细信息:
我不太清楚当一个玩家打破一个砖块,比如石头,它会在他们的库存中放置超过一个街区。我想要做的是,如果他们在他们的镐上说财富6,它可能会在他们的库存中放置5-7个街区,但如果他们有财富30,它将在他们的库存中放置10-15个街区。我只是试着摆弄各种选择,看看能不能弄清楚,但我想不出来。我也没有使用hashmap的经验,所以如果我也做错了,我很抱歉。
代码:
@EventHandler
public void fortuneBlock(BlockBreakEvent e) {
Player p = (Player) e.getPlayer();
Block b = (Block) e.getBlock();
ItemStack DP = new ItemStack(Material.DIAMOND_PICKAXE);
if (p.getInventory().contains(DP)) {
if (DP.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
HashMap<Enchantment, Integer> pickaxe = p.getInventory().getItem(Material.DIAMOND_PICKAXE);
}
}
}如果你需要其他信息告诉我。
发布于 2016-09-12 09:14:00
getEnchantments()
//Map containing all enchantments of the ItemStack
//The Map looks like: [KEY,VALUE]
// [Enchantment.DURABILITY,2],
// [Enchantment.LOOT_BONUS_BLOCKS,4]
HashMap<Enchantment, Integer> enchantmentMap = YourItemStack.getEnchantments();
//Check if this map contains the wanted Enchantment
if(enchantmentMap.containsKey(Enchantment.LOOT_BONUS_BLOCKS))
//Get VALUE of KEY which is the enchantLevel "4"
Integer enchantmentLevel = enchantmentMap.get(Enchantment.LOOT_BONUS_BLOCKS);您可以想象一个像表一样的地图,每个KEY都有自己的value。因此,KEY是独一无二的。
https://stackoverflow.com/questions/39442529
复制相似问题