From 4267bcf7dd944e736fec8fe0fbda3db413da4902 Mon Sep 17 00:00:00 2001 From: ProfElements Date: Mon, 29 Apr 2024 01:23:25 -0500 Subject: [PATCH 1/2] :bug: fix: Change `DURABILTY` to `UNBREAKING` --- pom.xml | 4 ++-- .../litexpansion/armor/AdvancedSolarHelmet.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 78ddab13..aaa4ad0f 100644 --- a/pom.xml +++ b/pom.xml @@ -23,14 +23,14 @@ org.spigotmc spigot-api - 1.19-R0.1-SNAPSHOT + 1.20.5-R0.1-SNAPSHOT provided com.github.Slimefun Slimefun4 - 1aeb0e8 + 03e5b9ab1e provided diff --git a/src/main/java/dev/j3fftw/litexpansion/armor/AdvancedSolarHelmet.java b/src/main/java/dev/j3fftw/litexpansion/armor/AdvancedSolarHelmet.java index b25e310f..f62f21a5 100644 --- a/src/main/java/dev/j3fftw/litexpansion/armor/AdvancedSolarHelmet.java +++ b/src/main/java/dev/j3fftw/litexpansion/armor/AdvancedSolarHelmet.java @@ -23,12 +23,12 @@ public AdvancedSolarHelmet(Type type) { type.getGenerationRate() ); this.type = type; - Items.ADVANCED_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 1); - Items.CARBONADO_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 2); - Items.ENERGIZED_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 3); - Items.ADVANCEDLX_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 4); - Items.HYBRID_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 5); - Items.ULTIMATE_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 6); + Items.ADVANCED_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 1); + Items.CARBONADO_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 2); + Items.ENERGIZED_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 3); + Items.ADVANCEDLX_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 4); + Items.HYBRID_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 5); + Items.ULTIMATE_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 6); } @Getter From 07ca9760be9d8835baa7ca155279985b6dd81bb3 Mon Sep 17 00:00:00 2001 From: ProfElements Date: Mon, 29 Apr 2024 01:41:49 -0500 Subject: [PATCH 2/2] fix enchantment thing potentially --- .../dev/j3fftw/litexpansion/GlowEnchant.java | 80 ------------------ .../java/dev/j3fftw/litexpansion/Items.java | 84 ++++++++++--------- .../dev/j3fftw/litexpansion/LiteXpansion.java | 19 ----- .../j3fftw/litexpansion/utils/Constants.java | 4 - .../litexpansion/weapons/NanoBlade.java | 9 +- 5 files changed, 50 insertions(+), 146 deletions(-) delete mode 100644 src/main/java/dev/j3fftw/litexpansion/GlowEnchant.java diff --git a/src/main/java/dev/j3fftw/litexpansion/GlowEnchant.java b/src/main/java/dev/j3fftw/litexpansion/GlowEnchant.java deleted file mode 100644 index 2cda0109..00000000 --- a/src/main/java/dev/j3fftw/litexpansion/GlowEnchant.java +++ /dev/null @@ -1,80 +0,0 @@ -package dev.j3fftw.litexpansion; - -import com.google.common.base.Preconditions; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import javax.annotation.Nonnull; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; - -public class GlowEnchant extends Enchantment { - - private final Set ids = new HashSet<>(); - - public GlowEnchant(@Nonnull NamespacedKey key, @Nonnull String[] applicableItems) { - super(key); - ids.addAll(Arrays.asList(applicableItems)); - } - - @Nonnull - @Override - @Deprecated - public String getName() { - return "LX_Glow"; - } - - @Override - public int getMaxLevel() { - return 1; - } - - @Override - public int getStartLevel() { - return 1; - } - - @Nonnull - @Override - @Deprecated - public EnchantmentTarget getItemTarget() { - return EnchantmentTarget.ALL; - } - - @Override - public boolean isTreasure() { - return false; - } - - @Override - @Deprecated - public boolean isCursed() { - return false; - } - - @Override - public boolean conflictsWith(@Nonnull Enchantment enchantment) { - return false; - } - - @Override - public boolean canEnchantItem(ItemStack item) { - if (item.hasItemMeta()) { - final ItemMeta itemMeta = item.getItemMeta(); - Preconditions.checkNotNull(itemMeta, "can not be null"); - final Optional id = Slimefun.getItemDataService().getItemData(itemMeta); - - if (id.isPresent()) { - return ids.contains(id.get()); - } - } - return false; - } - -} diff --git a/src/main/java/dev/j3fftw/litexpansion/Items.java b/src/main/java/dev/j3fftw/litexpansion/Items.java index 852ee2e4..447348e9 100644 --- a/src/main/java/dev/j3fftw/litexpansion/Items.java +++ b/src/main/java/dev/j3fftw/litexpansion/Items.java @@ -19,6 +19,8 @@ import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; +import java.util.List; + public final class Items { //region Category @@ -64,12 +66,15 @@ public final class Items { "GLASS_CUTTER", Material.GHAST_TEAR, "&bGlass Cutter", - "", - "&7> &eLeft Click &7- Cut glass quickly", - "&7> &eRight Click &7- Cut glass slowly", - "", - "&c&o&8\u21E8 &e\u26A1 &70 / 300 J" - ); + meta -> { + meta.setEnchantmentGlintOverride(true); + meta.setLore(List.of( + "", + "&7> &eLeft Click &7- Cut glass quickly", + "&7> &eRight Click &7- Cut glass slowly", + "", + "&c&o&8\u21E8 &e\u26A1 &70 / 300 J")); + }); public static final SlimefunItemStack MINING_DRILL = new SlimefunItemStack( "MINING_DRILL", Material.IRON_SHOVEL, @@ -84,12 +89,16 @@ public final class Items { "DIAMOND_DRILL", Material.DIAMOND_SHOVEL, "&bDiamond Drill", - "", - "&7Instantly breaks obsidian, stone, and stone variants", - "&7Right click to break block slower", - "", - "&c&o&8\u21E8 &e\u26A1 &70 / 1000 J" - ); + meta -> { + meta.setEnchantmentGlintOverride(true); + meta.setLore(List.of( + "", + "&7Instantly breaks obsidian, stone, and stone variants", + "&7Right click to break block slower", + "", + "&c&o&8\u21E8 &e\u26A1 &70 / 1000 J" + )); + }); public static final SlimefunItemStack TREETAP = new SlimefunItemStack( "TREETAP", Material.WOODEN_HOE, @@ -228,7 +237,8 @@ public final class Items { public static final SlimefunItemStack ADVANCED_CIRCUIT = new SlimefunItemStack( "ADVANCED_CIRCUIT", Material.COBWEB, - "&7Advanced Circuit" + "&7Advanced Circuit", + meta -> {meta.setEnchantmentGlintOverride(true);} ); //endregion @@ -272,8 +282,10 @@ public final class Items { public static final SlimefunItemStack LAPOTRON_CRYSTAL = new SlimefunItemStack( "LAPOTRON_CRYSTAL", Material.DIAMOND, - "&7Lapotron Crystal" - ); + "&7Lapotron Crystal", + meta -> { + meta.setEnchantmentGlintOverride(true); + }); public static final SlimefunItemStack REINFORCED_STONE = new SlimefunItemStack( "REINFORCED_STONE", Material.STONE, @@ -443,20 +455,26 @@ public final class Items { public static final SlimefunItemStack ADVANCEDLX_SOLAR_HELMET = new SlimefunItemStack( "ADVANCEDLX_SOLAR_HELMET", Material.DIAMOND_HELMET, - "&7Super Advanced Solar Helmet" - ); + "&7Super Advanced Solar Helmet", + meta -> { + meta.setEnchantmentGlintOverride(true); + }); public static final SlimefunItemStack HYBRID_SOLAR_HELMET = new SlimefunItemStack( "HYBRID_SOLAR_HELMET", Material.DIAMOND_HELMET, - "&7Hybrid Solar Helmet" - ); + "&7Hybrid Solar Helmet", + meta -> { + meta.setEnchantmentGlintOverride(true); + }); public static final SlimefunItemStack ULTIMATE_SOLAR_HELMET = new SlimefunItemStack( "ULTIMATE_SOLAR_HELMET", Material.DIAMOND_HELMET, - "&7Ultimate Solar Helmet" - ); + "&7Ultimate Solar Helmet", + meta -> { + meta.setEnchantmentGlintOverride(true); + }); public static final SlimefunItemStack FOOD_SYNTHESIZER = new SlimefunItemStack( "FOOD_SYNTHESIZER", @@ -550,24 +568,14 @@ public final class Items { Material.COAL_BLOCK, "&7Converter" ); - - private static final Enchantment glowEnchant = Enchantment.getByKey(Constants.GLOW_ENCHANT); - + static { - ADVANCED_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 1); - CARBONADO_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 2); - ENERGIZED_SOLAR_HELMET.addEnchantment(Enchantment.DURABILITY, 3); - ADVANCEDLX_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 4); - HYBRID_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 5); - ULTIMATE_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.DURABILITY, 6); - ADVANCED_CIRCUIT.addEnchantment(glowEnchant, 1); - GLASS_CUTTER.addEnchantment(glowEnchant, 1); - - DIAMOND_DRILL.addEnchantment(glowEnchant, 1); - LAPOTRON_CRYSTAL.addEnchantment(glowEnchant, 1); - ADVANCEDLX_SOLAR_HELMET.addEnchantment(glowEnchant, 1); - HYBRID_SOLAR_HELMET.addEnchantment(glowEnchant, 1); - ULTIMATE_SOLAR_HELMET.addEnchantment(glowEnchant, 1); + ADVANCED_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 1); + CARBONADO_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 2); + ENERGIZED_SOLAR_HELMET.addEnchantment(Enchantment.UNBREAKING, 3); + ADVANCEDLX_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 4); + HYBRID_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 5); + ULTIMATE_SOLAR_HELMET.addUnsafeEnchantment(Enchantment.UNBREAKING, 6); } private Items() {} diff --git a/src/main/java/dev/j3fftw/litexpansion/LiteXpansion.java b/src/main/java/dev/j3fftw/litexpansion/LiteXpansion.java index 19bdb14a..70116717 100644 --- a/src/main/java/dev/j3fftw/litexpansion/LiteXpansion.java +++ b/src/main/java/dev/j3fftw/litexpansion/LiteXpansion.java @@ -41,8 +41,6 @@ public void onEnable() { new BlobBuildUpdater(this, getFile(), "LiteXpansion", "Dev").start(); } - registerEnchantments(); - if (getConfig().getBoolean("options.nerf-other-addons", true)) { getServer().getScheduler().runTask(this, this::nerfCrap); } @@ -65,23 +63,6 @@ public void onDisable() { setInstance(null); } - private void registerEnchantments() { - if (!Enchantment.isAcceptingRegistrations()) { - Reflections.setStaticField(Enchantment.class, "acceptingNew", true); - } - - Enchantment glowEnchantment = new GlowEnchant(Constants.GLOW_ENCHANT, new String[] { - "ADVANCED_CIRCUIT", "NANO_BLADE", "GLASS_CUTTER", "LAPOTRON_CRYSTAL", - "ADVANCEDLX_SOLAR_HELMET", "HYBRID_SOLAR_HELMET", "ULTIMATE_SOLAR_HELMET", - "DIAMOND_DRILL" - }); - - // Prevent double-registration errors - if (Enchantment.getByKey(glowEnchantment.getKey()) == null) { - Enchantment.registerEnchantment(glowEnchantment); - } - } - private void nerfCrap() { // Vanilla SF final SlimefunItem energizedPanel = SlimefunItem.getById("SOLAR_GENERATOR_4"); diff --git a/src/main/java/dev/j3fftw/litexpansion/utils/Constants.java b/src/main/java/dev/j3fftw/litexpansion/utils/Constants.java index 6b59e0b9..30fdae4e 100644 --- a/src/main/java/dev/j3fftw/litexpansion/utils/Constants.java +++ b/src/main/java/dev/j3fftw/litexpansion/utils/Constants.java @@ -4,10 +4,6 @@ import org.bukkit.NamespacedKey; public final class Constants { - - public static final NamespacedKey GLOW_ENCHANT = new NamespacedKey(LiteXpansion.getInstance(), - "glow_enchant"); - public static final NamespacedKey NANO_BLADE_ENABLED = new NamespacedKey(LiteXpansion.getInstance(), "nano_blade_enabled"); diff --git a/src/main/java/dev/j3fftw/litexpansion/weapons/NanoBlade.java b/src/main/java/dev/j3fftw/litexpansion/weapons/NanoBlade.java index de8df7da..f1d2545b 100644 --- a/src/main/java/dev/j3fftw/litexpansion/weapons/NanoBlade.java +++ b/src/main/java/dev/j3fftw/litexpansion/weapons/NanoBlade.java @@ -47,13 +47,12 @@ public float getMaxItemCharge(ItemStack item) { public ItemUseHandler getItemHandler() { return event -> { final ItemMeta nanoBladeMeta = event.getItem().getItemMeta(); - final Enchantment enchantment = Enchantment.getByKey(Constants.GLOW_ENCHANT); - boolean enabled = !nanoBladeMeta.removeEnchant(enchantment); + boolean enabled = !nanoBladeMeta.getEnchantmentGlintOverride(); int damage; if (enabled && getItemCharge(event.getItem()) > getRemovedChargePerTick()) { - nanoBladeMeta.addEnchant(enchantment, 1, false); + nanoBladeMeta.setEnchantmentGlintOverride(true); nanoBladeMeta.setDisplayName(ChatColor.DARK_GREEN + "Nano Blade" + ChatColor.GREEN + " (On)"); damage = 13; // Base is 7 so 7 + 13 = 20 @@ -89,7 +88,7 @@ public float getCapacity() { @Override public boolean isEnabled(@Nonnull ItemMeta meta) { final Optional opt = Utils.getOptionalBoolean(meta, Constants.NANO_BLADE_ENABLED); - - return (opt.isPresent() && opt.get()) || meta.hasEnchant(Enchantment.getByKey(Constants.GLOW_ENCHANT)); + final Boolean hasOverride = meta.getEnchantmentGlintOverride(); + return (opt.isPresent() && opt.get()) || hasOverride; } }