|
@@ -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<Repairable> {
|
|
|
- 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(BASE_XP_REWARD).getValueType() != ValueType.NULL) {
|
|
|
+ repairableBuilder.setBaseXP(value.getNode(BASE_XP_REWARD).getInt());
|
|
|
+ }
|
|
|
|
|
|
- if(value.getNode(PERMISSION).getValueType() != ValueType.NULL) {
|
|
|
- builder = builder.permissionWrapper(value.getNode(PERMISSION).getValue(TypeToken.of(PermissionWrapper.class)));
|
|
|
+ if(value.getNode(BASE_REPAIR_COUNT).getValueType() != ValueType.NULL) {
|
|
|
+ repairableBuilder.setRepairCount(value.getNode(BASE_REPAIR_COUNT).getInt());
|
|
|
}
|
|
|
|
|
|
- return builder.build();
|
|
|
+ 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.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.hasPermission())
|
|
|
- value.getNode(PERMISSION).setValue(obj.getPermissionWrapper());
|
|
|
+ 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.");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|