Changed EcoEnchant#getName to EcoEnchant#getDisplayName for bukkit parity

This commit is contained in:
Auxilor 2021-04-27 10:45:04 +01:00
parent 77053e71f8
commit 0784e12496
5 changed files with 31 additions and 14 deletions

View File

@ -52,7 +52,7 @@ public class CommandEnchantinfo extends AbstractCommand {
if (enchantment == null) {
String finalSearchName = searchName;
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getDisplayName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
}
if (enchantment == null || !enchantment.isEnabled()) {
@ -74,7 +74,7 @@ public class CommandEnchantinfo extends AbstractCommand {
conflicts.forEach((enchantment1 -> {
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName());
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getDisplayName());
} else {
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
}

View File

@ -20,7 +20,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter {
/**
* The cached enchantment names.
*/
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList());
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList());
/**
* Instantiate a new tab-completer for /enchantinfo.
@ -37,7 +37,7 @@ public class TabCompleterEnchantinfo extends AbstractTabCompleter {
@ConfigUpdater
public static void reload() {
ENCHANT_NAMES.clear();
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList()));
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList()));
}
/**

View File

@ -103,7 +103,7 @@ public class EnchantmentCache {
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
description = ecoEnchant.getWrappedDescription();
name = ecoEnchant.getName();
name = ecoEnchant.getDisplayName();
type = ecoEnchant.getType();
rarity = ecoEnchant.getRarity();
} else {

View File

@ -43,84 +43,102 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
*/
@Getter(AccessLevel.PROTECTED)
private final EcoEnchantsPlugin plugin = EcoEnchantsPlugin.getInstance();
/**
* The permission/config name of the enchantment.
*/
@Getter
private final String permissionName;
/**
* The type of the enchantment.
*/
@Getter
private final EnchantmentType type;
/**
* The enchantment's config.
*/
@Getter
private final EnchantmentConfig config;
/**
* The targets of the enchantment.
*/
@Getter
private final Set<EnchantmentTarget> targets = new HashSet<>();
/**
* The materials of the targets.
*/
@Getter
private final Set<Material> targetMaterials = new HashSet<>();
/**
* The names of the worlds that this enchantment is disabled in.
*/
@Getter
private final Set<String> disabledWorldNames = new HashSet<>();
/**
* The worlds that this enchantment is disabled in.
*/
@Getter
private final List<World> disabledWorlds = new ArrayList<>();
/**
* The display name of the enchantment.
*/
private String name;
@Getter
private String displayName;
/**
* The description of the enchantment.
*/
@Getter
private String description;
/**
* If the enchantment can be removed in a grindstone.
*/
@Getter
private boolean grindstoneable;
/**
* If the enchantment can be obtained from an enchanting table.
*/
@Getter
private boolean availableFromTable;
/**
* If the enchantment can be obtained from a villager.
*/
@Getter
private boolean availableFromVillager;
/**
* If the enchantment can be obtained from a loot chest.
*/
@Getter
private boolean availableFromLoot;
/**
* The maximum level for the enchantment to be obtained naturally.
*/
private int maxLevel;
/**
* The enchantments that conflict with this enchantment.
*/
@Getter
private Set<Enchantment> conflicts;
/**
* The rarity of the enchantment.
*/
@Getter
private EnchantmentRarity rarity;
/**
* If the enchantment is enabled.
*/
@ -187,7 +205,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
availableFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager");
availableFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot");
maxLevel = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1);
name = StringUtils.translate(config.getString("name"));
displayName = StringUtils.translate(config.getString("name"));
description = StringUtils.translate(config.getString("description"));
disabledWorldNames.clear();
disabledWorldNames.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "disabled-in-worlds"));
@ -223,7 +241,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) byIdField.get(null);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
byKey.remove(this.getKey());
byName.remove(this.getName());
byName.remove(this.getDisplayName());
Map<String, Enchantment> byNameClone = new HashMap<>(byName);
for (Map.Entry<String, Enchantment> entry : byNameClone.entrySet()) {
@ -271,16 +289,15 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
}
/**
* Get the display name of the enchantment.
* <p>
* Not deprecated, unlike superclass.
* Get the internal name of the enchantment.
*
* @return The name.
* @deprecated Exists for parity.
*/
@Override
@NotNull
@Deprecated
public String getName() {
return name;
return this.getKey().getKey().toUpperCase();
}
/**

View File

@ -592,7 +592,7 @@ public class EcoEnchants {
BY_KEY.remove(enchant.getKey());
BY_NAME.inverse().remove(enchant);
BY_KEY.put(enchant.getKey(), enchant);
BY_NAME.put(enchant.getName(), enchant);
BY_NAME.put(enchant.getDisplayName(), enchant);
}
/**