Minor code optimizations

This commit is contained in:
Nanit 2022-01-23 12:25:39 +02:00
parent 1d75272c83
commit 4bdf856363
3 changed files with 10 additions and 5 deletions

View File

@ -40,13 +40,19 @@ public enum Version {
V1_17(755), V1_17(755),
V1_17_1(756), V1_17_1(756),
V1_18(757); V1_18(757);
// 1.18.1 has same protocol number
private static final Map<Integer, Version> VERSION_MAP; private static final Map<Integer, Version> VERSION_MAP;
private static final Version MAX;
static { static {
Version[] values = values();
VERSION_MAP = new HashMap<>(); VERSION_MAP = new HashMap<>();
MAX = values[values.length - 1];
Version last = null; Version last = null;
for (Version version : values()) { for (Version version : values) {
version.prev = last; version.prev = last;
last = version; last = version;
VERSION_MAP.put(version.getProtocolNumber(), version); VERSION_MAP.put(version.getProtocolNumber(), version);
@ -97,8 +103,7 @@ public enum Version {
} }
public static Version getMax() { public static Version getMax() {
Version[] values = Version.values(); return MAX;
return values[values.length - 1];
} }
public static Version of(int protocolNumber) { public static Version of(int protocolNumber) {

View File

@ -44,7 +44,7 @@ public final class Logger {
public static void print(Level level, Object msg, Throwable t, Object... args) { public static void print(Level level, Object msg, Throwable t, Object... args) {
if (debugLevel >= level.getIndex()) { if (debugLevel >= level.getIndex()) {
System.out.println(String.format("%s: %s", getPrefix(level), String.format(msg.toString(), args))); System.out.printf("%s: %s%n", getPrefix(level), String.format(msg.toString(), args));
if (t != null) t.printStackTrace(); if (t != null) t.printStackTrace();
} }
} }