feat: added GUI configuration
Some checks are pending
Build and test / build-and-test (push) Waiting to run
Some checks are pending
Build and test / build-and-test (push) Waiting to run
This commit is contained in:
parent
b8da1ca68e
commit
f5ad43ce0f
|
@ -1,6 +1,7 @@
|
|||
package moe.yuyui.mcstreamerbot;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
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
|
||||
// GameRegistry." (Remove if not needed)
|
||||
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)
|
||||
public void init(FMLInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(new OnWorldJoin());
|
||||
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)
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package moe.yuyui.mcstreamerbot;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public class Config {
|
||||
|
||||
private static final String CATEGORY_WEBSOCKET = "websocket";
|
||||
public static final String CATEGORY_WEBSOCKET = "websocket";
|
||||
public static int portNumber = 8069;
|
||||
public static String ipAddress = "127.0.0.1";
|
||||
public static String authToken = "";
|
||||
public static Configuration configuration;
|
||||
|
||||
public static void synchronizeConfiguration(File configFile) {
|
||||
Configuration configuration = new Configuration(configFile);
|
||||
configuration.addCustomCategoryComment("General", "General configuration of the bot");
|
||||
public static void synchronizeConfiguration() {
|
||||
configuration.addCustomCategoryComment(CATEGORY_WEBSOCKET, "Configuration for the websocket");
|
||||
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
|
||||
.getString("ip", CATEGORY_WEBSOCKET, ipAddress, "The ip that the websocket will listen on");
|
||||
authToken = configuration
|
||||
.getString("authToken", CATEGORY_WEBSOCKET, authToken, "The authentication token for the websocket");
|
||||
.getString("IP Address", CATEGORY_WEBSOCKET, ipAddress, "The IP Address that the websocket will listen on");
|
||||
authToken = configuration.getString(
|
||||
"Authentication Token",
|
||||
CATEGORY_WEBSOCKET,
|
||||
authToken,
|
||||
"The authentication token for the websocket. Leave empty to disable authentication.");
|
||||
|
||||
if (configuration.hasChanged()) {
|
||||
configuration.save();
|
||||
|
|
|
@ -12,15 +12,15 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
|||
import moe.yuyui.mcstreamerbot.common.EventListener;
|
||||
|
||||
@Mod(
|
||||
modid = MinecraftStreamerBotIntegration.MODID,
|
||||
version = Tags.VERSION,
|
||||
name = "MyMod",
|
||||
acceptedMinecraftVersions = "[1.7.10]")
|
||||
public class MinecraftStreamerBotIntegration {
|
||||
modid = MCStreamerBot.MODID,
|
||||
version = "1.0.1-" + Tags.VERSION,
|
||||
name = "MCStreamerBot",
|
||||
acceptedMinecraftVersions = "[1.7.10]",
|
||||
guiFactory = "moe.yuyui." + MCStreamerBot.MODID + ".gui.MCStreamerBotGuiFactory")
|
||||
public class MCStreamerBot {
|
||||
|
||||
public static final String MODID = "mcstreamerbot";
|
||||
public static final Logger LOG = LogManager.getLogger(MODID);
|
||||
|
||||
public static EventListener eventListener;
|
||||
|
||||
@SidedProxy(clientSide = "moe.yuyui.mcstreamerbot.ClientProxy", serverSide = "moe.yuyui.mcstreamerbot.CommonProxy")
|
|
@ -8,7 +8,7 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
|||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
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.WSServer;
|
||||
|
||||
|
@ -18,16 +18,16 @@ public class OnWorldJoin {
|
|||
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
|
||||
if (event.entity == Minecraft.getMinecraft().thePlayer && Minecraft.getMinecraft()
|
||||
.isIntegratedServerRunning() && event.world.isRemote) {
|
||||
if (MinecraftStreamerBotIntegration.eventListener != null) {
|
||||
if (MinecraftStreamerBotIntegration.eventListener.isAlive()) {
|
||||
if (MCStreamerBot.eventListener != null) {
|
||||
if (MCStreamerBot.eventListener.isAlive()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
MinecraftStreamerBotIntegration.eventListener = new EventListener(
|
||||
MCStreamerBot.eventListener = new EventListener(
|
||||
new WSServer(new InetSocketAddress(Config.ipAddress, Config.portNumber), Config.authToken));
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@ package moe.yuyui.mcstreamerbot.events.minecraft;
|
|||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import moe.yuyui.mcstreamerbot.MinecraftStreamerBotIntegration;
|
||||
import moe.yuyui.mcstreamerbot.MCStreamerBot;
|
||||
|
||||
public class OnWorldLeave {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(WorldEvent.Unload event) {
|
||||
try {
|
||||
MinecraftStreamerBotIntegration.eventListener.end();
|
||||
MCStreamerBot.eventListener.end();
|
||||
} catch (InterruptedException | NullPointerException ignored) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user