Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jules 2023-04-02 16:16:33 +02:00
commit 6c3edb2b37
8 changed files with 604 additions and 447 deletions

View File

@ -158,6 +158,7 @@ public class ItemStats {
REMOVE_ON_CRAFT = new BooleanStat("REMOVE_ON_CRAFT", Material.GLASS_BOTTLE, "Remove on Craft", new String[]{"If the item should be completely", "removed when used in a recipe,", "or if it should become an", "empty bottle or bucket."}, new String[]{"all"}, Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.MILK_BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET),
COMPATIBLE_TYPES = new CompatibleTypes(),
COMPATIBLE_IDS = new CompatibleIds(),
COMPATIBLE_MATERIALS = new CompatibleMaterials(),
GEM_SOCKETS = new GemSockets(),
RANDOM_UNSOCKET = new RandomUnsocket(),
//todo CAN_UNSOCKET = new CanUnsocket(),

View File

@ -5,12 +5,12 @@ import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -25,245 +25,240 @@ import java.lang.reflect.Field;
import java.util.List;
public class ItemSkin extends UseItem {
public ItemSkin(Player player, NBTItem item) {
super(player, item);
}
public ItemSkin(Player player, NBTItem item) {
super(player, item);
}
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
if (targetType == Type.SKIN)
return new ApplyResult(ResultType.NONE);
public ApplyResult applyOntoItem(NBTItem target, Type targetType) {
if (targetType == Type.SKIN)
return new ApplyResult(ResultType.NONE);
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
if (MMOItems.plugin.getConfig().getBoolean("locked-skins") && target.getBoolean("MMOITEMS_HAS_SKIN")) {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
Message.SKIN_REJECTED.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
boolean compatible = false;
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Applying onto " + MMOUtils.getDisplayName(target.getItem()));
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Applying onto " + MMOUtils.getDisplayName(target.getItem()));
// Types compatibility check
if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: ");
final List<String> acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList();
if (acceptedTypes.size() > 0 && acceptedTypes.stream().noneMatch(s -> s.equalsIgnoreCase(targetType.getId()))) {
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
}
if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: ");
// IDs compatibility check
if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: ");
final List<String> acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList();
final String targetId = target.getString("MMOITEMS_ITEM_ID");
List<String> acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList();
if (acceptedIDs.size() > 0 && acceptedIDs.stream()
.noneMatch(s -> s.equalsIgnoreCase(targetId))) {
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
}
for (String type : acceptedTypes) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7e >\u00a7f " + type);
// Material compatibility check
if (getMMOItem().hasData(ItemStats.COMPATIBLE_MATERIALS)) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: ");
List<String> acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList();
if (type.equalsIgnoreCase(targetType.getId())) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched");
compatible = true; break; }
}
if (acceptedMaterials.size() > 0 && acceptedMaterials.stream()
.noneMatch(s -> s.equalsIgnoreCase(target.getItem().getType().name()))) {
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
}
if (!compatible && acceptedTypes.size() > 0) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible");
// check for success rate
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
if (successRate != 0)
if (RANDOM.nextDouble() < 1 - successRate / 100) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.FAILURE);
}
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
}
// Apply skin
ItemStack item = applySkin(target, getMMOItem());
if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: ");
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
List<String> acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList();
return new ApplyResult(item);
}
for (String id : acceptedIDs) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id);
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched");
compatible = true;break; }
}
/**
* When applying a skin to an item, the skin item ID is saved
* in the target item so that if deskined, it can be retrieved
* and given back to the player.
*/
public static final String SKIN_ID_TAG = "MMOITEMS_SKIN_ID";
if (!compatible && acceptedIDs.size() > 0) {
//SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible");
/**
* Applies the skin information from a skin consumable onto any item.
*
* @param target Target item that the skin has been <b>successfully</b> applied to
* @param skinItemMMO Skin consumable
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
*/
@NotNull
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
final NBTItem skinItemNBT = skinItemMMO.getNBT();
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.NONE);
}
}
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
if (skinItemNBT.getInteger("CustomModelData") != 0)
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
// check for success rate
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
if (successRate != 0)
if (RANDOM.nextDouble() < 1 - successRate / 100) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
Message.SKIN_BROKE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem()))
.send(player);
return new ApplyResult(ResultType.FAILURE);
}
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
// Apply skin
ItemStack item = applySkin(target, getMMOItem());
ItemStack item = target.toItem();
if (item.getType() != skinItemNBT.getItem().getType())
item.setType(skinItemNBT.getItem().getType());
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
ItemMeta meta = item.getItemMeta();
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
if (skinMeta != null && meta != null) {
return new ApplyResult(item);
}
// TODO factorize with a ItemSkinStat stat interface
if (skinMeta.isUnbreakable()) {
meta.setUnbreakable(true);
if (meta instanceof Damageable && skinMeta instanceof Damageable)
((Damageable) meta).setDamage(((Damageable) skinMeta).getDamage());
}
public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN";
if (skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor());
/**
* When applying a skin to an item, the skin item ID is saved
* in the target item so that if deskined, it can be retrieved
* and given back to the player.
*
*
*/
public static final String SKIN_ID_TAG = "MMOITEMS_SKIN_ID";
if (skinItemMMO.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
&& skinItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta,
((SkullTextureData) skinItemMMO.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
MMOItems.plugin.getLogger().warning("Could not read skull texture");
}
}
/**
* Applies the skin information from a skin consumable onto any item.
*
* @param target Target item that the skin has been <b>successfully</b> applied to
* @param skinItemMMO Skin consumable
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
*/
@NotNull
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull VolatileMMOItem skinItemMMO) {
final NBTItem skinItemNBT = skinItemMMO.getNBT();
item.setItemMeta(meta);
}
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
target.addTag(new ItemTag(SKIN_ID_TAG, skinItemNBT.getString("MMOITEMS_ITEM_ID")));
if (skinItemNBT.getInteger("CustomModelData") != 0)
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData")));
return item;
}
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty())
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
/**
* Copies a skin from one item to another
*
* @param target Target item that you are copying the skin onto
* @param originalItemNBT Item with a skin already, as NBT. Operation will fail
* if it doesnt have a skin.
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
* @author Gunging
*/
@Nullable
public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
ItemStack item = target.toItem();
if (item.getType() != skinItemNBT.getItem().getType())
item.setType(skinItemNBT.getItem().getType());
// No skin no service
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) {
return null;
}
ItemMeta meta = item.getItemMeta();
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
if (skinMeta != null && meta != null) {
// Copy over data
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
if (originalItemNBT.getInteger("CustomModelData") != 0) {
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData")));
}
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES")));
}
// TODO factorize with a ItemSkinStat stat interface
if (skinMeta.isUnbreakable()) {
meta.setUnbreakable(true);
if (meta instanceof Damageable && skinMeta instanceof Damageable)
((Damageable) meta).setDamage(((Damageable) skinMeta).getDamage());
}
// ItemMeta values copy-over
ItemStack item = target.toItem();
if (item.getType() != originalItemNBT.getItem().getType()) {
item.setType(originalItemNBT.getItem().getType());
}
if(skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor());
ItemMeta meta = item.getItemMeta();
ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta();
if (originalMeta != null && meta != null) {
if (skinItemMMO.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
&& skinItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta,
((SkullTextureData) skinItemMMO.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
MMOItems.plugin.getLogger().warning("Could not read skull texture");
}
}
if (originalMeta.isUnbreakable()) {
meta.setUnbreakable(true);
if (meta instanceof Damageable && originalMeta instanceof Damageable)
((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage());
}
item.setItemMeta(meta);
}
if (originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor());
return item;
}
VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT);
if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
&& originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
/**
* Copies a skin from one item to another
*
* @param target Target item that you are copying the skin onto
*
* @param originalItemNBT Item with a skin already, as NBT. Operation will fail
* if it doesnt have a skin.
*
* @return Built ItemStack from the target NBT but with the skin data contained in the skin consumable
*
* @author Gunging
*/
@Nullable public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem originalItemNBT) {
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta,
((SkullTextureData) originalVolatile.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
MMOItems.plugin.getLogger().warning("Could not read skull texture");
}
}
// No skin no service
if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) { return null; }
item.setItemMeta(meta);
}
// Copy over data
target.addTag(new ItemTag(HAS_SKIN_TAG, true));
target.addTag(new ItemTag(SKIN_ID_TAG, originalItemNBT.getString("MMOITEMS_ITEM_ID")));
if (originalItemNBT.getInteger("CustomModelData") != 0) {
target.addTag(new ItemTag("CustomModelData", originalItemNBT.getInteger("CustomModelData"))); }
if (!originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", originalItemNBT.getString("MMOITEMS_ITEM_PARTICLES"))); }
return item;
}
// ItemMeta values copy-over
ItemStack item = target.toItem();
if (item.getType() != originalItemNBT.getItem().getType()) { item.setType(originalItemNBT.getItem().getType()); }
public static class ApplyResult {
private final ResultType type;
private final ItemStack result;
ItemMeta meta = item.getItemMeta();
ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta();
if (originalMeta != null && meta != null) {
public ApplyResult(ResultType type) {
this(null, type);
}
if (originalMeta.isUnbreakable()) {
meta.setUnbreakable(true);
if (meta instanceof Damageable && originalMeta instanceof Damageable)
((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage());
}
public ApplyResult(ItemStack result) {
this(result, ResultType.SUCCESS);
}
if(originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta)
((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor());
public ApplyResult(ItemStack result, ResultType type) {
this.type = type;
this.result = result;
}
VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT);
if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()
&& originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
public ResultType getType() {
return type;
}
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta,
((SkullTextureData) originalVolatile.getData(ItemStats.SKULL_TEXTURE)).getGameProfile());
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
MMOItems.plugin.getLogger().warning("Could not read skull texture");
}
}
public ItemStack getResult() {
return result;
}
}
item.setItemMeta(meta);
}
return item;
}
public static class ApplyResult {
private final ResultType type;
private final ItemStack result;
public ApplyResult(ResultType type) {
this(null, type);
}
public ApplyResult(ItemStack result) {
this(result, ResultType.SUCCESS);
}
public ApplyResult(ItemStack result, ResultType type) {
this.type = type;
this.result = result;
}
public ResultType getType() {
return type;
}
public ItemStack getResult() {
return result;
}
}
public enum ResultType {
FAILURE, NONE, SUCCESS
}
public enum ResultType {
FAILURE, NONE, SUCCESS
}
}

