Removed useless calls of parseColors()

This commit is contained in:
Indyuce 2022-08-18 23:31:08 +02:00
parent 2ab667e979
commit 7e25308dfd
11 changed files with 45 additions and 77 deletions

View File

@ -135,18 +135,19 @@ public class ItemTier {
@NotNull private UnidentificationInfo getDefaultUnident() { return new UnidentificationInfo(UnidentificationInfo.UNIDENT_NAME, UnidentificationInfo.UNIDENT_PREFIX, 0); }
public class UnidentificationInfo {
@NotNull private final String unidentificationName, prefix;
@NotNull
private final String name, prefix;
private final int range;
public static final String UNIDENT_NAME = "Unidentified Item";
public static final String UNIDENT_PREFIX = "Unknown";
public UnidentificationInfo(@NotNull ConfigurationSection config) {
this(color(config.getString("name", UNIDENT_NAME)), color(config.getString("prefix", UNIDENT_PREFIX)), config.getInt("range"));
this(config.getString("name", UNIDENT_NAME), config.getString("prefix", UNIDENT_PREFIX), config.getInt("range"));
}
public UnidentificationInfo(@NotNull String name, @NotNull String prefix, int range) {
unidentificationName = name;
this.name = name;
this.prefix = prefix;
this.range = range;
}
@ -154,7 +155,7 @@ public class ItemTier {
@NotNull public String getPrefix() { return prefix; }
@NotNull public String getDisplayName() {
return unidentificationName;
return name;
}
public int[] calculateRange(int level) {
@ -163,8 +164,4 @@ public class ItemTier {
}
}
private String color(@Nullable String str) {
return MythicLib.plugin.parseColors(str);
}
}

View File

@ -42,7 +42,7 @@ public class CraftingStation extends PostLoadObject {
super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = MythicLib.plugin.parseColors(config.getString("name", "Station"));
this.name = config.getString("name", "Unnamed");
this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default"));
this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase());
@ -66,7 +66,7 @@ public class CraftingStation extends PostLoadObject {
Validate.notNull(sound, "Crafting station sound must not be null");
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = MythicLib.plugin.parseColors(name);
this.name = name;
this.layout = layout;
this.sound = sound;
this.itemOptions = itemOptions;
@ -78,7 +78,12 @@ public class CraftingStation extends PostLoadObject {
return id;
}
@Deprecated
public String getName() {
return MythicLib.plugin.parseColors(name);
}
public String getUnformattedName() {
return name;
}

View File

@ -88,9 +88,9 @@ public class Consumable extends UseItem {
/**
* This dynamically updates the item lore
*/
String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("max-consume"));
String old = format.replace("#", "" + (usesLeft + 1));
String replaced = format.replace("#", "" + usesLeft);
final String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("max-consume"));
final String old = format.replace("#", String.valueOf(usesLeft + 1));
final String replaced = format.replace("#", String.valueOf(usesLeft));
ItemStack newItem = new LoreUpdate(nbtItem.toItem(), old, replaced).updateLore();
/**

View File

@ -238,9 +238,9 @@ public class DurabilityItem {
ItemStack item = nbtItem.toItem();
// Item lore update
String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("durability").replace("#m", String.valueOf(maxDurability)));
String old = format.replace("#c", String.valueOf(initialDurability));
String replaced = format.replace("#c", String.valueOf(durability));
final String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("durability").replace("#m", String.valueOf(maxDurability)));
final String old = format.replace("#c", String.valueOf(initialDurability));
final String replaced = format.replace("#c", String.valueOf(durability));
return new LoreUpdate(item, old, replaced).updateLore();
}
}

View File

@ -74,14 +74,10 @@ public class UnidentifiedItem extends ConfigItem {
} else
name = name.replace("#prefix#", "");
/*
* remove useless lore lines
*/
// Remove useless lore lines
lore.removeIf(s -> (s.startsWith("{tier}") && tier == null) || (s.startsWith("{range}") && (tier == null || level < 0)));
/*
* apply placeholders
*/
// Apply placeholders
for (String placeholder : placeholders.keySet())
name = name.replace("#" + placeholder + "#", placeholders.get(placeholder));
for (int n = 0; n < lore.size(); n++) {
@ -91,9 +87,7 @@ public class UnidentifiedItem extends ConfigItem {
lore.set(n, MythicLib.plugin.parseColors(str.replace("{range}", "").replace("{tier}", "")));
}
/*
* apply changes to item
*/
// Apply changes to item
item.getItem().setAmount(1);
ItemStack unidentified = MythicLib.plugin.getVersion().getWrapper().copyTexture(item)
.addTag(new ItemTag("MMOITEMS_UNIDENTIFIED_ITEM", serialize(item.toItem()))).toItem();

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.version.VersionMaterial;
@ -9,8 +8,6 @@ import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.NameData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
@ -23,6 +20,7 @@ import java.util.ArrayList;
public class DisplayName extends StringStat implements GemStoneStat {
private final String[] cleanFilter = {ChatColor.BOLD.toString(), ChatColor.ITALIC.toString(), ChatColor.UNDERLINE.toString(), ChatColor.STRIKETHROUGH.toString(), ChatColor.MAGIC.toString()};
public DisplayName() {
super("NAME", VersionMaterial.OAK_SIGN.toMaterial(), "Display Name", new String[] { "The item display name." },
new String[] { "all" });
@ -30,33 +28,23 @@ public class DisplayName extends StringStat implements GemStoneStat {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
// Bake
String format;
if (data instanceof NameData) {
format = ((NameData) data).bake();
} else {
format = data.toString();
}
String format = data.toString();
ItemTier tier = item.getMMOItem().getTier();
format = format.replace("<tier-name>", tier != null ? ChatColor.stripColor(tier.getName()) : "");
format = format.replace("<tier-color>", tier != null ? ChatColor.getLastColors(tier.getName()) : "&f");
if (tier != null) {
for (String filter: cleanFilter){
if (ChatColor.getLastColors(tier.getName()).contains(filter)){
if (tier != null)
for (String filter : cleanFilter)
if (ChatColor.getLastColors(tier.getName()).contains(filter))
format = format.replace("<tier-color-cleaned>", ChatColor.getLastColors(tier.getName().replace(filter, "")));
}
}
}
// Is this upgradable?
format = cropUpgrade(format);
if (item.getMMOItem().hasUpgradeTemplate()) { format = appendUpgradeLevel(format, item.getMMOItem().getUpgradeLevel()); }
item.getMeta().setDisplayName(MythicLib.plugin.parseColors(format));
item.getMeta().setDisplayName(format);
// Force Stat History generation
StatHistory.from(item.getMMOItem(), this);
@ -66,9 +54,8 @@ public class DisplayName extends StringStat implements GemStoneStat {
}
@NotNull String cropUpgrade(@NotNull String format) {
String suff = MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix", " &8(&e+#lvl#&8)");
if (suff == null || suff.isEmpty()) { return format; }
String suffix = MythicLib.plugin.parseColors(suff);
String suffix = MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix", " &8(&e+#lvl#&8)");
if (suffix == null || suffix.isEmpty()) { return format; }
//MMOItems.getConsole().sendMessage("Level " + upgradeLevel);
//MMOItems.getConsole().sendMessage("Format " + format);
@ -141,37 +128,22 @@ public class DisplayName extends StringStat implements GemStoneStat {
return format;
}
@NotNull public static String appendUpgradeLevel(@NotNull String format, int lvl) {
String suffix = MythicLib.plugin.parseColors(MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix"));
//MMOItems.getConsole().sendMessage("Level " + upgradeLevel);
//MMOItems.getConsole().sendMessage("Format " + format);
@NotNull
public static String appendUpgradeLevel(@NotNull String format, int lvl) {
String suffix = MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix");
if (suffix != null && lvl != 0) {
// Get the current suffix
String actSuffix = levelPrefix(suffix, lvl);
//MMOItems.getConsole().sendMessage("Current " + actSuffix);
// Append it
return format + actSuffix;
}
return format;
}
@NotNull public static String levelPrefix(@NotNull String template, int toLevel) {
// Ez
template = template.replace("#lvl#", String.valueOf(toLevel));
// 00f
template = template.replace("+-", "-");
// Yes
return template;
@NotNull
public static String levelPrefix(@NotNull String template, int toLevel) {
return template
.replace("#lvl#", String.valueOf(toLevel))
.replace("+-", "-");
}
/**

View File

@ -75,8 +75,8 @@ public class GrantedPermissions extends StringListStat implements GemStoneStat {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
StringListData data = (StringListData) statData.get();
data.getList().forEach(element -> lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(element)));
StringListData data = statData.get();
data.getList().forEach(element -> lore.add(ChatColor.GRAY + element));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");

View File

@ -119,7 +119,7 @@ public class DoubleStat extends ItemStat<NumericStatFormula, DoubleData> impleme
if (value != 0 || upgradeShift != 0) {
String loreInsert = formatPath(getId(), MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter, value * multiplyWhenDisplaying());
if (upgradeShift != 0)
loreInsert += MythicLib.plugin.parseColors(UpgradeTemplate.getUpgradeChangeSuffix(plus(upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying())));
loreInsert += UpgradeTemplate.getUpgradeChangeSuffix(plus(upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying()));
item.getLore().insert(getPath(), loreInsert);
}

View File

@ -61,7 +61,7 @@ public class NameData extends StringData implements Mergeable<StringData> {
}
/**
* @return The full, built name.
* @return The built suffix
*/
@NotNull
public String bakeSuffix() {

View File

@ -234,7 +234,7 @@ public class StringListStat extends ItemStat<StringListData, StringListData> {
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
StringListData data = (StringListData) statData.get();
StringListData data = statData.get();
data.getList().forEach(element -> lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(element)));
} else

View File

@ -70,7 +70,7 @@ public class StringStat extends ItemStat<StringData, StringData> {
inv.getEditedSection().set(getPath(), message);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(
MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + MythicLib.plugin.parseColors(message) + ChatColor.GRAY + ".");
MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + MythicLib.plugin.parseColors(message) + ChatColor.GRAY + "'.");
}
@Override
@ -84,7 +84,7 @@ public class StringStat extends ItemStat<StringData, StringData> {
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Use that
StringData bakedData = (StringData) getLoadedNBT(relevantTags);
StringData bakedData = getLoadedNBT(relevantTags);
// Valid?
if (bakedData != null) {