Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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!");
}
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -1315,7 +1318,7 @@ private static class CollisionBehaviorValidator extends EnumConfigValidator<Coll
@Override
public CollisionBehavior stringConvert(@NotNull String value) throws IllegalArgumentException {
if (value.equalsIgnoreCase("BLOCK_SHAPE_VANILLA")) {
LeavesLogger.LOGGER.warning("Paper has updated the collision behavior to BLOCK_SHAPE_VANILLA mode, converting this to PAPER...");
LeavesLogger.LOGGER.warn("Paper has updated the collision behavior to BLOCK_SHAPE_VANILLA mode, converting this to PAPER...");
value = "PAPER";
}
return super.stringConvert(value);
Expand Down
25 changes: 5 additions & 20 deletions leaves-server/src/main/java/org/leavesmc/leaves/LeavesLogger.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
package org.leavesmc.leaves;

import org.bukkit.Bukkit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.logging.Level;
import java.util.logging.Logger;
public class LeavesLogger {

public class LeavesLogger extends Logger {
public static final LeavesLogger LOGGER = new LeavesLogger();

private LeavesLogger() {
super("Leaves", null);
setParent(Bukkit.getLogger());
setLevel(Level.ALL);
}

public void severe(String msg, Exception exception) {
this.log(Level.SEVERE, msg, exception);
}

public void warning(String msg, Exception exception) {
this.log(Level.WARNING, msg, exception);
}
}
public static final Logger LOGGER = LoggerFactory.getLogger("Leaves");
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class BotDataStorage {
private final File botDir;
private final File botListFile;

private CompoundTag savedBotList;
private final CompoundTag savedBotList;

public BotDataStorage(LevelStorageSource.@NotNull LevelStorageAccess session, String dataDir, String listFileName) {
this.botDir = session.getLevelPath(new LevelResource(dataDir)).toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -449,7 +448,7 @@ public void readAdditionalSaveData(@NotNull ValueInput nbt) {
for (CompoundTag configTag : configNbt) {
String key = configTag.getString("configName").orElseThrow();
if (!this.configs.containsKey(key)) {
LeavesLogger.LOGGER.warning("Trying to load a unknown config \"" + key + "\", discard.");
LeavesLogger.LOGGER.warn("Trying to load a unknown config \"{}\", discard.", key);
continue;
}
this.configs.get(key).load(configTag);
Expand All @@ -475,7 +474,7 @@ public void sendFakeData(ServerPlayerConnection playerConnection, boolean login)
ChunkMap.TrackedEntity entityTracker = this.level().getChunkSource().chunkMap.entityMap.get(this.getId());

if (entityTracker == null) {
LeavesLogger.LOGGER.warning("Fakeplayer cant get entity tracker for " + this.getId());
LeavesLogger.LOGGER.warn("Fakeplayer cant get entity tracker for {}", this.getId());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void tryTick(ServerBot bot) {
e.providePlayer(bot);
e.consume();
} catch (Exception e) {
LeavesLogger.LOGGER.severe("An error occurred while executing bot " + bot.displayName + ", action " + this.name, e);
LeavesLogger.LOGGER.error("An error occurred while executing bot {}, action {}", bot.displayName, this.name, e);
}

if (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.LeavesLogger;
import org.leavesmc.leaves.bytebuf.Bytebuf;
import org.leavesmc.leaves.bytebuf.PacketAudience;
import org.leavesmc.leaves.bytebuf.PacketFlow;
Expand All @@ -34,13 +35,26 @@ public class InternalBytebufHandler {
private static final UniversalCodec CODEC = new UniversalCodec();

public static void init() {
if (!LeavesConfig.mics.leavesPacketEvent) {
return;
}
ChannelInitializeListenerHolder.addListener(Key.key("leaves:bytebuf"), channel ->
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() {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<VALUE ERROR>";
}
}
Expand All @@ -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();
}
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, ServerCommonPacketListenerImpl> ACTIVE_LISTENERS = new ConcurrentHashMap<>();
private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(runnable -> {
Thread thread = new Thread(runnable, "Leaves Async Keepalive");
Expand All @@ -36,7 +36,6 @@ public static void register(ServerCommonPacketListenerImpl listener) {
if (!LeavesConfig.mics.asyncKeepalive.enable) {
return;
}

ACTIVE_LISTENERS.put(listener.connection, listener);
}

Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static <T extends Comparable<T>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Map<Integer, String> 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;
}
}
Expand All @@ -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);
}
}

Expand Down
Loading
Loading