Added new dynamic display name placeholders. See usage here:

https://git.lumine.io/mythiccraft/mmoitems/-/wikis/Display%20Name%20Placeholders
This commit is contained in:
Ethan 2020-08-30 06:56:25 -04:00
parent f5a1c37fb9
commit 6c87b6255a
2 changed files with 38 additions and 4 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.0</version>
<version>6.0.1</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -1,8 +1,8 @@
package net.Indyuce.mmoitems.stat;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -10,6 +10,8 @@ import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.version.VersionMaterial;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
public class DisplayName extends StringStat {
public DisplayName() {
@ -19,7 +21,8 @@ public class DisplayName extends StringStat {
@Override
public void whenApplied(ItemStackBuilder item, StatData data) {
item.getMeta().setDisplayName(MMOLib.plugin.parseColors(data.toString()));
item.getMeta().setDisplayName(new DisplayNamePlaceholders(data.toString(), item.getMMOItem()).parse());
}
@Override
@ -27,4 +30,35 @@ public class DisplayName extends StringStat {
if (mmoitem.getNBT().getItem().getItemMeta().hasDisplayName())
mmoitem.setData(ItemStat.NAME, new StringData(mmoitem.getNBT().getItem().getItemMeta().getDisplayName()));
}
private class DisplayNamePlaceholders {
private String name;
private final MMOItem mmoitem;
private DisplayNamePlaceholders(String name, MMOItem mmoitem) {
this.name = name;
this.mmoitem = mmoitem;
}
private String parse() {
name = name.replace("<tier-name>", (mmoitem.hasData(ItemStat.TIER))
? stripColorCodes(MMOItems.plugin.getTiers().findTier(mmoitem).getName()) : "");
name = name.replace("<tier-color>", (mmoitem.hasData(ItemStat.TIER))
? stripText(MMOItems.plugin.getTiers().findTier(mmoitem).getName()) : "&f");
name = name.replace("<type-name>", (mmoitem.hasData(ItemStat.DISPLAYED_TYPE))
? stripColorCodes(mmoitem.getData(ItemStat.DISPLAYED_TYPE).toString()) : stripColorCodes(mmoitem.getType().getName()));
return MMOLib.plugin.parseColors(name);
}
private String stripColorCodes(String message) {
return ChatColor.stripColor(MMOLib.plugin.parseColors(message));
}
private String stripText(String message) {
return ChatColor.getLastColors(MMOLib.plugin.parseColors(message));
}
}
}