feat: added GUI configuration
Some checks are pending
Build and test / build-and-test (push) Waiting to run

This commit is contained in:
Yui 2024-12-01 17:33:29 -03:00
parent b8da1ca68e
commit f5ad43ce0f
Signed by: yui
GPG Key ID: F368D23A0ABA04B4
7 changed files with 99 additions and 26 deletions

View File

@ -1,6 +1,7 @@
package moe.yuyui.mcstreamerbot; package moe.yuyui.mcstreamerbot;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
@ -14,16 +15,17 @@ public class CommonProxy {
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the // preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
// GameRegistry." (Remove if not needed) // GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
Config.synchronizeConfiguration(event.getSuggestedConfigurationFile()); Config.configuration = new Configuration(event.getSuggestedConfigurationFile());
Config.synchronizeConfiguration();
MinecraftStreamerBotIntegration.LOG.info("MCStreamerBot is meowing in version " + Tags.VERSION); MCStreamerBot.LOG.info("MCStreamerBot is meowing in version " + Tags.VERSION);
} }
// load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed) // load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed)
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new OnWorldJoin()); MinecraftForge.EVENT_BUS.register(new OnWorldJoin());
MinecraftForge.EVENT_BUS.register(new OnWorldLeave()); MinecraftForge.EVENT_BUS.register(new OnWorldLeave());
MinecraftStreamerBotIntegration.LOG.info("Loaded MCStreamerBot"); MCStreamerBot.LOG.info("Loaded MCStreamerBot");
} }
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) // postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)

View File

