!add mini message support for item names and lores

This commit is contained in:
Ethan 2021-02-11 13:53:39 -07:00
parent 1dbcd3b2f6
commit 1e5a72dd0b
5 changed files with 53 additions and 73 deletions

BIN
lib/MythicLib.jar Normal file

Binary file not shown.

14
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.5.2-SNAPSHOT</version>
<version>6.5.3</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server!</description>
@ -96,8 +96,18 @@
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicLib</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
<!-- USING THIS FOR INTERNAL TESTING -->
<!-- <dependency>-->
<!-- <groupId>io.lumine</groupId>-->
<!-- <artifactId>MythicLib</artifactId>-->
<!-- <version>1.0.0</version>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${basedir}/lib/MythicLib.jar</systemPath>-->
<!-- </dependency>-->
<!--
<dependency>
<groupId>net.Indyuce</groupId>

View File

@ -4,13 +4,18 @@ import com.google.gson.JsonArray;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.utils.text.minimessage.MiniMessage;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.*;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.data.StoredTagsData;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
@ -23,7 +28,11 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class ItemStackBuilder {
@ -162,10 +171,7 @@ public class ItemStackBuilder {
nbtItem.addTag(tags);
if (nbtItem.getDisplayNameComponent() != null) {
nbtItem.setDisplayNameComponent(MythicLib.plugin.getComponentBuilder().parse(nbtItem.getDisplayNameComponent()));
}
nbtItem.setDisplayNameComponent(MiniMessage.get().parse(meta.getDisplayName()));
return nbtItem;
}

View File

@ -4,9 +4,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.utils.text.Component;
import io.lumine.mythic.utils.text.minimessage.MiniMessage;
import net.Indyuce.mmoitems.MMOItems;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
@ -19,25 +20,17 @@ public class DynamicLore {
}
public ItemStack build() {
ItemStack stack = item.toItem();
if (item.hasTag("MMOITEMS_DYNAMIC_LORE")) {
JsonArray array = MythicLib.plugin.getJson().parse(item.getString("MMOITEMS_DYNAMIC_LORE"), JsonArray.class);
List<String> lore = new ArrayList<>();
List<Component> lore = new ArrayList<>(array.size());
for (JsonElement e : array) {
String s = replace(e.getAsString());
if(!s.equals("!INVALID!"))
lore.add(s);
lore.add(MiniMessage.get().parse(s));
}
ItemMeta meta = stack.getItemMeta();
meta.setLore(lore);
stack.setItemMeta(meta);
item.setLoreComponents(lore);
}
NBTItem nbt = NBTItem.get(stack);
if (nbt.getLoreComponents() != null) {
nbt.setLoreComponents(MythicLib.plugin.getComponentBuilder().parse(nbt.getLoreComponents()));
}
return nbt.toItem();
return item.toItem();
}
private String replace(String input) {

View File

@ -1,18 +1,18 @@
package net.Indyuce.mmoitems.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.api.util.ComponentUtil;
import io.lumine.mythic.lib.version.VersionMaterial;
import io.lumine.mythic.utils.text.Component;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.gui.edition.ItemEdition;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -129,48 +129,24 @@ public class ItemBrowser extends PluginInventory {
continue;
}
NBTItem nbtItem = NBTItem.get(item);
List<Component> lore = nbtItem.getLoreComponents();
ItemStack stack;
List<BaseComponent> lore = nbtItem.getLoreComponents();
if(lore == null) {
stack = nbtItem.toItem();
ItemMeta meta = stack.getItemMeta();
List<String> newLore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
newLore.add("");
if (deleteMode) {
newLore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
meta.setDisplayName(ChatColor.RED + "DELETE: " + meta.getDisplayName());
}
newLore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.");
newLore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.");
meta.setLore(newLore);
stack.setItemMeta(meta);
}
else {
List<BaseComponent> newLore = new ArrayList<>();
newLore.add(toComponent(""));
if (deleteMode) {
newLore.add(toComponent(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross));
BaseComponent display = nbtItem.getDisplayNameComponent();
if (display != null && display.getExtra() != null) {
List<BaseComponent> extra = new ArrayList<>(display.getExtra());
extra.add(0, toComponent(ChatColor.RED + "DELETE: "));
display.setExtra(extra);
nbtItem.setDisplayNameComponent(display);
}
} else {
newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item."));
newLore.add(toComponent(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."));
}
lore.addAll(newLore);
nbtItem.setLoreComponents(lore);
stack = nbtItem.toItem();
lore.add(Component.empty());
if (deleteMode) {
lore.add(ComponentUtil.fromString(
ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross));
nbtItem.setDisplayNameComponent(Component.text()
.append(ComponentUtil.fromString(ChatColor.RED + "DELETE: "))
.append(nbtItem.getDisplayNameComponent())
.build());
}
cached.put(template.getId(), stack);
lore.add(ComponentUtil.fromString(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item."));
lore.add(ComponentUtil.fromString(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."));
nbtItem.setLoreComponents(lore);
cached.put(template.getId(), nbtItem.toItem());
inv.setItem(slots[n++], cached.get(template.getId()));
}
@ -299,13 +275,8 @@ public class ItemBrowser extends PluginInventory {
}
private ItemStack removeLastLoreLines(NBTItem item) {
List<BaseComponent> lore = item.getLoreComponents();
List<Component> lore = item.getLoreComponents();
item.setLoreComponents(lore.subList(0, lore.size() - 3));
return item.toItem();
}
private BaseComponent toComponent(String text) {
BaseComponent component = TextComponent.fromLegacyText(text)[0];
component.setItalic(false);
return component;
}
}