minecraft 1.16.4 spigot新尼日项目发布

xjreopfe  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(504)

试图实现插件,将使玩家只下降昂贵的项目。下面是代码的快捷方式:

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());
        }
    }

它工作正常,但是新的netherite块有一个问题,它们的.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

我在1.16.4build337上运行服务器,并使用spigot1.16.4(最新版本)作为插件库。

wpcxdonn

wpcxdonn1#

我想这是因为在球员死的那一刻 PlayerDeathEvent 触发)他的库存已经丢弃了该项目,因此插槽变空这解释了 AIR 价值,但奇怪的是这只发生在尼日教的物品上。
但是,您可以使用 org.bukkit.event.entity.EntityDeathEvent#getDrops 方法,该方法返回所有项,包括尼日教内容。

相关问题