Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-14 20:10:05 +01:00
add test plugin for PlayerLiddedOpenEvent
Dieser Commit ist enthalten in:
Ursprung
65a31d2032
Commit
08840a3902
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren