mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-20 04:09:41 +00:00
Fix running in a headless Swing/AWT environment (#16)
This commit is contained in:
1 parent
9e878b295f
commit
568080d9ab
4 files changed
+28
-5
No files matched your search
@@ -12,6 +12,7 @@ public enum MessageHandlerRegistrar {
|
||||
INSTANCE;
|
||||
|
||||
private HashMap<Message, HashSet<IMessageHandler>> msgHandlers = new HashMap<Message, HashSet<IMessageHandler>>();
|
||||
public boolean suppressUnhandledMsgLogs = false;
|
||||
|
||||
public void registerHandler(Message msg, IMessageHandler handler) {
|
||||
if (!msgHandlers.containsKey(msg)) msgHandlers.put(msg, new HashSet<IMessageHandler>());
|
||||
@@ -27,7 +28,7 @@ public enum MessageHandlerRegistrar {
|
||||
modOpis.log.warn(String.format("Unhandled msg %s in handler %s", msg, handler));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (!suppressUnhandledMsgLogs) {
|
||||
modOpis.log.warn(String.format("Unhandled msg : %s", msg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,16 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import mcp.mobius.Tags;
|
||||
import mcp.mobius.mobiuscore.profiler.ProfilerSection;
|
||||
import mcp.mobius.opis.api.MessageHandlerRegistrar;
|
||||
import mcp.mobius.opis.commands.client.CommandOpis;
|
||||
import mcp.mobius.opis.commands.server.CommandAddPrivileged;
|
||||
import mcp.mobius.opis.commands.server.CommandAmountEntities;
|
||||
@@ -72,7 +73,6 @@ public class modOpis {
|
||||
|
||||
public static Logger log = LogManager.getLogger("Opis");
|
||||
|
||||
@SidedProxy(clientSide = "mcp.mobius.opis.proxy.ProxyClient", serverSide = "mcp.mobius.opis.proxy.ProxyServer")
|
||||
public static ProxyServer proxy;
|
||||
|
||||
public static int profilerDelay = 1;
|
||||
@@ -93,6 +93,17 @@ public class modOpis {
|
||||
public static String commentOpis = "Minimum access level to be open Opis interface. Valid values : NONE, PRIVILEGED, ADMIN";
|
||||
public static String commentPrivileged = "List of players with PRIVILEGED access level.";
|
||||
|
||||
public modOpis() throws ReflectiveOperationException {
|
||||
final boolean isHeadless = Boolean.getBoolean("java.awt.headless");
|
||||
if (FMLLaunchHandler.side().isClient() && !isHeadless) {
|
||||
// Instantiate via reflection to avoid triggering client-only class loading
|
||||
proxy = (ProxyServer) Class.forName("mcp.mobius.opis.proxy.ProxyClient").getConstructor().newInstance();
|
||||
} else {
|
||||
proxy = new ProxyServer();
|
||||
}
|
||||
MessageHandlerRegistrar.INSTANCE.suppressUnhandledMsgLogs = FMLLaunchHandler.side().isClient() && isHeadless;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
|
||||
@@ -123,9 +134,11 @@ public class modOpis {
|
||||
|
||||
config.save();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new OpisClientEventHandler());
|
||||
if (proxy.isClient()) {
|
||||
MinecraftForge.EVENT_BUS.register(new OpisClientEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(OpisClientTickHandler.INSTANCE);
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new OpisServerEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(OpisClientTickHandler.INSTANCE);
|
||||
FMLCommonHandler.instance().bus().register(OpisServerTickHandler.INSTANCE);
|
||||
FMLCommonHandler.instance().bus().register(PlayerTracker.INSTANCE);
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ public class ProxyClient extends ProxyServer implements IMessageHandler {
|
||||
|
||||
public static TrueTypeFont fontMC8, fontMC12, fontMC16, fontMC18, fontMC24;
|
||||
|
||||
@Override
|
||||
public boolean isClient() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
fontMC8 = Fonts.createFont(new ResourceLocation("opis", "fonts/LiberationMono-Bold.ttf"), 14, true);
|
||||
|
||||
@@ -6,6 +6,10 @@ import mcp.mobius.opis.network.enums.Message;
|
||||
|
||||
public class ProxyServer implements IMessageHandler {
|
||||
|
||||
public boolean isClient() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void init() {}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user