mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Lets generify some of this stuff
This commit is contained in:
parent
d843108164
commit
5c31bdbd49
@ -52,7 +52,7 @@ 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.ItemMatch;
|
||||||
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.items.MMOItem;
|
||||||
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||||
@ -70,7 +70,6 @@ import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
|||||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
|
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
|
||||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
|
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -284,9 +283,10 @@ public final class ConfigManager {
|
|||||||
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(ItemWildcards.class), new ItemWildcardSerializer());
|
customSerializers.registerType(TypeToken.of(ItemWildcards.class), new ItemWildcardSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
|
customSerializers.registerType(TypeToken.of(ItemMatch.class), new CustomItemTargetSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
||||||
customSerializers.registerType(TypeToken.of(RawNBT.class), new RawNBTSerializer());
|
customSerializers.registerType(TypeToken.of(RawNBT.class), new RawNBTSerializer());
|
||||||
|
customSerializers.registerType(TypeToken.of(RepairCost.class), new RepairCostSerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.gmail.nossr50.config.hocon.serializers;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||||
|
import com.gmail.nossr50.datatypes.items.ItemMatchProperty;
|
||||||
|
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
|
import ninja.leaping.configurate.ValueType;
|
||||||
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
|
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class CustomItemTargetSerializer implements TypeSerializer<ItemMatch> {
|
||||||
|
|
||||||
|
private static final String ITEM_CONSUMED_FOR_REPAIR = "Item-Consumed-For-Repair";
|
||||||
|
private static final String NBT_REQUIREMENTS = "NBT-Requirements";
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemMatch deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||||
|
MMOItem<?> mmoItem = value.getNode(ITEM_CONSUMED_FOR_REPAIR).getValue(new TypeToken<MMOItem<?>>() {});
|
||||||
|
if(value.getNode(NBT_REQUIREMENTS).getValueType() != ValueType.NULL)
|
||||||
|
{
|
||||||
|
HashSet<ItemMatchProperty> itemMatchProperties = value.getNode(NBT_REQUIREMENTS).getValue(new TypeToken<HashSet<ItemMatchProperty>>() {});
|
||||||
|
return new ItemMatch(mmoItem, itemMatchProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemMatch(mmoItem, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(@NonNull TypeToken<?> type, @Nullable ItemMatch obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||||
|
value.getNode(ITEM_CONSUMED_FOR_REPAIR).setValue(obj.getItem());
|
||||||
|
|
||||||
|
if(obj.getItemMatchProperties().size() > 0) {
|
||||||
|
value.getNode(NBT_REQUIREMENTS).setValue(obj.getItemMatchProperties());
|
||||||
|
SerializerUtil.addCommentIfCompatible(value.getNode(NBT_REQUIREMENTS), "List optional NBT that is required here, you write it the same way you do in vanilla commands.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,12 @@
|
|||||||
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.ItemMatch;
|
||||||
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;
|
||||||
import ninja.leaping.configurate.ValueType;
|
import ninja.leaping.configurate.ValueType;
|
||||||
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.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;
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ public class ItemWildcardSerializer 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<CustomItemTarget> matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken<Set<CustomItemTarget>>() {});
|
Set<ItemMatch> matchCandidates = value.getNode(WILDCARD_IDENTIFIER_NAME).getNode(MATCHING_ITEMS).getValue(new TypeToken<Set<ItemMatch>>() {});
|
||||||
|
|
||||||
return new ItemWildcards(wildCardName, new HashSet<>(matchCandidates));
|
return new ItemWildcards(wildCardName, new HashSet<>(matchCandidates));
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
package com.gmail.nossr50.config.hocon.serializers;
|
package com.gmail.nossr50.config.hocon.serializers;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||||
import com.gmail.nossr50.skills.repair.RepairCost;
|
import com.gmail.nossr50.skills.repair.RepairCost;
|
||||||
|
import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||||
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.objectmapping.ObjectMappingException;
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
|
||||||
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 RepairCostSerializer implements TypeSerializer<RepairCost> {
|
public class RepairCostSerializer implements TypeSerializer<RepairCost<?>> {
|
||||||
|
|
||||||
|
private static final String TARGET_ITEM = "Target-Item";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public RepairCost deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
public RepairCost<?> deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||||
return null;
|
ItemMatch itemMatch = value.getNode(TARGET_ITEM).getValue(TypeToken.of(ItemMatch.class));
|
||||||
|
return new SimpleRepairCost(itemMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(@NonNull TypeToken<?> type, @Nullable RepairCost obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
public void serialize(@NonNull TypeToken<?> type, @Nullable RepairCost<?> obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||||
|
value.getNode(TARGET_ITEM).setValue(obj.getRepairCosts());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +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.ItemMatch;
|
||||||
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;
|
||||||
@ -8,11 +8,8 @@ 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;
|
|
||||||
|
|
||||||
public class RepairableSerializer implements TypeSerializer<Repairable> {
|
public class RepairableSerializer implements TypeSerializer<Repairable> {
|
||||||
private static final String REPAIRABLE_ITEM = "Repairable-Item";
|
private static final String REPAIRABLE_ITEM = "Repairable-Item";
|
||||||
@ -26,11 +23,11 @@ public class RepairableSerializer implements TypeSerializer<Repairable> {
|
|||||||
@Override
|
@Override
|
||||||
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
public Repairable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
|
||||||
/* Necessary fields */
|
/* Necessary fields */
|
||||||
CustomItemTarget customItemTarget = value.getNode(REPAIRABLE_ITEM).getValue(TypeToken.of(CustomItemTarget.class));
|
ItemMatch itemMatch = value.getNode(REPAIRABLE_ITEM).getValue(TypeToken.of(ItemMatch.class));
|
||||||
Short maximumDurability = value.getNode(MAXIMUM_DURABILITY).getValue(TypeToken.of(Short.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));
|
RepairTransaction repairTransaction = value.getNode(ITEMS_REQUIRED_TO_REPAIR).getValue(TypeToken.of(RepairTransaction.class));
|
||||||
|
|
||||||
RepairableBuilder repairableBuilder = new RepairableBuilder(customItemTarget, maximumDurability, repairTransaction);
|
RepairableBuilder repairableBuilder = new RepairableBuilder(itemMatch, maximumDurability, repairTransaction);
|
||||||
|
|
||||||
if(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getValueType() != ValueType.NULL) {
|
if(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getValueType() != ValueType.NULL) {
|
||||||
repairableBuilder.addMinLevel(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getInt());
|
repairableBuilder.addMinLevel(value.getNode(SKILL_LEVEL_REQUIRED_TO_REPAIR).getInt());
|
||||||
@ -53,7 +50,7 @@ public class RepairableSerializer implements TypeSerializer<Repairable> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(TypeToken<?> type, Repairable obj, ConfigurationNode value) {
|
public void serialize(TypeToken<?> type, Repairable obj, ConfigurationNode value) {
|
||||||
value.getNode(REPAIRABLE_ITEM).setValue(obj.getCustomItemTarget());
|
value.getNode(REPAIRABLE_ITEM).setValue(obj.getItemMatch());
|
||||||
value.getNode(MAXIMUM_DURABILITY).setValue(obj.getMaximumDurability());
|
value.getNode(MAXIMUM_DURABILITY).setValue(obj.getMaximumDurability());
|
||||||
value.getNode(ITEMS_REQUIRED_TO_REPAIR).setValue(obj.getRepairTransaction());
|
value.getNode(ITEMS_REQUIRED_TO_REPAIR).setValue(obj.getRepairTransaction());
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package com.gmail.nossr50.datatypes.items;
|
|
||||||
|
|
||||||
public interface CustomItemMatching {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether or not an item matches this one
|
|
||||||
* Behaviours for matching can vary based on the implementation
|
|
||||||
* @param otherItem target item to compare itself to
|
|
||||||
* @return true if this item matches the target item
|
|
||||||
*/
|
|
||||||
boolean isMatch(MMOItem otherItem);
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.gmail.nossr50.datatypes.items;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Defined match.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
*/
|
||||||
|
public interface DefinedMatch<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether or not this object of type T matches certain criteria of another object of type T
|
||||||
|
* Behaviours for matching depend solely on the implementation of DefinedMatch
|
||||||
|
*
|
||||||
|
* @param other target item to compare itself to
|
||||||
|
* @return true if this item matches the target item
|
||||||
|
*/
|
||||||
|
boolean isMatch(T other);
|
||||||
|
|
||||||
|
}
|
@ -26,17 +26,17 @@ import java.util.Objects;
|
|||||||
* 1) Abstract away platform specific implementations of MC Items
|
* 1) Abstract away platform specific implementations of MC Items
|
||||||
* 2) Contain information about an item and which properties of said item that are considered important and thus will be used to equate equivalency to another item when doing comparisons
|
* 2) Contain information about an item and which properties of said item that are considered important and thus will be used to equate equivalency to another item when doing comparisons
|
||||||
*/
|
*/
|
||||||
public class CustomItemTarget implements CustomItemMatching {
|
public class ItemMatch<T extends MMOItem<?>> implements DefinedMatch<T> {
|
||||||
|
|
||||||
private MMOItem item; //Abstract representation of the item
|
private T item; //Abstract representation of the item
|
||||||
private HashSet<ItemMatchProperty> itemMatchProperties; //Item properties used for matching
|
private HashSet<ItemMatchProperty> itemMatchProperties; //Item properties used for matching
|
||||||
|
|
||||||
public CustomItemTarget(MMOItem item) {
|
public ItemMatch(T item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
itemMatchProperties = new HashSet<>();
|
itemMatchProperties = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomItemTarget(MMOItem item, HashSet<ItemMatchProperty> itemMatchProperties) {
|
public ItemMatch(T item, HashSet<ItemMatchProperty> itemMatchProperties) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.itemMatchProperties = itemMatchProperties;
|
this.itemMatchProperties = itemMatchProperties;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ public class CustomItemTarget implements CustomItemMatching {
|
|||||||
* @return true if this item matches the target item
|
* @return true if this item matches the target item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isMatch(MMOItem otherItem) {
|
public boolean isMatch(T otherItem) {
|
||||||
if(hasStrictMatching()) {
|
if(hasStrictMatching()) {
|
||||||
return isStrictMatch(otherItem);
|
return isStrictMatch(otherItem);
|
||||||
} else {
|
} else {
|
||||||
@ -69,7 +69,7 @@ public class CustomItemTarget implements CustomItemMatching {
|
|||||||
* @param otherItem item to strictly match
|
* @param otherItem item to strictly match
|
||||||
* @return true if the items are considered a match
|
* @return true if the items are considered a match
|
||||||
*/
|
*/
|
||||||
private boolean isStrictMatch(MMOItem otherItem) {
|
private boolean isStrictMatch(T 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;
|
||||||
@ -106,10 +106,10 @@ public class CustomItemTarget implements CustomItemMatching {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof CustomItemTarget)) return false;
|
if (!(o instanceof ItemMatch)) return false;
|
||||||
CustomItemTarget that = (CustomItemTarget) o;
|
ItemMatch<?> itemMatch = (ItemMatch<?>) o;
|
||||||
return getItem().equals(that.getItem()) &&
|
return getItem().equals(itemMatch.getItem()) &&
|
||||||
getItemMatchProperties().equals(that.getItemMatchProperties());
|
getItemMatchProperties().equals(itemMatch.getItemMatchProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -1,7 +1,5 @@
|
|||||||
package com.gmail.nossr50.datatypes.items;
|
package com.gmail.nossr50.datatypes.items;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -19,12 +17,13 @@ import java.util.Objects;
|
|||||||
* to solve a problem with Repair. Given its flexible nature it can be used for many purposes.
|
* to solve a problem with Repair. Given its flexible nature it can be used for many purposes.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ItemWildcards {
|
public class ItemWildcards<T extends MMOItem<?>> {
|
||||||
|
|
||||||
private String wildcardName;
|
private String wildcardName;
|
||||||
private HashSet<CustomItemTarget> itemTargets;
|
private HashSet<ItemMatch<T>> itemTargets;
|
||||||
|
|
||||||
public ItemWildcards(String wildcardName, HashSet<CustomItemTarget> itemTargets) {
|
public ItemWildcards(String wildcardName, HashSet<ItemMatch<T>> itemTargets) {
|
||||||
|
super();
|
||||||
this.wildcardName = wildcardName;
|
this.wildcardName = wildcardName;
|
||||||
this.itemTargets = itemTargets;
|
this.itemTargets = itemTargets;
|
||||||
}
|
}
|
||||||
@ -33,11 +32,11 @@ public class ItemWildcards {
|
|||||||
return itemTargets.size();
|
return itemTargets.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<CustomItemTarget> getItemTargets() {
|
public HashSet<ItemMatch<T>> getItemTargets() {
|
||||||
return itemTargets;
|
return itemTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemTargets(HashSet<CustomItemTarget> itemTargets) {
|
public void setItemTargets(HashSet<ItemMatch<T>> itemTargets) {
|
||||||
this.itemTargets = itemTargets;
|
this.itemTargets = itemTargets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
*/
|
*/
|
||||||
public interface RepairCost {
|
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
|
||||||
|
@ -22,8 +22,8 @@ import java.util.HashSet;
|
|||||||
public class RepairTransaction {
|
public class RepairTransaction {
|
||||||
private HashSet<RepairCost> repairCosts;
|
private HashSet<RepairCost> repairCosts;
|
||||||
|
|
||||||
public RepairTransaction() {
|
public RepairTransaction(HashSet<RepairCost> repairCosts) {
|
||||||
repairCosts = new HashSet<>();
|
this.repairCosts = repairCosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRepairCost(RepairCost repairCost) {
|
public void addRepairCost(RepairCost repairCost) {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.gmail.nossr50.skills.repair;
|
package com.gmail.nossr50.skills.repair;
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
||||||
import com.gmail.nossr50.datatypes.items.CustomItemTarget;
|
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||||
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.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of RepairCost
|
* Implementation of RepairCost
|
||||||
*
|
*
|
||||||
@ -15,12 +17,12 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
* This type is strictly for use with RepairTransaction, which represents the full cost of a Repair.
|
* This type is strictly for use with RepairTransaction, which represents the full cost of a Repair.
|
||||||
* @see com.gmail.nossr50.skills.repair.RepairTransaction for more details
|
* @see com.gmail.nossr50.skills.repair.RepairTransaction for more details
|
||||||
*/
|
*/
|
||||||
public class SimpleRepairCost implements RepairCost {
|
public class SimpleRepairCost<T extends ItemMatch> implements RepairCost {
|
||||||
|
|
||||||
private CustomItemTarget desiredItemTarget;
|
private T itemMatch;
|
||||||
|
|
||||||
public SimpleRepairCost(CustomItemTarget customItemTarget) {
|
public SimpleRepairCost(T customItemTarget) {
|
||||||
this.desiredItemTarget = customItemTarget;
|
this.itemMatch = customItemTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,14 +33,31 @@ public class SimpleRepairCost implements RepairCost {
|
|||||||
|
|
||||||
BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack);
|
BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack);
|
||||||
|
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO: Write the code that compares playerInventoryItem with the <T extends itemMatch>
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
//TODO:
|
||||||
|
|
||||||
//If the item matches return it
|
//If the item matches return it
|
||||||
if(desiredItemTarget.isMatch(playerInventoryItem))
|
if(itemMatch.isMatch(playerInventoryItem))
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemMatch getItemMatch() {
|
||||||
|
return itemMatch;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPayment(PlayerInventory playerInventory) {
|
public boolean hasPayment(PlayerInventory playerInventory) {
|
||||||
return findPayment(playerInventory) != null;
|
return findPayment(playerInventory) != null;
|
||||||
|
@ -1,27 +1,25 @@
|
|||||||
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.items.ItemMatch;
|
||||||
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 org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class Repairable {
|
public class Repairable {
|
||||||
private int minimumLevel;
|
private int minimumLevel;
|
||||||
private short maximumDurability;
|
private short maximumDurability;
|
||||||
private RepairTransaction repairTransaction;
|
private RepairTransaction repairTransaction;
|
||||||
private int baseXP;
|
private int baseXP;
|
||||||
private CustomItemTarget customItemTarget;
|
private ItemMatch itemMatch;
|
||||||
private int repairCount;
|
private int repairCount;
|
||||||
private PermissionWrapper permissionWrapper;
|
private PermissionWrapper permissionWrapper;
|
||||||
private boolean hasPermission = false;
|
private boolean hasPermission = false;
|
||||||
|
|
||||||
public Repairable(CustomItemTarget customItemTarget, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, int baseXP, int repairCount, PermissionWrapper permissionWrapper) {
|
public Repairable(ItemMatch itemMatch, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, int baseXP, int repairCount, PermissionWrapper permissionWrapper) {
|
||||||
this.minimumLevel = minimumLevel;
|
this.minimumLevel = minimumLevel;
|
||||||
this.maximumDurability = maximumDurability;
|
this.maximumDurability = maximumDurability;
|
||||||
this.repairTransaction = repairTransaction;
|
this.repairTransaction = repairTransaction;
|
||||||
this.baseXP = baseXP;
|
this.baseXP = baseXP;
|
||||||
this.customItemTarget = customItemTarget;
|
this.itemMatch = itemMatch;
|
||||||
this.repairCount = repairCount;
|
this.repairCount = repairCount;
|
||||||
this.permissionWrapper = permissionWrapper;
|
this.permissionWrapper = permissionWrapper;
|
||||||
|
|
||||||
@ -61,12 +59,12 @@ public class Repairable {
|
|||||||
this.baseXP = baseXP;
|
this.baseXP = baseXP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomItemTarget getCustomItemTarget() {
|
public ItemMatch getItemMatch() {
|
||||||
return customItemTarget;
|
return itemMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCustomItemTarget(CustomItemTarget customItemTarget) {
|
public void setItemMatch(ItemMatch itemMatch) {
|
||||||
this.customItemTarget = customItemTarget;
|
this.itemMatch = itemMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRepairCount() {
|
public int getRepairCount() {
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
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.items.ItemMatch;
|
||||||
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 org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class RepairableBuilder {
|
public class RepairableBuilder {
|
||||||
|
|
||||||
@ -12,12 +10,12 @@ public class RepairableBuilder {
|
|||||||
private short maximumDurability;
|
private short maximumDurability;
|
||||||
private RepairTransaction repairTransaction;
|
private RepairTransaction repairTransaction;
|
||||||
private int baseXP;
|
private int baseXP;
|
||||||
private CustomItemTarget customItemTarget;
|
private ItemMatch itemMatch;
|
||||||
private int repairCount;
|
private int repairCount;
|
||||||
private PermissionWrapper permissionWrapper;
|
private PermissionWrapper permissionWrapper;
|
||||||
|
|
||||||
public RepairableBuilder(CustomItemTarget customItemTarget, Short maximumDurability, RepairTransaction repairTransaction) {
|
public RepairableBuilder(ItemMatch itemMatch, Short maximumDurability, RepairTransaction repairTransaction) {
|
||||||
this.customItemTarget = customItemTarget;
|
this.itemMatch = itemMatch;
|
||||||
this.maximumDurability = maximumDurability;
|
this.maximumDurability = maximumDurability;
|
||||||
this.repairTransaction = repairTransaction;
|
this.repairTransaction = repairTransaction;
|
||||||
}
|
}
|
||||||
@ -57,7 +55,7 @@ public class RepairableBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Repairable makeRepairable() {
|
private Repairable makeRepairable() {
|
||||||
Repairable repairable = new Repairable(customItemTarget, minimumLevel, maximumDurability, repairTransaction,
|
Repairable repairable = new Repairable(itemMatch, minimumLevel, maximumDurability, repairTransaction,
|
||||||
baseXP, repairCount, permissionWrapper);
|
baseXP, repairCount, permissionWrapper);
|
||||||
|
|
||||||
return repairable;
|
return repairable;
|
||||||
|
Loading…
Reference in New Issue
Block a user