From 3a10bb1b39f2aa7bc4f4e3ab5583caf586f1742c Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 19 Mar 2023 12:53:48 +0100 Subject: [PATCH 01/15] Support for other AS stats --- .../mmoitems/comp/rpg/AureliumSkillsHook.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java index 92846440..262c993e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java @@ -7,6 +7,7 @@ import com.archyx.aureliumskills.data.PlayerDataLoadEvent; import com.archyx.aureliumskills.skills.Skill; import com.archyx.aureliumskills.skills.Skills; import com.archyx.aureliumskills.stats.Stats; +import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.MMOItems; @@ -22,21 +23,28 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; public class AureliumSkillsHook implements RPGHandler, Listener { private final AureliumSkills aSkills; - private static final ItemStat WISDOM = new DoubleStat("WISDOM", Material.BOOK, - "Additional Wisdom", - new String[]{"Additional wisdom (AureliumSkills)"}, - new String[]{"!miscellaneous", "!block", "all"}); + private final Map statExtra = new HashMap<>(); + public AureliumSkillsHook() { aSkills = (AureliumSkills) Bukkit.getPluginManager().getPlugin("AureliumSkills"); - // Register wisdom for the max mana stat - MMOItems.plugin.getStats().register(WISDOM); + for (Stats stat : Stats.values()) { + final String statName = UtilityMethods.caseOnWords(stat.name().toLowerCase()); + final ItemStat miStat = new DoubleStat(stat.name(), Material.BOOK, + "Additional " + statName, + new String[]{"Additional " + statName + " (AureliumSkills)"}, + new String[]{"!miscellaneous", "!block", "all"}); + + MMOItems.plugin.getStats().register(miStat); + } // Register stat for required professions for (Skills skill : Skills.values()) @@ -50,9 +58,11 @@ public class AureliumSkillsHook implements RPGHandler, Listener { PlayerData.get(player).getInventory().scheduleUpdate(); } + private static final String MODIFIER_KEY = "mmoitems"; + @Override public void refreshStats(PlayerData data) { - AureliumAPI.addStatModifier(data.getPlayer(), "mmoitems", Stats.WISDOM, data.getStats().getStat(WISDOM)); + statExtra.forEach((stat, miStat) -> AureliumAPI.addStatModifier(data.getPlayer(), MODIFIER_KEY, stat, data.getStats().getStat(miStat))); } @Override From ace0d26a89fa57a5009881918ea037d56b6689d8 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 19 Mar 2023 15:17:23 +0100 Subject: [PATCH 02/15] Fixed repair type --- .../java/net/Indyuce/mmoitems/util/MMOUtils.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java index d47eed22..dc5fcd2e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java @@ -61,12 +61,11 @@ public class MMOUtils { * They are a piece of text stored as an NBTTag for instance. Items can * interact (in a certain way) only if the corresponding reference match. *

- * A null reference is considered just like a non-null reference. - * Any item can interact with an item with the universal reference 'all' + * Any item can interact with an item with the universal reference 'all'. + * A null/empty reference is considered like the universal reference. *

- * TODO * This is a simple symmetrical computation. Used for: - * - for item upgrading + * - for item upgrading TODO * - item repairing * * @param ref1 First reference @@ -74,11 +73,7 @@ public class MMOUtils { * @return If items can interact */ public static boolean checkReference(@Nullable String ref1, @Nullable String ref2) { - if (ref1 == null) - return ref2 == null || ref2.equals(UNIVERSAL_REFERENCE); - if (ref2 == null) - return ref1 == null || ref1.equals(UNIVERSAL_REFERENCE); - return ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2); + return ref1 == null || ref1.isEmpty() || ref2 == null || ref2.isEmpty() || ref1.equals(UNIVERSAL_REFERENCE) || ref2.equals(UNIVERSAL_REFERENCE) || ref1.equals(ref2); } /** From a4afdda6284af7c33bdf5d08542efb49d02924b4 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 19 Mar 2023 15:20:08 +0100 Subject: [PATCH 03/15] Updated repair type description --- .../main/java/net/Indyuce/mmoitems/stat/RepairReference.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java index 5bf80d57..0388a482 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RepairReference.java @@ -6,6 +6,6 @@ import org.bukkit.Material; public class RepairReference extends StringStat implements GemStoneStat { public RepairReference() { - super("REPAIR_TYPE", Material.ANVIL, "Repair Reference", new String[]{"If items have a repair type they can", "only be repaired by consumables", "with the same repair type.", "(And vice-versa)"}, new String[]{"all"}); + super("REPAIR_TYPE", Material.ANVIL, "Repair Reference", new String[]{"If items have a repair reference, they can", "only be repaired by consumables", "with the same repair reference,", "and vice-versa."}, new String[]{"all"}); } } From 67eae457ca6cc815b6a84e2abf588b19ec761a71 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sat, 25 Mar 2023 14:43:51 +0100 Subject: [PATCH 04/15] Compatible Materials stat addition --- .../java/net/Indyuce/mmoitems/ItemStats.java | 1 + .../mmoitems/api/interaction/ItemSkin.java | 32 ++- .../Indyuce/mmoitems/stat/CompatibleIds.java | 225 ++++++++-------- .../mmoitems/stat/CompatibleMaterials.java | 167 ++++++++++++ .../mmoitems/stat/CompatibleTypes.java | 247 +++++++++--------- 5 files changed, 422 insertions(+), 250 deletions(-) create mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java 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; + } } From 27065aa540806563aeffc8b5b1a380a9e999e17a Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sat, 25 Mar 2023 14:56:37 +0100 Subject: [PATCH 05/15] Compatible materials stat bug fixed --- .../mmoitems/api/interaction/ItemSkin.java | 430 +++++++++--------- .../mmoitems/stat/CompatibleMaterials.java | 10 +- 2 files changed, 219 insertions(+), 221 deletions(-) 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 924905c9..b634ca10 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 @@ -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,269 +25,265 @@ 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; + 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: "); - List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); - for (String type : acceptedTypes) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7e >\u00a7f " + type); + // 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; - } - } + if (type.equalsIgnoreCase(targetType.getId())) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); + 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); - return new ApplyResult(ResultType.NONE); - } - } + 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); + return new ApplyResult(ResultType.NONE); + } + } - // IDs compatibility check - if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: "); + // IDs compatibility check + if (getMMOItem().hasData(ItemStats.COMPATIBLE_IDS)) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that ID is compatible: "); - List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); + List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); - for (String id : acceptedIDs) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id); + for (String id : acceptedIDs) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id); - if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true;break; } - } + if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) { + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); + compatible = true; + break; + } + } - if (!compatible && acceptedIDs.size() > 0) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); + if (!compatible && acceptedIDs.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); - } - } + 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); + } + } - // Material compatibility check - if (getMMOItem().hasData(ItemStats.COMPATIBLE_MATERIALS)) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); + // 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(); - List acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList(); + if (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); + } + } - for (String material : acceptedMaterials) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + material); + // 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 (material.equalsIgnoreCase(target.getItem().getType().name())) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true;break; } - } + // Apply skin + ItemStack item = applySkin(target, getMMOItem()); - 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); - } - } + player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); + Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player); - // 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); - } + return new ApplyResult(item); + } - // Apply skin - ItemStack item = applySkin(target, getMMOItem()); + public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN"; - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2); - Message.SKIN_APPLIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player); + /** + * 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"; - return new ApplyResult(item); - } + /** + * Applies the skin information from a skin consumable onto any item. + * + * @param target Target item that the skin has been successfully 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(); - public static final String HAS_SKIN_TAG = "MMOITEMS_HAS_SKIN"; + 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"))); - /** - * 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 (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) + target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES"))); - /** - * Applies the skin information from a skin consumable onto any item. - * - * @param target Target item that the skin has been successfully 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(); + ItemStack item = target.toItem(); + if (item.getType() != skinItemNBT.getItem().getType()) + item.setType(skinItemNBT.getItem().getType()); - 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"))); + ItemMeta meta = item.getItemMeta(); + ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta(); + if (skinMeta != null && meta != null) { - if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) - target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.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()); + } - ItemStack item = target.toItem(); - if (item.getType() != skinItemNBT.getItem().getType()) - item.setType(skinItemNBT.getItem().getType()); + if (skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta) + ((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor()); - ItemMeta meta = item.getItemMeta(); - ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta(); - if (skinMeta != 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"); + } + } - // 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()); - } + item.setItemMeta(meta); + } - if(skinMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta) - ((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) skinMeta).getColor()); + return item; + } - 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"); - } - } + /** + * 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) { - item.setItemMeta(meta); - } + // No skin no service + if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) { + return null; + } - return item; - } + // 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"))); + } - /** - * 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) { + // ItemMeta values copy-over + ItemStack item = target.toItem(); + if (item.getType() != originalItemNBT.getItem().getType()) { + item.setType(originalItemNBT.getItem().getType()); + } - // No skin no service - if (!originalItemNBT.getBoolean(HAS_SKIN_TAG)) { return null; } + ItemMeta meta = item.getItemMeta(); + ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta(); + if (originalMeta != 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"))); } + if (originalMeta.isUnbreakable()) { + meta.setUnbreakable(true); + if (meta instanceof Damageable && originalMeta instanceof Damageable) + ((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage()); + } - // ItemMeta values copy-over - ItemStack item = target.toItem(); - if (item.getType() != originalItemNBT.getItem().getType()) { item.setType(originalItemNBT.getItem().getType()); } + if (originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta) + ((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor()); - ItemMeta meta = item.getItemMeta(); - ItemMeta originalMeta = originalItemNBT.getItem().getItemMeta(); - if (originalMeta != null && meta != null) { + VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT); + if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() + && originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) { - if (originalMeta.isUnbreakable()) { - meta.setUnbreakable(true); - if (meta instanceof Damageable && originalMeta instanceof Damageable) - ((Damageable) meta).setDamage(((Damageable) originalMeta).getDamage()); - } + 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"); + } + } - if(originalMeta instanceof LeatherArmorMeta && meta instanceof LeatherArmorMeta) - ((LeatherArmorMeta) meta).setColor(((LeatherArmorMeta) originalMeta).getColor()); + item.setItemMeta(meta); + } - VolatileMMOItem originalVolatile = new VolatileMMOItem(originalItemNBT); - if (originalVolatile.hasData(ItemStats.SKULL_TEXTURE) && item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() - && originalItemNBT.getItem().getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) { + return item; + } - 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 static class ApplyResult { + private final ResultType type; + private final ItemStack result; - item.setItemMeta(meta); - } + public ApplyResult(ResultType type) { + this(null, type); + } - return item; - } + public ApplyResult(ItemStack result) { + this(result, ResultType.SUCCESS); + } - public static class ApplyResult { - private final ResultType type; - private final ItemStack result; + public ApplyResult(ItemStack result, ResultType type) { + this.type = type; + this.result = result; + } - public ApplyResult(ResultType type) { - this(null, type); - } + public ResultType getType() { + return type; + } - public ApplyResult(ItemStack result) { - this(result, ResultType.SUCCESS); - } + public ItemStack getResult() { + return result; + } + } - 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 + } } 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 index 590791b0..12692893 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CompatibleMaterials.java @@ -18,6 +18,7 @@ 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; @@ -30,6 +31,7 @@ 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"}); @@ -45,7 +47,7 @@ public class CompatibleMaterials extends ItemStat versionMaterial.name().equalsIgnoreCase(message))) { + if (Arrays.stream(Material.values()).noneMatch(versionMaterial -> versionMaterial.name().equalsIgnoreCase(message))) { player.sendMessage(MMOItems.plugin.getPrefix() + "Invalid material name."); return; } @@ -99,8 +101,8 @@ public class CompatibleMaterials extends ItemStat compatibleTypes = new ArrayList<>(data.getList()); - item.getLore().insert("compatible-materials", compatibleTypes); + List compatibleMaterials = new ArrayList<>(data.getList()); + item.getLore().insert("compatible-materials", compatibleMaterials); // Add data item.addItemTag(getAppliedNBT(data)); From 75c345483d838e6f74436b4fed305d6391cff426 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sat, 25 Mar 2023 14:58:48 +0100 Subject: [PATCH 06/15] Optimization --- .../mmoitems/api/interaction/ItemSkin.java | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) 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 b634ca10..8adb585d 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 @@ -40,26 +40,13 @@ public class ItemSkin extends UseItem { return new ApplyResult(ResultType.NONE); } - boolean compatible = false; - //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; - } - } - - if (!compatible && acceptedTypes.size() > 0) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); + final List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); + if (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); @@ -70,22 +57,11 @@ 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: "); + final List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); + final String targetId = target.getString("MMOITEMS_ITEM_ID"); - List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); - - for (String id : acceptedIDs) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a76 >\u00a7f " + id); - - if (id.equalsIgnoreCase(target.getString("MMOITEMS_ITEM_ID"))) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7a Matched"); - compatible = true; - break; - } - } - - if (!compatible && acceptedIDs.size() > 0) { - //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a7c Incompatible"); - + if (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); @@ -95,8 +71,7 @@ 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: "); + //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); List acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList(); if (acceptedMaterials.stream() From 393c7cfc789a443e108662ec7733bcf00e604246 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sat, 25 Mar 2023 15:15:50 +0100 Subject: [PATCH 07/15] Bug fix --- .../java/net/Indyuce/mmoitems/api/interaction/ItemSkin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 8adb585d..e01215ee 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 @@ -46,7 +46,7 @@ public class ItemSkin extends UseItem { if (getMMOItem().hasData(ItemStats.COMPATIBLE_TYPES)) { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that TYPE is compatible: "); final List acceptedTypes = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_TYPES)).getList(); - if (acceptedTypes.stream().noneMatch(s -> s.equalsIgnoreCase(targetType.getId()))) { + 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); @@ -60,7 +60,7 @@ public class ItemSkin extends UseItem { final List acceptedIDs = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_IDS)).getList(); final String targetId = target.getString("MMOITEMS_ITEM_ID"); - if (acceptedIDs.stream() + 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())) @@ -74,7 +74,7 @@ public class ItemSkin extends UseItem { //SKIN//MMOItems.log("\u00a78SKIN \u00a7eCPT\u00a77 Testing that MATERIAL is compatible: "); List acceptedMaterials = ((StringListData) getMMOItem().getData(ItemStats.COMPATIBLE_MATERIALS)).getList(); - if (acceptedMaterials.stream() + 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())) From 0aef22ad1e9606edcd2670676bf767ae9f3f8524 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sun, 26 Mar 2023 17:45:25 +0200 Subject: [PATCH 08/15] Issue fixed --- .../net/Indyuce/mmoitems/comp/eco/MoneyCondition.java | 4 ++++ .../net/Indyuce/mmoitems/gui/CraftingStationView.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java index 587c17b2..6e238180 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java @@ -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; + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java index 8bb8c1a0..07fe19b1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/CraftingStationView.java @@ -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(); From d56cd46e97955762fb603f3088464ebaa11eda89 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Sun, 26 Mar 2023 17:52:15 +0200 Subject: [PATCH 09/15] Bug fixed --- .../mmoitems/api/interaction/projectile/ArrowParticles.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/projectile/ArrowParticles.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/projectile/ArrowParticles.java index a3849037..5cd3088a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/projectile/ArrowParticles.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/projectile/ArrowParticles.java @@ -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)); } } From 4f8577736b9956842223865f1de6a3e4f015bc90 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 1 Apr 2023 23:03:36 +0200 Subject: [PATCH 10/15] Fixed lang3 import --- .../src/main/java/net/Indyuce/mmoitems/manager/StatManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java index 0961ba27..38f77726 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java @@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.stat.type.*; import net.Indyuce.mmoitems.util.ElementStatType; -import org.apache.commons.lang3.Validate; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; From 78c445bb5ae4b104bb519b81c79c1596733f254e Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 1 Apr 2023 23:27:38 +0200 Subject: [PATCH 11/15] Made stat placeholder more lenient --- .../mmoitems/comp/placeholders/MMOItemsPlaceholders.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java index 1ae9dde4..74e2f43f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.comp.placeholders; import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.MMOPlayerData; import io.lumine.mythic.lib.api.util.AltChar; @@ -59,8 +60,8 @@ public class MMOItemsPlaceholders extends PlaceholderExpansion { } if (identifier.startsWith("stat_")) { - final String stat = identifier.substring(5).toUpperCase(); - return StatManager.format(stat, MMOPlayerData.get(player).getStatMap().getStat(stat)); + final String stat = UtilityMethods.caseOnWords(identifier.substring(5)); + return StatManager.format(stat, MMOPlayerData.get(player)); } if (identifier.startsWith("ability_cd_")) From 2290fe70667824fb318f36e71c31bf1ca26f7a24 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 1 Apr 2023 23:31:11 +0200 Subject: [PATCH 12/15] Fixed stat placeholder --- .../mmoitems/comp/placeholders/MMOItemsPlaceholders.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java index 74e2f43f..4e33e042 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java @@ -60,7 +60,7 @@ public class MMOItemsPlaceholders extends PlaceholderExpansion { } if (identifier.startsWith("stat_")) { - final String stat = UtilityMethods.caseOnWords(identifier.substring(5)); + final String stat = UtilityMethods.enumName(identifier.substring(5)); return StatManager.format(stat, MMOPlayerData.get(player)); } From 147df215f847102836aadd8b0d5bb331cb19679b Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 1 Apr 2023 23:45:50 +0200 Subject: [PATCH 13/15] Fixed issue saying 'Template Data is not Numeric Stat Formula' --- .../Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java | 9 +++------ .../api/crafting/ingredient/MMOItemIngredient.java | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java index db94f713..512559a4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java @@ -11,7 +11,7 @@ import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; +import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; @@ -265,7 +265,7 @@ public class MMOItemUIFilter implements UIFilter { if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } } data = data.replace(" ", "_").replace("-", "_").toUpperCase(); - MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getTypes().get(argument), data); + MMOItem m = new MMOItemBuilder(MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getTypes().get(argument), data), 0, null, true).build(); // Find upgrade? if (!dataments.isEmpty()) { @@ -287,11 +287,8 @@ public class MMOItemUIFilter implements UIFilter { } } - //noinspection ConstantConditions - ItemStackBuilder builder = m.newBuilder(); - // Build display NBT and roll - return builder.buildNBT(true).toItem(); + return m.newBuilder().buildNBT(true).toItem(); } @NotNull diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java index 777723e8..43681749 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java @@ -88,7 +88,7 @@ public class MMOItemIngredient extends Ingredient { public ItemStack generateItemStack(@NotNull RPGPlayer player) { // Generate fresh from the template - MMOItem mmo = template.newBuilder(player).build(); + MMOItem mmo = template.newBuilder(player, true).build(); // Build it for display, obviously ItemStack item = mmo.newBuilder().build(true); From 63ca5bb41351bb30da5ee799b1c477aea0aae326 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 2 Apr 2023 00:52:00 +0200 Subject: [PATCH 14/15] Now supports multiple RPG cores at the same time --- .../java/net/Indyuce/mmoitems/MMOItems.java | 87 +++++++++++-------- .../mmoitems/api/player/PlayerData.java | 7 +- .../mmoitems/comp/rpg/AureliumSkillsHook.java | 1 - .../mmoitems/comp/rpg/ProSkillAPIHook.java | 28 +++--- .../mmoitems/comp/rpg/SkillAPIHook.java | 30 ++++--- MMOItems-Dist/src/main/resources/config.yml | 26 ++++-- 6 files changed, 108 insertions(+), 71 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java index c4b542fa..5823bc53 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -47,6 +47,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; @@ -54,6 +55,7 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -83,7 +85,7 @@ public class MMOItems extends JavaPlugin { private SetManager setManager; private VaultSupport vaultSupport; - private RPGHandler rpgPlugin; + private final List rpgPlugins = new ArrayList<>(); /** * Startup issues usually prevent the plugin from loading and just @@ -152,7 +154,7 @@ public class MMOItems extends JavaPlugin { }); PluginUtils.hookDependencyIfPresent("MMOInventory", unused -> new MMOInventorySupport()); - findRpgPlugin(); + findRpgPlugins(); /* * After tiers, sets and upgrade templates are loaded, MI template data @@ -293,8 +295,19 @@ public class MMOItems extends JavaPlugin { return setManager; } + @Deprecated public RPGHandler getRPG() { - return rpgPlugin; + return getMainRPG(); + } + + @Nullable + public RPGHandler getMainRPG() { + Validate.isTrue(!rpgPlugins.isEmpty(), "No RPG plugin was found"); + return rpgPlugins.get(0); + } + + public List getRPGs() { + return rpgPlugins; } /** @@ -306,21 +319,38 @@ public class MMOItems extends JavaPlugin { * provider in the main plugin config. If it can't be found, it will look for RPG * plugins in the installed plugin list. */ - public void findRpgPlugin() { - if (rpgPlugin != null) return; + public void findRpgPlugins() { + Validate.isTrue(rpgPlugins.isEmpty(), "RPG hooks have already been computed"); - // Preferred rpg provider - String preferred = plugin.getConfig().getString("preferred-rpg-provider", null); - if (preferred != null && setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase()))) - return; + // Default hook + rpgPlugins.add(new DefaultHook()); + + // Find preferred provider + final @NotNull String preferredName = plugin.getConfig().getString("preferred-rpg-provider"); // Look through installed plugins - for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) - if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null && setRPG(pluginEnum)) - return; + for (RPGHandler.PluginEnum enumPlugin : RPGHandler.PluginEnum.values()) + if (Bukkit.getPluginManager().getPlugin(enumPlugin.getName()) != null) + try { + final RPGHandler handler = enumPlugin.load(); + rpgPlugins.add(handler); + getLogger().log(Level.INFO, "Hooked onto " + enumPlugin.getName()); - // Just use the default - setRPG(new DefaultHook()); + // Register as main RPG plugin + if (preferredName.equalsIgnoreCase(enumPlugin.name())) { + Collections.swap(rpgPlugins, 0, rpgPlugins.size() - 1); + getLogger().log(Level.INFO, "Now using " + enumPlugin.getName() + " as RPG core plugin"); + } + + } catch (Exception exception) { + MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + enumPlugin.getName() + ":"); + exception.printStackTrace(); + } + + // Register listener for preferred provider + final @NotNull RPGHandler preferred = rpgPlugins.get(0); + if (rpgPlugins.get(0) instanceof Listener) + Bukkit.getPluginManager().registerEvents((Listener) preferred, this); } /** @@ -330,14 +360,14 @@ public class MMOItems extends JavaPlugin { * * @param handler Your RPGHandler instance */ - public void setRPG(RPGHandler handler) { + public void setRPG(@NotNull RPGHandler handler) { Validate.notNull(handler, "RPGHandler cannot be null"); - // Unregister events from current RPGPlugin instance - if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled()) - HandlerList.unregisterAll((Listener) rpgPlugin); + // Unregister old events + if (getMainRPG() instanceof Listener && isEnabled()) + HandlerList.unregisterAll((Plugin) getMainRPG()); - rpgPlugin = handler; + rpgPlugins.add(0, handler); getLogger().log(Level.INFO, "Now using " + handler.getClass().getSimpleName() + " as RPG provider"); // Register new events @@ -345,25 +375,6 @@ public class MMOItems extends JavaPlugin { Bukkit.getPluginManager().registerEvents((Listener) handler, this); } - /** - * @param potentialPlugin Some plugin that the user wants compatibility with - * @return If it worked - */ - public boolean setRPG(RPGHandler.PluginEnum potentialPlugin) { - - try { - Validate.notNull(Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()), "Plugin is not installed"); - setRPG(potentialPlugin.load()); - return true; - - // Some loading issue - } catch (Exception exception) { - MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ":"); - exception.printStackTrace(); - return false; - } - } - public PluginUpdateManager getUpdates() { return pluginUpdateManager; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 45204eb6..f7c30dbb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -63,7 +63,7 @@ public class PlayerData { private PlayerData(@NotNull MMOPlayerData mmoData) { this.mmoData = mmoData; - rpgPlayer = MMOItems.plugin.getRPG().getInfo(this); + rpgPlayer = MMOItems.plugin.getMainRPG().getInfo(this); stats = new PlayerStats(this); load(new ConfigFile("/userdata", getUniqueId().toString()).getConfig()); @@ -305,7 +305,7 @@ public class PlayerData { stats.updateStats(); // Update stats from external plugins - MMOItems.plugin.getRPG().refreshStats(this); + MMOItems.plugin.getRPGs().forEach(rpg -> rpg.refreshStats(this)); // Actually update cached player inventory so the task doesn't infinitely loop inventory.helmet = getPlayer().getInventory().getHelmet(); @@ -443,6 +443,7 @@ public class PlayerData { * Called when the corresponding MMOPlayerData has already been initialized. */ public static PlayerData load(@NotNull UUID player) { + /* * Double check they are online, for some reason even if this is fired * from the join event the player can be offline if they left in the @@ -460,7 +461,7 @@ public class PlayerData { * data of other rpg plugins */ PlayerData playerData = data.get(player); - playerData.rpgPlayer = MMOItems.plugin.getRPG().getInfo(playerData); + playerData.rpgPlayer = MMOItems.plugin.getMainRPG().getInfo(playerData); return playerData; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java index 262c993e..9884c054 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/AureliumSkillsHook.java @@ -32,7 +32,6 @@ public class AureliumSkillsHook implements RPGHandler, Listener { private final Map statExtra = new HashMap<>(); - public AureliumSkillsHook() { aSkills = (AureliumSkills) Bukkit.getPluginManager().getPlugin("AureliumSkills"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java index 32094687..e704690d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java @@ -11,7 +11,9 @@ import io.lumine.mythic.lib.damage.AttackHandler; import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; +import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.RPGPlayer; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,6 +30,7 @@ public class ProSkillAPIHook implements RPGHandler, Listener, AttackHandler { public ProSkillAPIHook() { MythicLib.plugin.getDamage().registerHandler(this); + Bukkit.getPluginManager().registerEvents(new InnerListener(), MMOItems.plugin); } @Override @@ -41,19 +44,22 @@ public class ProSkillAPIHook implements RPGHandler, Listener, AttackHandler { return damageInfo.get(event.getEntity().getEntityId()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(SkillDamageEvent event) { - if (!(event.getDamager() instanceof Player)) - return; + class InnerListener implements Listener { - DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); - AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); - damageInfo.put(event.getTarget().getEntityId(), attackMeta); - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void a(SkillDamageEvent event) { + if (!(event.getDamager() instanceof Player)) + return; - @EventHandler(priority = EventPriority.MONITOR) - public void c(EntityDamageByEntityEvent event) { - damageInfo.remove(event.getEntity().getEntityId()); + DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); + AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); + damageInfo.put(event.getTarget().getEntityId(), attackMeta); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void c(EntityDamageByEntityEvent event) { + damageInfo.remove(event.getEntity().getEntityId()); + } } @EventHandler diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java index cb0db8c0..b04150ba 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java @@ -11,7 +11,9 @@ import io.lumine.mythic.lib.damage.AttackHandler; import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageMetadata; import io.lumine.mythic.lib.damage.DamageType; +import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.RPGPlayer; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -23,11 +25,12 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; -public class SkillAPIHook implements RPGHandler, Listener, AttackHandler { +public class SkillAPIHook implements RPGHandler, AttackHandler { private final Map damageInfo = new HashMap<>(); public SkillAPIHook() { MythicLib.plugin.getDamage().registerHandler(this); + Bukkit.getPluginManager().registerEvents(new InnerListener(), MMOItems.plugin); } @Override @@ -41,19 +44,22 @@ public class SkillAPIHook implements RPGHandler, Listener, AttackHandler { return damageInfo.get(event.getEntity().getEntityId()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(SkillDamageEvent event) { - if (!(event.getDamager() instanceof Player)) - return; + class InnerListener implements Listener { - DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); - AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); - damageInfo.put(event.getTarget().getEntityId(), attackMeta); - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void a(SkillDamageEvent event) { + if (!(event.getDamager() instanceof Player)) + return; - @EventHandler(priority = EventPriority.MONITOR) - public void c(EntityDamageByEntityEvent event) { - damageInfo.remove(event.getEntity().getEntityId()); + DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); + AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); + damageInfo.put(event.getTarget().getEntityId(), attackMeta); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void b(EntityDamageByEntityEvent event) { + damageInfo.remove(event.getEntity().getEntityId()); + } } @EventHandler diff --git a/MMOItems-Dist/src/main/resources/config.yml b/MMOItems-Dist/src/main/resources/config.yml index cb094211..8c389625 100644 --- a/MMOItems-Dist/src/main/resources/config.yml +++ b/MMOItems-Dist/src/main/resources/config.yml @@ -15,6 +15,23 @@ iterate-whole-inventory: false # When this is set to true, skins can only be applied to an item ONCE. locked-skins: true +# Since 6.9.3 dev builds, MMOItems supports the use of multiple +# RPG core plugins at the same time. However, MMOItems needs one +# specific plugin to hook onto level, class, etc. +# +# Available plugins: +# - MMOCORE (level, class, mana, stamina) +# - HEROES (level, class, mana, stamina) +# - SKILLAPI or PROSKILLAPI (level, class, mana) +# - RPGPLAYERLEVELING (level, mana, power) +# - RACESANDCLASSES (level, class, mana) +# - BATTLELEVELS (level) +# - MCMMO (power level) +# - MCRPG (power level) +# - SKILLS or SKILLSPRO (class, level, mana) +# - AURELIUM_SKILLS (power level, mana) +preferred-rpg-provider: MMOCORE + # By default, all player inventories will be updated every # 10 ticks which corresponds to 2 inventory updates a second. inventory-update-delay: 10 @@ -103,11 +120,11 @@ soulbound: damage: base: 1 per-lvl: 1 - + # Whether or not soulbound items should be # kept when a player dies. keep-on-death: true - + # Whether or not soulbound item can be # dropped by the player can-drop: true @@ -194,7 +211,7 @@ action-bar-display: item-break: false recipes: - + # Enables the vanilla recipe book for MMOItems recipes use-recipe-book: true @@ -381,6 +398,3 @@ gem-upgrade-default: 'NEVER' # This option allows you to disable the ability to # use MMOItems that have been removed from your config. disable-removed-items: true - -# When I was a kid, I saw the Mona Lisa in my school art book... -# The fist time I saw her, with her hands on her knee... how do I say this... \ No newline at end of file From e7b807afaaeb7a3051d3b9ad8fc8731e1f0d3b98 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 2 Apr 2023 15:50:34 +0200 Subject: [PATCH 15/15] ML now handles custom SkillAPI dmg --- .../mmoitems/comp/rpg/ProSkillAPIHook.java | 50 +------------------ .../mmoitems/comp/rpg/SkillAPIHook.java | 50 +------------------ 2 files changed, 2 insertions(+), 98 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java index e704690d..5acbb1a6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/ProSkillAPIHook.java @@ -2,66 +2,18 @@ package net.Indyuce.mmoitems.comp.rpg; import com.sucy.skill.SkillAPI; import com.sucy.skill.api.event.PlayerLevelUpEvent; -import com.sucy.skill.api.event.SkillDamageEvent; import com.sucy.skill.api.player.PlayerData; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.player.EquipmentSlot; -import io.lumine.mythic.lib.api.player.MMOPlayerData; -import io.lumine.mythic.lib.damage.AttackHandler; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; -import io.lumine.mythic.lib.damage.DamageType; -import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.RPGPlayer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.Map; - -public class ProSkillAPIHook implements RPGHandler, Listener, AttackHandler { - private final Map damageInfo = new HashMap<>(); - - public ProSkillAPIHook() { - MythicLib.plugin.getDamage().registerHandler(this); - Bukkit.getPluginManager().registerEvents(new InnerListener(), MMOItems.plugin); - } +public class ProSkillAPIHook implements RPGHandler, Listener { @Override public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) { return new SkillAPIPlayer(data); } - @Override - @Nullable - public AttackMetadata getAttack(EntityDamageEvent event) { - return damageInfo.get(event.getEntity().getEntityId()); - } - - class InnerListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(SkillDamageEvent event) { - if (!(event.getDamager() instanceof Player)) - return; - - DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); - AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); - damageInfo.put(event.getTarget().getEntityId(), attackMeta); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void c(EntityDamageByEntityEvent event) { - damageInfo.remove(event.getEntity().getEntityId()); - } - } - @EventHandler public void b(PlayerLevelUpEvent event) { net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java index b04150ba..60a61442 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/SkillAPIHook.java @@ -2,66 +2,18 @@ package net.Indyuce.mmoitems.comp.rpg; import com.sucy.skill.SkillAPI; import com.sucy.skill.api.event.PlayerLevelUpEvent; -import com.sucy.skill.api.event.SkillDamageEvent; import com.sucy.skill.api.player.PlayerData; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.player.EquipmentSlot; -import io.lumine.mythic.lib.api.player.MMOPlayerData; -import io.lumine.mythic.lib.damage.AttackHandler; -import io.lumine.mythic.lib.damage.AttackMetadata; -import io.lumine.mythic.lib.damage.DamageMetadata; -import io.lumine.mythic.lib.damage.DamageType; -import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.RPGPlayer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.Map; - -public class SkillAPIHook implements RPGHandler, AttackHandler { - private final Map damageInfo = new HashMap<>(); - - public SkillAPIHook() { - MythicLib.plugin.getDamage().registerHandler(this); - Bukkit.getPluginManager().registerEvents(new InnerListener(), MMOItems.plugin); - } +public class SkillAPIHook implements RPGHandler, Listener { @Override public RPGPlayer getInfo(net.Indyuce.mmoitems.api.player.PlayerData data) { return new SkillAPIPlayer(data); } - @Override - @Nullable - public AttackMetadata getAttack(EntityDamageEvent event) { - return damageInfo.get(event.getEntity().getEntityId()); - } - - class InnerListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(SkillDamageEvent event) { - if (!(event.getDamager() instanceof Player)) - return; - - DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), DamageType.SKILL); - AttackMetadata attackMeta = new AttackMetadata(damageMeta, event.getTarget(), MMOPlayerData.get(event.getDamager().getUniqueId()).getStatMap().cache(EquipmentSlot.MAIN_HAND)); - damageInfo.put(event.getTarget().getEntityId(), attackMeta); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void b(EntityDamageByEntityEvent event) { - damageInfo.remove(event.getEntity().getEntityId()); - } - } - @EventHandler public void b(PlayerLevelUpEvent event) { net.Indyuce.mmoitems.api.player.PlayerData.get(event.getPlayerData().getPlayer()).getInventory().scheduleUpdate();