Newest MMOLib is required to run this version:

https://github.com/mmopluginteam/mmolib

Adds custom font support in items. More examples will be added to the wiki soon.

<font=uniform>Hello
This commit is contained in:
Ethan 2020-11-23 07:03:05 -05:00
parent 07c8894e10
commit e9257e9e92
4 changed files with 40 additions and 17 deletions

Binary file not shown.

View File

@ -6,7 +6,12 @@ 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.StringData;
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;
@ -140,7 +145,15 @@ public class ItemStackBuilder {
meta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, fakeModifier);
item.setItemMeta(meta);
return MMOLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(tags);
NBTItem nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item);
nbtItem.addTag(tags);
if (nbtItem.getDisplayNameComponent() != null) {
nbtItem.setDisplayNameComponent(MMOLib.plugin.getComponentBuilder().parse(nbtItem.getDisplayNameComponent()));
}
return nbtItem;
}
/**

View File

@ -1,17 +1,15 @@
package net.Indyuce.mmoitems.api.item.util;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class DynamicLore {
private final NBTItem item;
@ -33,6 +31,12 @@ public class DynamicLore {
ItemMeta meta = stack.getItemMeta();
meta.setLore(lore);
stack.setItemMeta(meta);
NBTItem nbt = NBTItem.get(stack);
if (nbt.getLoreComponents() != null) {
nbt.setLoreComponents(MMOLib.plugin.getComponentBuilder().parse(nbt.getLoreComponents()));
}
stack = nbt.toItem();
}
return stack;
}

View File

@ -10,6 +10,7 @@ import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.api.item.NBTItem;
import net.mmogroup.mmolib.api.util.AltChar;
import net.mmogroup.mmolib.api.util.ItemMetaLore;
import net.mmogroup.mmolib.version.VersionMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -23,7 +24,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.Map;
public class ItemBrowser extends PluginInventory {
private final Map<String, ItemStack> cached = new HashMap<>();
@ -125,17 +130,18 @@ public class ItemBrowser extends PluginInventory {
}
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
lore.add("");
List<String> newLore = new ArrayList<>();
newLore.add("");
if (deleteMode) {
lore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
newLore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
meta.setDisplayName(ChatColor.RED + "DELETE: " + meta.getDisplayName());
} 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.");
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(lore);
item.setItemMeta(meta);
ItemMetaLore.addLoreLines(item, newLore);
cached.put(template.getId(), item);
}
@ -256,7 +262,7 @@ public class ItemBrowser extends PluginInventory {
if (event.getAction() == InventoryAction.PICKUP_ALL) {
// this refreshes the item if it's unstackable
ItemStack generatedItem = (NBTItem.get(item).getBoolean("UNSTACKABLE")) ? MMOItems.plugin.getItem(type, id, playerData)
: removeLastLoreLines(item, 3);
: ItemMetaLore.removeLoreLines(item, 3);
getPlayer().getInventory().addItem(generatedItem);
getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}