mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Tier placeholders fix
This commit is contained in:
parent
192804f504
commit
5e55049369
@ -18,7 +18,9 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ItemTier {
|
||||
private final String name, id;
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String unparsedName;
|
||||
private final UnidentificationInfo unidentificationInfo;
|
||||
|
||||
// Deconstruction
|
||||
@ -44,10 +46,10 @@ public class ItemTier {
|
||||
* @param config Configuration section to get all values from
|
||||
*/
|
||||
public ItemTier(@NotNull ConfigurationSection config) {
|
||||
|
||||
// The name and ID, crucial parts.
|
||||
id = config.getName().toUpperCase().replace("-", "_");
|
||||
name = MythicLib.plugin.parseColors(config.getString("name"));
|
||||
this.id = config.getName().toUpperCase().replace("-", "_");
|
||||
this.unparsedName = config.getString("name");
|
||||
this.name = MythicLib.plugin.parseColors(unparsedName);
|
||||
|
||||
// Deconstruct and Unidentification
|
||||
deconstructTable = config.contains("deconstruct-item") ? new DropTable(config.getConfigurationSection("deconstruct-item")) : null;
|
||||
@ -140,6 +142,10 @@ public class ItemTier {
|
||||
return unidentificationInfo;
|
||||
}
|
||||
|
||||
public @NotNull String getUnparsedName() {
|
||||
return unparsedName;
|
||||
}
|
||||
|
||||
public static class UnidentificationInfo {
|
||||
@NotNull
|
||||
private final String name, prefix;
|
||||
|
@ -1,7 +1,9 @@
|
||||
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.comp.adventure.AdventureParser;
|
||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
@ -22,27 +24,26 @@ 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 AdventureParser parser = MythicLib.plugin.getAdventureParser();
|
||||
// Bake
|
||||
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))
|
||||
format = format.replace("<tier-color-cleaned>", ChatColor.getLastColors(tier.getName().replace(filter, "")));
|
||||
format = format.replace("<tier-name>", tier != null ? parser.stripColors(tier.getUnparsedName()) : "");
|
||||
format = format.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f");
|
||||
format = format.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
|
||||
|
||||
// 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,9 +54,12 @@ 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);
|
||||
@ -64,7 +68,9 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
|
||||
// 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 +84,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 +106,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;
|
||||
@ -160,8 +176,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 +194,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 +210,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()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user