mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
Simplify the design of Repairable
This commit is contained in:
parent
0050a73be8
commit
d782d64750
@ -7,7 +7,7 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
|||||||
public class ConfigAdmin {
|
public class ConfigAdmin {
|
||||||
|
|
||||||
@Setting(value = "Admin-Notifications", comment = "Settings related to admin alerts in mcMMO.")
|
@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() {
|
public boolean isSendAdminNotifications() {
|
||||||
return configAdminNotifications.isSendAdminNotifications();
|
return configAdminNotifications.isSendAdminNotifications();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.config.hocon.serializers;
|
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.datatypes.permissions.PermissionWrapper;
|
||||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
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 com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.ValueType;
|
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.ObjectMappingException;
|
||||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class RepairableSerializer implements TypeSerializer<Repairable> {
|
public class RepairableSerializer implements TypeSerializer<Repairable> {
|
||||||
private static final String ITEM = "Item";
|
public static final String REPAIRABLE_ITEM = "Repairable-Item";
|
||||||
private static final String BASE_XP = "XP-Per-Repair";
|
public static final String MAXIMUM_DURABILITY = "Maximum-Durability";
|
||||||
private static final String REPAIR_TRANSACTION = "Repair-Transaction";
|
public static final String ITEMS_REQUIRED_TO_REPAIR = "Items-Required-To-Repair";
|
||||||
private static final String STRICT_MATCH_ITEM = "Strict-Match-Item";
|
public static final String SKILL_LEVEL_REQUIRED_TO_REPAIR = "Skill-Level-Required-To-Repair";
|
||||||
private static final String STRICT_MATCHING_REPAIR_TRANSACTION = "Strict-Matching-Repair-Transaction";
|
public static final String BASE_XP_REWARD = "Base-XP-Reward";
|
||||||
private static final String REPAIR_COUNT = "Repair-Count";
|
public static final String BASE_REPAIR_COUNT = "Base-Repair-Count";
|
||||||
// private static final String NBT = "NBT";
|
public static final String REQUIRED_PERMISSION_NODE = "Required-Permission-Node";
|
||||||
private static final String PERMISSION = "Permission";
|
|
||||||
private static final String MINIMUM_LEVEL = "Minimum-Level";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
||||||
ItemStack itemStack = value.getNode(ITEM).getValue(TypeToken.of(ItemStack.class));
|
/* Necessary fields */
|
||||||
RepairableBuilder builder = new RepairableBuilder(itemStack)
|
CustomItemTarget customItemTarget = value.getNode(REPAIRABLE_ITEM).getValue(TypeToken.of(CustomItemTarget.class));
|
||||||
.repairTransaction(value.getNode(REPAIR_TRANSACTION).getValue(TypeToken.of(RepairTransaction.class)))
|
Short maximumDurability = value.getNode(MAXIMUM_DURABILITY).getValue(TypeToken.of(Short.class));
|
||||||
.strictMatchingItem(value.getNode(STRICT_MATCH_ITEM).getValue(TypeToken.of(Boolean.class)))
|
RepairTransaction repairTransaction = value.getNode(ITEMS_REQUIRED_TO_REPAIR).getValue(TypeToken.of(RepairTransaction.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)));
|
|
||||||
|
|
||||||
if(value.getNode(MINIMUM_LEVEL).getValueType() != ValueType.NULL) {
|
RepairableBuilder repairableBuilder = new RepairableBuilder(customItemTarget, maximumDurability, repairTransaction);
|
||||||
builder = builder.minLevel(value.getNode(MINIMUM_LEVEL).getValue(TypeToken.of(Integer.class)));
|
|
||||||
|
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) {
|
if(value.getNode(BASE_XP_REWARD).getValueType() != ValueType.NULL) {
|
||||||
// builder = builder.rawNBT(value.getNode(NBT).getValue(TypeToken.of(RawNBT.class)));
|
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void serialize(TypeToken<?> type, Repairable obj, ConfigurationNode value) {
|
public void serialize(TypeToken<?> type, Repairable obj, ConfigurationNode value) {
|
||||||
value.getNode(ITEM).setValue(obj.getItem());
|
value.getNode(REPAIRABLE_ITEM).setValue(obj.getCustomItemTarget());
|
||||||
value.getNode(REPAIR_TRANSACTION).setValue(obj.getRepairTransaction());
|
value.getNode(MAXIMUM_DURABILITY).setValue(obj.getMaximumDurability());
|
||||||
value.getNode(STRICT_MATCH_ITEM).setValue(obj.isStrictMatchingItem());
|
value.getNode(ITEMS_REQUIRED_TO_REPAIR).setValue(obj.getRepairTransaction());
|
||||||
// value.getNode(STRICT_MATCHING_REPAIR_TRANSACTION).setValue(obj.isStrictMatchingRepairTransaction());
|
|
||||||
value.getNode(BASE_XP).setValue(obj.getBaseXP());
|
|
||||||
value.getNode(REPAIR_COUNT).setValue(obj.getRepairCount());
|
|
||||||
|
|
||||||
if(obj.getMinimumLevel() > 0)
|
if(obj.getMinimumLevel() > 0) {
|
||||||
value.getNode(MINIMUM_LEVEL).setValue(obj.getMinimumLevel());
|
value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).setValue(obj.getMinimumLevel());
|
||||||
|
}
|
||||||
|
|
||||||
// if(obj.hasNBT())
|
if(obj.getBaseXP() != 0) {
|
||||||
// value.getNode(NBT).setValue(obj.getRawNBT());
|
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())
|
if(obj.getRepairCount() != 0) {
|
||||||
value.getNode(PERMISSION).setValue(obj.getPermissionWrapper());
|
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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
package com.gmail.nossr50.datatypes.items;
|
package com.gmail.nossr50.datatypes.items;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
|
||||||
import java.util.HashSet;
|
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.
|
* 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) {
|
public boolean isMatch(MMOItem otherItem) {
|
||||||
//First compare the basic things that need to match between each item
|
//First compare the basic things that need to match between each item
|
||||||
if(item.equals(otherItem)) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.gmail.nossr50.datatypes.items;
|
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
|
* Represents a property of an item which is used in strict matching
|
||||||
* Typically this represents and NBT field and its value
|
* Typically this represents and NBT field and its value
|
||||||
@ -7,20 +11,20 @@ package com.gmail.nossr50.datatypes.items;
|
|||||||
*/
|
*/
|
||||||
public class ItemMatchProperty {
|
public class ItemMatchProperty {
|
||||||
|
|
||||||
final private Object propertyValue;
|
final private NBTTagCompound nbtData;
|
||||||
final private String nbtID;
|
final private String nbtID;
|
||||||
|
|
||||||
public ItemMatchProperty(Object propertyValue, String nbtID) {
|
public ItemMatchProperty(String nbtID, NBTTagCompound nbtData) {
|
||||||
this.propertyValue = propertyValue;
|
this.nbtData = nbtData;
|
||||||
this.nbtID = nbtID;
|
this.nbtID = nbtID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The expected value for this NBT entry
|
* The expected value for this NBT
|
||||||
* @return the expected value for this NBT entry
|
* @return the expected value for this NBT entry
|
||||||
*/
|
*/
|
||||||
public Object getPropertyValue() {
|
public NBTTagCompound getNbtData() {
|
||||||
return propertyValue;
|
return nbtData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,4 +34,18 @@ public class ItemMatchProperty {
|
|||||||
public String getID() {
|
public String getID() {
|
||||||
return nbtID;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class ItemWildcards {
|
|||||||
return itemTargets.size();
|
return itemTargets.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<ItemStack> getItemTargets() {
|
public HashSet<CustomItemTarget> getItemTargets() {
|
||||||
return itemTargets;
|
return itemTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||||
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
||||||
import com.gmail.nossr50.util.experience.FormulaManager;
|
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.NotificationManager;
|
||||||
import com.gmail.nossr50.util.player.PlayerLevelUtils;
|
import com.gmail.nossr50.util.player.PlayerLevelUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -65,6 +66,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private static PlayerLevelUtils playerLevelUtils;
|
private static PlayerLevelUtils playerLevelUtils;
|
||||||
private static NotificationManager notificationManager;
|
private static NotificationManager notificationManager;
|
||||||
private static CommandRegistrationManager commandRegistrationManager;
|
private static CommandRegistrationManager commandRegistrationManager;
|
||||||
|
private static NBTManager nbtManager;
|
||||||
|
|
||||||
/* File Paths */
|
/* File Paths */
|
||||||
private static String mainDirectory;
|
private static String mainDirectory;
|
||||||
@ -153,6 +155,8 @@ public class mcMMO extends JavaPlugin {
|
|||||||
commandRegistrationManager = new CommandRegistrationManager(this);
|
commandRegistrationManager = new CommandRegistrationManager(this);
|
||||||
commandRegistrationManager.registerCommands();
|
commandRegistrationManager.registerCommands();
|
||||||
|
|
||||||
|
nbtManager = new NBTManager();
|
||||||
|
|
||||||
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
|
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
|
||||||
|
|
||||||
if (getConfigManager().getConfigParty().getPTP().isPtpWorldBasedPermissions()) {
|
if (getConfigManager().getConfigParty().getPTP().isPtpWorldBasedPermissions()) {
|
||||||
@ -318,6 +322,10 @@ public class mcMMO extends JavaPlugin {
|
|||||||
return databaseManager;
|
return databaseManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NBTManager getNbtManager() {
|
||||||
|
return nbtManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setDatabaseManager(DatabaseManager newDatabaseManager) {
|
public static void setDatabaseManager(DatabaseManager newDatabaseManager) {
|
||||||
databaseManager = newDatabaseManager;
|
databaseManager = newDatabaseManager;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.gmail.nossr50.skills.repair;
|
package com.gmail.nossr50.skills.repair;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,21 +20,25 @@ import java.util.HashSet;
|
|||||||
* to pay that part of the RepairTransaction
|
* to pay that part of the RepairTransaction
|
||||||
*/
|
*/
|
||||||
public class RepairTransaction {
|
public class RepairTransaction {
|
||||||
private HashSet<RepairCost> repairItems;
|
private HashSet<RepairCost> repairCosts;
|
||||||
|
|
||||||
public RepairTransaction() {
|
public RepairTransaction() {
|
||||||
repairItems = new HashSet<>();
|
repairCosts = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRepairCost(RepairCost repairCost) {
|
public void addRepairCost(RepairCost repairCost) {
|
||||||
repairItems.add(repairCost);
|
repairCosts.add(repairCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<RepairCost> getRepairItems() {
|
public HashSet<RepairCost> getRepairCosts() {
|
||||||
return repairItems;
|
return repairCosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepairItems(HashSet<RepairCost> repairItems) {
|
public void setRepairCosts(HashSet<RepairCost> repairItems) {
|
||||||
this.repairItems = repairItems;
|
this.repairCosts = repairItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canPayRepairCosts(PlayerInventory playerInventory) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,32 @@
|
|||||||
package com.gmail.nossr50.skills.repair.repairables;
|
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.datatypes.permissions.PermissionWrapper;
|
||||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class Repairable {
|
public class Repairable {
|
||||||
private final ItemStack item;
|
private int minimumLevel;
|
||||||
private int minimumLevel = 0;
|
|
||||||
private short maximumDurability;
|
private short maximumDurability;
|
||||||
private RepairTransaction repairTransaction;
|
private RepairTransaction repairTransaction;
|
||||||
private boolean strictMatchingItem = false;
|
private int baseXP;
|
||||||
// private boolean strictMatchingRepairTransaction = false;
|
private CustomItemTarget customItemTarget;
|
||||||
private int baseXP = 0;
|
private int repairCount;
|
||||||
private RawNBT rawNBT;
|
|
||||||
private int repairCount = 1;
|
|
||||||
private PermissionWrapper permissionWrapper;
|
private PermissionWrapper permissionWrapper;
|
||||||
private boolean hasPermission = false;
|
private boolean hasPermission = false;
|
||||||
private boolean hasNBT = false;
|
|
||||||
|
|
||||||
public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, int baseXP, int repairCount) {
|
public Repairable(CustomItemTarget customItemTarget, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, int baseXP, int repairCount, PermissionWrapper permissionWrapper) {
|
||||||
this.item = item;
|
|
||||||
this.minimumLevel = minimumLevel;
|
this.minimumLevel = minimumLevel;
|
||||||
this.maximumDurability = maximumDurability;
|
this.maximumDurability = maximumDurability;
|
||||||
this.repairTransaction = repairTransaction;
|
this.repairTransaction = repairTransaction;
|
||||||
this.strictMatchingItem = strictMatchingItem;
|
|
||||||
// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
|
||||||
this.baseXP = baseXP;
|
this.baseXP = baseXP;
|
||||||
|
this.customItemTarget = customItemTarget;
|
||||||
this.repairCount = repairCount;
|
this.repairCount = repairCount;
|
||||||
}
|
this.permissionWrapper = permissionWrapper;
|
||||||
|
|
||||||
public ItemStack getItem() {
|
if(permissionWrapper != null)
|
||||||
return item;
|
hasPermission = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinimumLevel() {
|
public int getMinimumLevel() {
|
||||||
@ -58,22 +53,6 @@ public class Repairable {
|
|||||||
this.repairTransaction = repairTransaction;
|
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() {
|
public int getBaseXP() {
|
||||||
return baseXP;
|
return baseXP;
|
||||||
}
|
}
|
||||||
@ -82,13 +61,12 @@ public class Repairable {
|
|||||||
this.baseXP = baseXP;
|
this.baseXP = baseXP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawNBT getRawNBT() {
|
public CustomItemTarget getCustomItemTarget() {
|
||||||
return rawNBT;
|
return customItemTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRawNBT(RawNBT rawNBT) {
|
public void setCustomItemTarget(CustomItemTarget customItemTarget) {
|
||||||
this.rawNBT = rawNBT;
|
this.customItemTarget = customItemTarget;
|
||||||
hasNBT = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRepairCount() {
|
public int getRepairCount() {
|
||||||
@ -105,10 +83,9 @@ public class Repairable {
|
|||||||
|
|
||||||
public void setPermissionWrapper(PermissionWrapper permissionWrapper) {
|
public void setPermissionWrapper(PermissionWrapper permissionWrapper) {
|
||||||
this.permissionWrapper = permissionWrapper;
|
this.permissionWrapper = permissionWrapper;
|
||||||
hasPermission = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission() {
|
public boolean hasPermissionNode() {
|
||||||
return hasPermission;
|
return hasPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,11 +93,4 @@ public class Repairable {
|
|||||||
this.hasPermission = hasPermission;
|
this.hasPermission = hasPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNBT() {
|
|
||||||
return hasNBT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasNBT(boolean hasNBT) {
|
|
||||||
this.hasNBT = hasNBT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.skills.repair.repairables;
|
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.datatypes.permissions.PermissionWrapper;
|
||||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||||
@ -7,63 +8,46 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
public class RepairableBuilder {
|
public class RepairableBuilder {
|
||||||
|
|
||||||
private final ItemStack item;
|
private int minimumLevel;
|
||||||
private int minimumLevel = 0;
|
|
||||||
private short maximumDurability;
|
private short maximumDurability;
|
||||||
private RepairTransaction repairTransaction;
|
private RepairTransaction repairTransaction;
|
||||||
private boolean strictMatchingItem = false;
|
private int baseXP;
|
||||||
// private boolean strictMatchingRepairTransaction = false;
|
private CustomItemTarget customItemTarget;
|
||||||
private int baseXP = 0;
|
private int repairCount;
|
||||||
private RawNBT rawNBT;
|
|
||||||
private int repairCount = 1;
|
|
||||||
private PermissionWrapper permissionWrapper;
|
private PermissionWrapper permissionWrapper;
|
||||||
|
|
||||||
public RepairableBuilder(ItemStack item) {
|
public RepairableBuilder(CustomItemTarget customItemTarget, Short maximumDurability, RepairTransaction repairTransaction) {
|
||||||
this.item = item;
|
this.customItemTarget = customItemTarget;
|
||||||
this.maximumDurability = item.getType().getMaxDurability();
|
this.maximumDurability = maximumDurability;
|
||||||
|
this.repairTransaction = repairTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder minLevel(Integer minimumLevel) {
|
public RepairableBuilder addMinLevel(Integer minimumLevel) {
|
||||||
this.minimumLevel = minimumLevel;
|
this.minimumLevel = minimumLevel;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder maximumDurability(Short maximumDurability) {
|
public RepairableBuilder setMaximumDurability(Short maximumDurability) {
|
||||||
this.maximumDurability = maximumDurability;
|
this.maximumDurability = maximumDurability;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder repairTransaction(RepairTransaction repairTransaction) {
|
public RepairableBuilder setRepairTransaction(RepairTransaction repairTransaction) {
|
||||||
this.repairTransaction = repairTransaction;
|
this.repairTransaction = repairTransaction;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder strictMatchingItem(Boolean strictMatchingItem) {
|
public RepairableBuilder setBaseXP(Integer baseXP) {
|
||||||
this.strictMatchingItem = strictMatchingItem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public RepairableBuilder strictMatchingRepairTransaction(Boolean strictMatchingRepairTransaction) {
|
|
||||||
// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
|
||||||
// return this;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public RepairableBuilder baseXP(Integer baseXP) {
|
|
||||||
this.baseXP = baseXP;
|
this.baseXP = baseXP;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder rawNBT(RawNBT rawNBT) {
|
public RepairableBuilder setRepairCount(Integer repairCount) {
|
||||||
this.rawNBT = rawNBT;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RepairableBuilder repairCount(Integer repairCount) {
|
|
||||||
this.repairCount = repairCount;
|
this.repairCount = repairCount;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepairableBuilder permissionWrapper(PermissionWrapper permissionWrapper) {
|
public RepairableBuilder addPermissionWrapper(PermissionWrapper permissionWrapper) {
|
||||||
this.permissionWrapper = permissionWrapper;
|
this.permissionWrapper = permissionWrapper;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -73,16 +57,8 @@ public class RepairableBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Repairable makeRepairable() {
|
private Repairable makeRepairable() {
|
||||||
Repairable repairable = new Repairable(item, minimumLevel, maximumDurability, repairTransaction,
|
Repairable repairable = new Repairable(customItemTarget, minimumLevel, maximumDurability, repairTransaction,
|
||||||
strictMatchingItem, baseXP, repairCount);
|
baseXP, repairCount, permissionWrapper);
|
||||||
|
|
||||||
if(permissionWrapper != null) {
|
|
||||||
repairable.setPermissionWrapper(permissionWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rawNBT != null) {
|
|
||||||
repairable.setRawNBT(rawNBT);
|
|
||||||
}
|
|
||||||
|
|
||||||
return repairable;
|
return repairable;
|
||||||
}
|
}
|
||||||
|
@ -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.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class NBTManager {
|
public class NBTManager {
|
||||||
|
|
||||||
private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.gmail.nossr50.util.nbt;
|
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
|
* 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
|
* 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
|
* 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
|
* 2) Check an items NBT tree for this NBT data during runtime once transformed
|
||||||
*/
|
*/
|
||||||
public class RawNBT<T> {
|
public class RawNBT {
|
||||||
private String nbtContents;
|
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;
|
this.nbtContents = nbtContents;
|
||||||
NBTManager
|
this.nbtData = nbtData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNbtContents() {
|
public String getNbtContents() {
|
||||||
@ -27,4 +30,7 @@ public class RawNBT<T> {
|
|||||||
this.nbtContents = nbtContents;
|
this.nbtContents = nbtContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound getNbtData() {
|
||||||
|
return nbtData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user