View File

@ -25,6 +25,6 @@ public class ArrowParticles extends BukkitRunnable {
return;
}
particleInfo.display(arrow.getLocation().add(0, .25, 0));
particleInfo.display(arrow.getLocation().add(0, 0, 0));
}
}

View File

@ -31,4 +31,8 @@ public class MoneyCondition extends Condition {
public void whenCrafting(PlayerData data) {
MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount);
}
public double getAmount() {
return amount;
}
}

View File

@ -16,6 +16,7 @@ import net.Indyuce.mmoitems.api.crafting.recipe.Recipe;
import net.Indyuce.mmoitems.api.event.PlayerUseCraftingStationEvent;
import net.Indyuce.mmoitems.api.item.util.ConfigItems;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.comp.eco.MoneyCondition;
import net.Indyuce.mmoitems.listener.CustomSoundListener;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
@ -221,6 +222,13 @@ public class CraftingStationView extends PluginInventory {
// Give ingredients back
for (Ingredient ingredient : recipeInfo.getRecipe().getIngredients())
new SmartGive(player).give(ingredient.generateItemStack(playerData.getRPG()));
// Give money back
recipe.getConditions()
.stream()
.filter(condition -> condition instanceof MoneyCondition)
.map(condition -> (MoneyCondition) condition)
.forEach(condition -> MMOItems.plugin.getVault().getEconomy().depositPlayer(player, condition.getAmount()));
}
updateData();

