mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-05 06:57:35 +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;
|
import java.util.Random;
|
||||||
|
|
||||||
public class ItemTier {
|
public class ItemTier {
|
||||||
private final String name, id;
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
private final String unparsedName;
|
||||||
private final UnidentificationInfo unidentificationInfo;
|
private final UnidentificationInfo unidentificationInfo;
|
||||||
|
|
||||||
// Deconstruction
|
// Deconstruction
|
||||||
@ -44,10 +46,10 @@ public class ItemTier {
|
|||||||
* @param config Configuration section to get all values from
|
* @param config Configuration section to get all values from
|
||||||
*/
|
*/
|
||||||
public ItemTier(@NotNull ConfigurationSection config) {
|
public ItemTier(@NotNull ConfigurationSection config) {
|
||||||
|
|
||||||
// The name and ID, crucial parts.
|
// The name and ID, crucial parts.
|
||||||
id = config.getName().toUpperCase().replace("-", "_");
|
this.id = config.getName().toUpperCase().replace("-", "_");
|
||||||
name = MythicLib.plugin.parseColors(config.getString("name"));
|
this.unparsedName = config.getString("name");
|
||||||
|
this.name = MythicLib.plugin.parseColors(unparsedName);
|
||||||
|
|
||||||
// Deconstruct and Unidentification
|
// Deconstruct and Unidentification
|
||||||
deconstructTable = config.contains("deconstruct-item") ? new DropTable(config.getConfigurationSection("deconstruct-item")) : null;
|
deconstructTable = config.contains("deconstruct-item") ? new DropTable(config.getConfigurationSection("deconstruct-item")) : null;
|
||||||
@ -140,6 +142,10 @@ public class ItemTier {
|
|||||||
return unidentificationInfo;
|
return unidentificationInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull String getUnparsedName() {
|
||||||
|
return unparsedName;
|
||||||
|
}
|
||||||
|
|
||||||
public static class UnidentificationInfo {
|
public static class UnidentificationInfo {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String name, prefix;
|
private final String name, prefix;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
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.comp.adventure.AdventureParser;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.ItemTier;
|
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()};
|
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"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
|
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
|
||||||
|
final AdventureParser parser = MythicLib.plugin.getAdventureParser();
|
||||||
// Bake
|
// Bake
|
||||||
String format = data.toString();
|
String 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 ? parser.stripColors(tier.getUnparsedName()) : "");
|
||||||
format = format.replace("<tier-color>", tier != null ? ChatColor.getLastColors(tier.getName()) : "&f");
|
format = format.replace("<tier-color>", tier != null ? parser.lastColor(tier.getUnparsedName(), true) : "&f");
|
||||||
if (tier != null)
|
format = format.replace("<tier-color-cleaned>", tier != null ? parser.lastColor(tier.getUnparsedName(), false) : "");
|
||||||
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?
|
// 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(format);
|
item.getMeta().setDisplayName(format);
|
||||||
|
|
||||||
@ -53,9 +54,12 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
item.addItemTag(getAppliedNBT(data));
|
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)");
|
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("Level " + upgradeLevel);
|
||||||
//MMOItems.getConsole().sendMessage("Format " + format);
|
//MMOItems.getConsole().sendMessage("Format " + format);
|
||||||
@ -64,7 +68,9 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
|
|
||||||
// Crop lvl
|
// Crop lvl
|
||||||
int lvlOFFSET = suffix.indexOf("#lvl#");
|
int lvlOFFSET = suffix.indexOf("#lvl#");
|
||||||
if (lvlOFFSET < 0) { return format; }
|
if (lvlOFFSET < 0) {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
String sB4 = suffix.substring(0, lvlOFFSET);
|
String sB4 = suffix.substring(0, lvlOFFSET);
|
||||||
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
|
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
|
||||||
String sB4_alt = sB4.replace("+", "-");
|
String sB4_alt = sB4.replace("+", "-");
|
||||||
@ -78,14 +84,19 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
int aFt_offset = format.lastIndexOf(aFt);
|
int aFt_offset = format.lastIndexOf(aFt);
|
||||||
|
|
||||||
// No after = to completion
|
// 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
|
// Remove that
|
||||||
String beforePrefix = format.substring(0, sB4_offset);
|
String beforePrefix = format.substring(0, sB4_offset);
|
||||||
String afterPrefix = format.substring(aFt_offset);
|
String afterPrefix = format.substring(aFt_offset);
|
||||||
|
|
||||||
// Replace
|
// Replace
|
||||||
format = beforePrefix + afterPrefix; }
|
format = beforePrefix + afterPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove it
|
// Remove it
|
||||||
if (format.contains(sB4_alt)) {
|
if (format.contains(sB4_alt)) {
|
||||||
@ -95,14 +106,19 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
int aFt_offset = format.lastIndexOf(aFt_alt);
|
int aFt_offset = format.lastIndexOf(aFt_alt);
|
||||||
|
|
||||||
// No after = to completion
|
// 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
|
// Remove that
|
||||||
String beforePrefix = format.substring(0, sB4_offset);
|
String beforePrefix = format.substring(0, sB4_offset);
|
||||||
String afterPrefix = format.substring(aFt_offset);
|
String afterPrefix = format.substring(aFt_offset);
|
||||||
|
|
||||||
// Replace
|
// Replace
|
||||||
format = beforePrefix + afterPrefix; }
|
format = beforePrefix + afterPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
/*/ Bake old indices for removal
|
/*/ Bake old indices for removal
|
||||||
ArrayList<String> oldSuffixii = new ArrayList<>(); boolean negativity = false;
|
ArrayList<String> oldSuffixii = new ArrayList<>(); boolean negativity = false;
|
||||||
@ -160,8 +176,12 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
|
|
||||||
// Append those
|
// Append those
|
||||||
tags.add(new ItemTag(getNBTPath(), ((NameData) data).getMainName()));
|
tags.add(new ItemTag(getNBTPath(), ((NameData) data).getMainName()));
|
||||||
if (((NameData) data).hasPrefixes()) { tags.add(((NameData) data).compressPrefixes(getNBTPath() + "_PRE"));}
|
if (((NameData) data).hasPrefixes()) {
|
||||||
if (((NameData) data).hasSuffixes()) { tags.add(((NameData) data).compressSuffixes(getNBTPath() + "_SUF"));}
|
tags.add(((NameData) data).compressPrefixes(getNBTPath() + "_PRE"));
|
||||||
|
}
|
||||||
|
if (((NameData) data).hasSuffixes()) {
|
||||||
|
tags.add(((NameData) data).compressSuffixes(getNBTPath() + "_SUF"));
|
||||||
|
}
|
||||||
|
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
@ -174,7 +194,8 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
|||||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||||
|
|
||||||
// Get tags
|
// 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);
|
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());
|
//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);
|
relevantTags.add(suffixes);
|
||||||
|
|
||||||
// No need to evaluate anvil changes if the item has no display name
|
// 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 {
|
} else {
|
||||||
|
|
||||||
// No need to continue if the item has no display name
|
// 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()));
|
//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