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 void onServerClosed(MinecraftServer server) {}
|
||||||
|
|
||||||
default String version() {return null;}
|
default String version() {return null;}
|
||||||
|
|
||||||
|
default void registerLoggers() {}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,6 @@ public class CarpetServer // static for now - easier to handle all around the co
|
|||||||
|
|
||||||
public static void onGameStarted()
|
public static void onGameStarted()
|
||||||
{
|
{
|
||||||
LoggerRegistry.initLoggers();
|
|
||||||
settingsManager = new SettingsManager(CarpetSettings.carpetVersion, "carpet", "Carpet Mod");
|
settingsManager = new SettingsManager(CarpetSettings.carpetVersion, "carpet", "Carpet Mod");
|
||||||
settingsManager.parseSettingsClass(CarpetSettings.class);
|
settingsManager.parseSettingsClass(CarpetSettings.class);
|
||||||
extensions.forEach(CarpetExtension::onGameStarted);
|
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 = new CarpetScriptServer();
|
||||||
scriptServer.loadAllWorldScripts();
|
scriptServer.loadAllWorldScripts();
|
||||||
MobAI.resetTrackers();
|
MobAI.resetTrackers();
|
||||||
|
LoggerRegistry.initLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tick(MinecraftServer server)
|
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();
|
LoggerRegistry.stopLoggers();
|
||||||
extensions.forEach(e -> e.onServerClosed(server));
|
extensions.forEach(e -> e.onServerClosed(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerExtensionLoggers()
|
||||||
|
{
|
||||||
|
extensions.forEach(CarpetExtension::registerLoggers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,16 +1,29 @@
|
|||||||
package carpet.logging;
|
package carpet.logging;
|
||||||
|
|
||||||
import carpet.utils.HUDController;
|
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.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.BaseText;
|
import net.minecraft.text.BaseText;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class HUDLogger extends Logger
|
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
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.BaseText;
|
import net.minecraft.text.BaseText;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -28,13 +29,30 @@ public class Logger
|
|||||||
|
|
||||||
private String[] options;
|
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<>();
|
subscribedOnlinePlayers = new HashMap<>();
|
||||||
subscribedOfflinePlayers = new HashMap<>();
|
subscribedOfflinePlayers = new HashMap<>();
|
||||||
|
this.acceleratorField = acceleratorField;
|
||||||
this.logName = logName;
|
this.logName = logName;
|
||||||
this.default_option = def;
|
this.default_option = def;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
if (acceleratorField == null)
|
||||||
|
CarpetSettings.LOG.error("[CM] Logger "+getLogName()+" is missing a specified accelerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefault()
|
public String getDefault()
|
||||||
@@ -94,6 +112,11 @@ public class Logger
|
|||||||
subscribedOfflinePlayers.clear();
|
subscribedOfflinePlayers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Field getField()
|
||||||
|
{
|
||||||
|
return acceleratorField;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* serves messages to players fetching them from the promise
|
* serves messages to players fetching them from the promise
|
||||||
* will repeat invocation for players that share the same option
|
* 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(",")));
|
Set<String> loggingOptions = new HashSet<>(Arrays.asList(CarpetSettings.defaultLoggers.split(",")));
|
||||||
if (loggingOptions.contains(getLogName()))
|
if (loggingOptions.contains(getLogName()))
|
||||||
{
|
{
|
||||||
subscribedOnlinePlayers.put(playerName, getDefault());
|
LoggerRegistry.subscribePlayer(playerName, getLogName(), getDefault());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LoggerRegistry.setAccess(this);
|
LoggerRegistry.setAccess(this);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package carpet.logging;
|
package carpet.logging;
|
||||||
|
|
||||||
|
import carpet.CarpetServer;
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.DyeColor;
|
import net.minecraft.util.DyeColor;
|
||||||
@@ -32,18 +33,26 @@ public class LoggerRegistry
|
|||||||
|
|
||||||
public static void initLoggers()
|
public static void initLoggers()
|
||||||
{
|
{
|
||||||
registerLogger("tnt", new Logger("tnt", "brief", new String[]{"brief", "full"}));
|
stopLoggers();
|
||||||
registerLogger("projectiles", new Logger("projectiles", "brief", new String[]{"brief", "full"}));
|
registerLoggers();
|
||||||
registerLogger("fallingBlocks",new Logger("fallingBlocks", "brief", new String[]{"brief", "full"}));
|
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("kills", new Logger("kills", null, null));
|
||||||
//registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
|
//registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
|
||||||
//registerLogger("weather", new Logger("weather", null, null));
|
//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();
|
boolean value = logger.hasOnlineSubscribers();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Field f = LoggerRegistry.class.getDeclaredField("__"+name);
|
Field f = logger.getField();
|
||||||
f.setBoolean(null, value);
|
f.setBoolean(null, value);
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException e)
|
catch (IllegalAccessException e)
|
||||||
{
|
{
|
||||||
CarpetSettings.LOG.error("Cannot change logger quick access field");
|
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.
|
* 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);
|
loggerRegistry.put(name, logger);
|
||||||
setAccess(logger);
|
setAccess(logger);
|
||||||
@@ -142,11 +147,13 @@ public class LoggerRegistry
|
|||||||
|
|
||||||
public static void stopLoggers()
|
public static void stopLoggers()
|
||||||
{
|
{
|
||||||
seenPlayers.clear();
|
|
||||||
for(Logger log: loggerRegistry.values() )
|
for(Logger log: loggerRegistry.values() )
|
||||||
{
|
{
|
||||||
log.serverStopped();
|
log.serverStopped();
|
||||||
}
|
}
|
||||||
|
seenPlayers.clear();
|
||||||
|
loggerRegistry.clear();
|
||||||
|
playerSubscriptions.clear();
|
||||||
}
|
}
|
||||||
public static void playerConnected(PlayerEntity player)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -24,7 +24,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
public abstract class PlayerManagerMixin
|
public abstract class PlayerManager_fakePlayersMixin
|
||||||
{
|
{
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
@@ -18,11 +18,6 @@ public class ServerPlayNetworkHandler_coreMixin {
|
|||||||
@Shadow
|
@Shadow
|
||||||
public ServerPlayerEntity player;
|
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"))
|
@Inject(method = "onDisconnected", at = @At("HEAD"))
|
||||||
private void onPlayerDisconnect(Text reason, CallbackInfo ci) {
|
private void onPlayerDisconnect(Text reason, CallbackInfo ci) {
|
||||||
CarpetServer.onPlayerLoggedOut(this.player);
|
CarpetServer.onPlayerLoggedOut(this.player);
|
||||||
|
|||||||
@@ -44,7 +44,8 @@
|
|||||||
"ExperienceOrbEntityMixin",
|
"ExperienceOrbEntityMixin",
|
||||||
"PlayerActionC2SPacketMixin",
|
"PlayerActionC2SPacketMixin",
|
||||||
"ServerPlayerEntityMixin",
|
"ServerPlayerEntityMixin",
|
||||||
"PlayerManagerMixin",
|
"PlayerManager_coreMixin",
|
||||||
|
"PlayerManager_fakePlayersMixin",
|
||||||
"RedstoneWireBlockMixin",
|
"RedstoneWireBlockMixin",
|
||||||
"CarpetBlockMixin",
|
"CarpetBlockMixin",
|
||||||
"SummonCommandMixin",
|
"SummonCommandMixin",
|
||||||
|
|||||||
Reference in new issue
Block a user