View File

@ -3,7 +3,10 @@ package net.Indyuce.mmoitems.stat;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
@ -11,12 +14,8 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
@ -29,138 +28,130 @@ import java.util.List;
import java.util.Optional;
public class CompatibleIds extends ItemStat<StringListData, StringListData> {
public CompatibleIds() {
super("COMPATIBLE_IDS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible IDs",
new String[] { "The item ids this skin is", "compatible with." }, new String[] { "skin" });
}
public CompatibleIds() {
super("COMPATIBLE_IDS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible IDs",
new String[]{"The item ids this skin is", "compatible with."}, new String[]{"skin"});
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.COMPATIBLE_IDS).enable("Write in the chat the item id you want to add.");
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.COMPATIBLE_IDS).enable("Write in the chat the item id you want to add.");
if (event.getAction() == InventoryAction.PICKUP_HALF) {
if (inv.getEditedSection().contains("compatible-ids")) {
List<String> lore = inv.getEditedSection().getStringList("compatible-ids");
if (lore.size() < 1)
return;
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-ids"))
return;
List<String> lore = inv.getEditedSection().getStringList("compatible-ids");
if (lore.size() < 1)
return;
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("compatible-ids", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
}
}
}
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("compatible-ids", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("compatible-ids") ? inv.getEditedSection().getStringList("compatible-ids")
: new ArrayList<>();
lore.add(message.toUpperCase());
inv.getEditedSection().set("compatible-ids", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible IDs successfully added.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("compatible-ids") ? inv.getEditedSection().getStringList("compatible-ids")
: new ArrayList<>();
lore.add(message.toUpperCase());
inv.getEditedSection().set("compatible-ids", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible IDs successfully added.");
}
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str));
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
}
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
@NotNull
@Override
public StringListData getClearStatData() {
return new StringListData();
}
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
// Copy Array, for lore
List<String> compatibleIds = new ArrayList<>(data.getList());
item.getLore().insert("compatible-ids", compatibleIds);
@NotNull
@Override
public StringListData getClearStatData() {
return new StringListData();
}
// Add data
item.addItemTag(getAppliedNBT(data));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
// Build Json Array
JsonArray array = new JsonArray();
// Copy Array, for lore
List<String> compatibleIds = new ArrayList<>(data.getList());
item.getLore().insert("compatible-ids", compatibleIds);
// For each string in the ids of the data
for (String sts : data.getList()) {
array.add(sts);
}
// Add data
item.addItemTag(getAppliedNBT(data));
}
// Make returning array
ArrayList<ItemTag> tags = new ArrayList<>();
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
// Add Json Array
tags.add(new ItemTag(getNBTPath(), array.toString()));
// Build Json Array
JsonArray array = new JsonArray();
return tags;
}
// For each string in the ids of the data
for (String sts : data.getList()) { array.add(sts); }
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
// FInd relvant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (mmoitem.getNBT().hasTag(getNBTPath()))
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Make returning array
ArrayList<ItemTag> tags = new ArrayList<>();
// Generate data
StatData data = getLoadedNBT(relevantTags);
// Add Json Array
tags.add(new ItemTag(getNBTPath(), array.toString()));
if (data != null)
mmoitem.setData(this, data);
}
return tags;
}
@Nullable
@Override
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
// Find relevant tag
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
// Found?
if (rTag == null)
// Nope
return null;
// FInd relvant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (mmoitem.getNBT().hasTag(getNBTPath()))
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Generate data
StatData data = getLoadedNBT(relevantTags);
if (data != null) { mmoitem.setData(this, data);}
}
@Nullable
@Override
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
// Find relevant tag
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
// Found?
if (rTag != null) {
try {
// Parse onto Json Array
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
// Make and return list
return new StringListData(array);
} catch (JsonSyntaxException |IllegalStateException exception) {
/*
* OLD ITEM WHICH MUST BE UPDATED.
*/
}
}
// Nope
return null;
}
try {
// Parse onto Json Array
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
// Make and return list
return new StringListData(array);
} catch (JsonSyntaxException | IllegalStateException exception) {
/*
* OLD ITEM WHICH MUST BE UPDATED.
*/
}
return null;
}
}

