diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java index 8367f50c..c1f624be 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java @@ -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(), diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java index c0c3c0b5..924905c9 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java @@ -44,22 +44,22 @@ public class ItemSkin extends UseItem { //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: "); - List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); - for (String type : acceptedTypes) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7e >\u00a7f " + type); if (type.equalsIgnoreCase(targetType.getId())) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true; break; } + compatible = true; + break; + } } if (!compatible && acceptedTypes.size() > 0) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); Message.SKIN_INCOMPATIBLE.format(ChatColor.RED, "#item#", MMOUtils.getDisplayName(target.getItem())) .send(player); @@ -67,6 +67,7 @@ public class ItemSkin extends UseItem { } } + // IDs compatibility check if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: "); @@ -90,6 +91,29 @@ public class ItemSkin extends UseItem { } } + // Material compatibility check + if (getMMOItem().hasData(ItemStats.COMPATIBLE_MATERIALS)) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); + + List acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList(); + + for (String material : acceptedMaterials) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + material); + + if (material.equalsIgnoreCase(target.getItem().getType().name())) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); + compatible = true;break; } + } + + if (!compatible && acceptedMaterials.size() > 0) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); + 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); + } + } + // check for success rate double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId()); if (successRate != 0) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java index 995272c7..5c1ef10c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleIds.java @@ -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 { - 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) object); - } + @Override + @SuppressWarnings("unchecked") + public StringListData whenInitialized(Object object) { + Validate.isTrue(object instanceof List, "Must specify a string list"); + return new StringListData((List) 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 lore = inv.getEditedSection().getStringList("compatible-ids"); - if (lore.size() < 1) - return; + if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-ids")) + return; + List 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 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 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 lore, Optional statData) { + @Override + public void whenDisplayed(List lore, Optional 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 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 getAppliedNBT(@NotNull StringListData data) { + // Build Json Array + JsonArray array = new JsonArray(); - // Copy Array, for lore - List 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 tags = new ArrayList<>(); - @NotNull - @Override - public ArrayList 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 relevantTags = new ArrayList<>(); + if (mmoitem.getNBT().hasTag(getNBTPath())) + relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING)); - // Make returning array - ArrayList 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 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 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 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; + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java new file mode 100644 index 00000000..590791b0 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java @@ -0,0 +1,167 @@ +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.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 { + 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) 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 material you want to add."); + + if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-materials")) + return; + List 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(VersionMaterial.values()).noneMatch(versionMaterial -> versionMaterial.name().equalsIgnoreCase(message))) { + player.sendMessage(MMOItems.plugin.getPrefix() + "Invalid material name."); + return; + } + + List 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 lore, Optional 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 compatibleTypes = new ArrayList<>(data.getList()); + item.getLore().insert("compatible-materials", compatibleTypes); + + // Add data + item.addItemTag(getAppliedNBT(data)); + } + + @NotNull + @Override + public ArrayList 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 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 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 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; + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java index 2248dd99..30caff1f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleTypes.java @@ -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 { - 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) object); - } + @Override + @SuppressWarnings("unchecked") + public StringListData whenInitialized(Object object) { + Validate.isTrue(object instanceof List, "Must specify a string list"); + return new StringListData((List) 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 lore = inv.getEditedSection().getStringList("compatible-types"); - if (lore.size() < 1) - return; + if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains("compatible-types")) + return; + List 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 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 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 lore, Optional statData) { + @Override + public void whenDisplayed(List lore, Optional 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 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 getAppliedNBT(@NotNull StringListData data) { + // Build Json Array + JsonArray array = new JsonArray(); - // Copy Array, for lore - List 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 tags = new ArrayList<>(); - @NotNull - @Override - public ArrayList 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 relevantTags = new ArrayList<>(); + if (mmoitem.getNBT().hasTag(getNBTPath())) + relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING)); - // Make returning array - ArrayList 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 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 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 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; + } }