change svar implementation
This commit is contained in:
parent
126ce64a24
commit
81613186e5
12 changed files with 197 additions and 184 deletions
|
@ -101,6 +101,7 @@ import server.network.HandshakeHandler;
|
|||
import server.network.Player;
|
||||
import server.network.User;
|
||||
import server.util.SVar;
|
||||
import server.util.ServerConfig;
|
||||
import server.world.Converter;
|
||||
import server.world.Region;
|
||||
import server.world.WorldServer;
|
||||
|
@ -257,16 +258,18 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
|
||||
private Server() {
|
||||
for(Field field : Config.class.getDeclaredFields()) {
|
||||
if(field.isAnnotationPresent(Var.class)) {
|
||||
if(!Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()))
|
||||
throw new IllegalArgumentException("Feld für Variable " + field + " muss statisch und änderbar sein!");
|
||||
Var value = field.getAnnotation(Var.class);
|
||||
if(value.name().isEmpty())
|
||||
throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!");
|
||||
if(this.variables.containsKey(value.name()))
|
||||
throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!");
|
||||
this.variables.put(value.name(), new SVar(field, value));
|
||||
for(Class<?> clazz : new Class[] {Config.class, ServerConfig.class}) {
|
||||
for(Field field : clazz.getDeclaredFields()) {
|
||||
if(field.isAnnotationPresent(Var.class)) {
|
||||
if(!Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()))
|
||||
throw new IllegalArgumentException("Feld für Variable " + field + " muss statisch und änderbar sein!");
|
||||
Var value = field.getAnnotation(Var.class);
|
||||
if(value.name().isEmpty())
|
||||
throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!");
|
||||
if(this.variables.containsKey(value.name()))
|
||||
throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!");
|
||||
this.variables.put(value.name(), new SVar(field, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setCallback(new Runnable() {
|
||||
|
@ -274,7 +277,7 @@ public final class Server implements IThreadListener {
|
|||
for(WorldServer world : Server.this.getWorlds()) {
|
||||
world.updatePhysics();
|
||||
}
|
||||
Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), Config.dayCycle, Config.timeFlow));
|
||||
Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), ServerConfig.dayCycle, ServerConfig.timeFlow));
|
||||
}
|
||||
}, "daylightCycle", "timeFlow", "gravity");
|
||||
this.setCallback(new Runnable() {
|
||||
|
@ -286,12 +289,12 @@ public final class Server implements IThreadListener {
|
|||
}, "viewDistance");
|
||||
this.setCallback(new Runnable() {
|
||||
public void run() {
|
||||
Server.this.bind(Config.port);
|
||||
Server.this.bind(ServerConfig.port);
|
||||
}
|
||||
}, "port");
|
||||
this.setCallback(new Runnable() {
|
||||
public void run() {
|
||||
if((!Config.password.isEmpty() && Config.password.length() < 8) || Config.password.length() > IPlayer.MAX_PASS_LENGTH)
|
||||
if((!ServerConfig.password.isEmpty() && ServerConfig.password.length() < 8) || ServerConfig.password.length() > IPlayer.MAX_PASS_LENGTH)
|
||||
Log.IO.warn("Passwort muss aus 8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen bestehen, Login wird nicht möglich sein");
|
||||
}
|
||||
}, "password");
|
||||
|
@ -436,11 +439,11 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
WorldServer.loadWarps(dim, this.warps);
|
||||
}
|
||||
if(Config.port >= 0)
|
||||
this.bind(Config.port);
|
||||
if(ServerConfig.port >= 0)
|
||||
this.bind(ServerConfig.port);
|
||||
else
|
||||
Log.SYSTEM.warn("Kein Port definiert, verwende 'sv port <1024-32767>' um einen Hosting-Port festzulegen");
|
||||
if(Config.accessRequired && Config.password.length() < 8)
|
||||
if(ServerConfig.accessRequired && ServerConfig.password.length() < 8)
|
||||
Log.SYSTEM.warn("Kein Passwort definiert, verwende 'sv password <8-" + IPlayer.MAX_PASS_LENGTH + " Zeichen>' um ein Zugangspasswort festzulegen");
|
||||
Thread con = new Thread(new Runnable() {
|
||||
private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(System.in)));
|
||||
|
@ -512,7 +515,7 @@ public final class Server implements IThreadListener {
|
|||
|
||||
public void preload(WorldServer world, int bx, int bz) {
|
||||
int done = 0;
|
||||
int total = Config.distance * 2 + 1;
|
||||
int total = ServerConfig.distance * 2 + 1;
|
||||
total *= total;
|
||||
Log.TICK.info("Generiere und lade Welt");
|
||||
// WorldServer world = this.getWorld(Config.spawnDim);
|
||||
|
@ -520,8 +523,8 @@ public final class Server implements IThreadListener {
|
|||
bx = bx >> 4;
|
||||
bz = bz >> 4;
|
||||
long last = System.currentTimeMillis();
|
||||
for(int x = -Config.distance; x <= Config.distance; x++) {
|
||||
for(int z = -Config.distance; z <= Config.distance; z++) {
|
||||
for(int x = -ServerConfig.distance; x <= ServerConfig.distance; x++) {
|
||||
for(int z = -ServerConfig.distance; z <= ServerConfig.distance; z++) {
|
||||
long time = System.currentTimeMillis();
|
||||
if(time - last > 1000L) {
|
||||
Log.TICK.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
|
||||
|
@ -607,7 +610,7 @@ public final class Server implements IThreadListener {
|
|||
this.sendPacket(new SPacketPlayerListItem((List)this.getPlayers()));
|
||||
this.pingTimer = 0;
|
||||
}
|
||||
if(Config.saveInterval > 0 && ++this.saveTimer >= Config.saveInterval) {
|
||||
if(ServerConfig.saveInterval > 0 && ++this.saveTimer >= ServerConfig.saveInterval) {
|
||||
this.saveAllPlayerData(false);
|
||||
this.saveAllWorlds(false);
|
||||
this.saveTimer = 0;
|
||||
|
@ -758,7 +761,7 @@ public final class Server implements IThreadListener {
|
|||
WorldServer world = this.getWorld(origin.getDimension());
|
||||
world = world == null ? this.space : world;
|
||||
BlockPos pos = origin;
|
||||
int radius = Config.spawnRadius;
|
||||
int radius = ServerConfig.spawnRadius;
|
||||
if(radius > 0) {
|
||||
pos = world.getTopSolidOrLiquidBlock(pos.add(
|
||||
ExtMath.clampi(world.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0,
|
||||
|
@ -779,10 +782,10 @@ public final class Server implements IThreadListener {
|
|||
Player conn = new Player(this, connection, loginUser);
|
||||
if(tag != null)
|
||||
conn.readTags(tag);
|
||||
if(Config.compression >= 0) {
|
||||
connection.sendPacket(new RPacketEnableCompression(Config.compression), new ChannelFutureListener() {
|
||||
if(ServerConfig.compression >= 0) {
|
||||
connection.sendPacket(new RPacketEnableCompression(ServerConfig.compression), new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
connection.setCompressionTreshold(Config.compression);
|
||||
connection.setCompressionTreshold(ServerConfig.compression);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -814,7 +817,7 @@ public final class Server implements IThreadListener {
|
|||
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
|
||||
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
|
||||
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
|
||||
Config.dayCycle, Config.timeFlow));
|
||||
ServerConfig.dayCycle, ServerConfig.timeFlow));
|
||||
// conn.initializeStats();
|
||||
this.sendPacket(new SPacketPlayerListItem(false, conn));
|
||||
|
||||
|
@ -945,7 +948,7 @@ public final class Server implements IThreadListener {
|
|||
// this.movePlayerToSpawn(nplayer);
|
||||
}
|
||||
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
|
||||
if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) {
|
||||
if(bed != null ? ServerConfig.checkBed : ServerConfig.spawnRadius >= 0) {
|
||||
while(!world.getCollidingBoundingBoxes(nplayer, nplayer.getEntityBoundingBox()).isEmpty() && nplayer.posY < 512.0D) {
|
||||
nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ);
|
||||
}
|
||||
|
@ -1202,7 +1205,7 @@ public final class Server implements IThreadListener {
|
|||
if(this.endpoint != null)
|
||||
this.terminateEndpoint("Wechsele auf Port " + port);
|
||||
// throw new IllegalStateException("Eingangspunkt bereits gesetzt");
|
||||
Log.NETWORK.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, Config.timeout);
|
||||
Log.NETWORK.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, ServerConfig.timeout);
|
||||
this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer<Channel>() {
|
||||
protected void initChannel(Channel channel) throws Exception {
|
||||
try {
|
||||
|
@ -1210,7 +1213,7 @@ public final class Server implements IThreadListener {
|
|||
}
|
||||
catch(ChannelException e) {
|
||||
}
|
||||
channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(Config.timeout)))
|
||||
channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(ServerConfig.timeout)))
|
||||
.addLast((String)"splitter", (ChannelHandler)(new PacketSplitter()))
|
||||
.addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true)))
|
||||
.addLast((String)"prepender", (ChannelHandler)(new PacketPrepender()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue