diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java index c849da433..259206483 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java @@ -78,13 +78,13 @@ public static void init(final @NotNull File file) { throw new IOException("Can't create file"); } } catch (final Exception ex) { - LeavesLogger.LOGGER.severe("Failure to create leaves config", ex); + LeavesLogger.LOGGER.error("Failure to create leaves config", ex); } } else { try { config.load(file); } catch (final Exception ex) { - LeavesLogger.LOGGER.severe("Failure to load leaves config", ex); + LeavesLogger.LOGGER.error("Failure to load leaves config", ex); throw new RuntimeException(ex); } } @@ -104,7 +104,7 @@ public static void reload() { try { config.load(LeavesConfig.configFile); } catch (final Exception ex) { - LeavesLogger.LOGGER.severe("Failure to reload leaves config", ex); + LeavesLogger.LOGGER.error("Failure to reload leaves config", ex); throw new RuntimeException(ex); } @@ -115,7 +115,7 @@ public static void save() { try { config.save(LeavesConfig.configFile); } catch (final Exception ex) { - LeavesLogger.LOGGER.severe("Unable to save leaves config", ex); + LeavesLogger.LOGGER.error("Unable to save leaves config", ex); } } @@ -863,6 +863,9 @@ public static class PerformanceRemoveConfig { @GlobalConfigCategory("protocol") public static class ProtocolConfig { + @GlobalConfig("strict-mode") + public boolean strictMode = false; + public BladerenConfig bladeren = new BladerenConfig(); @GlobalConfigCategory("bladeren") @@ -1113,7 +1116,7 @@ public void runAfterLoader(Boolean value, boolean reload) { if (!reload) { LeavesUpdateHelper.init(); if (value) { - LeavesLogger.LOGGER.warning("Auto-Update is not completely safe. Enabling it may cause data security problems!"); + LeavesLogger.LOGGER.warn("Auto-Update is not completely safe. Enabling it may cause data security problems!"); } } } @@ -1149,7 +1152,7 @@ public static class ExtraYggdrasilValidator extends BooleanConfigValidator { @Override public void verify(Boolean old, Boolean value) throws IllegalArgumentException { if (value) { - LeavesLogger.LOGGER.warning("extra-yggdrasil-service is an unofficial support. Enabling it may cause data security problems!"); + LeavesLogger.LOGGER.warn("extra-yggdrasil-service is an unofficial support. Enabling it may cause data security problems!"); GlobalConfiguration.get().unsupportedSettings.performUsernameValidation = true; // always check username } } @@ -1315,7 +1318,7 @@ private static class CollisionBehaviorValidator extends EnumConfigValidator channel.pipeline().addBefore("packet_handler", PacketHandler.handlerName, new PacketHandler(channel))); } public static void updatePlayer(ServerPlayer player) { - PacketHandler handler = (PacketHandler) player.connection.connection.channel.pipeline().get(PacketHandler.handlerName); - handler.audienceHolder.setPlayer(player.getBukkitEntity()); + if (!LeavesConfig.mics.leavesPacketEvent) { + return; + } + try { + PacketHandler handler = (PacketHandler) player.connection.connection.channel.pipeline().get(PacketHandler.handlerName); + if (handler == null) { + return; + } + handler.audienceHolder.setPlayer(player.getBukkitEntity()); + } catch (Exception e) { + LeavesLogger.LOGGER.warn("Failed to inject player for bytebuf API", e); + } } public static SimpleBytebufAllocator allocator() { @@ -74,12 +88,16 @@ public static net.minecraft.network.protocol.Packet callPacketEvent(PacketAud public static void sendPacket(PacketAudience audience, PacketType type, Bytebuf bytebuf) { Channel channel = (Channel) audience.getChannel(); - Connection connection = (Connection) channel.pipeline().get("packet_handler"); + Connection connection = (Connection) channel.pipeline().get(PacketHandler.vanillaHandlerName); + if (connection == null) { + return; + } connection.send(CODEC.decode(type, ((WrappedBytebuf) bytebuf).getRegistryBuf(), audience.getPlayer() == null)); } private static class PacketHandler extends ChannelDuplexHandler { + private final static String vanillaHandlerName = "packet_handler"; private final static String handlerName = "leaves-bytebuf-handler"; private final AudienceHolder audienceHolder; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/config/GlobalConfigManager.java b/leaves-server/src/main/java/org/leavesmc/leaves/config/GlobalConfigManager.java index 36302c926..9d1402e4d 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/config/GlobalConfigManager.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/config/GlobalConfigManager.java @@ -83,7 +83,7 @@ private static void initCategory(@NotNull Field categoryField, @NotNull GlobalCo } traverseToNodeOrCreate(categoryPath.substring(CONFIG_START.length())); } catch (Exception e) { - LeavesLogger.LOGGER.severe("Failure to load leaves config" + upstreamPath, e); + LeavesLogger.LOGGER.error("Failure to load leaves config {}", upstreamPath, e); } } @@ -112,13 +112,13 @@ private static void initConfig(@NotNull Field field, GlobalConfig globalConfig, field.set(upstreamField, savedValue); } catch (IllegalArgumentException | ClassCastException e) { LeavesConfig.config.set(path, defValue); - LeavesLogger.LOGGER.warning(e.getMessage() + ", reset to " + defValue); + LeavesLogger.LOGGER.warn("{}, reset to {}", e.getMessage(), defValue); } verifiedConfigs.put(path.substring(CONFIG_START.length()), verifiedConfig); traverseToNodeOrCreate(path.substring(CONFIG_START.length())); } catch (Exception e) { - LeavesLogger.LOGGER.severe("Failure to load leaves config", e); + LeavesLogger.LOGGER.error("Failure to load leaves config", e); throw new RuntimeException(); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedConfig.java index a8dc1dae0..e96d20dda 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedConfig.java @@ -39,7 +39,7 @@ public Object get() { try { return field.get(upstreamField); } catch (IllegalAccessException e) { - LeavesLogger.LOGGER.severe("Failure to get " + path + " value", e); + LeavesLogger.LOGGER.error("Failure to get {} value", path, e); return ""; } } @@ -56,7 +56,7 @@ public String getString() { } } } catch (IllegalArgumentException e) { - LeavesLogger.LOGGER.severe("Failure to get " + path + " value", e); + LeavesLogger.LOGGER.error("Failure to get {} value", path, e); } return value.toString(); } @@ -70,7 +70,7 @@ public static VerifiedConfig build(@NotNull GlobalConfig config, @NotNull Field try { validator = createValidator(config.validator(), field); } catch (Exception e) { - LeavesLogger.LOGGER.severe("Failure to load leaves config" + path, e); + LeavesLogger.LOGGER.error("Failure to load leaves config {}", path, e); throw new RuntimeException(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedTransferConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedTransferConfig.java index 814714440..8f53d3a00 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedTransferConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/config/VerifiedTransferConfig.java @@ -23,11 +23,11 @@ public void run() { field.set(upstreamField, savedValue); LeavesConfig.config.set(path, null); } catch (IllegalAccessException | IllegalArgumentException e) { - LeavesLogger.LOGGER.warning("Failure to load leaves config" + path, e); + LeavesLogger.LOGGER.warn("Failure to load leaves config{}", path, e); } catch (ConfigTransformer.StopTransformException ignored) { } } else { - LeavesLogger.LOGGER.warning("Failed to convert saved value for " + path + ", reset to default"); + LeavesLogger.LOGGER.warn("Failed to convert saved value for {}, reset to default", path); } } } @@ -40,7 +40,7 @@ public void run() { try { transformer = createTransformer(config.transformer(), field); } catch (Exception e) { - LeavesLogger.LOGGER.warning("Failure to load leaves config transformer for " + path, e); + LeavesLogger.LOGGER.warn("Failure to load leaves config transformer for {}", path, e); } return new VerifiedTransferConfig(transformer, field, upstreamField, path); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/network/AsyncKeepaliveManager.java b/leaves-server/src/main/java/org/leavesmc/leaves/network/AsyncKeepaliveManager.java index c249daf44..76d9ba2a1 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/network/AsyncKeepaliveManager.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/network/AsyncKeepaliveManager.java @@ -5,17 +5,17 @@ import net.minecraft.util.Util; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.LeavesLogger; +import org.slf4j.Logger; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; public final class AsyncKeepaliveManager { - private static final LeavesLogger LOGGER = LeavesLogger.LOGGER; + private static final Logger LOGGER = LeavesLogger.LOGGER; private static final Map ACTIVE_LISTENERS = new ConcurrentHashMap<>(); private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(runnable -> { Thread thread = new Thread(runnable, "Leaves Async Keepalive"); @@ -36,7 +36,6 @@ public static void register(ServerCommonPacketListenerImpl listener) { if (!LeavesConfig.mics.asyncKeepalive.enable) { return; } - ACTIVE_LISTENERS.put(listener.connection, listener); } @@ -56,7 +55,7 @@ private static void tickAll() { } } catch (Throwable throwable) { ACTIVE_LISTENERS.remove(listener.connection, listener); - LOGGER.log(Level.SEVERE, "Failed to run async keepalive for connection " + listener.connection.getRemoteAddress(), throwable); + LOGGER.error("Failed to run async keepalive for connection {}", listener.connection.getRemoteAddress(), throwable); } } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/CarpetServerProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/CarpetServerProtocol.java index 318666db5..aa61591c3 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/CarpetServerProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/CarpetServerProtocol.java @@ -54,7 +54,7 @@ private static void handleHello(@NotNull ServerPlayer player, @NotNull CarpetSer if (!payload.nbt.contains(HELLO)) { return; } - LeavesLogger.LOGGER.info("Player " + player.getScoreboardName() + " joined with carpet " + payload.nbt.getString(HELLO).orElse("Unknown")); + LeavesLogger.LOGGER.info("Player {} joined with carpet {}", player.getScoreboardName(), payload.nbt.getString(HELLO).orElse("Unknown")); sendServerData(player); activePlayers.add(player); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java index 931e2a024..b1d571f0f 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LitematicaEasyPlaceProtocol.java @@ -119,7 +119,7 @@ private static > BlockState applyPlacementProtocolV3(Blo } } } catch (Exception e) { - LeavesLogger.LOGGER.warning("Exception trying to apply placement protocol value", e); + LeavesLogger.LOGGER.warn("Exception trying to apply placement protocol value", e); } if (state.getBlock() instanceof RepeaterBlock repeaterBlock) { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/PcaSyncProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/PcaSyncProtocol.java index 7a4b66db3..1d4c58747 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/PcaSyncProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/PcaSyncProtocol.java @@ -153,7 +153,7 @@ private static void syncEntityHandler(ServerPlayer player, SyncEntityPayload pay } case EVERYONE -> { } - case null -> LeavesLogger.LOGGER.warning("pcaSyncPlayerEntity wtf???"); + case null -> LeavesLogger.LOGGER.warn("pcaSyncPlayerEntity wtf???"); } } updateEntity(player, entity); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java index e60bee575..95b54639b 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java @@ -36,7 +36,7 @@ private static void handleHello(@NotNull ServerPlayer player, @NotNull BladerenH String clientVersion = payload.version; CompoundTag tag = payload.nbt; - LeavesLogger.LOGGER.info("Player " + player.getScoreboardName() + " joined with bladeren " + clientVersion); + LeavesLogger.LOGGER.info("Player {} joined with bladeren {}", player.getScoreboardName(), clientVersion); if (tag != null) { CompoundTag featureNbt = tag.getCompound("Features").orElseThrow(); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/chatimage/ServerBlockCache.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/chatimage/ServerBlockCache.java index de169073e..bf13a30d3 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/chatimage/ServerBlockCache.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/chatimage/ServerBlockCache.java @@ -27,7 +27,7 @@ public Map createBlock(ChatImageProtocol.ChatImageIndex title, this.fileCount.put(title.url(), title.total()); return blocks; } catch (Exception e) { - LeavesLogger.LOGGER.warning("Failed to create block for title " + title.url() + ": " + e); + LeavesLogger.LOGGER.warn("Failed to create block for title {}: {}", title.url(), e); return null; } } @@ -49,7 +49,7 @@ public void tryAddUser(String url, UUID uuid) { names.add(uuid); this.userCache.put(url, names); } catch (Exception e) { - LeavesLogger.LOGGER.warning("Failed to add user " + uuid + ": " + e); + LeavesLogger.LOGGER.warn("Failed to add user {}: {}", uuid, e); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java index 96f2824bf..02e853f2c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java @@ -13,6 +13,7 @@ import org.leavesmc.leaves.protocol.core.invoker.MinecraftRegisterInvokerHolder; import org.leavesmc.leaves.protocol.core.invoker.PayloadReceiverInvokerHolder; import org.leavesmc.leaves.protocol.core.invoker.PlayerInvokerHolder; +import org.slf4j.Logger; import java.io.File; import java.io.IOException; @@ -37,7 +38,7 @@ public class LeavesProtocolManager { - private static final LeavesLogger LOGGER = LeavesLogger.LOGGER; + private static final Logger LOGGER = LeavesLogger.LOGGER; private static final Map, PayloadReceiverInvokerHolder> PAYLOAD_RECEIVERS = new HashMap<>(); private static final Map, Identifier> IDS = new HashMap<>(); @@ -94,7 +95,7 @@ public static void init() { constructor.setAccessible(true); protocol = (LeavesProtocol) constructor.newInstance(); } catch (Throwable throwable) { - LOGGER.severe("Failed to load class " + clazz.getName() + ". " + throwable); + LOGGER.error("Failed to load class {}. {}", clazz.getName(), throwable); return; } @@ -110,7 +111,7 @@ public static void init() { try { holder.invoke(); } catch (RuntimeException exception) { - LOGGER.severe("Failed to invoke init method " + method.getName() + " in " + clazz.getName() + ", " + exception.getCause() + ": " + exception.getMessage()); + LOGGER.error("Failed to invoke init method {} in {}, {}: {}", method.getName(), clazz.getName(), exception.getCause(), exception.getMessage()); } continue; } @@ -208,7 +209,7 @@ public static LeavesCustomPayload decode(Identifier location, FriendlyByteBuf bu try { return codec.decode(ProtocolUtils.decorate(buf)); } catch (Exception e) { - LOGGER.severe("Failed to decode payload " + location, e); + LOGGER.error("Failed to decode payload {}", location, e); throw e; } } @@ -223,7 +224,7 @@ public static void encode(FriendlyByteBuf buf, LeavesCustomPayload payload) { buf.writeIdentifier(location); codec.encode(ProtocolUtils.decorate(buf), payload); } catch (Exception e) { - LOGGER.severe("Failed to encode payload " + location, e); + LOGGER.error("Failed to encode payload {}", location, e); throw e; } } @@ -347,12 +348,12 @@ public static Set> getClasses(String pack) { Enumeration entries = jar.entries(); findClassesInPackageByJar(pack, entries, packageDirName, classes); } catch (IOException exception) { - LOGGER.warning("Failed to load jar file, " + exception.getCause() + ": " + exception.getMessage()); + LOGGER.warn("Failed to load jar file, {}: {}", exception.getCause(), exception.getMessage()); } } } } catch (IOException exception) { - LOGGER.warning("Failed to load classes, " + exception.getCause() + ": " + exception.getMessage()); + LOGGER.warn("Failed to load classes, {}: {}", exception.getCause(), exception.getMessage()); } return classes; } @@ -372,7 +373,7 @@ private static void findClassesInPackageByFile(String packageName, String packag try { classes.add(Class.forName(packageName + '.' + className)); } catch (ClassNotFoundException exception) { - LOGGER.warning("Failed to load class " + className + ", " + exception.getCause() + ": " + exception.getMessage()); + LOGGER.warn("Failed to load class {}, {}: {}", className, exception.getCause(), exception.getMessage()); } } } @@ -396,7 +397,7 @@ private static void findClassesInPackageByJar(String packageName, Enumeration void throwOrLog(Exception e) throws T { + Throwable t = e instanceof InvocationTargetException ex ? ex.getTargetException() : e; + if (LeavesConfig.protocol.strictMode) { + throw (T) t; + } + LeavesLogger.LOGGER.error("Exception on invoking protocol ", t); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java index 3e07913ff..7dcd40e41 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java @@ -186,7 +186,7 @@ public static void requestEntityData(ServerPlayer player, RequestEntityPayload p try { provider.appendServerData(tag, accessor); } catch (Exception e) { - LeavesLogger.LOGGER.warning("Error while saving data for entity " + entity); + LeavesLogger.LOGGER.warn("Error while saving data for entity {}", entity); } } tag.putInt("EntityId", entity.getId()); @@ -230,7 +230,7 @@ public static void requestBlockData(ServerPlayer player, RequestBlockPayload pay try { provider.appendServerData(tag, accessor); } catch (Exception e) { - LeavesLogger.LOGGER.warning("Error while saving data for block " + accessor.getBlockState()); + LeavesLogger.LOGGER.warn("Error while saving data for block {}", accessor.getBlockState()); } } NbtUtils.writeBlockPosToTag(pos, tag); @@ -256,7 +256,7 @@ private static void rebuildShearableBlocks() { )); } catch (Throwable ignore) { shearableBlocks = List.of(); - LeavesLogger.LOGGER.severe("Failed to collect shearable blocks"); + LeavesLogger.LOGGER.error("Failed to collect shearable blocks"); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java index d04ec3fef..266f52ee8 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/provider/ItemStorageExtensionProvider.java @@ -126,7 +126,7 @@ public List> getGroups(Accessor request) { try { itemCollector = targetCache.get(target, () -> createItemCollector(request)); } catch (ExecutionException e) { - LeavesLogger.LOGGER.severe("Failed to get item collector for " + target); + LeavesLogger.LOGGER.error("Failed to get item collector for {}", target); return null; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/CommonUtil.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/CommonUtil.java index eb635d0eb..33aa5021e 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/CommonUtil.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/CommonUtil.java @@ -45,7 +45,7 @@ public static Map.Entry>> getServerExtensionDa try { groups = provider.getGroups(accessor); } catch (Exception e) { - LeavesLogger.LOGGER.severe(e.toString()); + LeavesLogger.LOGGER.error(e.toString()); continue; } if (groups != null) { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/HierarchyLookup.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/HierarchyLookup.java index 940e33d35..4be10d1b0 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/HierarchyLookup.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/HierarchyLookup.java @@ -80,7 +80,7 @@ public List get(Class clazz) { return list; }); } catch (ExecutionException e) { - LeavesLogger.LOGGER.warning("HierarchyLookup error", e); + LeavesLogger.LOGGER.warn("HierarchyLookup error", e); } return List.of(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/PairHierarchyLookup.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/PairHierarchyLookup.java index 03ae640db..fb3e85e45 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/PairHierarchyLookup.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/PairHierarchyLookup.java @@ -47,7 +47,7 @@ public List getMerged(Object first, Object second) { return ImmutableList.sortedCopyOf(COMPARATOR, Iterables.concat(firstList, secondList)); }); } catch (ExecutionException e) { - LeavesLogger.LOGGER.severe(e.toString()); + LeavesLogger.LOGGER.error(e.toString()); } return List.of(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/PacketTransformer.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/PacketTransformer.java index ee825c09a..627c94e6f 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/PacketTransformer.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/PacketTransformer.java @@ -43,17 +43,17 @@ public void inbound(Identifier id, RegistryFriendlyByteBuf buf, ServerPlayer pla int partsNum = buf.readInt(); data = new PartData(id, partsNum); if (cache.put(key, data) != null) { - LeavesLogger.LOGGER.warning("Received invalid START packet for SplitPacketTransformer with packet id " + id); + LeavesLogger.LOGGER.warn("Received invalid START packet for SplitPacketTransformer with packet id {}", id); } buf.retain(); data.parts.add(buf); } case PART -> { if ((data = cache.get(key)) == null) { - LeavesLogger.LOGGER.warning("Received invalid PART packet for SplitPacketTransformer with packet id " + id); + LeavesLogger.LOGGER.warn("Received invalid PART packet for SplitPacketTransformer with packet id {}", id); buf.release(); } else if (!data.id.equals(id)) { - LeavesLogger.LOGGER.warning("Received invalid PART packet for SplitPacketTransformer with packet id " + id + ", id in cache is {}" + data.id); + LeavesLogger.LOGGER.warn("Received invalid PART packet for SplitPacketTransformer with packet id {}, id in cache is {}", id, data.id); buf.release(); for (RegistryFriendlyByteBuf part : data.parts) { if (part != buf) { @@ -68,10 +68,10 @@ public void inbound(Identifier id, RegistryFriendlyByteBuf buf, ServerPlayer pla } case END -> { if ((data = cache.get(key)) == null) { - LeavesLogger.LOGGER.warning("Received invalid END packet for SplitPacketTransformer with packet id {}" + id); + LeavesLogger.LOGGER.warn("Received invalid END packet for SplitPacketTransformer with packet id {}", id); buf.release(); } else if (!data.id.equals(id)) { - LeavesLogger.LOGGER.warning("Received invalid END packet for SplitPacketTransformer with packet id " + id + ", id in cache is {}" + data.id); + LeavesLogger.LOGGER.warn("Received invalid END packet for SplitPacketTransformer with packet id {}, id in cache is{}", id, data.id); buf.release(); for (RegistryFriendlyByteBuf part : data.parts) { if (part != buf) { @@ -87,7 +87,7 @@ public void inbound(Identifier id, RegistryFriendlyByteBuf buf, ServerPlayer pla return; } if (data.parts.size() != data.partsNum) { - LeavesLogger.LOGGER.warning("Received invalid END packet for SplitPacketTransformer with packet id " + id + " with size " + data.parts + ", parts expected is {}" + data.partsNum); + LeavesLogger.LOGGER.warn("Received invalid END packet for SplitPacketTransformer with packet id {} with size {}, parts expected is {}", id, data.parts, data.partsNum); for (RegistryFriendlyByteBuf part : data.parts) { if (part != buf) { part.release(); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java index 2d4fed33e..97e0616f8 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java @@ -329,17 +329,17 @@ public static void handleMoveItem(ServerPlayer player, RegistryFriendlyByteBuf b player.sendSystemMessage(Component.translatable(e.getMessage()).withStyle(ChatFormatting.RED)); } catch (Exception e) { player.sendSystemMessage(Component.translatable("error.rei.internal.error", e.getMessage()).withStyle(ChatFormatting.RED)); - LeavesLogger.LOGGER.severe("Failed to move items for player " + player.getScoreboardName(), e); + LeavesLogger.LOGGER.error("Failed to move items for player {}", player.getScoreboardName(), e); } }); } catch (IllegalStateException e) { player.sendSystemMessage(Component.translatable(e.getMessage()).withStyle(ChatFormatting.RED)); } catch (Exception e) { player.sendSystemMessage(Component.translatable("error.rei.internal.error", e.getMessage()).withStyle(ChatFormatting.RED)); - LeavesLogger.LOGGER.severe("Failed to move items for player " + player.getScoreboardName(), e); + LeavesLogger.LOGGER.error("Failed to move items for player {}", player.getScoreboardName(), e); } } catch (Exception e) { - LeavesLogger.LOGGER.severe("Failed to move items for player " + player.getScoreboardName(), e); + LeavesLogger.LOGGER.error("Failed to move items for player {}", player.getScoreboardName(), e); } }; inboundTransform(player, MOVE_ITEMS_NEW_PACKET, buf, consumer); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DisplaySyncPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DisplaySyncPayload.java index 0a1f41797..b7ad8084b 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DisplaySyncPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DisplaySyncPayload.java @@ -37,7 +37,7 @@ public void encode(@NotNull RegistryFriendlyByteBuf buf, @NotNull Display displa } catch (Exception e) { tmpBuf.release(); buf.writeBoolean(false); - LeavesLogger.LOGGER.warning("Failed to encode display: " + display, e); + LeavesLogger.LOGGER.warn("Failed to encode display: {}", display, e); return; } buf.writeBoolean(true); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java index 1accca79b..553935b46 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxEntityDataProtocol.java @@ -65,7 +65,7 @@ public static void onPacketReceive(ServerPlayer player, EntityDataPayload payloa if (fullPacket != null) { readingSessionKeys.remove(uuid); - LeavesLogger.LOGGER.warning("ServuxEntityDataProtocol,PACKET_C2S_NBT_RESPONSE_DATA NOT Implemented!"); + LeavesLogger.LOGGER.warn("ServuxEntityDataProtocol,PACKET_C2S_NBT_RESPONSE_DATA NOT Implemented!"); } } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java index c495f9e92..3eafd1b02 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/servux/ServuxStructuresProtocol.java @@ -118,7 +118,7 @@ public static void onPlayerSubscribed(@NotNull ServerPlayer player) { if (!players.containsKey(player.getId())) { players.put(player.getId(), player); } else { - LeavesLogger.LOGGER.warning(player.getScoreboardName() + " re-register servux:structures"); + LeavesLogger.LOGGER.warn(player.getScoreboardName() + " re-register servux:structures"); } MinecraftServer server = getServer(); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java index 3c6c3ecf1..88d929d84 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.block.Rotation; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; +import org.leavesmc.leaves.LeavesLogger; import org.leavesmc.leaves.protocol.core.LeavesProtocol; import org.leavesmc.leaves.protocol.core.ProtocolHandler; import org.leavesmc.leaves.protocol.syncmatica.exchange.DownloadExchange; @@ -109,7 +110,7 @@ protected static void handle(ExchangeTarget source, @NotNull Identifier id, Frie try { upload = new UploadExchange(placement, toUpload, source); } catch (final FileNotFoundException e) { - e.printStackTrace(); + LeavesLogger.LOGGER.error(e.toString()); return; } startExchange(upload); @@ -137,7 +138,7 @@ protected static void handle(ExchangeTarget source, @NotNull Identifier id, Frie try { download(placement, source); } catch (final Exception e) { - e.printStackTrace(); + LeavesLogger.LOGGER.error(e.toString()); } return; } @@ -169,6 +170,10 @@ protected static void handle(ExchangeTarget source, @NotNull Identifier id, Frie if (id.equals(PacketType.MODIFY_REQUEST.identifier)) { final UUID placementId = packetBuf.readUUID(); final ModifyExchangeServer modifier = new ModifyExchangeServer(placementId, source); + if (modifier.getPlacement() == null) { + LeavesLogger.LOGGER.warn("Could not find placement for modify request {}", placementId); + return; + } startExchange(modifier); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ModifyExchangeServer.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ModifyExchangeServer.java index bb3a09699..8d6c3df1f 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ModifyExchangeServer.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/syncmatica/exchange/ModifyExchangeServer.java @@ -75,6 +75,9 @@ public ServerPlacement getPlacement() { @Override protected void onClose() { + if (placement == null) { + return; + } if (CommunicationManager.getModifier(placement) == this) { CommunicationManager.setModifier(placement, null); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/region/linear/LinearRegionFile.java b/leaves-server/src/main/java/org/leavesmc/leaves/region/linear/LinearRegionFile.java index 1bd20ec80..da48676c4 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/region/linear/LinearRegionFile.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/region/linear/LinearRegionFile.java @@ -179,11 +179,9 @@ private void openRegionFile() { parseLinearV2(buffer); } else { LOGGER.error("Invalid version {} in region file {}", version, this.regionFile); - return; } } catch (IOException e) { LOGGER.error("Failed to open region file {}", this.regionFile, e); - return; } finally { writeLock.unlock(); } @@ -223,9 +221,9 @@ private void parseLinearV1(ByteBuffer buffer) throws IOException { byte[] chunkData = new byte[size]; decompressedBuffer.get(chunkData); - int maxCompressedLength = this.compressor.maxCompressedLength(size); + int maxCompressedLength = compressor.maxCompressedLength(size); byte[] compressed = new byte[maxCompressedLength]; - int compressedLength = this.compressor.compress(chunkData, 0, size, compressed, 0, maxCompressedLength); + int compressedLength = compressor.compress(chunkData, 0, size, compressed, 0, maxCompressedLength); byte[] finalCompressed = new byte[compressedLength]; System.arraycopy(compressed, 0, finalCompressed, 0, compressedLength); @@ -382,7 +380,7 @@ private void flushLinearV1() throws IOException { if (this.bufferUncompressedSize[i] != 0) { chunkCount += 1; byte[] content = new byte[bufferUncompressedSize[i]]; - this.decompressor.decompress(buffer[i], 0, content, 0, bufferUncompressedSize[i]); + decompressor.decompress(buffer[i], 0, content, 0, bufferUncompressedSize[i]); byteBuffers.add(content); } else { @@ -475,7 +473,7 @@ private void flushLinearV2() throws IOException { if (this.bufferUncompressedSize[chunkIndex] > 0) { hasData = true; byte[] chunkData = new byte[this.bufferUncompressedSize[chunkIndex]]; - this.decompressor.decompress(this.buffer[chunkIndex], 0, chunkData, 0, this.bufferUncompressedSize[chunkIndex]); + decompressor.decompress(this.buffer[chunkIndex], 0, chunkData, 0, this.bufferUncompressedSize[chunkIndex]); bucketDataStream.writeInt(chunkData.length + 8); bucketDataStream.writeLong(this.chunkTimestamps[chunkIndex]); bucketDataStream.write(chunkData); @@ -567,9 +565,9 @@ private void openBucket(int chunkX, int chunkZ) { byte[] chunkData = new byte[chunkSize - 8]; bucketBuffer.get(chunkData); - int maxCompressedLength = this.compressor.maxCompressedLength(chunkData.length); + int maxCompressedLength = compressor.maxCompressedLength(chunkData.length); byte[] compressed = new byte[maxCompressedLength]; - int compressedLength = this.compressor.compress(chunkData, 0, chunkData.length, compressed, 0, maxCompressedLength); + int compressedLength = compressor.compress(chunkData, 0, chunkData.length, compressed, 0, maxCompressedLength); byte[] finalCompressed = new byte[compressedLength]; System.arraycopy(compressed, 0, finalCompressed, 0, compressedLength); @@ -585,7 +583,7 @@ private void openBucket(int chunkX, int chunkZ) { } bucketBuffers[idx] = null; } - }finally { + } finally { readLock.unlock(); } } @@ -604,9 +602,9 @@ public void write(ChunkPos pos, ByteBuffer buffer) { LOGGER.error("Chunk dupe attempt {}", this.regionFile); clear(pos); } else { - int maxCompressedLength = this.compressor.maxCompressedLength(b.length); + int maxCompressedLength = compressor.maxCompressedLength(b.length); byte[] compressed = new byte[maxCompressedLength]; - int compressedLength = this.compressor.compress(b, 0, b.length, compressed, 0, maxCompressedLength); + int compressedLength = compressor.compress(b, 0, b.length, compressed, 0, maxCompressedLength); b = new byte[compressedLength]; System.arraycopy(compressed, 0, b, 0, compressedLength); @@ -680,7 +678,7 @@ public DataInputStream getChunkDataInputStream(ChunkPos pos) { if (this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] != 0) { byte[] content = new byte[bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]]; - this.decompressor.decompress(this.buffer[getChunkIndex(pos.x, pos.z)], 0, content, 0, bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]); + decompressor.decompress(this.buffer[getChunkIndex(pos.x, pos.z)], 0, content, 0, bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]); return new DataInputStream(new ByteArrayInputStream(content)); } return null; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/replay/RecordMetaData.java b/leaves-server/src/main/java/org/leavesmc/leaves/replay/RecordMetaData.java index 0e8cd7e87..f8f617557 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/replay/RecordMetaData.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/replay/RecordMetaData.java @@ -1,8 +1,8 @@ package org.leavesmc.leaves.replay; -import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class RecordMetaData { @@ -19,5 +19,5 @@ public class RecordMetaData { public String generator; public int selfId = -1; - public Set players = new HashSet<>(); + public Set players = ConcurrentHashMap.newKeySet(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/replay/Recorder.java b/leaves-server/src/main/java/org/leavesmc/leaves/replay/Recorder.java index 76b70cc81..0f56f2171 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/replay/Recorder.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/replay/Recorder.java @@ -41,6 +41,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.leavesmc.leaves.LeavesLogger; +import org.slf4j.Logger; import java.io.File; import java.io.IOException; @@ -56,7 +57,7 @@ public class Recorder extends Connection { - public static final LeavesLogger LOGGER = LeavesLogger.LOGGER; + public static final Logger LOGGER = LeavesLogger.LOGGER; public final ExecutorService saveService = Executors.newSingleThreadExecutor(); private final ReplayFile replayFile; @@ -224,7 +225,7 @@ private void saveMetadata() { try { replayFile.saveMetaData(metaData); } catch (IOException e) { - LOGGER.severe("Error saving metadata", e); + LOGGER.error("Error saving metadata", e); } }); } @@ -238,7 +239,7 @@ private void savePacket(Packet packet, final ConnectionProtocol protocol) { try { replayFile.savePacket(timestamp, packet, protocol); } catch (Exception e) { - LOGGER.severe("Error saving packet on thread " + Thread.currentThread() + ". Are you using some plugin that modify data asynchronously?", e); + LOGGER.error("Error saving packet on thread {}. Are you using some plugin that modify data asynchronously?", Thread.currentThread(), e); } } @@ -248,7 +249,7 @@ public boolean isSaved() { public CompletableFuture saveRecording(File dest, boolean save) { if (!isSaving.compareAndSet(false, true)) { - LOGGER.warning("saveRecording() called twice"); + LOGGER.warn("saveRecording() called twice"); return CompletableFuture.failedFuture(new IllegalStateException("saveRecording() called twice")); } isSaved = true; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/replay/ReplayFile.java b/leaves-server/src/main/java/org/leavesmc/leaves/replay/ReplayFile.java index cc07fe665..74d59f3a7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/replay/ReplayFile.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/replay/ReplayFile.java @@ -120,7 +120,7 @@ public void savePacket(long timestamp, Packet packet, ConnectionProtocol prot packetStream.writeInt(data.length); packetStream.write(data); } catch (Exception e) { - LOGGER.severe("Error saving packet", e); + LOGGER.error("Error saving packet", e); } }); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java b/leaves-server/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java index 240afb93d..0782f0442 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java @@ -69,7 +69,7 @@ public static ServerPhotographer createPhotographer(@NotNull PhotographerCreateS photographer.setInvisible(true); photographers.add(photographer); - LeavesLogger.LOGGER.info("Photographer " + state.id + " created"); + LeavesLogger.LOGGER.info("Photographer {} created", state.id); // TODO record distance @@ -135,7 +135,7 @@ public void remove(boolean async, boolean save) { this.recorder.stop(); getServer().getPlayerList().removePhotographer(this); - LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed"); + LeavesLogger.LOGGER.info("Photographer {} removed", createState.id); if (!recorder.isSaved()) { CompletableFuture future = recorder.saveRecording(saveFile, save); @@ -222,7 +222,7 @@ public ServerPhotographer createSync() { try { return createPhotographer(this); } catch (IOException e) { - e.printStackTrace(); + LeavesLogger.LOGGER.error(e.toString()); } return null; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/util/LeavesUpdateHelper.java b/leaves-server/src/main/java/org/leavesmc/leaves/util/LeavesUpdateHelper.java index a966bcbff..43f942d47 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/util/LeavesUpdateHelper.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/util/LeavesUpdateHelper.java @@ -51,7 +51,7 @@ public static void init() { File workingDirFile = new File(autoUpdateDir); if (!workingDirFile.exists()) { if (!workingDirFile.mkdir()) { - LeavesLogger.LOGGER.warning("Failed to create working directory: " + autoUpdateDir); + LeavesLogger.LOGGER.warn("Failed to create working directory: {}", autoUpdateDir); } } @@ -62,14 +62,14 @@ public static void init() { throw new IOException(); } } catch (IOException e) { - LeavesLogger.LOGGER.severe("Failed to create core path file: " + corePathFileName, e); + LeavesLogger.LOGGER.error("Failed to create core path file: {}", corePathFileName, e); } } File leavesUpdateDir = new File(autoUpdateDir + File.separator + "leaves"); if (!leavesUpdateDir.exists()) { if (!leavesUpdateDir.mkdir()) { - LeavesLogger.LOGGER.warning("Failed to create leaves update directory: " + leavesUpdateDir); + LeavesLogger.LOGGER.warn("Failed to create leaves update directory: {}", leavesUpdateDir); } } @@ -86,7 +86,7 @@ public static void init() { } autoUpdateExecutor.scheduleAtFixedRate(LeavesUpdateHelper::tryUpdateLeaves, task.toMillis(), dailyTaskPeriod, TimeUnit.MILLISECONDS); } catch (Exception ignored) { - LeavesLogger.LOGGER.warning("Illegal auto-update time ignored: " + time); + LeavesLogger.LOGGER.warn("Illegal auto-update time ignored: {}", time); } } } @@ -112,18 +112,18 @@ private static void downloadLeaves() { return; } - LeavesLogger.LOGGER.info("Now gitHash: " + version.gitCommit().get()); + LeavesLogger.LOGGER.info("Now gitHash: {}", version.gitCommit().get()); LeavesLogger.LOGGER.info("Trying to get latest build info."); LeavesBuildInfo buildInfo = getLatestBuildInfo(version.minecraftVersionId(), version.gitCommit().get()); if (buildInfo != LeavesBuildInfo.ERROR) { if (!buildInfo.needUpdate) { - LeavesLogger.LOGGER.warning("You are running the latest version, stopping update."); + LeavesLogger.LOGGER.warn("You are running the latest version, stopping update."); updateTaskStarted = false; return; } - LeavesLogger.LOGGER.info("Got build info, trying to download " + buildInfo.fileName); + LeavesLogger.LOGGER.info("Got build info, trying to download {}", buildInfo.fileName); try { Path outFile = Path.of(autoUpdateDir, "leaves", buildInfo.fileName + ".cache"); Files.deleteIfExists(outFile); @@ -135,16 +135,16 @@ private static void downloadLeaves() { final FileChannel fileChannel = FileChannel.open(outFile, CREATE, WRITE, TRUNCATE_EXISTING) ) { fileChannel.transferFrom(source, 0, Long.MAX_VALUE); - LeavesLogger.LOGGER.info("Download " + buildInfo.fileName + " completed."); + LeavesLogger.LOGGER.info("Download {} completed.", buildInfo.fileName); } catch (final IOException e) { - LeavesLogger.LOGGER.warning("Download " + buildInfo.fileName + " failed.", e); + LeavesLogger.LOGGER.warn("Download {} failed.", buildInfo.fileName, e); Files.deleteIfExists(outFile); updateTaskStarted = false; return; } if (!isFileValid(outFile, buildInfo.sha256)) { - LeavesLogger.LOGGER.warning("Hash check failed for downloaded file " + buildInfo.fileName); + LeavesLogger.LOGGER.warn("Hash check failed for downloaded file {}", buildInfo.fileName); Files.deleteIfExists(outFile); updateTaskStarted = false; return; @@ -157,17 +157,17 @@ private static void downloadLeaves() { try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(corePathFileName))) { bufferedWriter.write(autoUpdateDir + File.separator + "leaves" + File.separator + buildInfo.fileName); } catch (IOException e) { - LeavesLogger.LOGGER.warning("Fail to download leaves core", e); + LeavesLogger.LOGGER.warn("Fail to download leaves core", e); updateTaskStarted = false; return; } LeavesLogger.LOGGER.info("Leaves update completed, please restart your server."); } catch (Exception e) { - LeavesLogger.LOGGER.severe("Leaves update failed", e); + LeavesLogger.LOGGER.error("Leaves update failed", e); } } else { - LeavesLogger.LOGGER.warning("Stopping update."); + LeavesLogger.LOGGER.warn("Stopping update."); } updateTaskStarted = false; } @@ -183,7 +183,7 @@ private static boolean isFileValid(Path file, String hash) { return toHexString(md5.digest()).equals(hash); } catch (Exception e) { - LeavesLogger.LOGGER.warning("Fail to validate file " + file, e); + LeavesLogger.LOGGER.warn("Fail to validate file {}", file, e); } return false; } @@ -210,7 +210,7 @@ private static LeavesBuildInfo getLatestBuildInfo(String mcVersion, String gitHa JsonObject obj = new Gson().fromJson(reader, JsonObject.class); String channel = obj.get("channel").getAsString(); if ("experimental".equals(channel) && !LeavesConfig.mics.autoUpdate.allowExperimental) { - LeavesLogger.LOGGER.warning("Experimental version is not allowed to update for default, if you really want to update, please set misc.auto-update.allow-experimental to true in leaves.yml"); + LeavesLogger.LOGGER.warn("Experimental version is not allowed to update for default, if you really want to update, please set misc.auto-update.allow-experimental to true in leaves.yml"); return LeavesBuildInfo.ERROR; } int build = obj.get("build").getAsInt(); @@ -230,11 +230,11 @@ private static LeavesBuildInfo getLatestBuildInfo(String mcVersion, String gitHa String url = "https://api.leavesmc.org/v2/projects/leaves/versions/" + mcVersion + "/builds/" + build + "/downloads/"; return new LeavesBuildInfo(build, fileName, sha256, needUpdate, url); } catch (JsonSyntaxException | NumberFormatException e) { - LeavesLogger.LOGGER.warning("Fail to get latest build info", e); + LeavesLogger.LOGGER.warn("Fail to get latest build info", e); return LeavesBuildInfo.ERROR; } } catch (IOException | URISyntaxException e) { - LeavesLogger.LOGGER.warning("Fail to get latest build info", e); + LeavesLogger.LOGGER.warn("Fail to get latest build info", e); return LeavesBuildInfo.ERROR; } }