View File

@ -0,0 +1,169 @@
package net.Indyuce.mmoitems.stat;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class CompatibleMaterials extends ItemStat<StringListData, StringListData> {
public CompatibleMaterials() {
super("COMPATIBLE_MATERIALS", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Materials",
new String[]{"The item materials this skin is", "compatible with."}, new String[]{"skin"});
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.COMPATIBLE_MATERIALS).enable("Write in the chat the name of the material you want to add.");
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-materials"))
return;
List<String> lore = inv.getEditedSection().getStringList("compatible-materials");
if (lore.size() < 1)
return;
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("compatible-materials", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
final Player player = inv.getPlayer();
// Check if material exists
if (Arrays.stream(Material.values()).noneMatch(versionMaterial -> versionMaterial.name().equalsIgnoreCase(message))) {
player.sendMessage(MMOItems.plugin.getPrefix() + "Invalid material name.");
return;
}
List<String> lore = inv.getEditedSection().contains("compatible-materials") ? inv.getEditedSection().getStringList("compatible-materials")
: new ArrayList<>();
lore.add(message.toUpperCase());
inv.getEditedSection().set("compatible-materials", lore);
inv.registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Compatible Materials successfully added.");
}
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any material.");
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new material.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last material.");
}
@NotNull
@Override
public StringListData getClearStatData() {
return new StringListData();
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
// Copy Array, for lore
List<String> compatibleMaterials = new ArrayList<>(data.getList());
item.getLore().insert("compatible-materials", compatibleMaterials);
// Add data
item.addItemTag(getAppliedNBT(data));
}
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
// Build Json Array
JsonArray array = new JsonArray();
// For each string in the ids of the data
for (String sts : data.getList()) {
array.add(sts);
}
// Make returning array
ArrayList<ItemTag> tags = new ArrayList<>();
// Add Json Array
tags.add(new ItemTag(getNBTPath(), array.toString()));
return tags;
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
// FInd relevant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (mmoitem.getNBT().hasTag(getNBTPath()))
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Generate data
StatData data = getLoadedNBT(relevantTags);
if (data != null)
mmoitem.setData(this, data);
}
@Nullable
@Override
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
// Find relevant tag
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
// Found?
if (rTag == null)
// Nope
return null;
try {
// Parse onto Json Array
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
// Make and return list
return new StringListData(array);
} catch (JsonSyntaxException | IllegalStateException exception) {
/*
* OLD ITEM WHICH MUST BE UPDATED.
*/
}
return null;
}
}

