Skip to content

Commit 60bca8b

Browse files
Merge pull request #1042 from JasperLorelai/fake-glint
Apply enchantment glint override
2 parents 4266d80 + 8d69602 commit 60bca8b

3 files changed

Lines changed: 13 additions & 41 deletions

File tree

‎core/src/main/java/com/nisovin/magicspells/spells/command/ScrollSpell.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public ItemStack createScroll(Spell spell, int uses, ItemStack item) {
222222
meta.lore(Collections.singletonList(lore));
223223
}
224224

225-
ItemUtil.addFakeEnchantment(meta);
225+
meta.setEnchantmentGlintOverride(true);
226226
meta.getPersistentDataContainer().set(KEY, PersistentDataType.STRING, spell.getInternalName() + (uses > 0 ? "," + uses : ""));
227227
item.setItemMeta(meta);
228228

‎core/src/main/java/com/nisovin/magicspells/util/ItemUtil.java‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
package com.nisovin.magicspells.util;
22

3-
import org.bukkit.inventory.ItemFlag;
43
import org.bukkit.inventory.ItemStack;
54
import org.bukkit.inventory.meta.ItemMeta;
6-
import org.bukkit.enchantments.Enchantment;
75
import org.bukkit.inventory.meta.Damageable;
86

97
public class ItemUtil {
108

11-
public static void addFakeEnchantment(ItemMeta meta) {
12-
if (meta == null) return;
13-
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
14-
meta.addEnchant(Enchantment.FROST_WALKER, -1, true);
15-
}
16-
17-
public static boolean hasFakeEnchantment(ItemMeta meta) {
18-
return meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS)
19-
&& meta.hasEnchant(Enchantment.FROST_WALKER)
20-
&& meta.getEnchantLevel(Enchantment.FROST_WALKER) == 65535;
21-
}
22-
239
public static int getDurability(ItemStack item) {
2410
return item.getItemMeta() instanceof Damageable damageable ? damageable.getDamage() : 0;
2511
}

‎core/src/main/java/com/nisovin/magicspells/util/magicitems/MagicItems.java‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.nisovin.magicspells.util.Util;
2020
import com.nisovin.magicspells.MagicSpells;
21-
import com.nisovin.magicspells.util.ItemUtil;
2221
import com.nisovin.magicspells.util.itemreader.*;
2322
import com.nisovin.magicspells.handlers.DebugHandler;
2423
import com.nisovin.magicspells.handlers.EnchantmentHandler;
@@ -134,23 +133,19 @@ private static MagicItemData getMagicItemDataFromItemStackInternal(ItemStack ite
134133
// author, title, pages
135134
WrittenBookHandler.processMagicItemData(meta, data);
136135

137-
// enchantments
138-
Map<Enchantment, Integer> enchants = new HashMap<>(meta.getEnchants());
139-
if (ItemUtil.hasFakeEnchantment(meta)) {
140-
enchants.remove(Enchantment.FROST_WALKER);
141-
136+
if (meta.hasEnchantmentGlintOverride() && meta.getEnchantmentGlintOverride())
142137
data.setAttribute(FAKE_GLINT, true);
143-
}
144-
if (!enchants.isEmpty()) data.setAttribute(ENCHANTS, enchants);
138+
139+
// enchantments
140+
if (meta.hasEnchants())
141+
data.setAttribute(ENCHANTS, meta.getEnchants());
145142

146143
// attributes
147144
AttributeHandler.processMagicItemData(meta, data);
148145

149146
// lore
150-
if (meta.hasLore()) {
151-
List<Component> lore = meta.lore();
152-
if (lore != null && !lore.isEmpty()) data.setAttribute(LORE, lore);
153-
}
147+
if (meta.hasLore())
148+
data.setAttribute(LORE, meta.lore());
154149

155150
// patterns
156151
BannerHandler.processMagicItemData(meta, data);
@@ -218,13 +213,8 @@ public static MagicItem getMagicItemFromData(MagicItemData data) {
218213
}
219214
}
220215

221-
if (data.hasAttribute(FAKE_GLINT)) {
222-
boolean fakeGlint = (boolean) data.getAttribute(FAKE_GLINT);
223-
224-
if (fakeGlint && !meta.hasEnchants()) {
225-
ItemUtil.addFakeEnchantment(meta);
226-
}
227-
}
216+
if (data.hasAttribute(FAKE_GLINT) && (boolean) data.getAttribute(FAKE_GLINT))
217+
meta.setEnchantmentGlintOverride(true);
228218

229219
// Armor color
230220
LeatherArmorHandler.processItemMeta(meta, data);
@@ -412,13 +402,9 @@ public static MagicItem getMagicItemFromSection(ConfigurationSection section) {
412402
}
413403
}
414404

415-
if (section.isBoolean("fake-glint")) {
416-
boolean fakeGlint = section.getBoolean("fake-glint");
417-
418-
if (fakeGlint && !meta.hasEnchants()) {
419-
ItemUtil.addFakeEnchantment(meta);
420-
itemData.setAttribute(FAKE_GLINT, true);
421-
}
405+
if (section.getBoolean("fake-glint")) {
406+
meta.setEnchantmentGlintOverride(true);
407+
itemData.setAttribute(FAKE_GLINT, true);
422408
}
423409

424410
// Armor color

0 commit comments

Comments
 (0)