add test plugin for PlayerLiddedOpenEvent

This commit is contained in:
Isaac - The456 2024-09-13 01:43:47 +01:00
parent 65a31d2032
commit 08840a3902
No known key found for this signature in database
GPG Key ID: 57A848D2F87C14EF
2 changed files with 54 additions and 0 deletions

View File

@ -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<ItemType> 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<ItemType> itemTypeRegistry = RegistryAccess.registryAccess()
.getRegistry(RegistryKey.ITEM);
if (!itemTypeRegistry.hasTag(WOOL_TAG_KEY)) {
logger.warning("Wool tag not found");
return;
}
Tag<ItemType> 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(
"<gray>Opening <gold>" + event.getLidded().getType().getKey().asString()
+ "</gold> Quietly");
event.setCancelled(true);
}
}
}

View File

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