mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
SoundSettingSerializer
This commit is contained in:
parent
86a4b74eb3
commit
307bf8b332
@ -44,6 +44,7 @@ import com.gmail.nossr50.config.hocon.skills.taming.ConfigTaming;
|
||||
import com.gmail.nossr50.config.hocon.skills.unarmed.ConfigUnarmed;
|
||||
import com.gmail.nossr50.config.hocon.skills.woodcutting.ConfigWoodcutting;
|
||||
import com.gmail.nossr50.config.hocon.sound.ConfigSound;
|
||||
import com.gmail.nossr50.config.hocon.sound.SoundSetting;
|
||||
import com.gmail.nossr50.config.hocon.superabilities.ConfigSuperAbilities;
|
||||
import com.gmail.nossr50.config.hocon.worldblacklist.ConfigWorldBlacklist;
|
||||
import com.gmail.nossr50.config.treasure.ExcavationTreasureConfig;
|
||||
@ -277,6 +278,7 @@ public final class ConfigManager {
|
||||
customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer());
|
||||
customSerializers.registerType(TypeToken.of(MaxBonusLevel.class), new MaxBonusLevelSerializer());
|
||||
customSerializers.registerType(TypeToken.of(PlayerNotificationSettings.class), new PlayerNotificationSerializer());
|
||||
customSerializers.registerType(TypeToken.of(SoundSetting.class), new SoundSettingSerializer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.gmail.nossr50.config.hocon.serializers;
|
||||
|
||||
import com.gmail.nossr50.config.hocon.sound.SoundSetting;
|
||||
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;
|
||||
|
||||
public class SoundSettingSerializer implements TypeSerializer<SoundSetting> {
|
||||
|
||||
private static final String VOLUME_NODE = "Volume";
|
||||
private static final String PITCH_NODE = "Pitch";
|
||||
public static final String ENABLED_NODE = "Enabled";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SoundSetting deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
float volume = 1.0f;
|
||||
float pitch = 1.0f;
|
||||
boolean enabled = true;
|
||||
|
||||
if(value.getNode(ENABLED_NODE).getValueType() != ValueType.NULL) {
|
||||
enabled = value.getNode(ENABLED_NODE).getValue(TypeToken.of(Boolean.class));
|
||||
}
|
||||
|
||||
if(value.getNode(VOLUME_NODE).getValueType() != ValueType.NULL) {
|
||||
volume = (float) value.getNode(VOLUME_NODE).getValue(TypeToken.of(Double.class)).doubleValue();
|
||||
}
|
||||
|
||||
if(value.getNode(PITCH_NODE).getValueType() != ValueType.NULL) {
|
||||
volume = (float) value.getNode(PITCH_NODE).getValue(TypeToken.of(Double.class)).doubleValue();
|
||||
}
|
||||
|
||||
SoundSetting soundSetting = new SoundSetting(enabled, volume, pitch);
|
||||
return soundSetting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable SoundSetting obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
value.getNode(ENABLED_NODE).setValue(obj.isEnabled());
|
||||
value.getNode(VOLUME_NODE).setValue(obj.getVolume());
|
||||
value.getNode(PITCH_NODE).setValue(obj.getPitch());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user