mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
More work on the repair rewrite, fleshing out more serializers
This commit is contained in:
parent
d782d64750
commit
d843108164
@ -52,7 +52,9 @@ import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
|||||||
import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig;
|
import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig;
|
||||||
import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
|
import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
|
||||||
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
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.ItemWildcards;
|
||||||
|
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||||
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||||
import com.gmail.nossr50.datatypes.skills.properties.DamageProperty;
|
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.RepairTransaction;
|
||||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||||
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
||||||
|
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
|
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
|
||||||
@ -268,6 +271,7 @@ public final class ConfigManager {
|
|||||||
customSerializers.registerType(new TypeToken<Material>() {}, new CustomEnumValueSerializer());
|
customSerializers.registerType(new TypeToken<Material>() {}, new CustomEnumValueSerializer());
|
||||||
customSerializers.registerType(new TypeToken<PartyFeature>() {}, new CustomEnumValueSerializer());
|
customSerializers.registerType(new TypeToken<PartyFeature>() {}, new CustomEnumValueSerializer());
|
||||||
customSerializers.registerType(new TypeToken<FormulaType>() {}, new CustomEnumValueSerializer());
|
customSerializers.registerType(new TypeToken<FormulaType>() {}, new CustomEnumValueSerializer());
|
||||||
|
customSerializers.registerType(new TypeToken<MMOItem<?>>() {}, new ItemStackSerializer());
|
||||||
customSerializers.registerType(new TypeToken<Set<?>>() {}, new SetSerializer());
|
customSerializers.registerType(new TypeToken<Set<?>>() {}, new SetSerializer());
|
||||||
|
|
||||||
customSerializers.registerType(TypeToken.of(Repairable.class), new RepairableSerializer());
|
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(MaxBonusLevel.class), new MaxBonusLevelSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(PlayerNotificationSettings.class), new PlayerNotificationSerializer());
|
customSerializers.registerType(TypeToken.of(PlayerNotificationSettings.class), new PlayerNotificationSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(SoundSetting.class), new SoundSettingSerializer());
|
customSerializers.registerType(TypeToken.of(SoundSetting.class), new SoundSettingSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(ItemStack.class), new ItemStackSerializer());
|
customSerializers.registerType(TypeToken.of(ItemWildcards.class), new ItemWildcardSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(ItemWildcards.class), new RepairWildcardSerializer());
|
|
||||||
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
|
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
||||||
|
customSerializers.registerType(TypeToken.of(RawNBT.class), new RawNBTSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.gmail.nossr50.config.hocon.serializers;
|
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.gmail.nossr50.mcMMO;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ItemStackSerializer implements TypeSerializer<ItemStack> {
|
public class ItemStackSerializer implements TypeSerializer<MMOItem<?>> {
|
||||||
|
|
||||||
private static final String ITEM_MINECRAFT_NAME = "Item-Name";
|
private static final String ITEM_MINECRAFT_NAME = "Item-Name";
|
||||||
private static final String AMOUNT = "Amount";
|
private static final String AMOUNT = "Amount";
|
||||||
private static final String NBT = "NBT";
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ItemStack deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
public MMOItem<?> deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||||
ItemStack itemStack;
|
|
||||||
|
|
||||||
String itemIdentifier = value.getNode(ITEM_MINECRAFT_NAME).getValue(TypeToken.of(String.class));
|
String itemIdentifier = value.getNode(ITEM_MINECRAFT_NAME).getValue(TypeToken.of(String.class));
|
||||||
|
|
||||||
Material itemMatch = Material.matchMaterial(itemIdentifier);
|
Material itemMatch = Material.matchMaterial(itemIdentifier);
|
||||||
@ -34,37 +33,22 @@ public class ItemStackSerializer implements TypeSerializer<ItemStack> {
|
|||||||
|
|
||||||
ConfigurationNode itemNode = value.getNode(ITEM_MINECRAFT_NAME);
|
ConfigurationNode itemNode = value.getNode(ITEM_MINECRAFT_NAME);
|
||||||
|
|
||||||
|
Integer amount;
|
||||||
//Get the amount of items in the stack
|
//Get the amount of items in the stack
|
||||||
if(itemNode.getNode(AMOUNT).getValueType() != ValueType.NULL) {
|
if(itemNode.getNode(AMOUNT).getValueType() != ValueType.NULL) {
|
||||||
Integer amount = itemNode.getNode(AMOUNT).getValue(TypeToken.of(Integer.class));
|
amount = itemNode.getNode(AMOUNT).getValue(TypeToken.of(Integer.class));
|
||||||
itemStack = new ItemStack(itemMatch, amount);
|
|
||||||
} else {
|
} else {
|
||||||
itemStack = new ItemStack(itemMatch, 1);
|
amount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Init default item meta
|
return new BukkitMMOItem(itemIdentifier, amount);
|
||||||
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<String> lore = itemNode.getNode(ITEM_LORE).getValue(new TypeToken<List<String>>() {});
|
|
||||||
// itemStack.getItemMeta().setLore(lore);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
ConfigurationNode itemNode = value.getNode(ITEM_MINECRAFT_NAME);
|
||||||
value.getNode(ITEM_MINECRAFT_NAME).setValue(obj.getType().getKey().toString());
|
value.getNode(ITEM_MINECRAFT_NAME).setValue(obj.getNamespaceKey());
|
||||||
itemNode.getNode(AMOUNT).setValue(obj.getAmount());
|
itemNode.getNode(AMOUNT).setValue(obj.getItemAmount());
|
||||||
//TODO: NBT Stuff
|
|
||||||
//itemNode.getNode(NBT).setValue()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.items.ItemWildcards;
|
import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RepairWildcardSerializer implements TypeSerializer<ItemWildcards> {
|
public class ItemWildcardSerializer implements TypeSerializer<ItemWildcards> {
|
||||||
|
|
||||||
private static final String WILDCARD_IDENTIFIER_NAME = "Wildcard-Identifier-Name";
|
private static final String WILDCARD_IDENTIFIER_NAME = "Wildcard-Identifier-Name";
|
||||||
private static final String MATCHING_ITEMS = "Matching-Items";
|
private static final String MATCHING_ITEMS = "Matching-Items";
|
||||||
@ -24,9 +26,9 @@ public class RepairWildcardSerializer implements TypeSerializer<ItemWildcards> {
|
|||||||
String wildCardName = value.getNode(WILDCARD_IDENTIFIER_NAME).getValue(TypeToken.of(String.class));
|
String wildCardName = value.getNode(WILDCARD_IDENTIFIER_NAME).getValue(TypeToken.of(String.class));
|
||||||
|
|
||||||
if(value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValueType() != ValueType.NULL) {
|
if(value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValueType() != ValueType.NULL) {
|
||||||
Set<ItemStack> matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken<Set<ItemStack>>() {});
|
Set<CustomItemTarget> matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken<Set<CustomItemTarget>>() {});
|
||||||
|
|
||||||
return new ItemWildcards(wildCardName, matchCandidates);
|
return new ItemWildcards(wildCardName, new HashSet<>(matchCandidates));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
@ -15,13 +15,13 @@ 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> {
|
||||||
public static final String REPAIRABLE_ITEM = "Repairable-Item";
|
private static final String REPAIRABLE_ITEM = "Repairable-Item";
|
||||||
public static final String MAXIMUM_DURABILITY = "Maximum-Durability";
|
private static final String MAXIMUM_DURABILITY = "Maximum-Durability";
|
||||||
public static final String ITEMS_REQUIRED_TO_REPAIR = "Items-Required-To-Repair";
|
private 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";
|
private static final String SKILL_LEVEL_REQUIRED_TO_REPAIR = "Skill-Level-Required-To-Repair";
|
||||||
public static final String BASE_XP_REWARD = "Base-XP-Reward";
|
private static final String BASE_XP_REWARD = "Base-XP-Reward";
|
||||||
public static final String BASE_REPAIR_COUNT = "Base-Repair-Count";
|
private static final String BASE_REPAIR_COUNT = "Base-Repair-Count";
|
||||||
public static final String REQUIRED_PERMISSION_NODE = "Required-Permission-Node";
|
private static final String REQUIRED_PERMISSION_NODE = "Required-Permission-Node";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package com.gmail.nossr50.datatypes.items;
|
package com.gmail.nossr50.datatypes.items;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||||
|
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class BukkitMMOItem implements MMOItem<ItemStack> {
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class BukkitMMOItem implements MMOItem {
|
||||||
|
|
||||||
private ItemStack itemImplementation;
|
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;
|
ItemStack itemStack;
|
||||||
Material material = Material.matchMaterial(namespaceKey);
|
Material material = Material.matchMaterial(namespaceKey);
|
||||||
|
|
||||||
@ -30,12 +33,12 @@ public class BukkitMMOItem implements MMOItem<ItemStack> {
|
|||||||
//Set amount
|
//Set amount
|
||||||
itemStack.setAmount(amount);
|
itemStack.setAmount(amount);
|
||||||
|
|
||||||
//Set item implementation
|
|
||||||
this.itemImplementation = itemStack;
|
this.itemImplementation = itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
//Set raw NBT
|
public BukkitMMOItem(ItemStack itemStack) {
|
||||||
if(rawNBT != null)
|
NBTTagCompound nbtTagCompound = mcMMO.getNbtManager().getNBT(itemStack);
|
||||||
this.rawNBT = rawNBT;
|
this.itemImplementation = itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,7 +58,8 @@ public class BukkitMMOItem implements MMOItem<ItemStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RawNBT getRawNBT() {
|
public RawNBT getRawNBT() {
|
||||||
return rawNBT;
|
NBTTagCompound nbtTagCompound = mcMMO.getNbtManager().getNBT(itemImplementation);
|
||||||
|
return new RawNBT(nbtTagCompound.toString(), nbtTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,17 +57,52 @@ public class CustomItemTarget implements CustomItemMatching {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isMatch(MMOItem otherItem) {
|
public boolean isMatch(MMOItem otherItem) {
|
||||||
//First compare the basic things that need to match between each item
|
if(hasStrictMatching()) {
|
||||||
if(item.equals(otherItem)) {
|
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) {
|
for(ItemMatchProperty itemMatchProperty : itemMatchProperties) {
|
||||||
if(!mcMMO.getNbtManager().hasNBT(otherItem.getRawNBT().getNbtData(), itemMatchProperty.getNbtData()))
|
if(!mcMMO.getNbtManager().hasNBT(otherItem.getRawNBT().getNbtData(), itemMatchProperty.getNbtData())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//All item match properties were found and matched
|
||||||
return true;
|
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;
|
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
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -36,5 +36,4 @@ public interface MMOItem<T> {
|
|||||||
* @return the raw NBT if it exists, null otherwise
|
* @return the raw NBT if it exists, null otherwise
|
||||||
*/
|
*/
|
||||||
RawNBT getRawNBT();
|
RawNBT getRawNBT();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
* 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
|
* @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);
|
ItemStack findPayment(PlayerInventory playerInventory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not this repair cost is strictly matched
|
* Whether or not there is an item that can be used for this repair cost in the player's inventory
|
||||||
* Strict matching compares Items by using metadata and material type
|
* @param playerInventory target player
|
||||||
* @return true if the RepairCost uses strict matching
|
* @return true if payment is found
|
||||||
*/
|
*/
|
||||||
boolean hasStrictMatching();
|
boolean hasPayment(PlayerInventory playerInventory);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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<SimpleRepairCost> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -39,6 +39,12 @@ public class RepairTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPayRepairCosts(PlayerInventory playerInventory) {
|
public boolean canPayRepairCosts(PlayerInventory playerInventory) {
|
||||||
|
for(RepairCost repairCost : repairCosts) {
|
||||||
|
if(!repairCost.hasPayment(playerInventory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package com.gmail.nossr50.skills.repair;
|
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.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of RepairCost
|
* Implementation of RepairCost
|
||||||
* <p>
|
*
|
||||||
* A SimpleRepairCost can be one or more items, any one of which can be used to pay for a RepairTransaction
|
* 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.
|
* 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 {
|
public class SimpleRepairCost implements RepairCost {
|
||||||
|
|
||||||
private ItemMatchProperty itemMatchProperty;
|
private CustomItemTarget desiredItemTarget;
|
||||||
|
|
||||||
public SimpleRepairCost(ItemMatchProperty itemMatchProperty) {
|
public SimpleRepairCost(CustomItemTarget customItemTarget) {
|
||||||
this.itemMatchProperty = itemMatchProperty;
|
this.desiredItemTarget = customItemTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack findPayment(PlayerInventory playerInventory) {
|
public ItemStack findPayment(PlayerInventory playerInventory) {
|
||||||
for(ItemStack itemStack : playerInventory.getContents()) {
|
for(ItemStack itemStack : playerInventory.getContents()) {
|
||||||
if(itemStack == null || itemStack.getType() == Material.AIR) {
|
if(itemStack == null || itemStack.getType() == Material.AIR)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
//Attempt to match the item in the inventory to any of the compatible repair items
|
BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack);
|
||||||
if(hasStrictMatching()) {
|
|
||||||
//TODO: Replace with strict matching code
|
//If the item matches return it
|
||||||
if(item)
|
if(desiredItemTarget.isMatch(playerInventoryItem))
|
||||||
return itemStack;
|
return itemStack;
|
||||||
} else {
|
|
||||||
if(itemStack.getType() == itemMatchProperty.getType()) {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public boolean hasPayment(PlayerInventory playerInventory) {
|
||||||
return Objects.hash(itemMatchProperty);
|
return findPayment(playerInventory) != null;
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.util.nbt;
|
|||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import net.minecraft.server.v1_13_R2.NBTBase;
|
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 net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
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 {
|
try {
|
||||||
return new RawNBT<NBTBase>(nbtString, CraftNBTTagConfigSerializer.deserialize(nbtString));
|
return CraftNBTTagConfigSerializer.deserialize(nbtString);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mcMMO.p.getLogger().severe("mcMMO was unable parse the NBT string from your config! Double check that it is proper NBT!");
|
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) {
|
public void printNBT(ItemStack itemStack) {
|
||||||
Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString());
|
for(String key : getNBT(itemStack).getKeys()) {
|
||||||
net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
|
||||||
NBTTagCompound rootTag = nmsItemStack.getTag();
|
|
||||||
for(String key : rootTag.getKeys()) {
|
|
||||||
Bukkit.broadcastMessage("NBT Key found: "+key);
|
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
|
//TODO: Implement this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.gmail.nossr50.util.nbt;
|
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
|
* 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 {
|
public class RawNBT {
|
||||||
private String nbtContents;
|
private String nbtContents;
|
||||||
private NBTTagCompound nbtData; //Will be constructed using server internals to make matching NBT easier
|
|
||||||
|
|
||||||
|
public RawNBT(String nbtContents) {
|
||||||
public RawNBT(String nbtContents, NBTTagCompound nbtData) {
|
|
||||||
this.nbtContents = nbtContents;
|
this.nbtContents = nbtContents;
|
||||||
this.nbtData = nbtData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNbtContents() {
|
public String getNbtContents() {
|
||||||
@ -30,7 +28,7 @@ public class RawNBT {
|
|||||||
this.nbtContents = nbtContents;
|
this.nbtContents = nbtContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound getNbtData() {
|
public NBTBase getNbtData() {
|
||||||
return nbtData;
|
return mcMMO.getNbtManager().constructNBT(nbtContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user