mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-26 15:45:12 +01:00
Lots of painful requirement display changes
This commit is contained in:
parent
dd6afacf73
commit
8bf70bb0fc
@ -8,9 +8,11 @@ import com.willfp.eco.core.display.DisplayPriority;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.enchantments.util.ItemConversionOptions;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -76,7 +78,6 @@ public class EnchantDisplay extends DisplayModule {
|
||||
EnchantmentCache.update();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:OperatorWrap")
|
||||
@Override
|
||||
protected void display(@NotNull final ItemStack itemStack,
|
||||
@Nullable final Player player,
|
||||
@ -135,9 +136,13 @@ public class EnchantDisplay extends DisplayModule {
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
if (player != null && enchantment instanceof EcoEnchant ecoEnchant) {
|
||||
if (!ecoEnchant.doesPlayerMeetRequirements(player)) {
|
||||
requirementLore.addAll(StringUtils.formatList(EnchantmentCache.getEntry(enchantment).getRequirementLore(), player));
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info((player == null) + " name: " + name + " requirementLore " + requirementLore);
|
||||
});
|
||||
|
||||
if (options.getShrinkOptions().isEnabled() && (enchantments.size() > options.getShrinkOptions().getThreshold())) {
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.enchantments.EnchantmentWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -207,6 +208,9 @@ public class EnchantmentCache {
|
||||
@Getter
|
||||
private final EnchantmentType type;
|
||||
|
||||
/**
|
||||
* The requirement lore.
|
||||
*/
|
||||
@Getter
|
||||
private final List<String> requirementLore;
|
||||
|
||||
@ -251,38 +255,38 @@ public class EnchantmentCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name with the level for a player.
|
||||
* Get the name with the level.
|
||||
*
|
||||
* @param level The level.
|
||||
* @param player The player.
|
||||
* @return The name with the level for the player.
|
||||
* @return The name with the level.
|
||||
*/
|
||||
public String getNameWithLevel(final int level,
|
||||
@NotNull final Player player) {
|
||||
String name = getNameWithLevel(level);
|
||||
if (enchantment instanceof EcoEnchant enchant) {
|
||||
boolean meets = enchant.doesPlayerMeetRequirement(player);
|
||||
if (meets) {
|
||||
return name;
|
||||
}
|
||||
|
||||
String color = PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor();
|
||||
if (color.contains("{}")) {
|
||||
name = name.replace("{}", name);
|
||||
} else {
|
||||
name = color + name;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
public String getNameWithLevel(final int level) {
|
||||
return getNameWithLevel(level, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enchantment with level.
|
||||
*
|
||||
* @param level The level.
|
||||
* @param player The player.
|
||||
* @return The name with the level.
|
||||
*/
|
||||
public String getNameWithLevel(final int level) {
|
||||
public String getNameWithLevel(final int level,
|
||||
@Nullable final Player player) {
|
||||
String unformattedName = rawName;
|
||||
String formattedName = name;
|
||||
if (enchantment instanceof EcoEnchant enchant && player != null) {
|
||||
if (!enchant.doesPlayerMeetRequirements(player)) {
|
||||
String color = PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor();
|
||||
if (color.contains("{}")) {
|
||||
unformattedName = color.replace("{}", unformattedName);
|
||||
formattedName = color.replace("{}", formattedName);
|
||||
} else {
|
||||
unformattedName = color + unformattedName;
|
||||
formattedName = color + formattedName;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||
String numberString = " ";
|
||||
|
||||
@ -303,9 +307,9 @@ public class EnchantmentCache {
|
||||
numberString = color + numberString;
|
||||
}
|
||||
|
||||
return name + StringUtils.format(numberString);
|
||||
return formattedName + StringUtils.format(numberString);
|
||||
} else {
|
||||
String clone = rawName;
|
||||
String clone = unformattedName;
|
||||
String color = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat();
|
||||
if (color.contains("{}")) {
|
||||
clone = color.replace("{}", clone);
|
||||
@ -315,10 +319,10 @@ public class EnchantmentCache {
|
||||
return StringUtils.format(clone + numberString);
|
||||
}
|
||||
} else {
|
||||
return name + numberString;
|
||||
return formattedName + numberString;
|
||||
}
|
||||
} else {
|
||||
return name;
|
||||
return formattedName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,6 @@ public class RequirementsOptions extends PluginDependent<EcoPlugin> {
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
requirementColor = this.getPlugin().getLangYml().getString("missing-requirements-format", false);
|
||||
requirementColor = this.getPlugin().getLangYml().getBukkitHandle().getString("missing-requirements-format", "");
|
||||
}
|
||||
}
|
||||
|
@ -255,10 +255,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
continue;
|
||||
}
|
||||
|
||||
this.requirements.put(requirement, split.subList(1, split.size() - 1));
|
||||
this.requirements.put(requirement, split.subList(1, split.size()));
|
||||
}
|
||||
requirementLore.clear();
|
||||
requirementLore.addAll(config.getStrings("requirements.not-met-lore", false));
|
||||
requirementLore.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "requirements.not-met-lore", false));
|
||||
|
||||
postUpdate();
|
||||
this.register();
|
||||
@ -294,7 +294,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
* @param player The player.
|
||||
* @return If the requirements are met.
|
||||
*/
|
||||
public boolean doesPlayerMeetRequirement(@NotNull final Player player) {
|
||||
public boolean doesPlayerMeetRequirements(@NotNull final Player player) {
|
||||
if (cachedRequirements.containsKey(player.getUniqueId())) {
|
||||
return cachedRequirements.get(player.getUniqueId());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user