9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 12:29:15 +00:00

添加禁用附魔台

This commit is contained in:
XiaoMoMi
2025-06-14 04:34:24 +08:00
parent ff4e1754c5
commit 52f9a7c9e7

View File

@@ -35,6 +35,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
@@ -414,4 +416,16 @@ public class ItemEventListener implements Listener {
});
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEnchant(PrepareItemEnchantEvent event) {
ItemStack itemToEnchant = event.getItem();
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(itemToEnchant);
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
if (optionalCustomItem.isEmpty()) return;
CustomItem<ItemStack> customItem = optionalCustomItem.get();
if (!customItem.settings().canEnchant()) {
event.setCancelled(true);
}
}
}