mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
NBT Manager will be a static abusing class for now
This commit is contained in:
parent
f1de5484ec
commit
df6386ec2f
@ -2,7 +2,7 @@ package com.gmail.nossr50.bukkit;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
||||
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.nbt.NBTManager;
|
||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -11,22 +11,16 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class BukkitFactory {
|
||||
|
||||
private final mcMMO pluginRef;
|
||||
|
||||
public BukkitFactory(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a BukkitMMOItem which contains Bukkit implementations for the type MMOItem
|
||||
* @return a new BukkitMMOItem
|
||||
*/
|
||||
public MMOItem<?> createItem(String namespaceKey, int amount, RawNBT rawNBT) {
|
||||
public static MMOItem<?> createItem(String namespaceKey, int amount, RawNBT rawNBT) {
|
||||
return new BukkitMMOItem(namespaceKey, amount, rawNBT);
|
||||
}
|
||||
|
||||
public MMOItem<?> createItem(ItemStack itemStack) {
|
||||
return createItem(itemStack.getType().getKey().toString(), itemStack.getAmount(), new RawNBT(pluginRef.getNbtManager().getNBT(itemStack).toString()));
|
||||
public static MMOItem<?> createItem(ItemStack itemStack) {
|
||||
return createItem(itemStack.getType().getKey().toString(), itemStack.getAmount(), new RawNBT(NBTManager.getNBT(itemStack).toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ import com.gmail.nossr50.datatypes.skills.properties.DamageProperty;
|
||||
import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.taming.TamingSummon;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.RepairCost;
|
||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||
import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
@ -262,6 +261,7 @@ public final class ConfigManager {
|
||||
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<SimpleRepairCost>() {}, new SimpleRepairCostSerializer());
|
||||
|
||||
customSerializers.registerType(TypeToken.of(TamingSummon.class), new TamingSummonSerializer());
|
||||
customSerializers.registerType(TypeToken.of(Repairable.class), new RepairableSerializer());
|
||||
@ -277,7 +277,6 @@ public final class ConfigManager {
|
||||
customSerializers.registerType(TypeToken.of(ItemMatch.class), new CustomItemTargetSerializer());
|
||||
customSerializers.registerType(TypeToken.of(RepairTransaction.class), new RepairTransactionSerializer());
|
||||
customSerializers.registerType(TypeToken.of(RawNBT.class), new RawNBTSerializer());
|
||||
customSerializers.registerType(TypeToken.of(SimpleRepairCost.class), new SimpleRepairCostSerializer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,20 +9,20 @@ import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class SimpleRepairCostSerializer implements TypeSerializer<SimpleRepairCost<?>> {
|
||||
public class SimpleRepairCostSerializer implements TypeSerializer<SimpleRepairCost> {
|
||||
|
||||
private static final String ITEM_MATCH = "Item-Match";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SimpleRepairCost<?> deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
public SimpleRepairCost deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
ItemMatch<?> itemMatch = value.getNode(ITEM_MATCH).getValue(new TypeToken<ItemMatch<?>>() {});
|
||||
SimpleRepairCost<?> simpleRepairCost = new SimpleRepairCost<>(itemMatch);
|
||||
return simpleRepairCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable SimpleRepairCost<?> obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable SimpleRepairCost obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
value.getNode(ITEM_MATCH).setValue(obj.getItemMatch());
|
||||
}
|
||||
}
|
||||
|
@ -6,16 +6,13 @@ import com.gmail.nossr50.config.hocon.skills.repair.repairmastery.ConfigRepairRe
|
||||
import com.gmail.nossr50.config.hocon.skills.repair.subskills.ConfigRepairSubSkills;
|
||||
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatchProperty;
|
||||
import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||
import com.gmail.nossr50.datatypes.permissions.PermissionWrapper;
|
||||
import com.gmail.nossr50.skills.repair.RepairCost;
|
||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||
import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -34,7 +34,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
||||
import com.gmail.nossr50.util.commands.CommandTools;
|
||||
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.PlayerLevelTools;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -77,7 +76,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private FormulaManager formulaManager;
|
||||
private NotificationManager notificationManager;
|
||||
private CommandRegistrationManager commandRegistrationManager;
|
||||
private NBTManager nbtManager;
|
||||
// private NBTManager nbtManager;
|
||||
private WorldGuardManager worldGuardManager;
|
||||
private PartyManager partyManager;
|
||||
private LocaleManager localeManager;
|
||||
@ -205,7 +204,7 @@ public class mcMMO extends JavaPlugin {
|
||||
commandRegistrationManager = new CommandRegistrationManager(this);
|
||||
commandRegistrationManager.registerCommands();
|
||||
|
||||
nbtManager = new NBTManager(this);
|
||||
// nbtManager = new NBTManager();
|
||||
|
||||
//Init Chunk Manager Factory
|
||||
chunkManagerFactory = new ChunkManagerFactory(this);
|
||||
@ -443,9 +442,9 @@ public class mcMMO extends JavaPlugin {
|
||||
return databaseManager;
|
||||
}
|
||||
|
||||
public NBTManager getNbtManager() {
|
||||
return nbtManager;
|
||||
}
|
||||
// public NBTManager getNbtManager() {
|
||||
// return nbtManager;
|
||||
// }
|
||||
|
||||
@Deprecated
|
||||
public void setDatabaseManager(DatabaseManager newDatabaseManager) {
|
||||
|
@ -6,14 +6,14 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
/**
|
||||
* Represents one item in a Repair Transaction
|
||||
*/
|
||||
public interface RepairCost<T extends ItemMatch<?>> {
|
||||
public interface RepairCost {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return any compatible payment items if found, can be null
|
||||
*/
|
||||
T findPayment(PlayerInventory playerInventory);
|
||||
ItemMatch<?> findPayment(PlayerInventory playerInventory);
|
||||
|
||||
/**
|
||||
* Whether or not there is an item that can be used for this repair cost in the player's inventory
|
||||
|
@ -16,7 +16,7 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
* 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
|
||||
*/
|
||||
public class SimpleRepairCost<T extends ItemMatch> implements RepairCost<ItemMatch<?>> {
|
||||
public class SimpleRepairCost<T extends ItemMatch> implements RepairCost {
|
||||
|
||||
private T itemMatch;
|
||||
|
||||
|
@ -1,41 +1,42 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||
import com.gmail.nossr50.skills.repair.RepairCost;
|
||||
import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MultiRepairCost<T extends MMOItem<T>, U extends ItemMatch<T>> implements RepairCost<U> {
|
||||
|
||||
//Multiple potential item matches
|
||||
private Set<SimpleRepairCost<U>> repairCostWildcards;
|
||||
|
||||
public MultiRepairCost(ItemWildcards<T> itemWildcards) {
|
||||
repairCostWildcards = new HashSet<>();
|
||||
for(ItemMatch<T> wildcard : itemWildcards.getItemTargets()) {
|
||||
SimpleRepairCost<U> simpleRepairCost = new SimpleRepairCost<U>((U)wildcard);
|
||||
repairCostWildcards.add(simpleRepairCost);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public U findPayment(PlayerInventory playerInventory) {
|
||||
for(SimpleRepairCost simpleRepairCost : repairCostWildcards) {
|
||||
if(simpleRepairCost.findPayment(playerInventory) != null) {
|
||||
return (U) simpleRepairCost.findPayment(playerInventory);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayment(PlayerInventory playerInventory) {
|
||||
return findPayment(playerInventory) != null;
|
||||
}
|
||||
}
|
||||
//package com.gmail.nossr50.skills.repair.repairables;
|
||||
//
|
||||
//import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
//import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||
//import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||
//import com.gmail.nossr50.skills.repair.RepairCost;
|
||||
//import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||
//import org.bukkit.inventory.PlayerInventory;
|
||||
//
|
||||
//import java.util.HashSet;
|
||||
//import java.util.Set;
|
||||
//
|
||||
////Do we need this?
|
||||
//public class MultiRepairCost<T extends MMOItem<T>, U extends ItemMatch<T>> implements RepairCost {
|
||||
//
|
||||
// //Multiple potential item matches
|
||||
// private Set<SimpleRepairCost<U>> repairCostWildcards;
|
||||
//
|
||||
// public MultiRepairCost(ItemWildcards<T> itemWildcards) {
|
||||
// repairCostWildcards = new HashSet<>();
|
||||
// for(ItemMatch<T> wildcard : itemWildcards.getItemTargets()) {
|
||||
// SimpleRepairCost<U> simpleRepairCost = new SimpleRepairCost<U>((U)wildcard);
|
||||
// repairCostWildcards.add(simpleRepairCost);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public U findPayment(PlayerInventory playerInventory) {
|
||||
// for(SimpleRepairCost simpleRepairCost : repairCostWildcards) {
|
||||
// if(simpleRepairCost.findPayment(playerInventory) != null) {
|
||||
// return (U) simpleRepairCost.findPayment(playerInventory);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasPayment(PlayerInventory playerInventory) {
|
||||
// return findPayment(playerInventory) != null;
|
||||
// }
|
||||
//}
|
||||
|
Loading…
Reference in New Issue
Block a user