From d843108164eb0586b411b4e07dd51d5cab12de77 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 21 Jun 2019 18:26:02 -0700 Subject: [PATCH] More work on the repair rewrite, fleshing out more serializers --- .../gmail/nossr50/config/ConfigManager.java | 8 ++- .../serializers/ItemStackSerializer.java | 38 ++++--------- ...lizer.java => ItemWildcardSerializer.java} | 8 ++- .../serializers/RepairableSerializer.java | 14 ++--- .../datatypes/items/BukkitMMOItem.java | 20 ++++--- .../datatypes/items/CustomItemTarget.java | 45 +++++++++++++-- .../nossr50/datatypes/items/MMOItem.java | 1 - .../nossr50/skills/repair/RepairCost.java | 10 ++-- .../skills/repair/RepairCostWildcard.java | 55 ------------------- .../skills/repair/RepairTransaction.java | 6 ++ .../skills/repair/SimpleRepairCost.java | 48 +++++----------- .../gmail/nossr50/util/nbt/NBTManager.java | 25 ++++++--- .../com/gmail/nossr50/util/nbt/RawNBT.java | 12 ++-- 13 files changed, 129 insertions(+), 161 deletions(-) rename src/main/java/com/gmail/nossr50/config/hocon/serializers/{RepairWildcardSerializer.java => ItemWildcardSerializer.java} (78%) delete mode 100644 src/main/java/com/gmail/nossr50/skills/repair/RepairCostWildcard.java diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index df1f4ec35..bf107f147 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -52,7 +52,9 @@ import com.gmail.nossr50.config.treasure.FishingTreasureConfig; import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig; import com.gmail.nossr50.datatypes.experience.CustomXPPerk; import com.gmail.nossr50.datatypes.experience.FormulaType; +import com.gmail.nossr50.datatypes.items.BukkitMMOItem; import com.gmail.nossr50.datatypes.items.ItemWildcards; +import com.gmail.nossr50.datatypes.items.MMOItem; import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; @@ -62,6 +64,7 @@ import com.gmail.nossr50.skills.repair.RepairCost; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; +import com.gmail.nossr50.util.nbt.RawNBT; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection; @@ -268,6 +271,7 @@ public final class ConfigManager { customSerializers.registerType(new TypeToken() {}, new CustomEnumValueSerializer()); customSerializers.registerType(new TypeToken() {}, new CustomEnumValueSerializer()); customSerializers.registerType(new TypeToken() {}, new CustomEnumValueSerializer()); + customSerializers.registerType(new TypeToken>() {}, new ItemStackSerializer()); customSerializers.registerType(new TypeToken>() {}, new SetSerializer()); customSerializers.registerType(TypeToken.of(Repairable.class), new RepairableSerializer()); @@ -279,10 +283,10 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(MaxBonusLevel.class), new MaxBonusLevelSerializer()); customSerializers.registerType(TypeToken.of(PlayerNotificationSettings.class), new PlayerNotificationSerializer()); customSerializers.registerType(TypeToken.of(SoundSetting.class), new SoundSettingSerializer()); - customSerializers.registerType(TypeToken.of(ItemStack.class), new ItemStackSerializer()); - customSerializers.registerType(TypeToken.of(ItemWildcards.class), new RepairWildcardSerializer()); + customSerializers.registerType(TypeToken.of(ItemWildcards.class), new ItemWildcardSerializer()); customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer()); customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer()); + customSerializers.registerType(TypeToken.of(RawNBT.class), new RawNBTSerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java index 4da79d156..862e0dae2 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.config.hocon.serializers; +import com.gmail.nossr50.datatypes.items.BukkitMMOItem; +import com.gmail.nossr50.datatypes.items.MMOItem; import com.gmail.nossr50.mcMMO; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; @@ -12,17 +14,14 @@ import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -public class ItemStackSerializer implements TypeSerializer { +public class ItemStackSerializer implements TypeSerializer> { private static final String ITEM_MINECRAFT_NAME = "Item-Name"; private static final String AMOUNT = "Amount"; - private static final String NBT = "NBT"; @Nullable @Override - public ItemStack deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { - ItemStack itemStack; - + public MMOItem deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { String itemIdentifier = value.getNode(ITEM_MINECRAFT_NAME).getValue(TypeToken.of(String.class)); Material itemMatch = Material.matchMaterial(itemIdentifier); @@ -34,37 +33,22 @@ public class ItemStackSerializer implements TypeSerializer { ConfigurationNode itemNode = value.getNode(ITEM_MINECRAFT_NAME); + Integer amount; //Get the amount of items in the stack if(itemNode.getNode(AMOUNT).getValueType() != ValueType.NULL) { - Integer amount = itemNode.getNode(AMOUNT).getValue(TypeToken.of(Integer.class)); - itemStack = new ItemStack(itemMatch, amount); + amount = itemNode.getNode(AMOUNT).getValue(TypeToken.of(Integer.class)); } else { - itemStack = new ItemStack(itemMatch, 1); + amount = 1; } - //Init default item meta - itemStack.setItemMeta(Bukkit.getItemFactory().getItemMeta(itemMatch)); - - if(itemNode.getNode(NBT).getValueType() != ValueType.NULL) { - //TODO: NBT Stuff - } - - return itemStack; - - //Set Lore if it exists -// if(itemNode.getNode(ITEM_LORE).getValueType() != ValueType.NULL) { -// List lore = itemNode.getNode(ITEM_LORE).getValue(new TypeToken>() {}); -// itemStack.getItemMeta().setLore(lore); -// } + return new BukkitMMOItem(itemIdentifier, amount); } @Override - public void serialize(@NonNull TypeToken type, @Nullable ItemStack obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + public void serialize(@NonNull TypeToken type, @Nullable MMOItem obj, @NonNull ConfigurationNode value) throws ObjectMappingException { ConfigurationNode itemNode = value.getNode(ITEM_MINECRAFT_NAME); - value.getNode(ITEM_MINECRAFT_NAME).setValue(obj.getType().getKey().toString()); - itemNode.getNode(AMOUNT).setValue(obj.getAmount()); - //TODO: NBT Stuff - //itemNode.getNode(NBT).setValue() + value.getNode(ITEM_MINECRAFT_NAME).setValue(obj.getNamespaceKey()); + itemNode.getNode(AMOUNT).setValue(obj.getItemAmount()); } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemWildcardSerializer.java similarity index 78% rename from src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java rename to src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemWildcardSerializer.java index af6e14a12..65c330acf 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemWildcardSerializer.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.config.hocon.serializers; +import com.gmail.nossr50.datatypes.items.CustomItemTarget; import com.gmail.nossr50.datatypes.items.ItemWildcards; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; @@ -10,9 +11,10 @@ import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import java.util.HashSet; import java.util.Set; -public class RepairWildcardSerializer implements TypeSerializer { +public class ItemWildcardSerializer implements TypeSerializer { private static final String WILDCARD_IDENTIFIER_NAME = "Wildcard-Identifier-Name"; private static final String MATCHING_ITEMS = "Matching-Items"; @@ -24,9 +26,9 @@ public class RepairWildcardSerializer implements TypeSerializer { String wildCardName = value.getNode(WILDCARD_IDENTIFIER_NAME).getValue(TypeToken.of(String.class)); if(value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValueType() != ValueType.NULL) { - Set matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken>() {}); + Set matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken>() {}); - return new ItemWildcards(wildCardName, matchCandidates); + return new ItemWildcards(wildCardName, new HashSet<>(matchCandidates)); } return null; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java index 11a084955..22acf8c24 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java @@ -15,13 +15,13 @@ import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; import org.bukkit.inventory.ItemStack; public class RepairableSerializer implements TypeSerializer { - public static final String REPAIRABLE_ITEM = "Repairable-Item"; - public static final String MAXIMUM_DURABILITY = "Maximum-Durability"; - public static final String ITEMS_REQUIRED_TO_REPAIR = "Items-Required-To-Repair"; - public static final String SKILL_LEVEL_REQUIRED_TO_REPAIR = "Skill-Level-Required-To-Repair"; - public static final String BASE_XP_REWARD = "Base-XP-Reward"; - public static final String BASE_REPAIR_COUNT = "Base-Repair-Count"; - public static final String REQUIRED_PERMISSION_NODE = "Required-Permission-Node"; + private static final String REPAIRABLE_ITEM = "Repairable-Item"; + private static final String MAXIMUM_DURABILITY = "Maximum-Durability"; + private static final String ITEMS_REQUIRED_TO_REPAIR = "Items-Required-To-Repair"; + private static final String SKILL_LEVEL_REQUIRED_TO_REPAIR = "Skill-Level-Required-To-Repair"; + private static final String BASE_XP_REWARD = "Base-XP-Reward"; + private static final String BASE_REPAIR_COUNT = "Base-Repair-Count"; + private static final String REQUIRED_PERMISSION_NODE = "Required-Permission-Node"; @Override public Repairable deserialize(TypeToken type, ConfigurationNode value) throws ObjectMappingException { diff --git a/src/main/java/com/gmail/nossr50/datatypes/items/BukkitMMOItem.java b/src/main/java/com/gmail/nossr50/datatypes/items/BukkitMMOItem.java index af73759cb..135b3909b 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/BukkitMMOItem.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/BukkitMMOItem.java @@ -1,17 +1,20 @@ package com.gmail.nossr50.datatypes.items; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.nbt.RawNBT; +import net.minecraft.server.v1_13_R2.NBTTagCompound; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -public class BukkitMMOItem implements MMOItem { +import java.util.HashSet; + +public class BukkitMMOItem implements MMOItem { private ItemStack itemImplementation; - private RawNBT rawNBT; - public BukkitMMOItem(String namespaceKey, int amount, RawNBT rawNBT) throws NullPointerException { + public BukkitMMOItem(String namespaceKey, int amount) throws NullPointerException { ItemStack itemStack; Material material = Material.matchMaterial(namespaceKey); @@ -30,12 +33,12 @@ public class BukkitMMOItem implements MMOItem { //Set amount itemStack.setAmount(amount); - //Set item implementation this.itemImplementation = itemStack; + } - //Set raw NBT - if(rawNBT != null) - this.rawNBT = rawNBT; + public BukkitMMOItem(ItemStack itemStack) { + NBTTagCompound nbtTagCompound = mcMMO.getNbtManager().getNBT(itemStack); + this.itemImplementation = itemStack; } @Override @@ -55,7 +58,8 @@ public class BukkitMMOItem implements MMOItem { @Override public RawNBT getRawNBT() { - return rawNBT; + NBTTagCompound nbtTagCompound = mcMMO.getNbtManager().getNBT(itemImplementation); + return new RawNBT(nbtTagCompound.toString(), nbtTagCompound); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java b/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java index 075481d4e..e36f198bf 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java @@ -57,17 +57,52 @@ public class CustomItemTarget implements CustomItemMatching { */ @Override public boolean isMatch(MMOItem otherItem) { - //First compare the basic things that need to match between each item - if(item.equals(otherItem)) { - for(ItemMatchProperty itemMatchProperty : itemMatchProperties) { - if(!mcMMO.getNbtManager().hasNBT(otherItem.getRawNBT().getNbtData(), itemMatchProperty.getNbtData())) - return false; + if(hasStrictMatching()) { + return isStrictMatch(otherItem); + } else { + return isUnstrictMatch(otherItem); + } + } + + /** + * Compare this item to another while comparing specific nbt tags for matching values, if all values are found and match it is considered a strict match + * @param otherItem item to strictly match + * @return true if the items are considered a match + */ + private boolean isStrictMatch(MMOItem otherItem) { + for(ItemMatchProperty itemMatchProperty : itemMatchProperties) { + if(!mcMMO.getNbtManager().hasNBT(otherItem.getRawNBT().getNbtData(), itemMatchProperty.getNbtData())) { + return false; } + } + + //All item match properties were found and matched + return true; + } + + /** + * Compare this item to another only by namespace key + * @param otherItem item to compare namespace keys with + * @return true if the items share namespace keys + */ + private boolean isUnstrictMatch(MMOItem otherItem) { + if(otherItem.getNamespaceKey().equalsIgnoreCase(item.getNamespaceKey())) { return true; } + + //Namespace didn't match reject item return false; } + /** + * If this item has strict matching or loose match + * Solely determined by having any item match properties present + * @return true if this item target has strict matching + */ + public boolean hasStrictMatching() { + return itemMatchProperties.size() > 1; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/com/gmail/nossr50/datatypes/items/MMOItem.java b/src/main/java/com/gmail/nossr50/datatypes/items/MMOItem.java index 62d00cf16..513f9fb76 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/MMOItem.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/MMOItem.java @@ -36,5 +36,4 @@ public interface MMOItem { * @return the raw NBT if it exists, null otherwise */ RawNBT getRawNBT(); - } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairCost.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairCost.java index d2392e78c..f04a08cf7 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairCost.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairCost.java @@ -11,15 +11,15 @@ public interface RepairCost { /** * Searches a player inventory for a matching ItemStack that can be used to pay for the repair transaction * @param playerInventory inventory of player attempting to pay the cost - * @return any compatible payment items if found + * @return any compatible payment items if found, can be null */ ItemStack findPayment(PlayerInventory playerInventory); /** - * Whether or not this repair cost is strictly matched - * Strict matching compares Items by using metadata and material type - * @return true if the RepairCost uses strict matching + * Whether or not there is an item that can be used for this repair cost in the player's inventory + * @param playerInventory target player + * @return true if payment is found */ - boolean hasStrictMatching(); + boolean hasPayment(PlayerInventory playerInventory); } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairCostWildcard.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairCostWildcard.java deleted file mode 100644 index 04d4c6ad3..000000000 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairCostWildcard.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.gmail.nossr50.skills.repair; - -import com.gmail.nossr50.datatypes.items.ItemWildcards; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -import java.util.HashSet; - -/** - * Represents a piece of a RepairTransaction - * Multiple RepairCost pieces are used to pay for a RepairTransaction - * This one represents a wildcard cost, which can be paid for with multiple items - * - */ -public class RepairCostWildcard implements RepairCost { - - private HashSet simpleRepairCosts; - private ItemWildcards itemWildcards; - - - public RepairCostWildcard(ItemWildcards itemWildcards) { - this.itemWildcards = itemWildcards; - simpleRepairCosts = new HashSet<>(); - - for(ItemStack itemStack : ) - } - - @Override - public ItemStack findPayment(PlayerInventory playerInventory) { - for(ItemStack itemStack : playerInventory.getContents()) { - if(itemStack == null || itemStack.getType() == Material.AIR) { - continue; - } - - for(SimpleRepairCost simpleRepairCost : simpleRepairCosts) { - //Attempt to match the item in the inventory to any of the compatible repair items - if(simpleRepairCost.findPayment(playerInventory) != null) { - return simpleRepairCost.findPayment(playerInventory); - } - } - } - - return null; - } - - public ItemWildcards getItemWildcards() { - return itemWildcards; - } - - public void setItemWildcards(ItemWildcards itemWildcards) { - this.itemWildcards = itemWildcards; - } - -} diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java index f713e5d7c..afb217611 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java @@ -39,6 +39,12 @@ public class RepairTransaction { } public boolean canPayRepairCosts(PlayerInventory playerInventory) { + for(RepairCost repairCost : repairCosts) { + if(!repairCost.hasPayment(playerInventory)) { + return false; + } + } + return true; } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairCost.java b/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairCost.java index 232c30807..aea366f0b 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairCost.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairCost.java @@ -1,15 +1,14 @@ package com.gmail.nossr50.skills.repair; -import com.gmail.nossr50.datatypes.items.ItemMatchProperty; +import com.gmail.nossr50.datatypes.items.BukkitMMOItem; +import com.gmail.nossr50.datatypes.items.CustomItemTarget; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import java.util.Objects; - /** * Implementation of RepairCost - *

+ * * A SimpleRepairCost can be one or more items, any one of which can be used to pay for a RepairTransaction * If a SimpleRepairCost is more than one item, then only one of the items are required to represent its cost. * @@ -18,49 +17,30 @@ import java.util.Objects; */ public class SimpleRepairCost implements RepairCost { - private ItemMatchProperty itemMatchProperty; + private CustomItemTarget desiredItemTarget; - public SimpleRepairCost(ItemMatchProperty itemMatchProperty) { - this.itemMatchProperty = itemMatchProperty; + public SimpleRepairCost(CustomItemTarget customItemTarget) { + this.desiredItemTarget = customItemTarget; } @Override public ItemStack findPayment(PlayerInventory playerInventory) { for(ItemStack itemStack : playerInventory.getContents()) { - if(itemStack == null || itemStack.getType() == Material.AIR) { + if(itemStack == null || itemStack.getType() == Material.AIR) continue; - } - //Attempt to match the item in the inventory to any of the compatible repair items - if(hasStrictMatching()) { - //TODO: Replace with strict matching code - if(item) - return itemStack; - } else { - if(itemStack.getType() == itemMatchProperty.getType()) { - return itemStack; - } - } + BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack); + + //If the item matches return it + if(desiredItemTarget.isMatch(playerInventoryItem)) + return itemStack; } return null; } @Override - public int hashCode() { - return Objects.hash(itemMatchProperty); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SimpleRepairCost)) return false; - SimpleRepairCost that = (SimpleRepairCost) o; - return itemMatchProperty.equals(that.itemMatchProperty); - } - - @Override - public boolean hasStrictMatching() { - return strictMatching; + public boolean hasPayment(PlayerInventory playerInventory) { + return findPayment(playerInventory) != null; } } diff --git a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java index f7c84a430..39a9765b3 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.util.nbt; import com.gmail.nossr50.mcMMO; import net.minecraft.server.v1_13_R2.NBTBase; +import net.minecraft.server.v1_13_R2.NBTList; import net.minecraft.server.v1_13_R2.NBTTagCompound; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; @@ -26,9 +27,16 @@ public class NBTManager { } } - public RawNBT constructNBT(String nbtString) { + public NBTTagCompound getNBT(ItemStack itemStack) { + Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString()); + net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound rootTag = nmsItemStack.getTag(); + return rootTag; + } + + public NBTBase constructNBT(String nbtString) { try { - return new RawNBT(nbtString, CraftNBTTagConfigSerializer.deserialize(nbtString)); + return CraftNBTTagConfigSerializer.deserialize(nbtString); } catch (Exception e) { e.printStackTrace(); mcMMO.p.getLogger().severe("mcMMO was unable parse the NBT string from your config! Double check that it is proper NBT!"); @@ -37,15 +45,18 @@ public class NBTManager { } public void printNBT(ItemStack itemStack) { - Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString()); - net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound rootTag = nmsItemStack.getTag(); - for(String key : rootTag.getKeys()) { + for(String key : getNBT(itemStack).getKeys()) { Bukkit.broadcastMessage("NBT Key found: "+key); } } - public boolean hasNBT(NBTTagCompound root, NBTTagCompound nbtData) { + public boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) { + if(nbt instanceof NBTList) { + + } else { + + } + //TODO: Implement this return false; } diff --git a/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java b/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java index a1a574f3e..a74749489 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.util.nbt; -import net.minecraft.server.v1_13_R2.NBTTagCompound; +import com.gmail.nossr50.mcMMO; +import net.minecraft.server.v1_13_R2.NBTBase; /** * A simple class that acts as a container for raw NBT data @@ -14,12 +15,9 @@ import net.minecraft.server.v1_13_R2.NBTTagCompound; */ public class RawNBT { private String nbtContents; - private NBTTagCompound nbtData; //Will be constructed using server internals to make matching NBT easier - - public RawNBT(String nbtContents, NBTTagCompound nbtData) { + public RawNBT(String nbtContents) { this.nbtContents = nbtContents; - this.nbtData = nbtData; } public String getNbtContents() { @@ -30,7 +28,7 @@ public class RawNBT { this.nbtContents = nbtContents; } - public NBTTagCompound getNbtData() { - return nbtData; + public NBTBase getNbtData() { + return mcMMO.getNbtManager().constructNBT(nbtContents); } }