fixed logger issues #156 and #155

This commit is contained in:
gnembon committed 2020-02-23 02:25:51 -04:00
1 parent 56d681560a
commit 72a7bed11a
9 files changed
+95 -29

No files matched your search

@@ -49,4 +49,6 @@ public interface CarpetExtension
default void onServerClosed(MinecraftServer server) {}
default String version() {return null;}
default void registerLoggers() {}
}
+6 -1
View File
@@ -41,7 +41,6 @@ public class CarpetServer // static for now - easier to handle all around the co
public static void onGameStarted()
{
LoggerRegistry.initLoggers();
settingsManager = new SettingsManager(CarpetSettings.carpetVersion, "carpet", "Carpet Mod");
settingsManager.parseSettingsClass(CarpetSettings.class);
extensions.forEach(CarpetExtension::onGameStarted);
@@ -59,6 +58,7 @@ public class CarpetServer // static for now - easier to handle all around the co
scriptServer = new CarpetScriptServer();
scriptServer.loadAllWorldScripts();
MobAI.resetTrackers();
LoggerRegistry.initLoggers();
}
public static void tick(MinecraftServer server)
@@ -117,5 +117,10 @@ public class CarpetServer // static for now - easier to handle all around the co
LoggerRegistry.stopLoggers();
extensions.forEach(e -> e.onServerClosed(server));
}
public static void registerExtensionLoggers()
{
extensions.forEach(CarpetExtension::registerLoggers);
}
}
+17 -4
View File
@@ -1,16 +1,29 @@
package carpet.logging;
import carpet.utils.HUDController;
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import java.lang.reflect.Field;
public class HUDLogger extends Logger
{
public HUDLogger(String logName, String def, String[] options)
static Logger stardardHUDLogger(String logName, String def, String [] options)
{
super(logName, def, options);
// should convert to factory method if more than 2 classes are here
try
{
return new HUDLogger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
}
catch (NoSuchFieldException e)
{
throw new RuntimeException("Failed to create logger "+logName);
}
}
public HUDLogger(Field field, String logName, String def, String[] options)
{
super(field, logName, def, options);
}
@Override
+25 -2
View File
@@ -6,6 +6,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -28,13 +29,30 @@ public class Logger
private String[] options;
public Logger(String logName, String def, String [] options)
private Field acceleratorField;
static Logger stardardLogger(String logName, String def, String [] options)
{
try
{
return new Logger(LoggerRegistry.class.getField("__"+logName), logName, def, options);
}
catch (NoSuchFieldException e)
{
throw new RuntimeException("Failed to create logger "+logName);
}
}
public Logger(Field acceleratorField, String logName, String def, String [] options)
{
subscribedOnlinePlayers = new HashMap<>();
subscribedOfflinePlayers = new HashMap<>();
this.acceleratorField = acceleratorField;
this.logName = logName;
this.default_option = def;
this.options = options;
if (acceleratorField == null)
CarpetSettings.LOG.error("[CM] Logger "+getLogName()+" is missing a specified accelerator");
}
public String getDefault()
@@ -94,6 +112,11 @@ public class Logger
subscribedOfflinePlayers.clear();
}
public Field getField()
{
return acceleratorField;
}
/**
* serves messages to players fetching them from the promise
* will repeat invocation for players that share the same option
@@ -185,7 +208,7 @@ public class Logger
Set<String> loggingOptions = new HashSet<>(Arrays.asList(CarpetSettings.defaultLoggers.split(",")));
if (loggingOptions.contains(getLogName()))
{
subscribedOnlinePlayers.put(playerName, getDefault());
LoggerRegistry.subscribePlayer(playerName, getLogName(), getDefault());
}
}
LoggerRegistry.setAccess(this);
@@ -1,5 +1,6 @@
package carpet.logging;
import carpet.CarpetServer;
import carpet.CarpetSettings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
@@ -32,18 +33,26 @@ public class LoggerRegistry
public static void initLoggers()
{
registerLogger("tnt", new Logger("tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",new Logger("fallingBlocks", "brief", new String[]{"brief", "full"}));
stopLoggers();
registerLoggers();
CarpetServer.registerExtensionLoggers();
}
public static void registerLoggers()
{
registerLogger("tnt", Logger.stardardLogger( "tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", Logger.stardardLogger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",Logger.stardardLogger("fallingBlocks", "brief", new String[]{"brief", "full"}));
//registerLogger("kills", new Logger("kills", null, null));
//registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
//registerLogger("weather", new Logger("weather", null, null));
registerLogger( "pathfinding", new Logger("pathfinding", "20", new String[]{"2", "5", "10"}));
registerLogger( "pathfinding", Logger.stardardLogger("pathfinding", "20", new String[]{"2", "5", "10"}));
registerLogger("tps", HUDLogger.stardardHUDLogger("tps", null, null));
registerLogger("packets", HUDLogger.stardardHUDLogger("packets", null, null));
registerLogger("counter",HUDLogger.stardardHUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", HUDLogger.stardardHUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
registerLogger("tps", new HUDLogger("tps", null, null));
registerLogger("packets", new HUDLogger("packets", null, null));
registerLogger("counter",new HUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", new HUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
}
/**
@@ -117,22 +126,18 @@ public class LoggerRegistry
boolean value = logger.hasOnlineSubscribers();
try
{
Field f = LoggerRegistry.class.getDeclaredField("__"+name);
Field f = logger.getField();
f.setBoolean(null, value);
}
catch (IllegalAccessException e)
{
CarpetSettings.LOG.error("Cannot change logger quick access field");
}
catch (NoSuchFieldException e)
{
CarpetSettings.LOG.error("Wrong logger name");
}
}
/**
* Called when the server starts. Creates the logs used by Carpet mod.
*/
private static void registerLogger(String name, Logger logger)
public static void registerLogger(String name, Logger logger)
{
loggerRegistry.put(name, logger);
setAccess(logger);
@@ -142,11 +147,13 @@ public class LoggerRegistry
public static void stopLoggers()
{
seenPlayers.clear();
for(Logger log: loggerRegistry.values() )
{
log.serverStopped();
}
seenPlayers.clear();
loggerRegistry.clear();
playerSubscriptions.clear();
}
public static void playerConnected(PlayerEntity player)
{
@@ -0,0 +1,20 @@
package carpet.mixins;
import carpet.CarpetServer;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerManager.class)
public class PlayerManager_coreMixin
{
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
{
CarpetServer.onPlayerLoggedIn(player);
}
}
@@ -24,7 +24,7 @@ import java.util.List;
import java.util.UUID;
@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin
public abstract class PlayerManager_fakePlayersMixin
{
@Shadow
@Final
@@ -18,11 +18,6 @@ public class ServerPlayNetworkHandler_coreMixin {
@Shadow
public ServerPlayerEntity player;
@Inject(method = "<init>", at = @At("RETURN"))
private void onPlayerConnect(MinecraftServer server, ClientConnection client, ServerPlayerEntity player, CallbackInfo ci) {
CarpetServer.onPlayerLoggedIn(player);
}
@Inject(method = "onDisconnected", at = @At("HEAD"))
private void onPlayerDisconnect(Text reason, CallbackInfo ci) {
CarpetServer.onPlayerLoggedOut(this.player);
+2 -1
View File
@@ -44,7 +44,8 @@
"ExperienceOrbEntityMixin",
"PlayerActionC2SPacketMixin",
"ServerPlayerEntityMixin",
"PlayerManagerMixin",
"PlayerManager_coreMixin",
"PlayerManager_fakePlayersMixin",
"RedstoneWireBlockMixin",
"CarpetBlockMixin",
"SummonCommandMixin",