Minecraft 1.16.4 Spigot 新下界合金物品问题
Minecraft 1.16.4 Spigot new netherite items issue
正在尝试实现让玩家只掉落昂贵物品的插件。这是代码的快捷方式:
public HashMap<Player , ItemStack[]> items = new HashMap<Player , ItemStack[]>();
@EventHandler
public void onDeath(PlayerDeathEvent event)
{
if (event.getEntity().getGameMode().equals(GameMode.SURVIVAL))
{
ItemStack[] content = event.getEntity().getInventory().getContents();
items.put(event.getEntity(), content);
event.getDrops().removeIf(stack -> !this.isExpensive(stack.getType().toString()));
// isExpensive method returns 1 if the itemstack is expensive, 0 either
}
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event)
{
if (event.getPlayer().getGameMode().equals(GameMode.SURVIVAL) && items.containsKey(event.getPlayer()))
{
for (ItemStack stack : items.get(event.getPlayer()))
{
if (!this.isExpensive(stack.getType().toString()))
event.getPlayer().getInventory().addItem(stack);
}
items.remove(event.getPlayer());
}
}
它工作正常,但新的下界合金块有问题,它们的 .typeName().toString() 是“AIR”,我在 PlayerDeathEvent 方法中编写了以下代码来检查这一点:
for (ItemStack stack : event.getDrops())
plugin.getLogger().info(stack.getType().toString());
结果如下:
[01:34:40 INFO]: h4sv issued server command: /give h4sv minecraft:diamond
[01:34:40 INFO]: §7§o[h4sv: Gave 1 [Diamond] to h4sv]
[01:34:44 INFO]: h4sv issued server command: /give h4sv minecraft:netherite_ingot
[01:34:44 INFO]: §7§o[h4sv: Gave 1 [Netherite Ingot] to h4sv]
[01:34:47 INFO]: h4sv issued server command: /give h4sv minecraft:netherite_block
[01:34:47 INFO]: §7§o[h4sv: Gave 1 [Block of Netherite] to h4sv]
[01:35:00 INFO]: h4sv issued server command: /give h4sv netherite_scrap
[01:35:00 INFO]: §7§o[h4sv: Gave 1 [Netherite Scrap] to h4sv]
[01:35:05 INFO]: h4sv issued server command: /give h4sv minecraft:ancient_debris
[01:35:05 INFO]: §7§o[h4sv: Gave 1 [Ancient Debris] to h4sv]
[01:35:10 INFO]: h4sv issued server command: /give h4sv minecraft:acacia_sapling 64
[01:35:10 INFO]: §7§o[h4sv: Gave 64 [Acacia Sapling] to h4sv]
[01:35:16 INFO]: h4sv issued server command: /kill
[01:35:16 INFO]: DIAMOND
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: SAPLING
[01:35:16 INFO]: h4sv fell out of the world
我 运行 服务器使用 Paper 1.16.4 build 337,并使用 Spigot 1.16.4(最新版本)作为插件库。
我认为这是因为在玩家死亡的那一刻(PlayerDeathEvent
被触发)他的库存已经掉落了物品,所以插槽变空了这解释了 AIR
值,但那是奇怪的是,这只发生在下界合金物品上。
但是,您可以使用 org.bukkit.event.entity.EntityDeathEvent#getDrops
方法解决此问题,该方法 returns 所有项目,包括下界合金材料。
正在尝试实现让玩家只掉落昂贵物品的插件。这是代码的快捷方式:
public HashMap<Player , ItemStack[]> items = new HashMap<Player , ItemStack[]>();
@EventHandler
public void onDeath(PlayerDeathEvent event)
{
if (event.getEntity().getGameMode().equals(GameMode.SURVIVAL))
{
ItemStack[] content = event.getEntity().getInventory().getContents();
items.put(event.getEntity(), content);
event.getDrops().removeIf(stack -> !this.isExpensive(stack.getType().toString()));
// isExpensive method returns 1 if the itemstack is expensive, 0 either
}
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event)
{
if (event.getPlayer().getGameMode().equals(GameMode.SURVIVAL) && items.containsKey(event.getPlayer()))
{
for (ItemStack stack : items.get(event.getPlayer()))
{
if (!this.isExpensive(stack.getType().toString()))
event.getPlayer().getInventory().addItem(stack);
}
items.remove(event.getPlayer());
}
}
它工作正常,但新的下界合金块有问题,它们的 .typeName().toString() 是“AIR”,我在 PlayerDeathEvent 方法中编写了以下代码来检查这一点:
for (ItemStack stack : event.getDrops())
plugin.getLogger().info(stack.getType().toString());
结果如下:
[01:34:40 INFO]: h4sv issued server command: /give h4sv minecraft:diamond
[01:34:40 INFO]: §7§o[h4sv: Gave 1 [Diamond] to h4sv]
[01:34:44 INFO]: h4sv issued server command: /give h4sv minecraft:netherite_ingot
[01:34:44 INFO]: §7§o[h4sv: Gave 1 [Netherite Ingot] to h4sv]
[01:34:47 INFO]: h4sv issued server command: /give h4sv minecraft:netherite_block
[01:34:47 INFO]: §7§o[h4sv: Gave 1 [Block of Netherite] to h4sv]
[01:35:00 INFO]: h4sv issued server command: /give h4sv netherite_scrap
[01:35:00 INFO]: §7§o[h4sv: Gave 1 [Netherite Scrap] to h4sv]
[01:35:05 INFO]: h4sv issued server command: /give h4sv minecraft:ancient_debris
[01:35:05 INFO]: §7§o[h4sv: Gave 1 [Ancient Debris] to h4sv]
[01:35:10 INFO]: h4sv issued server command: /give h4sv minecraft:acacia_sapling 64
[01:35:10 INFO]: §7§o[h4sv: Gave 64 [Acacia Sapling] to h4sv]
[01:35:16 INFO]: h4sv issued server command: /kill
[01:35:16 INFO]: DIAMOND
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: AIR
[01:35:16 INFO]: SAPLING
[01:35:16 INFO]: h4sv fell out of the world
我 运行 服务器使用 Paper 1.16.4 build 337,并使用 Spigot 1.16.4(最新版本)作为插件库。
我认为这是因为在玩家死亡的那一刻(PlayerDeathEvent
被触发)他的库存已经掉落了物品,所以插槽变空了这解释了 AIR
值,但那是奇怪的是,这只发生在下界合金物品上。
但是,您可以使用 org.bukkit.event.entity.EntityDeathEvent#getDrops
方法解决此问题,该方法 returns 所有项目,包括下界合金材料。