mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 22:26:46 +01:00
Add serializer for TamingSummon
This commit is contained in:
parent
d484ccc15e
commit
46b881e730
@ -56,6 +56,7 @@ import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
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;
|
||||
@ -261,6 +262,7 @@ public final class ConfigManager {
|
||||
customSerializers.registerType(new TypeToken<MMOItem<?>>() {}, new ItemStackSerializer());
|
||||
customSerializers.registerType(new TypeToken<Set<?>>() {}, new SetSerializer());
|
||||
|
||||
customSerializers.registerType(TypeToken.of(TamingSummon.class), new TamingSummonSerializer());
|
||||
customSerializers.registerType(TypeToken.of(Repairable.class), new RepairableSerializer());
|
||||
customSerializers.registerType(TypeToken.of(Salvageable.class), new SalvageableSerializer());
|
||||
customSerializers.registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.config.hocon.serializers;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.taming.TamingSummon;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
@ -10,24 +11,37 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class TamingSummonSerializer implements TypeSerializer<TamingSummon> {
|
||||
|
||||
private static final String ITEM_MATERIAL = "Item-Id";
|
||||
private static final String AMOUNT_REQUIRED = "Amount-Required";
|
||||
private static final String ENTITIES_SUMMONED = "Entities-Summoned";
|
||||
private static final String SUMMON_LIFESPAN_SECONDS = "Summon-Lifespan-Seconds";
|
||||
private static final String SUMMON_LIMIT = "Summon-Limit";
|
||||
private static final String CALL_OF_THE_WILD_TYPE = "Call-Of-The-Wild-Type";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TamingSummon deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
/*
|
||||
private Material itemType;
|
||||
private int itemAmountRequired;
|
||||
private int entitiesSummoned;
|
||||
private int summonLifespan;
|
||||
private int summonCap;
|
||||
private CallOfTheWildType callOfTheWildType;
|
||||
private EntityType entityType;
|
||||
*/
|
||||
String itemMaterialStr = value.getNode(ITEM_MATERIAL).getValue(TypeToken.of(String.class));
|
||||
//TODO: Make platform independent instead of Bukkit dependent
|
||||
Material itemMaterial = Material.matchMaterial(itemMaterialStr);
|
||||
int amountRequired = value.getNode(AMOUNT_REQUIRED).getValue(TypeToken.of(Integer.class));
|
||||
int entitiesSummoned = value.getNode(ENTITIES_SUMMONED).getValue(TypeToken.of(Integer.class));
|
||||
int summonLifespanSeconds = value.getNode(SUMMON_LIFESPAN_SECONDS).getValue(TypeToken.of(Integer.class));
|
||||
int summonLimit = value.getNode(SUMMON_LIMIT).getValue(TypeToken.of(Integer.class));
|
||||
CallOfTheWildType callOfTheWildType = value.getNode(CALL_OF_THE_WILD_TYPE).getValue(new TypeToken<CallOfTheWildType>() {});
|
||||
|
||||
Material itemType = value.getNode("Item-Material").getValue(TypeToken.of(Material.class));
|
||||
TamingSummon tamingSummon = new TamingSummon(callOfTheWildType, itemMaterial, amountRequired, entitiesSummoned, summonLifespanSeconds, summonLimit);
|
||||
return tamingSummon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable TamingSummon obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
|
||||
value.getNode(ITEM_MATERIAL).setValue(obj.getItemType().getKey().toString());
|
||||
value.getNode(AMOUNT_REQUIRED).setValue(obj.getItemAmountRequired());
|
||||
value.getNode(ENTITIES_SUMMONED).setValue(obj.getEntitiesSummoned());
|
||||
value.getNode(SUMMON_LIFESPAN_SECONDS).setValue(obj.getSummonLifespan());
|
||||
value.getNode(SUMMON_LIMIT).setValue(obj.getSummonCap());
|
||||
value.getNode(CALL_OF_THE_WILD_TYPE).setValue(obj.getCallOfTheWildType());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user