mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-21 09:21:21 +01:00
<tier-color-cleaned> fixed
This commit is contained in:
parent
ecf8fda224
commit
077a4ce0ef
@ -12,6 +12,7 @@ import net.Indyuce.mmoitems.stat.type.GemStoneStat;
|
||||
import net.Indyuce.mmoitems.stat.type.NameData;
|
||||
import net.Indyuce.mmoitems.stat.type.StatHistory;
|
||||
import net.Indyuce.mmoitems.stat.type.StringStat;
|
||||
import net.Indyuce.mmoitems.util.ColorUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -19,30 +20,32 @@ import org.jetbrains.annotations.Nullable;
|
||||
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" });
|
||||
super("NAME", VersionMaterial.OAK_SIGN.toMaterial(), "Display Name", new String[]{"The item display name."},
|
||||
new String[]{"all"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
|
||||
final ItemTier tier = item.getMMOItem().getTier();
|
||||
|
||||
// Bake
|
||||
String format = data.toString();
|
||||
String format = data.toString()
|
||||
.replace("<tier-name>", tier != null ? ChatColor.stripColor(tier.getName()) : "")
|
||||
.replace("<tier-color>", tier != null ? ChatColor.getLastColors(tier.getName()) : "&f")
|
||||
.replace("<tier-color-cleaned>", tier != null ? ColorUtils.stripDecoration(ChatColor.getLastColors(tier.getName())) : "&f");
|
||||
|
||||
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))
|
||||
format = format.replace("<tier-color-cleaned>", ChatColor.getLastColors(tier.getName().replace(filter, "")));
|
||||
if (tier != null) {
|
||||
System.out.println("Format: " + format);
|
||||
System.out.println("Last Colors: " + ChatColor.getLastColors(tier.getName()) + " w: " + ColorUtils.stripDecoration(ChatColor.getLastColors(tier.getName())));
|
||||
System.out.println("===================\n");
|
||||
}
|
||||
|
||||
// Is this upgradable?
|
||||
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(format);
|
||||
|
||||
@ -53,18 +56,20 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
|
||||
@NotNull String cropUpgrade(@NotNull String format) {
|
||||
@NotNull
|
||||
String cropUpgrade(@NotNull String format) {
|
||||
String suffix = MMOItems.plugin.getConfig().getString("item-upgrading.name-suffix", " &8(&e+#lvl#&8)");
|
||||
if (suffix == null || suffix.isEmpty()) { return format; }
|
||||
if (suffix == null || suffix.isEmpty())
|
||||
return format;
|
||||
|
||||
//MMOItems.getConsole().sendMessage("Level " + upgradeLevel);
|
||||
//MMOItems.getConsole().sendMessage("Format " + format);
|
||||
|
||||
if (suffix != null) {
|
||||
|
||||
// Crop lvl
|
||||
int lvlOFFSET = suffix.indexOf("#lvl#");
|
||||
if (lvlOFFSET < 0) { return format; }
|
||||
if (lvlOFFSET < 0)
|
||||
return format;
|
||||
String sB4 = suffix.substring(0, lvlOFFSET);
|
||||
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
|
||||
String sB4_alt = sB4.replace("+", "-");
|
||||
@ -78,14 +83,19 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
int aFt_offset = format.lastIndexOf(aFt);
|
||||
|
||||
// No after = to completion
|
||||
if (aFt_offset < 0) { aFt_offset = format.length(); } else { aFt_offset += aFt.length(); }
|
||||
if (aFt_offset < 0) {
|
||||
aFt_offset = format.length();
|
||||
} else {
|
||||
aFt_offset += aFt.length();
|
||||
}
|
||||
|
||||
// Remove that
|
||||
String beforePrefix = format.substring(0, sB4_offset);
|
||||
String afterPrefix = format.substring(aFt_offset);
|
||||
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix; }
|
||||
format = beforePrefix + afterPrefix;
|
||||
}
|
||||
|
||||
// Remove it
|
||||
if (format.contains(sB4_alt)) {
|
||||
@ -95,14 +105,19 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
int aFt_offset = format.lastIndexOf(aFt_alt);
|
||||
|
||||
// No after = to completion
|
||||
if (aFt_offset < 0) { aFt_offset = format.length(); } else { aFt_offset += aFt_alt.length(); }
|
||||
if (aFt_offset < 0) {
|
||||
aFt_offset = format.length();
|
||||
} else {
|
||||
aFt_offset += aFt_alt.length();
|
||||
}
|
||||
|
||||
// Remove that
|
||||
String beforePrefix = format.substring(0, sB4_offset);
|
||||
String afterPrefix = format.substring(aFt_offset);
|
||||
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix; }
|
||||
format = beforePrefix + afterPrefix;
|
||||
}
|
||||
|
||||
/*/ Bake old indices for removal
|
||||
ArrayList<String> oldSuffixii = new ArrayList<>(); boolean negativity = false;
|
||||
@ -123,7 +138,6 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
} //*/
|
||||
|
||||
//MMOItems.getConsole().sendMessage("Final " + format);
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
@ -135,7 +149,6 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
String actSuffix = levelPrefix(suffix, lvl);
|
||||
return format + actSuffix;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
@ -160,8 +173,12 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
|
||||
// Append those
|
||||
tags.add(new ItemTag(getNBTPath(), ((NameData) data).getMainName()));
|
||||
if (((NameData) data).hasPrefixes()) { tags.add(((NameData) data).compressPrefixes(getNBTPath() + "_PRE"));}
|
||||
if (((NameData) data).hasSuffixes()) { tags.add(((NameData) data).compressSuffixes(getNBTPath() + "_SUF"));}
|
||||
if (((NameData) data).hasPrefixes()) {
|
||||
tags.add(((NameData) data).compressPrefixes(getNBTPath() + "_PRE"));
|
||||
}
|
||||
if (((NameData) data).hasSuffixes()) {
|
||||
tags.add(((NameData) data).compressSuffixes(getNBTPath() + "_SUF"));
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
@ -174,7 +191,8 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
// Get tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>(); boolean stored = false;
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
boolean stored = false;
|
||||
ItemTag mainName = ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Loading name of \u00a7b" + mmoitem.getType() + " " + mmoitem.getId());
|
||||
@ -189,12 +207,16 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
relevantTags.add(suffixes);
|
||||
|
||||
// No need to evaluate anvil changes if the item has no display name
|
||||
if (mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) { stored = true; }
|
||||
if (mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) {
|
||||
stored = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// No need to continue if the item has no display name
|
||||
if (!mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) { return; }
|
||||
if (!mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//NME//MMOItems.log("\u00a7a\u00a2\u00a2\u00a2\u00a77 Older item, decrypting as main name as:\u00a7f " + cropUpgrade(mmoitem.getNBT().getItem().getItemMeta().getDisplayName()));
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
package net.Indyuce.mmoitems.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* mmoitems
|
||||
* 09/11/2022
|
||||
*
|
||||
* @author Roch Blondiaux (Kiwix).
|
||||
*/
|
||||
public class ColorUtils {
|
||||
|
||||
private static final Pattern STRIP_DECORATION_PATTERN = Pattern.compile("(?i)" + '§' + "[K-O]");
|
||||
|
||||
public static @NotNull String stripDecoration(@NotNull String input) {
|
||||
return "%s%s".formatted(ChatColor.RESET, STRIP_DECORATION_PATTERN.matcher(input).replaceAll("")).replace('§', '&');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user