cache registry getters

This commit is contained in:
2024-10-20 22:04:34 +02:00
parent 680b0af5d7
commit a0cbe0cf20
2 changed files with 6 additions and 4 deletions
@@ -12,10 +12,11 @@ import org.bukkit.event.entity.PlayerDeathEvent;
public class SoulboundListener implements Listener { public class SoulboundListener implements Listener {
private final Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
private final Enchantment soulbound = registry.get(SoulboundEnchant.KEY);
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onSoulboundEnchantDeath(PlayerDeathEvent event) { public void onSoulboundEnchantDeath(PlayerDeathEvent event) {
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
Enchantment soulbound = registry.get(SoulboundEnchant.KEY);
if (soulbound == null) return; if (soulbound == null) return;
event.getPlayer().getInventory().forEach(itemStack -> { event.getPlayer().getInventory().forEach(itemStack -> {
if (itemStack != null && itemStack.containsEnchantment(soulbound)) { if (itemStack != null && itemStack.containsEnchantment(soulbound)) {
@@ -17,10 +17,11 @@ import org.bukkit.inventory.ItemStack;
public class TelepathyListener implements Listener { public class TelepathyListener implements Listener {
private final Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
private final Enchantment telepathy = registry.get(TelepathyEnchant.KEY);
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onTelepathyTool(BlockDropItemEvent event) { public void onTelepathyTool(BlockDropItemEvent event) {
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
Enchantment telepathy = registry.get(TelepathyEnchant.KEY);
if (telepathy == null) return; if (telepathy == null) return;
ItemStack tool = event.getPlayer().getInventory().getItemInMainHand(); ItemStack tool = event.getPlayer().getInventory().getItemInMainHand();