mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-25 15:35:11 +01:00
Reworked EnchantmentType into instantiatable system
This commit is contained in:
parent
b143eb279c
commit
7c0e17f1f3
@ -55,12 +55,7 @@ public class EnchantDisplay {
|
||||
|
||||
public static final String PREFIX = "§w";
|
||||
|
||||
static String normalColor;
|
||||
static String curseColor;
|
||||
static String specialColor;
|
||||
static String artifactColor;
|
||||
static String descriptionColor;
|
||||
static String spellColor;
|
||||
|
||||
static int numbersThreshold;
|
||||
static boolean useNumerals;
|
||||
@ -78,11 +73,6 @@ public class EnchantDisplay {
|
||||
*/
|
||||
public static void update() {
|
||||
descriptionColor = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
||||
curseColor = StringUtils.translate(ConfigManager.getLang().getString("curse-color"));
|
||||
specialColor = StringUtils.translate(ConfigManager.getLang().getString("special-color"));
|
||||
artifactColor = StringUtils.translate(ConfigManager.getLang().getString("artifact-color"));
|
||||
spellColor = StringUtils.translate(ConfigManager.getLang().getString("spell-color"));
|
||||
normalColor = StringUtils.translate(ConfigManager.getLang().getString("not-curse-color"));
|
||||
|
||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||
numbersThreshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
||||
|
@ -52,23 +52,7 @@ public class EnchantmentCache {
|
||||
type = enchantment.isCursed() ? EcoEnchant.EnchantmentType.CURSE : EcoEnchant.EnchantmentType.NORMAL;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case ARTIFACT:
|
||||
color = EnchantDisplay.artifactColor;
|
||||
break;
|
||||
case SPECIAL:
|
||||
color = EnchantDisplay.specialColor;
|
||||
break;
|
||||
case CURSE:
|
||||
color = EnchantDisplay.curseColor;
|
||||
break;
|
||||
case SPELL:
|
||||
color = EnchantDisplay.spellColor;
|
||||
break;
|
||||
default:
|
||||
color = EnchantDisplay.normalColor;
|
||||
break;
|
||||
}
|
||||
color = type.getColor();
|
||||
|
||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EnchantmentRarity rarity = EcoEnchants.getFromEnchantment(enchantment).getRarity();
|
||||
|
@ -10,8 +10,10 @@ import com.willfp.ecoenchants.integrations.placeholder.PlaceholderEntry;
|
||||
import com.willfp.ecoenchants.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
import com.willfp.ecoenchants.util.interfaces.ObjectCallable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -433,24 +435,43 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
return targetMaterials.contains(itemStack.getType()) || itemStack.getType().equals(Material.BOOK) || itemStack.getType().equals(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* The types of {@link EcoEnchant}
|
||||
*/
|
||||
public enum EnchantmentType {
|
||||
NORMAL(false),
|
||||
CURSE(false),
|
||||
SPECIAL(true),
|
||||
ARTIFACT(true),
|
||||
SPELL(true);
|
||||
public static class EnchantmentType {
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType(false, () -> ConfigManager.getLang().getString("not-curse-color"));
|
||||
public static final EnchantmentType CURSE = new EnchantmentType(false, () -> ConfigManager.getLang().getString("curse-color"));
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType(() -> !ConfigManager.getConfig().getBool("types.special.allow-multiple"), () -> ConfigManager.getLang().getString("special-color"));
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType(() -> !ConfigManager.getConfig().getBool("types.artifact.allow-multiple"), () -> ConfigManager.getLang().getString("artifact-color"));
|
||||
public static final EnchantmentType SPELL = new EnchantmentType(true, () -> ConfigManager.getLang().getString("spell-color"));
|
||||
|
||||
static {
|
||||
update();
|
||||
private static final Set<EnchantmentType> values = new HashSet<>();
|
||||
|
||||
private boolean singular;
|
||||
private String color;
|
||||
private final ObjectCallable<String> colorCallable;
|
||||
private final ObjectCallable<Boolean> singularCallable;
|
||||
|
||||
public EnchantmentType(boolean singular, String color) {
|
||||
this(() -> singular, () -> color);
|
||||
}
|
||||
|
||||
boolean singular;
|
||||
public EnchantmentType(boolean singular, ObjectCallable<String> colorCallable) {
|
||||
this(() -> singular, colorCallable);
|
||||
}
|
||||
|
||||
EnchantmentType(boolean singular) {
|
||||
this.singular = singular;
|
||||
public EnchantmentType(ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable) {
|
||||
this.singularCallable = singularCallable;
|
||||
this.colorCallable = colorCallable;
|
||||
color = colorCallable.call();
|
||||
singular = singularCallable.call();
|
||||
values.add(this);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
this.color = colorCallable.call();
|
||||
this.singular = singularCallable.call();
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isSingular() {
|
||||
@ -458,8 +479,11 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
SPECIAL.singular = !ConfigManager.getConfig().getBool("types.special.allow-multiple");
|
||||
ARTIFACT.singular = !ConfigManager.getConfig().getBool("types.artifact.allow-multiple");
|
||||
values.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
||||
public static Set<EnchantmentType> getValues() {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class AnvilMerge {
|
||||
rightEnchants.forEach(((enchantment, integer) -> {
|
||||
AtomicBoolean doesConflict = new AtomicBoolean(false);
|
||||
|
||||
Arrays.stream(EcoEnchant.EnchantmentType.values()).forEach(enchantmentType -> {
|
||||
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
||||
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if(enchant == null) return;
|
||||
if(enchant.getType().equals(enchantmentType) && EcoEnchants.hasAnyOfType(left, enchantmentType) && enchantmentType.isSingular()) doesConflict.set(true);
|
||||
|
@ -1,18 +1,18 @@
|
||||
package com.willfp.ecoenchants.integrations.placeholder;
|
||||
|
||||
import com.willfp.ecoenchants.util.interfaces.ObjectCallable;
|
||||
import com.willfp.ecoenchants.util.interfaces.ObjectBiCallable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlaceholderEntry {
|
||||
private final String identifier;
|
||||
private final ObjectCallable<String, Player> function;
|
||||
private final ObjectBiCallable<String, Player> function;
|
||||
private final boolean requiresPlayer;
|
||||
|
||||
public PlaceholderEntry(String identifier, ObjectCallable<String, Player> function) {
|
||||
public PlaceholderEntry(String identifier, ObjectBiCallable<String, Player> function) {
|
||||
this(identifier, function, false);
|
||||
}
|
||||
|
||||
public PlaceholderEntry(String identifier, ObjectCallable<String, Player> function, boolean requiresPlayer) {
|
||||
public PlaceholderEntry(String identifier, ObjectBiCallable<String, Player> function, boolean requiresPlayer) {
|
||||
this.identifier = identifier;
|
||||
this.function = function;
|
||||
this.requiresPlayer = requiresPlayer;
|
||||
|
@ -0,0 +1,6 @@
|
||||
package com.willfp.ecoenchants.util.interfaces;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ObjectBiCallable<A, B> {
|
||||
A call(B object);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.util.interfaces;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ObjectCallable<A, B> {
|
||||
A call(B object);
|
||||
public interface ObjectCallable<A> {
|
||||
A call();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user