mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
cleanup: replace all old switch statements with enhanced switch statements
This commit is contained in:
parent
6703c58295
commit
cba9f9ed25
@ -94,12 +94,12 @@ public class Minosoft {
|
||||
if (!path.endsWith(File.separator)) {
|
||||
path += "/";
|
||||
}
|
||||
switch (OSUtil.getOS()) {
|
||||
case LINUX -> path += ".local/share/minosoft/";
|
||||
case WINDOWS -> path += "AppData/Roaming/Minosoft/";
|
||||
case MAC -> path += "Library/Application Support/Minosoft/";
|
||||
case OTHER -> path += ".minosoft/";
|
||||
}
|
||||
path += switch (OSUtil.getOS()) {
|
||||
case LINUX -> ".local/share/minosoft/";
|
||||
case WINDOWS -> "AppData/Roaming/Minosoft/";
|
||||
case MAC -> "Library/Application Support/Minosoft/";
|
||||
case OTHER -> ".minosoft/";
|
||||
};
|
||||
File folder = new File(path);
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
// failed creating folder
|
||||
|
@ -41,28 +41,20 @@ public class Pufferfish extends Mob implements MobInterface {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
switch (metaData.getPufferState()) {
|
||||
case UN_PUFFED:
|
||||
return 0.35F;
|
||||
case SEMI_PUFFED:
|
||||
return 0.5F;
|
||||
case FULLY_PUFFED:
|
||||
return 0.7F;
|
||||
}
|
||||
return 0.35F;
|
||||
return switch (metaData.getPufferState()) {
|
||||
case UN_PUFFED -> 0.35F;
|
||||
case SEMI_PUFFED -> 0.5F;
|
||||
case FULLY_PUFFED -> 0.7F;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
switch (metaData.getPufferState()) {
|
||||
case UN_PUFFED:
|
||||
return 0.35F;
|
||||
case SEMI_PUFFED:
|
||||
return 0.5F;
|
||||
case FULLY_PUFFED:
|
||||
return 0.7F;
|
||||
}
|
||||
return 0.35F;
|
||||
return switch (metaData.getPufferState()) {
|
||||
case UN_PUFFED -> 0.35F;
|
||||
case SEMI_PUFFED -> 0.5F;
|
||||
case FULLY_PUFFED -> 0.7F;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,15 +55,12 @@ public class Slime extends Mob implements MobInterface {
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
switch (metaData.getSize()) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 4;
|
||||
case 4:
|
||||
return 16;
|
||||
}
|
||||
return 0;
|
||||
return switch (metaData.getSize()) {
|
||||
case 1 -> 1;
|
||||
case 2 -> 4;
|
||||
case 4 -> 16;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,7 +156,7 @@ public class Connection {
|
||||
ConnectionStates previousState = this.state;
|
||||
this.state = state;
|
||||
switch (state) {
|
||||
case HANDSHAKING:
|
||||
case HANDSHAKING -> {
|
||||
// connection established, starting threads and logging in
|
||||
startHandlingThread();
|
||||
ConnectionStates next = ((reason == ConnectionReasons.CONNECT) ? ConnectionStates.LOGIN : ConnectionStates.STATUS);
|
||||
@ -168,19 +168,19 @@ public class Connection {
|
||||
network.sendPacket(new PacketHandshake(address, next, (next == ConnectionStates.STATUS) ? -1 : getVersion().getProtocolVersion()));
|
||||
// after sending it, switch to next state
|
||||
setConnectionState(next);
|
||||
break;
|
||||
case STATUS:
|
||||
}
|
||||
case STATUS -> {
|
||||
// send status request and ping
|
||||
network.sendPacket(new PacketStatusRequest());
|
||||
connectionStatusPing = new ConnectionPing();
|
||||
network.sendPacket(new PacketStatusPing(connectionStatusPing));
|
||||
break;
|
||||
case LOGIN:
|
||||
}
|
||||
case LOGIN -> {
|
||||
network.sendPacket(new PacketLoginStart(player));
|
||||
pluginChannelHandler = new PluginChannelHandler(this);
|
||||
registerDefaultChannels();
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
}
|
||||
case DISCONNECTED -> {
|
||||
if (reason == ConnectionReasons.GET_VERSION) {
|
||||
setReason(ConnectionReasons.CONNECT);
|
||||
connect();
|
||||
@ -188,8 +188,8 @@ public class Connection {
|
||||
// unregister all custom recipes
|
||||
Recipes.removeCustomRecipes();
|
||||
}
|
||||
break;
|
||||
case FAILED:
|
||||
}
|
||||
case FAILED -> {
|
||||
// connect to next hostname, if available
|
||||
if (previousState == ConnectionStates.PLAY) {
|
||||
// connection was good, do not reconnect
|
||||
@ -205,10 +205,8 @@ public class Connection {
|
||||
// no connection and no servers available anymore... sorry, but you can not play today :(
|
||||
handlePingCallbacks(null);
|
||||
}
|
||||
break;
|
||||
case FAILED_NO_RETRY:
|
||||
handlePingCallbacks(null);
|
||||
break;
|
||||
}
|
||||
case FAILED_NO_RETRY -> handlePingCallbacks(null);
|
||||
}
|
||||
// handle callbacks
|
||||
connectionChangeCallbacks.forEach((callback -> callback.handle(this)));
|
||||
|
@ -38,28 +38,20 @@ public class PacketBossBar implements ClientboundPacket {
|
||||
uuid = buffer.readUUID();
|
||||
action = BossBarActions.byId(buffer.readVarInt());
|
||||
switch (action) {
|
||||
case ADD:
|
||||
case ADD -> {
|
||||
title = buffer.readTextComponent();
|
||||
health = buffer.readFloat();
|
||||
color = BossBarColors.byId(buffer.readVarInt());
|
||||
divisions = BossBarDivisions.byId(buffer.readVarInt());
|
||||
flags = buffer.readByte();
|
||||
break;
|
||||
case REMOVE:
|
||||
break;
|
||||
case UPDATE_HEALTH:
|
||||
health = buffer.readFloat();
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
title = buffer.readTextComponent();
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
}
|
||||
case UPDATE_HEALTH -> health = buffer.readFloat();
|
||||
case UPDATE_TITLE -> title = buffer.readTextComponent();
|
||||
case UPDATE_STYLE -> {
|
||||
color = BossBarColors.byId(buffer.readVarInt());
|
||||
divisions = BossBarDivisions.byId(buffer.readVarInt());
|
||||
break;
|
||||
case UPDATE_FLAGS:
|
||||
flags = buffer.readByte();
|
||||
break;
|
||||
}
|
||||
case UPDATE_FLAGS -> flags = buffer.readByte();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -80,18 +80,12 @@ public class PacketHandler {
|
||||
long pingDifference = System.currentTimeMillis() - ping.getSendingTime();
|
||||
Log.debug(String.format("Pong received (ping=%dms, pingBars=%s)", pingDifference, PingBars.byPing(pingDifference)));
|
||||
switch (connection.getReason()) {
|
||||
case PING:
|
||||
// pong arrived, closing connection
|
||||
connection.disconnect();
|
||||
break;
|
||||
case GET_VERSION:
|
||||
case PING -> connection.disconnect();// pong arrived, closing connection
|
||||
case GET_VERSION -> {
|
||||
// reconnect...
|
||||
connection.disconnect();
|
||||
Log.info(String.format("Server is running on version %s (%d), reconnecting...", connection.getVersion().getVersionName(), connection.getVersion().getProtocolVersion()));
|
||||
break;
|
||||
case CONNECT:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
version: 1 # do not edit this, used for migration between versions of config
|
||||
|
||||
general:
|
||||
log-level: DEBUG # possible values: GAME, FATAL, INFO, WARNING, DEBUG, VERBOSE, PROTOCOL
|
||||
log-level: WARNING # possible values: GAME, FATAL, INFO, WARNING, DEBUG, VERBOSE, PROTOCOL
|
||||
|
||||
# game
|
||||
game:
|
||||
|
Loading…
x
Reference in New Issue
Block a user