mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-18 04:51:20 +01:00
Added new lore system
This commit is contained in:
parent
7e1cc48766
commit
87494afacc
@ -37,6 +37,7 @@ public class EnchantDisplay {
|
|||||||
*/
|
*/
|
||||||
public static final NamespacedKey keySkip = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip");
|
public static final NamespacedKey keySkip = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip");
|
||||||
|
|
||||||
|
private static final String prefix = ChatColor.translateAlternateColorCodes('&',"&a&e&a&r");
|
||||||
|
|
||||||
private static String normalColor;
|
private static String normalColor;
|
||||||
private static String curseColor;
|
private static String curseColor;
|
||||||
@ -94,6 +95,8 @@ public class EnchantDisplay {
|
|||||||
if(meta.hasLore())
|
if(meta.hasLore())
|
||||||
itemLore = meta.getLore();
|
itemLore = meta.getLore();
|
||||||
|
|
||||||
|
if(itemLore == null) itemLore = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) {
|
if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) {
|
||||||
int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER);
|
int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER);
|
||||||
@ -103,7 +106,7 @@ public class EnchantDisplay {
|
|||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
|
|
||||||
|
itemLore.removeIf((s -> s.startsWith(prefix)));
|
||||||
|
|
||||||
if (meta instanceof EnchantmentStorageMeta) {
|
if (meta instanceof EnchantmentStorageMeta) {
|
||||||
EnchantmentStorageMeta metaBook = (EnchantmentStorageMeta) meta;
|
EnchantmentStorageMeta metaBook = (EnchantmentStorageMeta) meta;
|
||||||
@ -200,12 +203,12 @@ public class EnchantDisplay {
|
|||||||
if(isEcoEnchant) {
|
if(isEcoEnchant) {
|
||||||
name = enchantment.getName();
|
name = enchantment.getName();
|
||||||
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
|
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
|
||||||
description.replaceAll(line -> descriptionColor + line);
|
description.replaceAll(line -> prefix + descriptionColor + line);
|
||||||
if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment);
|
if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment);
|
||||||
} else {
|
} else {
|
||||||
name = ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".name");
|
name = ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".name");
|
||||||
description = Arrays.asList(WordUtils.wrap(ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".description"), ConfigManager.getConfig().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
description = Arrays.asList(WordUtils.wrap(ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".description"), ConfigManager.getConfig().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
||||||
description.replaceAll(line -> descriptionColor + line);
|
description.replaceAll(line -> prefix + descriptionColor + line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(isMaxLevelOne || type == EcoEnchant.EnchantmentType.CURSE)) {
|
if(!(isMaxLevelOne || type == EcoEnchant.EnchantmentType.CURSE)) {
|
||||||
@ -222,11 +225,11 @@ public class EnchantDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(type == EcoEnchant.EnchantmentType.CURSE) {
|
if(type == EcoEnchant.EnchantmentType.CURSE) {
|
||||||
curseLore.add(color + name);
|
curseLore.add(prefix + color + name);
|
||||||
if(describe) curseLore.addAll(description);
|
if(describe) curseLore.addAll(description);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
normalLore.add(color + name);
|
normalLore.add(prefix + color + name);
|
||||||
if(describe) normalLore.addAll(description);
|
if(describe) normalLore.addAll(description);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -260,14 +263,12 @@ public class EnchantDisplay {
|
|||||||
metaBook.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee!
|
metaBook.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee!
|
||||||
metaBook.addItemFlags(ItemFlag.HIDE_ENCHANTS); // Here just in case
|
metaBook.addItemFlags(ItemFlag.HIDE_ENCHANTS); // Here just in case
|
||||||
metaBook.setLore(itemLore);
|
metaBook.setLore(itemLore);
|
||||||
metaBook.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, enchantLore.size());
|
|
||||||
item.setItemMeta(metaBook);
|
item.setItemMeta(metaBook);
|
||||||
} else {
|
} else {
|
||||||
if(!meta.getEnchants().equals(oldItem.getItemMeta().getEnchants())) return oldItem;
|
if(!meta.getEnchants().equals(oldItem.getItemMeta().getEnchants())) return oldItem;
|
||||||
forRemoval.forEach((meta::removeEnchant));
|
forRemoval.forEach((meta::removeEnchant));
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
meta.setLore(itemLore);
|
meta.setLore(itemLore);
|
||||||
meta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, enchantLore.size());
|
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public abstract class EnchantChecks {
|
public final class EnchantChecks {
|
||||||
public static boolean item(ItemStack item, Enchantment enchantment) {
|
public static boolean item(ItemStack item, Enchantment enchantment) {
|
||||||
return getItemLevel(item, enchantment) != 0;
|
return getItemLevel(item, enchantment) != 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user