From d782d647508e8228a0e0f9e02382e89bc5e15706 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 21 Jun 2019 15:10:43 -0700 Subject: [PATCH] Simplify the design of Repairable --- .../config/hocon/admin/ConfigAdmin.java | 2 +- .../serializers/RepairableSerializer.java | 87 +++++++++++-------- .../hocon/serializers/SerializerUtil.java | 19 ++++ .../datatypes/items/CustomItemTarget.java | 24 ++++- .../datatypes/items/ItemMatchProperty.java | 30 +++++-- .../datatypes/items/ItemWildcards.java | 2 +- src/main/java/com/gmail/nossr50/mcMMO.java | 8 ++ .../skills/repair/RepairTransaction.java | 20 +++-- .../skills/repair/repairables/Repairable.java | 60 ++++--------- .../repair/repairables/RepairableBuilder.java | 58 ++++--------- .../gmail/nossr50/util/nbt/NBTManager.java | 7 +- .../com/gmail/nossr50/util/nbt/RawNBT.java | 14 ++- 12 files changed, 186 insertions(+), 145 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/serializers/SerializerUtil.java diff --git a/src/main/java/com/gmail/nossr50/config/hocon/admin/ConfigAdmin.java b/src/main/java/com/gmail/nossr50/config/hocon/admin/ConfigAdmin.java index af4dc0396..1bec371c8 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/admin/ConfigAdmin.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/admin/ConfigAdmin.java @@ -7,7 +7,7 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigAdmin { @Setting(value = "Admin-Notifications", comment = "Settings related to admin alerts in mcMMO.") - public ConfigAdminNotifications configAdminNotifications = new ConfigAdminNotifications(); + private ConfigAdminNotifications configAdminNotifications = new ConfigAdminNotifications(); public boolean isSendAdminNotifications() { return configAdminNotifications.isSendAdminNotifications(); 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 bf61273d1..11a084955 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 @@ -1,5 +1,6 @@ package com.gmail.nossr50.config.hocon.serializers; +import com.gmail.nossr50.datatypes.items.CustomItemTarget; import com.gmail.nossr50.datatypes.permissions.PermissionWrapper; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.skills.repair.repairables.Repairable; @@ -7,63 +8,75 @@ import com.gmail.nossr50.skills.repair.repairables.RepairableBuilder; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ValueType; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; import org.bukkit.inventory.ItemStack; public class RepairableSerializer implements TypeSerializer { - private static final String ITEM = "Item"; - private static final String BASE_XP = "XP-Per-Repair"; - private static final String REPAIR_TRANSACTION = "Repair-Transaction"; - private static final String STRICT_MATCH_ITEM = "Strict-Match-Item"; - private static final String STRICT_MATCHING_REPAIR_TRANSACTION = "Strict-Matching-Repair-Transaction"; - private static final String REPAIR_COUNT = "Repair-Count"; -// private static final String NBT = "NBT"; - private static final String PERMISSION = "Permission"; - private static final String MINIMUM_LEVEL = "Minimum-Level"; + 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"; @Override public Repairable deserialize(TypeToken type, ConfigurationNode value) throws ObjectMappingException { - ItemStack itemStack = value.getNode(ITEM).getValue(TypeToken.of(ItemStack.class)); - RepairableBuilder builder = new RepairableBuilder(itemStack) - .repairTransaction(value.getNode(REPAIR_TRANSACTION).getValue(TypeToken.of(RepairTransaction.class))) - .strictMatchingItem(value.getNode(STRICT_MATCH_ITEM).getValue(TypeToken.of(Boolean.class))) -// .strictMatchingRepairTransaction(value.getNode(STRICT_MATCHING_REPAIR_TRANSACTION).getValue(TypeToken.of(Boolean.class))) - .baseXP(value.getNode(BASE_XP).getValue(TypeToken.of(Integer.class))) - .repairCount(value.getNode(REPAIR_COUNT).getValue(TypeToken.of(Integer.class))); + /* Necessary fields */ + CustomItemTarget customItemTarget = value.getNode(REPAIRABLE_ITEM).getValue(TypeToken.of(CustomItemTarget.class)); + Short maximumDurability = value.getNode(MAXIMUM_DURABILITY).getValue(TypeToken.of(Short.class)); + RepairTransaction repairTransaction = value.getNode(ITEMS_REQUIRED_TO_REPAIR).getValue(TypeToken.of(RepairTransaction.class)); - if(value.getNode(MINIMUM_LEVEL).getValueType() != ValueType.NULL) { - builder = builder.minLevel(value.getNode(MINIMUM_LEVEL).getValue(TypeToken.of(Integer.class))); + RepairableBuilder repairableBuilder = new RepairableBuilder(customItemTarget, maximumDurability, repairTransaction); + + if(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getValueType() != ValueType.NULL) { + repairableBuilder.addMinLevel(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getInt()); } -// if(value.getNode(NBT).getValueType() != ValueType.NULL) { -// builder = builder.rawNBT(value.getNode(NBT).getValue(TypeToken.of(RawNBT.class))); -// } - - if(value.getNode(PERMISSION).getValueType() != ValueType.NULL) { - builder = builder.permissionWrapper(value.getNode(PERMISSION).getValue(TypeToken.of(PermissionWrapper.class))); + if(value.getNode(BASE_XP_REWARD).getValueType() != ValueType.NULL) { + repairableBuilder.setBaseXP(value.getNode(BASE_XP_REWARD).getInt()); } - return builder.build(); + if(value.getNode(BASE_REPAIR_COUNT).getValueType() != ValueType.NULL) { + repairableBuilder.setRepairCount(value.getNode(BASE_REPAIR_COUNT).getInt()); + } + + if(value.getNode(REQUIRED_PERMISSION_NODE).getValueType() != ValueType.NULL) { + repairableBuilder.addPermissionWrapper(value.getNode(REQUIRED_PERMISSION_NODE).getValue(TypeToken.of(PermissionWrapper.class))); + } + + return repairableBuilder.build(); } @Override public void serialize(TypeToken type, Repairable obj, ConfigurationNode value) { - value.getNode(ITEM).setValue(obj.getItem()); - value.getNode(REPAIR_TRANSACTION).setValue(obj.getRepairTransaction()); - value.getNode(STRICT_MATCH_ITEM).setValue(obj.isStrictMatchingItem()); -// value.getNode(STRICT_MATCHING_REPAIR_TRANSACTION).setValue(obj.isStrictMatchingRepairTransaction()); - value.getNode(BASE_XP).setValue(obj.getBaseXP()); - value.getNode(REPAIR_COUNT).setValue(obj.getRepairCount()); + value.getNode(REPAIRABLE_ITEM).setValue(obj.getCustomItemTarget()); + value.getNode(MAXIMUM_DURABILITY).setValue(obj.getMaximumDurability()); + value.getNode(ITEMS_REQUIRED_TO_REPAIR).setValue(obj.getRepairTransaction()); - if(obj.getMinimumLevel() > 0) - value.getNode(MINIMUM_LEVEL).setValue(obj.getMinimumLevel()); + if(obj.getMinimumLevel() > 0) { + value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).setValue(obj.getMinimumLevel()); + } -// if(obj.hasNBT()) -// value.getNode(NBT).setValue(obj.getRawNBT()); + if(obj.getBaseXP() != 0) { + value.getNode(BASE_XP_REWARD).setValue(obj.getBaseXP()); + SerializerUtil.addCommentIfCompatible(value.getNode(BASE_XP_REWARD), "The minimum amount of XP to reward a player when they repair this item."); + } - if(obj.hasPermission()) - value.getNode(PERMISSION).setValue(obj.getPermissionWrapper()); + if(obj.getRepairCount() != 0) { + value.getNode(BASE_REPAIR_COUNT).setValue(obj.getRepairCount()); + SerializerUtil.addCommentIfCompatible(value.getNode(BASE_REPAIR_COUNT), "How many times it should take a player to repair this item from fully damaged to brand new without any skill in Repair." + + "\nThis value is used in calculating how much damage to remove from an item, typically you want this to be at least equal to the number of mats used to craft the item."); + } + + if(obj.getPermissionWrapper() != null) { + value.getNode(REQUIRED_PERMISSION_NODE).setValue(obj.getPermissionWrapper()); + SerializerUtil.addCommentIfCompatible(value.getNode(REQUIRED_PERMISSION_NODE), "A custom permission node required to repair this item." + + "\nThis setting is optional."); + } } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/SerializerUtil.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/SerializerUtil.java new file mode 100644 index 000000000..481880d5c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/SerializerUtil.java @@ -0,0 +1,19 @@ +package com.gmail.nossr50.config.hocon.serializers; + +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; + +public class SerializerUtil { + + /** + * Adds a comment to a Configuration node if its possible + * @param configurationNode target configuration node + * @param comment desired comment + */ + public static void addCommentIfCompatible(ConfigurationNode configurationNode, String comment) { + if(configurationNode instanceof CommentedConfigurationNode) { + CommentedConfigurationNode node = (CommentedConfigurationNode) configurationNode; + node.setComment(comment); + } + } +} 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 e8c4eb2ac..075481d4e 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/CustomItemTarget.java @@ -1,6 +1,9 @@ package com.gmail.nossr50.datatypes.items; +import com.gmail.nossr50.mcMMO; + import java.util.HashSet; +import java.util.Objects; /** * This type contains data and rules which govern equating equivalency between one item and another in Minecraft. @@ -56,7 +59,26 @@ public class CustomItemTarget implements CustomItemMatching { 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; + } + return true; } + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof CustomItemTarget)) return false; + CustomItemTarget that = (CustomItemTarget) o; + return getItem().equals(that.getItem()) && + getItemMatchProperties().equals(that.getItemMatchProperties()); + } + + @Override + public int hashCode() { + return Objects.hash(getItem(), getItemMatchProperties()); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/items/ItemMatchProperty.java b/src/main/java/com/gmail/nossr50/datatypes/items/ItemMatchProperty.java index b7061dfbf..18c033b1a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/ItemMatchProperty.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/ItemMatchProperty.java @@ -1,5 +1,9 @@ package com.gmail.nossr50.datatypes.items; +import net.minecraft.server.v1_13_R2.NBTTagCompound; + +import java.util.Objects; + /** * Represents a property of an item which is used in strict matching * Typically this represents and NBT field and its value @@ -7,20 +11,20 @@ package com.gmail.nossr50.datatypes.items; */ public class ItemMatchProperty { - final private Object propertyValue; + final private NBTTagCompound nbtData; final private String nbtID; - public ItemMatchProperty(Object propertyValue, String nbtID) { - this.propertyValue = propertyValue; + public ItemMatchProperty(String nbtID, NBTTagCompound nbtData) { + this.nbtData = nbtData; this.nbtID = nbtID; } /** - * The expected value for this NBT entry + * The expected value for this NBT * @return the expected value for this NBT entry */ - public Object getPropertyValue() { - return propertyValue; + public NBTTagCompound getNbtData() { + return nbtData; } /** @@ -30,4 +34,18 @@ public class ItemMatchProperty { public String getID() { return nbtID; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ItemMatchProperty)) return false; + ItemMatchProperty that = (ItemMatchProperty) o; + return getNbtData().equals(that.getNbtData()) && + nbtID.equals(that.nbtID); + } + + @Override + public int hashCode() { + return Objects.hash(getNbtData(), nbtID); + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/items/ItemWildcards.java b/src/main/java/com/gmail/nossr50/datatypes/items/ItemWildcards.java index 2c37b5d08..87087e414 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/items/ItemWildcards.java +++ b/src/main/java/com/gmail/nossr50/datatypes/items/ItemWildcards.java @@ -33,7 +33,7 @@ public class ItemWildcards { return itemTargets.size(); } - public HashSet getItemTargets() { + public HashSet getItemTargets() { return itemTargets; } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 4bcd97a84..5d1b5f967 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -31,6 +31,7 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.experience.FormulaManager; +import com.gmail.nossr50.util.nbt.NBTManager; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.PlayerLevelUtils; import com.gmail.nossr50.util.player.UserManager; @@ -65,6 +66,7 @@ public class mcMMO extends JavaPlugin { private static PlayerLevelUtils playerLevelUtils; private static NotificationManager notificationManager; private static CommandRegistrationManager commandRegistrationManager; + private static NBTManager nbtManager; /* File Paths */ private static String mainDirectory; @@ -153,6 +155,8 @@ public class mcMMO extends JavaPlugin { commandRegistrationManager = new CommandRegistrationManager(this); commandRegistrationManager.registerCommands(); + nbtManager = new NBTManager(); + placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager if (getConfigManager().getConfigParty().getPTP().isPtpWorldBasedPermissions()) { @@ -318,6 +322,10 @@ public class mcMMO extends JavaPlugin { return databaseManager; } + public static NBTManager getNbtManager() { + return nbtManager; + } + @Deprecated public static void setDatabaseManager(DatabaseManager newDatabaseManager) { databaseManager = newDatabaseManager; 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 009122dd5..f713e5d7c 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairTransaction.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.skills.repair; +import org.bukkit.inventory.PlayerInventory; + import java.util.HashSet; /** @@ -18,21 +20,25 @@ import java.util.HashSet; * to pay that part of the RepairTransaction */ public class RepairTransaction { - private HashSet repairItems; + private HashSet repairCosts; public RepairTransaction() { - repairItems = new HashSet<>(); + repairCosts = new HashSet<>(); } public void addRepairCost(RepairCost repairCost) { - repairItems.add(repairCost); + repairCosts.add(repairCost); } - public HashSet getRepairItems() { - return repairItems; + public HashSet getRepairCosts() { + return repairCosts; } - public void setRepairItems(HashSet repairItems) { - this.repairItems = repairItems; + public void setRepairCosts(HashSet repairItems) { + this.repairCosts = repairItems; + } + + public boolean canPayRepairCosts(PlayerInventory playerInventory) { + return true; } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java index b1543e6a3..cc06c3ca6 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java @@ -1,37 +1,32 @@ package com.gmail.nossr50.skills.repair.repairables; +import com.gmail.nossr50.datatypes.items.CustomItemTarget; import com.gmail.nossr50.datatypes.permissions.PermissionWrapper; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.util.nbt.RawNBT; import org.bukkit.inventory.ItemStack; public class Repairable { - private final ItemStack item; - private int minimumLevel = 0; + private int minimumLevel; private short maximumDurability; private RepairTransaction repairTransaction; - private boolean strictMatchingItem = false; -// private boolean strictMatchingRepairTransaction = false; - private int baseXP = 0; - private RawNBT rawNBT; - private int repairCount = 1; + private int baseXP; + private CustomItemTarget customItemTarget; + private int repairCount; private PermissionWrapper permissionWrapper; private boolean hasPermission = false; - private boolean hasNBT = false; - public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, int baseXP, int repairCount) { - this.item = item; + public Repairable(CustomItemTarget customItemTarget, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, int baseXP, int repairCount, PermissionWrapper permissionWrapper) { this.minimumLevel = minimumLevel; this.maximumDurability = maximumDurability; this.repairTransaction = repairTransaction; - this.strictMatchingItem = strictMatchingItem; -// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction; this.baseXP = baseXP; + this.customItemTarget = customItemTarget; this.repairCount = repairCount; - } + this.permissionWrapper = permissionWrapper; - public ItemStack getItem() { - return item; + if(permissionWrapper != null) + hasPermission = true; } public int getMinimumLevel() { @@ -58,22 +53,6 @@ public class Repairable { this.repairTransaction = repairTransaction; } - public boolean isStrictMatchingItem() { - return strictMatchingItem; - } - - public void setStrictMatchingItem(boolean strictMatchingItem) { - this.strictMatchingItem = strictMatchingItem; - } - -// public boolean isStrictMatchingRepairTransaction() { -// return strictMatchingRepairTransaction; -// } -// -// public void setStrictMatchingRepairTransaction(boolean strictMatchingRepairTransaction) { -// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction; -// } - public int getBaseXP() { return baseXP; } @@ -82,13 +61,12 @@ public class Repairable { this.baseXP = baseXP; } - public RawNBT getRawNBT() { - return rawNBT; + public CustomItemTarget getCustomItemTarget() { + return customItemTarget; } - public void setRawNBT(RawNBT rawNBT) { - this.rawNBT = rawNBT; - hasNBT = true; + public void setCustomItemTarget(CustomItemTarget customItemTarget) { + this.customItemTarget = customItemTarget; } public int getRepairCount() { @@ -105,10 +83,9 @@ public class Repairable { public void setPermissionWrapper(PermissionWrapper permissionWrapper) { this.permissionWrapper = permissionWrapper; - hasPermission = true; } - public boolean hasPermission() { + public boolean hasPermissionNode() { return hasPermission; } @@ -116,11 +93,4 @@ public class Repairable { this.hasPermission = hasPermission; } - public boolean hasNBT() { - return hasNBT; - } - - public void setHasNBT(boolean hasNBT) { - this.hasNBT = hasNBT; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java index 7699a03b1..c6a4a7c57 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableBuilder.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.skills.repair.repairables; +import com.gmail.nossr50.datatypes.items.CustomItemTarget; import com.gmail.nossr50.datatypes.permissions.PermissionWrapper; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.util.nbt.RawNBT; @@ -7,63 +8,46 @@ import org.bukkit.inventory.ItemStack; public class RepairableBuilder { - private final ItemStack item; - private int minimumLevel = 0; + private int minimumLevel; private short maximumDurability; private RepairTransaction repairTransaction; - private boolean strictMatchingItem = false; -// private boolean strictMatchingRepairTransaction = false; - private int baseXP = 0; - private RawNBT rawNBT; - private int repairCount = 1; + private int baseXP; + private CustomItemTarget customItemTarget; + private int repairCount; private PermissionWrapper permissionWrapper; - public RepairableBuilder(ItemStack item) { - this.item = item; - this.maximumDurability = item.getType().getMaxDurability(); + public RepairableBuilder(CustomItemTarget customItemTarget, Short maximumDurability, RepairTransaction repairTransaction) { + this.customItemTarget = customItemTarget; + this.maximumDurability = maximumDurability; + this.repairTransaction = repairTransaction; } - public RepairableBuilder minLevel(Integer minimumLevel) { + public RepairableBuilder addMinLevel(Integer minimumLevel) { this.minimumLevel = minimumLevel; return this; } - public RepairableBuilder maximumDurability(Short maximumDurability) { + public RepairableBuilder setMaximumDurability(Short maximumDurability) { this.maximumDurability = maximumDurability; return this; } - public RepairableBuilder repairTransaction(RepairTransaction repairTransaction) { + public RepairableBuilder setRepairTransaction(RepairTransaction repairTransaction) { this.repairTransaction = repairTransaction; return this; } - public RepairableBuilder strictMatchingItem(Boolean strictMatchingItem) { - this.strictMatchingItem = strictMatchingItem; - return this; - } - -// public RepairableBuilder strictMatchingRepairTransaction(Boolean strictMatchingRepairTransaction) { -// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction; -// return this; -// } - - public RepairableBuilder baseXP(Integer baseXP) { + public RepairableBuilder setBaseXP(Integer baseXP) { this.baseXP = baseXP; return this; } - public RepairableBuilder rawNBT(RawNBT rawNBT) { - this.rawNBT = rawNBT; - return this; - } - - public RepairableBuilder repairCount(Integer repairCount) { + public RepairableBuilder setRepairCount(Integer repairCount) { this.repairCount = repairCount; return this; } - public RepairableBuilder permissionWrapper(PermissionWrapper permissionWrapper) { + public RepairableBuilder addPermissionWrapper(PermissionWrapper permissionWrapper) { this.permissionWrapper = permissionWrapper; return this; } @@ -73,16 +57,8 @@ public class RepairableBuilder { } private Repairable makeRepairable() { - Repairable repairable = new Repairable(item, minimumLevel, maximumDurability, repairTransaction, - strictMatchingItem, baseXP, repairCount); - - if(permissionWrapper != null) { - repairable.setPermissionWrapper(permissionWrapper); - } - - if(rawNBT != null) { - repairable.setRawNBT(rawNBT); - } + Repairable repairable = new Repairable(customItemTarget, minimumLevel, maximumDurability, repairTransaction, + baseXP, repairCount, permissionWrapper); return repairable; } 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 9a1b12137..f7c84a430 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -9,8 +9,6 @@ import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer; import org.bukkit.inventory.ItemStack; - - public class NBTManager { private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem"; @@ -47,4 +45,9 @@ public class NBTManager { } } + public boolean hasNBT(NBTTagCompound root, NBTTagCompound nbtData) { + //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 53c64b469..a1a574f3e 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.util.nbt; +import net.minecraft.server.v1_13_R2.NBTTagCompound; + /** * A simple class that acts as a container for raw NBT data * NBT data will be constructed from the raw NBT string using server internals @@ -10,13 +12,14 @@ package com.gmail.nossr50.util.nbt; * 1) Read partial or complete NBT from the config file for an item * 2) Check an items NBT tree for this NBT data during runtime once transformed */ -public class RawNBT { +public class RawNBT { private String nbtContents; - private T nbtTree; //Will be constructed using server internals to make matching NBT easier + private NBTTagCompound nbtData; //Will be constructed using server internals to make matching NBT easier - public RawNBT(String nbtContents, T nbtTree) { + + public RawNBT(String nbtContents, NBTTagCompound nbtData) { this.nbtContents = nbtContents; - NBTManager + this.nbtData = nbtData; } public String getNbtContents() { @@ -27,4 +30,7 @@ public class RawNBT { this.nbtContents = nbtContents; } + public NBTTagCompound getNbtData() { + return nbtData; + } }