View File

@ -1,19 +1,12 @@
package net.Indyuce.mmoitems.stat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
@ -21,149 +14,145 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class CompatibleTypes extends ItemStat<StringListData, StringListData> {
public CompatibleTypes() {
super("COMPATIBLE_TYPES", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Types",
new String[] { "The item types this skin is", "compatible with." }, new String[] { "skin" });
}
public CompatibleTypes() {
super("COMPATIBLE_TYPES", VersionMaterial.COMMAND_BLOCK.toMaterial(), "Compatible Types",
new String[]{"The item types this skin is", "compatible with."}, new String[]{"skin"});
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.COMPATIBLE_TYPES).enable("Write in the chat the name of the type you want to add.");
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(inv, ItemStats.COMPATIBLE_TYPES).enable("Write in the chat the name of the type you want to add.");
if (event.getAction() == InventoryAction.PICKUP_HALF) {
if (inv.getEditedSection().contains("compatible-types")) {
List<String> lore = inv.getEditedSection().getStringList("compatible-types");
if (lore.size() < 1)
return;
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-types"))
return;
List<String> lore = inv.getEditedSection().getStringList("compatible-types");
if (lore.size() < 1)
return;
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("compatible-types", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
}
}
}
String last = lore.get(lore.size() - 1);
lore.remove(last);
inv.getEditedSection().set("compatible-types", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("compatible-types") ? inv.getEditedSection().getStringList("compatible-types")
: new ArrayList<>();
lore.add(message.toUpperCase());
inv.getEditedSection().set("compatible-types", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible Types successfully added.");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
List<String> lore = inv.getEditedSection().contains("compatible-types") ? inv.getEditedSection().getStringList("compatible-types")
: new ArrayList<>();
lore.add(message.toUpperCase());
inv.getEditedSection().set("compatible-types", lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Compatible Types successfully added.");
}
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
@Override
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + str));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
((StringListData) statData.get()).getList().forEach(str -> lore.add(ChatColor.GRAY + str));
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new type.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last type.");
}
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
@NotNull
@Override
public StringListData getClearStatData() {
return new StringListData();
}
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new type.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last type.");
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
// Copy Array, for lore
List<String> compatibleTypes = new ArrayList<>(data.getList());
item.getLore().insert("compatible-types", compatibleTypes);
@NotNull
@Override
public StringListData getClearStatData() {
return new StringListData();
}
// Add data
item.addItemTag(getAppliedNBT(data));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
// Build Json Array
JsonArray array = new JsonArray();
// Copy Array, for lore
List<String> compatibleTypes = new ArrayList<>(((StringListData) data).getList());
item.getLore().insert("compatible-types", compatibleTypes);
// For each string in the ids of the data
for (String sts : data.getList()) {
array.add(sts);
}
// Add data
item.addItemTag(getAppliedNBT(data));
}
// Make returning array
ArrayList<ItemTag> tags = new ArrayList<>();
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull StringListData data) {
// Add Json Array
tags.add(new ItemTag(getNBTPath(), array.toString()));
// Build Json Array
JsonArray array = new JsonArray();
return tags;
}
// For each string in the ids of the data
for (String sts : ((StringListData) data).getList()) { array.add(sts); }
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
// FInd relevant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (mmoitem.getNBT().hasTag(getNBTPath()))
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
// Make returning array
ArrayList<ItemTag> tags = new ArrayList<>();
// Generate data
StatData data = getLoadedNBT(relevantTags);
// Add Json Array
tags.add(new ItemTag(getNBTPath(), array.toString()));
if (data != null)
mmoitem.setData(this, data);
}
return tags;
}
@Nullable
@Override
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
// Find relevant tag
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
// Found?
if (rTag == null)
// Nope
return null;
// FInd relvant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (mmoitem.getNBT().hasTag(getNBTPath()))
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
try {
// Parse onto Json Array
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
// Generate data
StatData data = getLoadedNBT(relevantTags);
if (data != null) { mmoitem.setData(this, data);}
}
@Nullable
@Override
public StringListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
// Find relevant tag
ItemTag rTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
// Found?
if (rTag != null) {
try {
// Parse onto Json Array
JsonArray array = new JsonParser().parse((String) rTag.getValue()).getAsJsonArray();
// Make and return list
return new StringListData(array);
} catch (JsonSyntaxException |IllegalStateException exception) {
/*
* OLD ITEM WHICH MUST BE UPDATED.
*/
}
}
// Nope
return null;
}
// Make and return list
return new StringListData(array);
} catch (JsonSyntaxException | IllegalStateException exception) {
/*
* OLD ITEM WHICH MUST BE UPDATED.
*/
}
return null;
}
}