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); } @NotNull private UnidentificationInfo getDefaultUnident() { return new UnidentificationInfo(UnidentificationInfo.UNIDENT_NAME, UnidentificationInfo.UNIDENT_PREFIX, 0); }
public class UnidentificationInfo { public class UnidentificationInfo {
@NotNull private final String unidentificationName, prefix; @NotNull
private final String name, prefix;
private final int range; private final int range;
public static final String UNIDENT_NAME = "Unidentified Item"; public static final String UNIDENT_NAME = "Unidentified Item";
public static final String UNIDENT_PREFIX = "Unknown"; public static final String UNIDENT_PREFIX = "Unknown";
public UnidentificationInfo(@NotNull ConfigurationSection config) { 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) { public UnidentificationInfo(@NotNull String name, @NotNull String prefix, int range) {
unidentificationName = name; this.name = name;
this.prefix = prefix; this.prefix = prefix;
this.range = range; this.range = range;
} }
@ -154,7 +155,7 @@ public class ItemTier {
@NotNull public String getPrefix() { return prefix; } @NotNull public String getPrefix() { return prefix; }
@NotNull public String getDisplayName() { @NotNull public String getDisplayName() {
return unidentificationName; return name;
} }
public int[] calculateRange(int level) { 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); super(config);
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); 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.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default"));
this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase()); 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"); Validate.notNull(sound, "Crafting station sound must not be null");
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
this.name = MythicLib.plugin.parseColors(name); this.name = name;
this.layout = layout; this.layout = layout;
this.sound = sound; this.sound = sound;
this.itemOptions = itemOptions; this.itemOptions = itemOptions;
@ -78,7 +78,12 @@ public class CraftingStation extends PostLoadObject {
return id; return id;
} }
@Deprecated
public String getName() { public String getName() {
return MythicLib.plugin.parseColors(name);
}
public String getUnformattedName() {
return name; return name;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -75,8 +75,8 @@ public class GrantedPermissions extends StringListStat implements GemStoneStat {
if (statData.isPresent()) { if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:"); 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))); data.getList().forEach(element -> lore.add(ChatColor.GRAY + element));
} else } else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None"); 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) { if (value != 0 || upgradeShift != 0) {
String loreInsert = formatPath(getId(), MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter, value * multiplyWhenDisplaying()); String loreInsert = formatPath(getId(), MMOItems.plugin.getLanguage().getStatFormat(getPath()), moreIsBetter, value * multiplyWhenDisplaying());
if (upgradeShift != 0) 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); 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 @NotNull
public String bakeSuffix() { 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) { public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) { if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:"); 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))); data.getList().forEach(element -> lore.add(ChatColor.GRAY + MythicLib.plugin.parseColors(element)));
} else } else

View File

@ -70,7 +70,7 @@ public class StringStat extends ItemStat<StringData, StringData> {
inv.getEditedSection().set(getPath(), message); inv.getEditedSection().set(getPath(), message);
inv.registerTemplateEdition(); inv.registerTemplateEdition();
inv.getPlayer().sendMessage( 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 @Override
@ -84,7 +84,7 @@ public class StringStat extends ItemStat<StringData, StringData> {
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING)); relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Use that // Use that
StringData bakedData = (StringData) getLoadedNBT(relevantTags); StringData bakedData = getLoadedNBT(relevantTags);
// Valid? // Valid?
if (bakedData != null) { if (bakedData != null) {