mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2026-02-10 02:46:13 +01:00
Rewrite confguration and serializers to new config library
This commit is contained in:
@@ -10,16 +10,12 @@ import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import napi.configurate.serializing.NodeSerializers;
|
||||
import ru.nanit.limbo.configuration.LimboConfig;
|
||||
import ru.nanit.limbo.configuration.SocketAddressSerializer;
|
||||
import ru.nanit.limbo.connection.ClientChannelInitializer;
|
||||
import ru.nanit.limbo.connection.ClientConnection;
|
||||
import ru.nanit.limbo.server.data.*;
|
||||
import ru.nanit.limbo.util.Logger;
|
||||
import ru.nanit.limbo.world.DimensionRegistry;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -51,12 +47,6 @@ public final class LimboServer {
|
||||
|
||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
|
||||
|
||||
NodeSerializers.register(SocketAddress.class, new SocketAddressSerializer());
|
||||
NodeSerializers.register(InfoForwarding.class, new InfoForwarding.Serializer());
|
||||
NodeSerializers.register(PingData.class, new PingData.Serializer());
|
||||
NodeSerializers.register(BossBar.class, new BossBar.Serializer());
|
||||
NodeSerializers.register(Position.class, new Position.Serializer());
|
||||
|
||||
config = new LimboConfig(Paths.get("./"));
|
||||
config.load();
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package ru.nanit.limbo.server.data;
|
||||
|
||||
import napi.configurate.data.ConfigNode;
|
||||
import napi.configurate.serializing.NodeSerializer;
|
||||
import napi.configurate.serializing.NodeSerializingException;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
import ru.nanit.limbo.util.Colors;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class BossBar {
|
||||
|
||||
private String text;
|
||||
@@ -84,35 +87,35 @@ public class BossBar {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Serializer implements NodeSerializer<BossBar>{
|
||||
public static class Serializer implements TypeSerializer<BossBar> {
|
||||
|
||||
@Override
|
||||
public BossBar deserialize(ConfigNode node) throws NodeSerializingException {
|
||||
public BossBar deserialize(Type type, ConfigurationNode node) throws SerializationException {
|
||||
BossBar bossBar = new BossBar();
|
||||
|
||||
bossBar.setText(Colors.of(node.getNode("text").getString()));
|
||||
bossBar.setHealth(node.getNode("health").getFloat());
|
||||
bossBar.setText(Colors.of(node.node("text").getString("")));
|
||||
bossBar.setHealth(node.node("health").getFloat());
|
||||
|
||||
if (bossBar.getHealth() < 0 || bossBar.getHealth() > 1)
|
||||
throw new NodeSerializingException("BossBar health value must be between 0.0 and 1.0");
|
||||
throw new SerializationException("BossBar health value must be between 0.0 and 1.0");
|
||||
|
||||
try {
|
||||
bossBar.setColor(Color.valueOf(node.getNode("color").getString().toUpperCase()));
|
||||
bossBar.setColor(Color.valueOf(node.node("color").getString("").toUpperCase()));
|
||||
} catch (IllegalArgumentException e){
|
||||
throw new NodeSerializingException("Invalid bossbar color");
|
||||
throw new SerializationException("Invalid bossbar color");
|
||||
}
|
||||
|
||||
try {
|
||||
bossBar.setDivision(Division.valueOf(node.getNode("division").getString().toUpperCase()));
|
||||
bossBar.setDivision(Division.valueOf(node.node("division").getString("").toUpperCase()));
|
||||
} catch (IllegalArgumentException e){
|
||||
throw new NodeSerializingException("Invalid bossbar division");
|
||||
throw new SerializationException("Invalid bossbar division");
|
||||
}
|
||||
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(BossBar bossBar, ConfigNode configNode) {
|
||||
public void serialize(Type type, @Nullable BossBar obj, ConfigurationNode node) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package ru.nanit.limbo.server.data;
|
||||
|
||||
import napi.configurate.data.ConfigNode;
|
||||
import napi.configurate.serializing.NodeSerializer;
|
||||
import napi.configurate.serializing.NodeSerializingException;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -37,27 +38,27 @@ public class InfoForwarding {
|
||||
MODERN
|
||||
}
|
||||
|
||||
public static class Serializer implements NodeSerializer<InfoForwarding> {
|
||||
public static class Serializer implements TypeSerializer<InfoForwarding> {
|
||||
|
||||
@Override
|
||||
public InfoForwarding deserialize(ConfigNode node) throws NodeSerializingException {
|
||||
public InfoForwarding deserialize(java.lang.reflect.Type type, ConfigurationNode node) throws SerializationException {
|
||||
InfoForwarding forwarding = new InfoForwarding();
|
||||
|
||||
try {
|
||||
forwarding.type = Type.valueOf(node.getNode("type").getString().toUpperCase());
|
||||
forwarding.type = Type.valueOf(node.node("type").getString("").toUpperCase());
|
||||
} catch (IllegalArgumentException e){
|
||||
throw new NodeSerializingException("Undefined info forwarding type");
|
||||
throw new SerializationException("Undefined info forwarding type");
|
||||
}
|
||||
|
||||
if (forwarding.type == Type.MODERN){
|
||||
forwarding.secretKey = node.getNode("secret").getString().getBytes(StandardCharsets.UTF_8);
|
||||
forwarding.secretKey = node.node("secret").getString("").getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
return forwarding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(InfoForwarding infoForwarding, ConfigNode configNode) {
|
||||
public void serialize(java.lang.reflect.Type type, @Nullable InfoForwarding obj, ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package ru.nanit.limbo.server.data;
|
||||
|
||||
import napi.configurate.data.ConfigNode;
|
||||
import napi.configurate.serializing.NodeSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
import ru.nanit.limbo.util.Colors;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class PingData {
|
||||
|
||||
private String version;
|
||||
@@ -25,18 +28,18 @@ public class PingData {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static class Serializer implements NodeSerializer<PingData> {
|
||||
public static class Serializer implements TypeSerializer<PingData> {
|
||||
|
||||
@Override
|
||||
public PingData deserialize(ConfigNode node) {
|
||||
public PingData deserialize(Type type, ConfigurationNode node) {
|
||||
PingData pingData = new PingData();
|
||||
pingData.setDescription(Colors.of(node.getNode("description").getString()));
|
||||
pingData.setVersion(Colors.of(node.getNode("version").getString()));
|
||||
pingData.setDescription(Colors.of(node.node("description").getString("")));
|
||||
pingData.setVersion(Colors.of(node.node("version").getString("")));
|
||||
return pingData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PingData pingData, ConfigNode configNode) {
|
||||
public void serialize(Type type, @Nullable PingData obj, ConfigurationNode node) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package ru.nanit.limbo.server.data;
|
||||
|
||||
import napi.configurate.data.ConfigNode;
|
||||
import napi.configurate.serializing.NodeSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class Position {
|
||||
|
||||
@@ -51,21 +54,21 @@ public class Position {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public static class Serializer implements NodeSerializer<Position> {
|
||||
public static class Serializer implements TypeSerializer<Position> {
|
||||
|
||||
@Override
|
||||
public Position deserialize(ConfigNode node) {
|
||||
public Position deserialize(Type type, ConfigurationNode node) {
|
||||
Position position = new Position();
|
||||
position.setX(node.getNode("x").getDouble());
|
||||
position.setY(node.getNode("y").getDouble());
|
||||
position.setZ(node.getNode("z").getDouble());
|
||||
position.setYaw(node.getNode("yaw").getFloat());
|
||||
position.setPitch(node.getNode("pitch").getFloat());
|
||||
position.setX(node.node("x").getDouble());
|
||||
position.setY(node.node("y").getDouble());
|
||||
position.setZ(node.node("z").getDouble());
|
||||
position.setYaw(node.node("yaw").getFloat());
|
||||
position.setPitch(node.node("pitch").getFloat());
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Position position, ConfigNode configNode) {
|
||||
public void serialize(Type type, @Nullable Position obj, ConfigurationNode node) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user