Updated to new eco display system

This commit is contained in:
Auxilor 2021-01-30 14:49:45 +00:00
parent 2437fc2753
commit 3b2677edd3
3 changed files with 5 additions and 43 deletions

View File

@ -77,8 +77,8 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
return EnchantDisplay.displayEnchantments(itemStack, hideEnchants); return EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
}, 500, this.getPluginName())); }, 500, this.getPluginName()));
Display.registerRevertModule(EnchantDisplay::revertDisplay); Display.registerRevertModule(EnchantDisplay::revertDisplay);
Display.registerFinalizeModule(EnchantDisplay::addV);
this.getExtensionLoader().loadExtensions(); this.getExtensionLoader().loadExtensions();

View File

@ -43,13 +43,6 @@ public class EnchantDisplay {
*/ */
public static final NamespacedKey KEY_SKIP = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-skip"); public static final NamespacedKey KEY_SKIP = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-skip");
/**
* The meta key to notify the server that an item is from a villager trade.
* <p>
* Bit of a bodge - plan on making it better.
*/
public static final NamespacedKey KEY_V = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-v");
/** /**
* The prefix for all enchantment lines to have in lore. * The prefix for all enchantment lines to have in lore.
*/ */
@ -69,25 +62,6 @@ public class EnchantDisplay {
EnchantmentCache.update(); EnchantmentCache.update();
} }
/**
* Bodge to fix hidden enchantments from villagers.
* <p>
* It isn't recommended to mess with this unless you <b>really</b> know your way around EcoEnchants.
*
* @param item The item to modify.
* @return The item, with KEY_V.
*/
public static ItemStack addV(@Nullable final ItemStack item) {
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) {
return item;
}
ItemMeta meta = item.getItemMeta();
meta.getPersistentDataContainer().set(KEY_V, PersistentDataType.INTEGER, 1);
item.setItemMeta(meta);
return item;
}
/** /**
* Revert display. * Revert display.
* *
@ -112,9 +86,6 @@ public class EnchantDisplay {
itemLore = new ArrayList<>(); itemLore = new ArrayList<>();
} }
if (meta.getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER)) {
meta.getPersistentDataContainer().remove(KEY_V);
}
itemLore.removeIf(s -> s.startsWith(PREFIX)); itemLore.removeIf(s -> s.startsWith(PREFIX));
if (!meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) { if (!meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
@ -144,22 +115,15 @@ public class EnchantDisplay {
* Show all enchantments in item lore. * Show all enchantments in item lore.
* *
* @param item The item to update. * @param item The item to update.
* @param hideEnchants If enchantments should be hidden. * @param hide If enchantments should be hidden.
* @return The item, updated. * @return The item, updated.
*/ */
public static ItemStack displayEnchantments(@Nullable final ItemStack item, public static ItemStack displayEnchantments(@Nullable final ItemStack item,
final boolean hideEnchants) { final boolean hide) {
boolean hide = hideEnchants;
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType())) { if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType())) {
return item; return item;
} }
if (item.getItemMeta().getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER) && hideEnchants) {
hide = false;
}
revertDisplay(item);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta == null) { if (meta == null) {
return item; return item;
@ -203,9 +167,7 @@ public class EnchantDisplay {
OPTIONS.getSorter().sortEnchantments(unsorted); OPTIONS.getSorter().sortEnchantments(unsorted);
enchantments.clear(); enchantments.clear();
unsorted.forEach(enchantment -> { unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment)));
enchantments.put(enchantment, tempEnchantments.get(enchantment));
});
enchantments.forEach((enchantment, level) -> { enchantments.forEach((enchantment, level) -> {
if (EcoEnchants.getFromEnchantment(enchantment) == null) { if (EcoEnchants.getFromEnchantment(enchantment) == null) {

View File

@ -1,2 +1,2 @@
version = 6.3.0 version = 6.3.1
plugin-name = EcoEnchants plugin-name = EcoEnchants