mirror of
https://github.com/YouHaveTrouble/Enchantio.git
synced 2026-05-11 21:56:55 +00:00
tiny refactor to reuse the enchant key
This commit is contained in:
@@ -38,7 +38,6 @@ public abstract class EnchantioEnchant {
|
|||||||
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
EnchantmentRegistryEntry.EnchantmentCost maximumCost,
|
||||||
TagKey<ItemType> primaryItems,
|
TagKey<ItemType> primaryItems,
|
||||||
TagKey<ItemType> supportedItems,
|
TagKey<ItemType> supportedItems,
|
||||||
|
|
||||||
Set<EquipmentSlotGroup> activeSlots
|
Set<EquipmentSlotGroup> activeSlots
|
||||||
) {
|
) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package me.youhavetrouble.enchantio.listeners;
|
|||||||
|
|
||||||
import io.papermc.paper.registry.RegistryAccess;
|
import io.papermc.paper.registry.RegistryAccess;
|
||||||
import io.papermc.paper.registry.RegistryKey;
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
import me.youhavetrouble.enchantio.Enchantio;
|
|
||||||
import me.youhavetrouble.enchantio.enchants.SoulboundEnchant;
|
import me.youhavetrouble.enchantio.enchants.SoulboundEnchant;
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@@ -17,15 +16,13 @@ public class SoulboundListener implements Listener {
|
|||||||
public void onSoulboundEnchantDeath(PlayerDeathEvent event) {
|
public void onSoulboundEnchantDeath(PlayerDeathEvent event) {
|
||||||
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
||||||
Enchantment soulbound = registry.get(SoulboundEnchant.KEY);
|
Enchantment soulbound = registry.get(SoulboundEnchant.KEY);
|
||||||
Enchantio.getPlugin(Enchantio.class).getLogger().info("Soulbound enchantment: " + soulbound);
|
if (soulbound == null) return;
|
||||||
|
|
||||||
event.getPlayer().getInventory().forEach(itemStack -> {
|
event.getPlayer().getInventory().forEach(itemStack -> {
|
||||||
if (itemStack != null && itemStack.getEnchantments().containsKey(soulbound)) {
|
if (itemStack != null && itemStack.containsEnchantment(soulbound)) {
|
||||||
event.getItemsToKeep().add(itemStack);
|
event.getItemsToKeep().add(itemStack);
|
||||||
event.getDrops().remove(itemStack);
|
event.getDrops().remove(itemStack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ public class TelepathyListener implements Listener {
|
|||||||
public void onTelepathyTool(BlockDropItemEvent event) {
|
public void onTelepathyTool(BlockDropItemEvent event) {
|
||||||
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
Registry<Enchantment> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT);
|
||||||
Enchantment telepathy = registry.get(TelepathyEnchant.KEY);
|
Enchantment telepathy = registry.get(TelepathyEnchant.KEY);
|
||||||
|
if (telepathy == null) return;
|
||||||
|
|
||||||
ItemStack tool = event.getPlayer().getInventory().getItemInMainHand();
|
ItemStack tool = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
if (!tool.getEnchantments().containsKey(telepathy)) return;
|
if (!tool.containsEnchantment(telepathy)) return;
|
||||||
|
|
||||||
for (Item item : event.getItems()) {
|
for (Item item : event.getItems()) {
|
||||||
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
item.teleport(event.getPlayer(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user