mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-03-11 13:11:50 +01:00
Merge remote-tracking branch 'origin/926-hex-colors-not-working-with-tier-color'
This commit is contained in:
commit
54a049e64f
@ -7,6 +7,7 @@ import io.lumine.mythic.lib.api.util.AltChar;
|
||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.util.ColorUtils;
|
||||
import net.Indyuce.mmoitems.util.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
|
||||
@ -49,7 +50,9 @@ public class ItemBrowser extends PluginInventory {
|
||||
}
|
||||
|
||||
|
||||
@NotNull @Override public Inventory getInventory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
|
||||
/*
|
||||
* ------------------------------
|
||||
@ -82,7 +85,7 @@ public class ItemBrowser extends PluginInventory {
|
||||
ItemStack item = currentType.getItem();
|
||||
item.setAmount(Math.max(1, Math.min(64, items)));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GREEN + currentType.getName() + ChatColor.DARK_GRAY + " (Click to browse)");
|
||||
meta.setDisplayName("%s%s %s(Click to browse)".formatted(ChatColor.GREEN, ColorUtils.stripColors(currentType.getName()), ChatColor.DARK_GRAY));
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(String.valueOf(ChatColor.GRAY) + ChatColor.ITALIC + "There " + (items == 1 ? "is" : "are") + " "
|
||||
@ -114,7 +117,9 @@ public class ItemBrowser extends PluginInventory {
|
||||
previous.setItemMeta(previousMeta);
|
||||
|
||||
// Fill
|
||||
while (n < slots.length) { inv.setItem(slots[n++], glass); }
|
||||
while (n < slots.length) {
|
||||
inv.setItem(slots[n++], glass);
|
||||
}
|
||||
inv.setItem(18, page > 1 ? previous : null);
|
||||
inv.setItem(26, max >= MMOItems.plugin.getTypes().getAll().size() ? null : next);
|
||||
|
||||
@ -129,7 +134,7 @@ public class ItemBrowser extends PluginInventory {
|
||||
* Displays all the items of the chosen Type
|
||||
* ------------------------------
|
||||
*/
|
||||
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + type.getName());
|
||||
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + ColorUtils.stripColors(type.getName()));
|
||||
|
||||
/*
|
||||
* Build cool Item Stacks for buttons and sh
|
||||
@ -181,7 +186,8 @@ public class ItemBrowser extends PluginInventory {
|
||||
ChatColor.RED + "By downloading the default resourcepack you can", ChatColor.RED + "edit the blocks however you want.",
|
||||
ChatColor.RED + "You will still have to add it to your server!"));
|
||||
downloadPack.setItemMeta(downloadMeta);
|
||||
inv.setItem(45, downloadPack); }
|
||||
inv.setItem(45, downloadPack);
|
||||
}
|
||||
|
||||
// Get templates of this type
|
||||
HashMap<Double, ArrayList<MMOItemTemplate>> templates = BrowserDisplayIDX.select(MMOItems.plugin.getTemplates().getTemplates(type));
|
||||
@ -208,7 +214,11 @@ public class ItemBrowser extends PluginInventory {
|
||||
|
||||
// Claim columns
|
||||
int totalSpaceAdd = indexTemplates.getValue().size();
|
||||
while (totalSpaceAdd > 0) { totalSpaceCount += sc; totalSpaceAdd -= sc; } }
|
||||
while (totalSpaceAdd > 0) {
|
||||
totalSpaceCount += sc;
|
||||
totalSpaceAdd -= sc;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Over the page-range currently in use...
|
||||
@ -231,7 +241,10 @@ public class ItemBrowser extends PluginInventory {
|
||||
* and add one
|
||||
*/
|
||||
n += 7;
|
||||
if (n >= usedSlots.length) { n -= 7 * sc; n++; }
|
||||
if (n >= usedSlots.length) {
|
||||
n -= 7 * sc;
|
||||
n++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -252,12 +265,18 @@ public class ItemBrowser extends PluginInventory {
|
||||
* and add one
|
||||
*/
|
||||
n += 7;
|
||||
if (n >= usedSlots.length) { n -= 7 * sc; n++; }
|
||||
continue; }
|
||||
if (n >= usedSlots.length) {
|
||||
n -= 7 * sc;
|
||||
n++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore == null) { lore = new ArrayList<>(); }
|
||||
if (lore == null) {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
lore.add("");
|
||||
|
||||
// Deleting lore?
|
||||
@ -265,10 +284,11 @@ public class ItemBrowser extends PluginInventory {
|
||||
lore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
|
||||
meta.setDisplayName(ChatColor.RED + "DELETE: " + (meta.hasDisplayName() ? meta.getDisplayName() : MMOUtils.getDisplayName(item)));
|
||||
|
||||
// Editing lore?
|
||||
// Editing lore?
|
||||
} else {
|
||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."); }
|
||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.");
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
@ -286,16 +306,25 @@ public class ItemBrowser extends PluginInventory {
|
||||
* and add one
|
||||
*/
|
||||
n += 7;
|
||||
if (n >= usedSlots.length) { n -= 7 * sc; n++; }
|
||||
if (n >= usedSlots.length) {
|
||||
n -= 7 * sc;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
// Put the buttons
|
||||
if (!deleteMode) { inv.setItem(51, create); }
|
||||
if (!deleteMode) {
|
||||
inv.setItem(51, create);
|
||||
}
|
||||
inv.setItem(47, delete);
|
||||
inv.setItem(49, back);
|
||||
inv.setItem(18, page > 1 ? previous : null);
|
||||
inv.setItem(26, max >= totalSpaceCount ? null : next);
|
||||
for (int i : usedSlots) { if (SilentNumbers.isAir(inv.getItem(i))) { inv.setItem(i, noItem); } }
|
||||
for (int i : usedSlots) {
|
||||
if (SilentNumbers.isAir(inv.getItem(i))) {
|
||||
inv.setItem(i, noItem);
|
||||
}
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
|
@ -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,90 +20,98 @@ 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" });
|
||||
}
|
||||
public DisplayName() {
|
||||
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) {
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
|
||||
final ItemTier tier = item.getMMOItem().getTier();
|
||||
|
||||
// Bake
|
||||
String format = data.toString();
|
||||
// Bake
|
||||
String format = data.toString()
|
||||
.replace("<tier-name>", tier != null ? ColorUtils.stripColors(tier.getName()) : "")
|
||||
.replace("<tier-color>", tier != null ? ColorUtils.getLastColors(tier.getName()) : "&f")
|
||||
.replace("<tier-color-cleaned>", tier != null ? ColorUtils.stripDecoration(ColorUtils.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, "")));
|
||||
// Is this upgradable?
|
||||
format = cropUpgrade(format);
|
||||
if (item.getMMOItem().hasUpgradeTemplate())
|
||||
format = appendUpgradeLevel(format, item.getMMOItem().getUpgradeLevel());
|
||||
|
||||
// Is this upgradable?
|
||||
format = cropUpgrade(format);
|
||||
if (item.getMMOItem().hasUpgradeTemplate()) { format = appendUpgradeLevel(format, item.getMMOItem().getUpgradeLevel()); }
|
||||
item.getMeta().setDisplayName(format);
|
||||
|
||||
item.getMeta().setDisplayName(format);
|
||||
// Force Stat History generation
|
||||
StatHistory.from(item.getMMOItem(), this);
|
||||
|
||||
// Force Stat History generation
|
||||
StatHistory.from(item.getMMOItem(), this);
|
||||
// Add NBT
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
|
||||
// Add NBT
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
@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;
|
||||
|
||||
@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; }
|
||||
//MMOItems.getConsole().sendMessage("Level " + upgradeLevel);
|
||||
//MMOItems.getConsole().sendMessage("Format " + 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;
|
||||
String sB4 = suffix.substring(0, lvlOFFSET);
|
||||
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
|
||||
String sB4_alt = sB4.replace("+", "-");
|
||||
String aFt_alt = aFt.replace("+", "-");
|
||||
|
||||
// Crop lvl
|
||||
int lvlOFFSET = suffix.indexOf("#lvl#");
|
||||
if (lvlOFFSET < 0) { return format; }
|
||||
String sB4 = suffix.substring(0, lvlOFFSET);
|
||||
String aFt = suffix.substring(lvlOFFSET + "#lvl#".length());
|
||||
String sB4_alt = sB4.replace("+", "-");
|
||||
String aFt_alt = aFt.replace("+", "-");
|
||||
// Remove it
|
||||
if (format.contains(sB4)) {
|
||||
|
||||
// Remove it
|
||||
if (format.contains(sB4)) {
|
||||
// Get offsets
|
||||
int sB4_offset = format.indexOf(sB4);
|
||||
int aFt_offset = format.lastIndexOf(aFt);
|
||||
|
||||
// Get offsets
|
||||
int sB4_offset = format.indexOf(sB4);
|
||||
int aFt_offset = format.lastIndexOf(aFt);
|
||||
// No after = to completion
|
||||
if (aFt_offset < 0) {
|
||||
aFt_offset = format.length();
|
||||
} else {
|
||||
aFt_offset += aFt.length();
|
||||
}
|
||||
|
||||
// No after = to completion
|
||||
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);
|
||||
|
||||
// Remove that
|
||||
String beforePrefix = format.substring(0, sB4_offset);
|
||||
String afterPrefix = format.substring(aFt_offset);
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix;
|
||||
}
|
||||
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix; }
|
||||
// Remove it
|
||||
if (format.contains(sB4_alt)) {
|
||||
|
||||
// Remove it
|
||||
if (format.contains(sB4_alt)) {
|
||||
// Get offsets
|
||||
int sB4_offset = format.indexOf(sB4_alt);
|
||||
int aFt_offset = format.lastIndexOf(aFt_alt);
|
||||
|
||||
// Get offsets
|
||||
int sB4_offset = format.indexOf(sB4_alt);
|
||||
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();
|
||||
}
|
||||
|
||||
// No after = to completion
|
||||
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);
|
||||
|
||||
// Remove that
|
||||
String beforePrefix = format.substring(0, sB4_offset);
|
||||
String afterPrefix = format.substring(aFt_offset);
|
||||
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix; }
|
||||
// Replace
|
||||
format = beforePrefix + afterPrefix;
|
||||
}
|
||||
|
||||
/*/ Bake old indices for removal
|
||||
ArrayList<String> oldSuffixii = new ArrayList<>(); boolean negativity = false;
|
||||
@ -122,193 +131,200 @@ public class DisplayName extends StringStat implements GemStoneStat {
|
||||
//MMOItems.getConsole().sendMessage("Edited " + format);
|
||||
} //*/
|
||||
|
||||
//MMOItems.getConsole().sendMessage("Final " + format);
|
||||
}
|
||||
//MMOItems.getConsole().sendMessage("Final " + format);
|
||||
|
||||
return format;
|
||||
}
|
||||
return 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) {
|
||||
String actSuffix = levelPrefix(suffix, lvl);
|
||||
return format + actSuffix;
|
||||
}
|
||||
@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) {
|
||||
String actSuffix = levelPrefix(suffix, lvl);
|
||||
return format + actSuffix;
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
@NotNull
|
||||
public static String levelPrefix(@NotNull String template, int toLevel) {
|
||||
return template
|
||||
.replace("#lvl#", String.valueOf(toLevel))
|
||||
.replace("+-", "-");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String levelPrefix(@NotNull String template, int toLevel) {
|
||||
return template
|
||||
.replace("#lvl#", String.valueOf(toLevel))
|
||||
.replace("+-", "-");
|
||||
}
|
||||
/**
|
||||
* This is not saved as a custom NBT data, instead it is stored as the name of the item itself.
|
||||
* Alas this returns an empty list
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringData data) {
|
||||
|
||||
/**
|
||||
* This is not saved as a custom NBT data, instead it is stored as the name of the item itself.
|
||||
* Alas this returns an empty list
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringData data) {
|
||||
if (data instanceof NameData) {
|
||||
|
||||
if (data instanceof NameData) {
|
||||
ArrayList<ItemTag> tags = new ArrayList<>();
|
||||
|
||||
ArrayList<ItemTag> tags = new ArrayList<>();
|
||||
// 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"));
|
||||
}
|
||||
|
||||
// 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"));}
|
||||
return tags;
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
// Thats it
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Thats it
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
// Get tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
boolean stored = false;
|
||||
ItemTag mainName = ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
|
||||
// Get tags
|
||||
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());
|
||||
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Loading name of \u00a7b" + mmoitem.getType() + " " + mmoitem.getId());
|
||||
if (mainName != null) {
|
||||
|
||||
if (mainName != null) {
|
||||
// Ah yes
|
||||
ItemTag prefixes = ItemTag.getTagAtPath(getNBTPath() + "_PRE", mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
ItemTag suffixes = ItemTag.getTagAtPath(getNBTPath() + "_SUF", mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
relevantTags.add(mainName);
|
||||
relevantTags.add(prefixes);
|
||||
relevantTags.add(suffixes);
|
||||
|
||||
// Ah yes
|
||||
ItemTag prefixes = ItemTag.getTagAtPath(getNBTPath() + "_PRE", mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
ItemTag suffixes = ItemTag.getTagAtPath(getNBTPath() + "_SUF", mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
relevantTags.add(mainName);
|
||||
relevantTags.add(prefixes);
|
||||
relevantTags.add(suffixes);
|
||||
// No need to evaluate anvil changes if the item has no display name
|
||||
if (mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) {
|
||||
stored = true;
|
||||
}
|
||||
|
||||
// No need to evaluate anvil changes if the item has no display name
|
||||
if (mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) { stored = true; }
|
||||
} else {
|
||||
|
||||
} else {
|
||||
// No need to continue if the item has no display name
|
||||
if (!mmoitem.getNBT().getItem().getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No need to continue if the item has no display name
|
||||
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()));
|
||||
// Add sole tag
|
||||
relevantTags.add(new ItemTag(getNBTPath(), cropUpgrade(mmoitem.getNBT().getItem().getItemMeta().getDisplayName())));
|
||||
}
|
||||
|
||||
// Add sole tag
|
||||
relevantTags.add(new ItemTag(getNBTPath(), cropUpgrade(mmoitem.getNBT().getItem().getItemMeta().getDisplayName())));
|
||||
}
|
||||
// Use that
|
||||
NameData bakedData = (NameData) getLoadedNBT(relevantTags);
|
||||
|
||||
// Use that
|
||||
NameData bakedData = (NameData) getLoadedNBT(relevantTags);
|
||||
// Valid?
|
||||
if (bakedData != null) {
|
||||
|
||||
// Valid?
|
||||
if (bakedData != null) {
|
||||
//NME//MMOItems.log("\u00a7e\u00a2\u00a2\u00a2\u00a77 Built:\u00a7f " + bakedData.toString());
|
||||
/*
|
||||
* Suppose we expect an item name with prefixes and suffixes,
|
||||
* well, removing those should leave the bare name, right?
|
||||
*
|
||||
* If the player has renamed their item, this bare name will be somewhat
|
||||
* different, and this is where those changes are updated.
|
||||
*/
|
||||
|
||||
//NME//MMOItems.log("\u00a7e\u00a2\u00a2\u00a2\u00a77 Built:\u00a7f " + bakedData.toString());
|
||||
/*
|
||||
* Suppose we expect an item name with prefixes and suffixes,
|
||||
* well, removing those should leave the bare name, right?
|
||||
*
|
||||
* If the player has renamed their item, this bare name will be somewhat
|
||||
* different, and this is where those changes are updated.
|
||||
*/
|
||||
@Nullable String itemName = null;
|
||||
if (stored) {
|
||||
|
||||
@Nullable String itemName = null;
|
||||
if (stored) {
|
||||
// Could the player have renamed?
|
||||
itemName = mmoitem.getNBT().getItem().getItemMeta().getDisplayName();
|
||||
String colorless = ChatColor.stripColor(itemName);
|
||||
|
||||
// Could the player have renamed?
|
||||
itemName = mmoitem.getNBT().getItem().getItemMeta().getDisplayName();
|
||||
String colorless = ChatColor.stripColor(itemName);
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Comparing: " + itemName + " | " + colorless);
|
||||
// By player
|
||||
if (!itemName.equals(colorless)) {
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Not anvil");
|
||||
itemName = null;
|
||||
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Comparing: " + itemName + " | " + colorless);
|
||||
// By player
|
||||
if (!itemName.equals(colorless)) {
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Not anvil");
|
||||
itemName = null;
|
||||
} else {
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Replaced main with \u00a7b " + itemName);
|
||||
bakedData.setString(itemName);
|
||||
}
|
||||
|
||||
} else {
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Replaced main with \u00a7b " + itemName);
|
||||
bakedData.setString(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Set
|
||||
mmoitem.setData(this, bakedData);
|
||||
|
||||
// Set
|
||||
mmoitem.setData(this, bakedData);
|
||||
// Update in SH. Must happen after setting the data
|
||||
if (stored && itemName != null) {
|
||||
|
||||
// Update in SH. Must happen after setting the data
|
||||
if (stored && itemName != null) {
|
||||
// History not prematurely loaded?
|
||||
if (mmoitem.getStatHistory(this) == null) {
|
||||
|
||||
// History not prematurely loaded?
|
||||
if (mmoitem.getStatHistory(this) == null) {
|
||||
// Also load history :think ing:
|
||||
ItemTag hisTag = ItemTag.getTagAtPath(ItemStackBuilder.history_keyword + getId(), mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
|
||||
// Also load history :think ing:
|
||||
ItemTag hisTag = ItemTag.getTagAtPath(ItemStackBuilder.history_keyword + getId(), mmoitem.getNBT(), SupportedNBTTagValues.STRING);
|
||||
if (hisTag != null) {
|
||||
|
||||
if (hisTag != null) {
|
||||
// Aye
|
||||
StatHistory hist = StatHistory.fromNBTString(mmoitem, (String) hisTag.getValue());
|
||||
|
||||
// Aye
|
||||
StatHistory hist = StatHistory.fromNBTString(mmoitem, (String) hisTag.getValue());
|
||||
// History valid? Record
|
||||
if (hist != null) {
|
||||
|
||||
// History valid? Record
|
||||
if (hist != null) {
|
||||
// Original Data
|
||||
NameData og = (NameData) hist.getOriginalData();
|
||||
|
||||
// Original Data
|
||||
NameData og = (NameData) hist.getOriginalData();
|
||||
// Overwrite
|
||||
og.setString(itemName);
|
||||
|
||||
// Overwrite
|
||||
og.setString(itemName);
|
||||
// Load its stat history
|
||||
mmoitem.setStatHistory(this, hist);
|
||||
|
||||
// Load its stat history
|
||||
mmoitem.setStatHistory(this, hist);
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Name History:");
|
||||
//NME//hist.log();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//NME//MMOItems.log("\u00a7b\u00a2\u00a2\u00a2\u00a77 Name History:");
|
||||
//NME//hist.log();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public StringData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public StringData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
// You got a double right
|
||||
ItemTag tg = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
|
||||
// You got a double right
|
||||
ItemTag tg = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
// Found righ
|
||||
if (tg != null) {
|
||||
|
||||
// Found righ
|
||||
if (tg != null) {
|
||||
// Get number
|
||||
String value = (String) tg.getValue();
|
||||
|
||||
// Get number
|
||||
String value = (String) tg.getValue();
|
||||
// That's it
|
||||
NameData nd = new NameData(value);
|
||||
|
||||
// That's it
|
||||
NameData nd = new NameData(value);
|
||||
nd.readPrefixes(ItemTag.getTagAtPath(getNBTPath() + "_PRE", storedTags));
|
||||
nd.readSuffixes(ItemTag.getTagAtPath(getNBTPath() + "_SUF", storedTags));
|
||||
|
||||
nd.readPrefixes(ItemTag.getTagAtPath(getNBTPath() + "_PRE", storedTags));
|
||||
nd.readSuffixes(ItemTag.getTagAtPath(getNBTPath() + "_SUF", storedTags));
|
||||
return nd;
|
||||
}
|
||||
|
||||
return nd;
|
||||
}
|
||||
// Fail
|
||||
return null;
|
||||
}
|
||||
|
||||
// Fail
|
||||
return null;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public StringData getClearStatData() {
|
||||
return new NameData("");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StringData getClearStatData() {
|
||||
return new NameData("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringData whenInitialized(Object object) {
|
||||
return new NameData(object.toString());
|
||||
}
|
||||
@Override
|
||||
public StringData whenInitialized(Object object) {
|
||||
return new NameData(object.toString());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package net.Indyuce.mmoitems.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
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]");
|
||||
private static final Pattern COLOR_TAG_PATTERN = Pattern.compile("(?i)<.*>");
|
||||
private static final Pattern START_COLOR_TAG_PATTERN = Pattern.compile("(?i)<[^/]*>");
|
||||
private static final Pattern MINI_MSG_DECORATION_PATTERN = Pattern.compile("(?i)(<|</)(bold|italic|underlined|strikethrough|obfuscated|b|em|i|u|st|obf).*>");
|
||||
|
||||
public static @NotNull String stripDecoration(@NotNull String input) {
|
||||
return "%s%s".formatted(ChatColor.RESET, MINI_MSG_DECORATION_PATTERN.matcher(STRIP_DECORATION_PATTERN.matcher(input).replaceAll("")).replaceAll(""))
|
||||
.replace('§', '&');
|
||||
}
|
||||
|
||||
public static @NotNull String stripColors(@NotNull String input) {
|
||||
return ChatColor.stripColor(COLOR_TAG_PATTERN.matcher(input).replaceAll(""));
|
||||
}
|
||||
|
||||
public static @NotNull String getLastColors(@NotNull String input) {
|
||||
Matcher matcher = START_COLOR_TAG_PATTERN.matcher(input);
|
||||
String lastMatch = null;
|
||||
while (matcher.find())
|
||||
lastMatch = matcher.group();
|
||||
return lastMatch == null ? ChatColor.getLastColors(input) : lastMatch;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user