diff --git a/test-plugin/src/main/java/io/papermc/testplugin/LiddedTestListener.java b/test-plugin/src/main/java/io/papermc/testplugin/LiddedTestListener.java new file mode 100644 index 0000000000..2eb1af82b6 --- /dev/null +++ b/test-plugin/src/main/java/io/papermc/testplugin/LiddedTestListener.java @@ -0,0 +1,52 @@ +package io.papermc.testplugin; + +import io.papermc.paper.event.player.PlayerLiddedOpenEvent; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.tag.Tag; +import io.papermc.paper.registry.tag.TagKey; +import java.util.Objects; +import java.util.logging.Logger; +import net.kyori.adventure.key.Key; +import org.bukkit.Registry; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ItemType; + +public class LiddedTestListener implements Listener { + + private static final TagKey WOOL_TAG_KEY = TagKey.create(RegistryKey.ITEM, + Key.key("minecraft:wool")); + private final Logger logger; + + public LiddedTestListener(Logger logger) { + this.logger = logger; + } + + @EventHandler + public void onLiddedEvent(PlayerLiddedOpenEvent event) { + Registry itemTypeRegistry = RegistryAccess.registryAccess() + .getRegistry(RegistryKey.ITEM); + if (!itemTypeRegistry.hasTag(WOOL_TAG_KEY)) { + logger.warning("Wool tag not found"); + return; + } + Tag woolTag = itemTypeRegistry.getTag(WOOL_TAG_KEY); + + ItemStack mainHandItem = event.getPlayer().getInventory().getItemInMainHand(); + + boolean isWool = woolTag.contains( + TypedKey.create(RegistryKey.ITEM, itemTypeRegistry.getKeyOrThrow( + Objects.requireNonNull(mainHandItem.getType().asItemType())))); + + if (isWool) { + event.getPlayer().sendRichMessage( + "Opening " + event.getLidded().getType().getKey().asString() + + " Quietly"); + event.setCancelled(true); + } + } + +} diff --git a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java index 9de339c257..ce08644b79 100644 --- a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java +++ b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java @@ -243,6 +243,8 @@ public final class TestPlugin extends JavaPlugin implements Listener { }); + getServer().getPluginManager().registerEvents(new LiddedTestListener(this.getLogger()), this); + // io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this); }