@ -1,25 +1,26 @@
package moe.yuyui.mcstreamerbot; package moe.yuyui.mcstreamerbot;
import java.io.File;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
public class Config { public class Config {
private static final String CATEGORY_WEBSOCKET = "websocket"; public static final String CATEGORY_WEBSOCKET = "websocket";
public static int portNumber = 8069; public static int portNumber = 8069;
public static String ipAddress = "127.0.0.1"; public static String ipAddress = "127.0.0.1";
public static String authToken = ""; public static String authToken = "";
public static Configuration configuration;
public static void synchronizeConfiguration(File configFile) { public static void synchronizeConfiguration() {
Configuration configuration = new Configuration(configFile); configuration.addCustomCategoryComment(CATEGORY_WEBSOCKET, "Configuration for the websocket");
configuration.addCustomCategoryComment("General", "General configuration of the bot");
portNumber = configuration portNumber = configuration
.getInt("port", CATEGORY_WEBSOCKET, portNumber, 1024, 65535, "The port that the websocket will listen on"); .getInt("Port", CATEGORY_WEBSOCKET, portNumber, 1024, 65535, "The Port that the websocket will listen on");
ipAddress = configuration ipAddress = configuration
.getString("ip", CATEGORY_WEBSOCKET, ipAddress, "The ip that the websocket will listen on"); .getString("IP Address", CATEGORY_WEBSOCKET, ipAddress, "The IP Address that the websocket will listen on");
authToken = configuration authToken = configuration.getString(
.getString("authToken", CATEGORY_WEBSOCKET, authToken, "The authentication token for the websocket"); "Authentication Token",
CATEGORY_WEBSOCKET,
authToken,
"The authentication token for the websocket. Leave empty to disable authentication.");
if (configuration.hasChanged()) { if (configuration.hasChanged()) {
configuration.save(); configuration.save();

View File

@ -12,15 +12,15 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent;
import moe.yuyui.mcstreamerbot.common.EventListener; import moe.yuyui.mcstreamerbot.common.EventListener;
@Mod( @Mod(
modid = MinecraftStreamerBotIntegration.MODID, modid = MCStreamerBot.MODID,
version = Tags.VERSION, version = "1.0.1-" + Tags.VERSION,
name = "MyMod", name = "MCStreamerBot",
acceptedMinecraftVersions = "[1.7.10]") acceptedMinecraftVersions = "[1.7.10]",
public class MinecraftStreamerBotIntegration { guiFactory = "moe.yuyui." + MCStreamerBot.MODID + ".gui.MCStreamerBotGuiFactory")
public class MCStreamerBot {
public static final String MODID = "mcstreamerbot"; public static final String MODID = "mcstreamerbot";
public static final Logger LOG = LogManager.getLogger(MODID); public static final Logger LOG = LogManager.getLogger(MODID);
public static EventListener eventListener; public static EventListener eventListener;
@SidedProxy(clientSide = "moe.yuyui.mcstreamerbot.ClientProxy", serverSide = "moe.yuyui.mcstreamerbot.CommonProxy") @SidedProxy(clientSide = "moe.yuyui.mcstreamerbot.ClientProxy", serverSide = "moe.yuyui.mcstreamerbot.CommonProxy")

View File

@ -8,7 +8,7 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import moe.yuyui.mcstreamerbot.Config; import moe.yuyui.mcstreamerbot.Config;
import moe.yuyui.mcstreamerbot.MinecraftStreamerBotIntegration; import moe.yuyui.mcstreamerbot.MCStreamerBot;
import moe.yuyui.mcstreamerbot.common.EventListener; import moe.yuyui.mcstreamerbot.common.EventListener;
import moe.yuyui.mcstreamerbot.common.WSServer; import moe.yuyui.mcstreamerbot.common.WSServer;
@ -18,16 +18,16 @@ public class OnWorldJoin {
public void onEntityJoinWorld(EntityJoinWorldEvent event) { public void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (event.entity == Minecraft.getMinecraft().thePlayer && Minecraft.getMinecraft() if (event.entity == Minecraft.getMinecraft().thePlayer && Minecraft.getMinecraft()
.isIntegratedServerRunning() && event.world.isRemote) { .isIntegratedServerRunning() && event.world.isRemote) {
if (MinecraftStreamerBotIntegration.eventListener != null) { if (MCStreamerBot.eventListener != null) {
if (MinecraftStreamerBotIntegration.eventListener.isAlive()) { if (MCStreamerBot.eventListener.isAlive()) {
return; return;
} }
} }
try { try {
MinecraftStreamerBotIntegration.eventListener = new EventListener( MCStreamerBot.eventListener = new EventListener(
new WSServer(new InetSocketAddress(Config.ipAddress, Config.portNumber), Config.authToken)); new WSServer(new InetSocketAddress(Config.ipAddress, Config.portNumber), Config.authToken));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
MinecraftStreamerBotIntegration.LOG.error("Your computer does not support SHA-256 hashing"); MCStreamerBot.LOG.error("Your computer does not support SHA-256 hashing");
} }
} }
} }

View File

@ -3,14 +3,14 @@ package moe.yuyui.mcstreamerbot.events.minecraft;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import moe.yuyui.mcstreamerbot.MinecraftStreamerBotIntegration; import moe.yuyui.mcstreamerbot.MCStreamerBot;
public class OnWorldLeave { public class OnWorldLeave {
@SubscribeEvent @SubscribeEvent
public void onPlayerLeave(WorldEvent.Unload event) { public void onPlayerLeave(WorldEvent.Unload event) {
try { try {
MinecraftStreamerBotIntegration.eventListener.end(); MCStreamerBot.eventListener.end();
} catch (InterruptedException | NullPointerException ignored) {} } catch (InterruptedException | NullPointerException ignored) {}
} }

View File

@ -0,0 +1,38 @@
package moe.yuyui.mcstreamerbot.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import cpw.mods.fml.client.config.GuiConfig;
import moe.yuyui.mcstreamerbot.Config;
import moe.yuyui.mcstreamerbot.MCStreamerBot;
public class MCStreamerBotGuiConfig extends GuiConfig {
public MCStreamerBotGuiConfig(GuiScreen parent) {
super(
parent,
new ConfigElement<>(Config.configuration.getCategory(Config.CATEGORY_WEBSOCKET)).getChildElements(),
MCStreamerBot.MODID,
true,
false,
"Configure the Websocket.");
titleLine2 = "Make sure you know what you're doing ;)";
}
@Override
public void initGui() {
super.initGui();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
}
}

View File

@ -0,0 +1,32 @@
package moe.yuyui.mcstreamerbot.gui;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import cpw.mods.fml.client.IModGuiFactory;
public class MCStreamerBotGuiFactory implements IModGuiFactory {
@Override
public void initialize(Minecraft minecraftInstance) {
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return MCStreamerBotGuiConfig.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}