aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/torui/coflsky/CoflSky.java42
-rw-r--r--src/main/java/de/torui/coflsky/CoflSkyCommand.java46
-rw-r--r--src/main/java/de/torui/coflsky/EventRegistry.java37
-rw-r--r--src/main/java/de/torui/coflsky/core/Command.java40
-rw-r--r--src/main/java/de/torui/coflsky/core/CommandType.java17
-rw-r--r--src/main/java/de/torui/coflsky/websocket/WSClient.java68
6 files changed, 250 insertions, 0 deletions
diff --git a/src/main/java/de/torui/coflsky/CoflSky.java b/src/main/java/de/torui/coflsky/CoflSky.java
new file mode 100644
index 0000000..3ef2119
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/CoflSky.java
@@ -0,0 +1,42 @@
+package de.torui.coflsky;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import de.torui.coflsky.websocket.WSClient;
+import net.minecraft.init.Blocks;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.common.Mod.EventHandler;
+import net.minecraftforge.fml.common.event.FMLInitializationEvent;
+import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
+import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
+
+@Mod(modid = CoflSky.MODID, version = CoflSky.VERSION)
+public class CoflSky
+{
+ public static final String MODID = "CoflSky";
+ public static final String VERSION = "1.0";
+
+ @EventHandler
+ public void init(FMLInitializationEvent event) throws URISyntaxException
+ {
+ // some example code
+ System.out.println("Initializing");
+
+ //new Thread(new WSClient(new URI("ws://localhost:8080"))).start();
+ System.out.println(">>>Started");
+
+ MinecraftForge.EVENT_BUS.register(new EventRegistry());
+ }
+
+
+ @EventHandler
+ public void init(FMLServerStartingEvent event)
+ {
+ event.registerServerCommand(new CoflSkyCommand());
+ }
+
+}
diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java
new file mode 100644
index 0000000..1219c94
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java
@@ -0,0 +1,46 @@
+package de.torui.coflsky;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.CommandException;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.IChatComponent;
+import scala.actors.threadpool.Arrays;
+
+public class CoflSkyCommand extends CommandBase {
+
+ @Override
+ public String getCommandName() {
+ return "coflsky";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender sender) {
+ return "/coflsky token <token> to register\n/coflsky start to connect\n/coflsky stop to stop";
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) throws CommandException {
+ System.out.println(Arrays.toString(args));
+
+ if(args.length == 1) {
+ switch(args[0]) {
+ case "start":
+ //todo: start
+ break;
+ case "stop":
+ //todo: stop
+ break;
+ default:
+ sender.addChatMessage(new ChatComponentText("" + args[1] +"is not a valid subcommand!"));
+ return;
+ }
+ }
+
+ if(args.length == 2 && args[0].equals("token")) {
+ //todo: send authorisation message
+ }
+
+ }
+
+}
diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java
new file mode 100644
index 0000000..216cd2c
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/EventRegistry.java
@@ -0,0 +1,37 @@
+package de.torui.coflsky;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.multiplayer.ServerData;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
+import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
+
+public class EventRegistry{
+
+ @SubscribeEvent
+ public void PlayerLoggedIn(PlayerLoggedInEvent plie) {
+
+ System.out.println("COFLSKY initialized");
+
+ if(plie.player.getEntityWorld().isRemote) {
+ //is a server
+ ServerData sd = Minecraft.getMinecraft().getCurrentServerData();
+ if(sd != null) {
+ System.out.println("ServerIP:= " + sd.serverIP);
+ } else {
+ System.out.println("Could not get serverdata");
+ }
+
+
+ } else {
+ System.out.println("World is not remote");
+ }
+
+ }
+
+ @SubscribeEvent
+ public void PlayerLoggedOut(PlayerLoggedOutEvent ploe) {
+ System.out.println("COFLSKY disabled");
+ }
+
+}
diff --git a/src/main/java/de/torui/coflsky/core/Command.java b/src/main/java/de/torui/coflsky/core/Command.java
new file mode 100644
index 0000000..fc6cd13
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/core/Command.java
@@ -0,0 +1,40 @@
+package de.torui.coflsky.core;
+
+import com.google.gson.annotations.SerializedName;
+
+public class Command {
+ @SerializedName("type")
+ private CommandType Type;
+ @SerializedName("data")
+ private String data;
+
+ public Command() {}
+
+ public Command(CommandType type, String data) {
+ super();
+ this.Type = type;
+ this.data = data;
+ }
+
+ public CommandType getType() {
+ return Type;
+ }
+
+ public void setType(CommandType type) {
+ Type = type;
+ }
+
+ public String getData() {
+ return data;
+ }
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ @Override
+ public String toString() {
+ return "Command [Type=" + Type + ", data=" + data + "]";
+ }
+
+
+}
diff --git a/src/main/java/de/torui/coflsky/core/CommandType.java b/src/main/java/de/torui/coflsky/core/CommandType.java
new file mode 100644
index 0000000..a6657a9
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/core/CommandType.java
@@ -0,0 +1,17 @@
+package de.torui.coflsky.core;
+
+import com.google.gson.annotations.SerializedName;
+
+public enum CommandType {
+ @SerializedName("writeToChat")
+ WriteToChat,
+
+ @SerializedName("execute")
+ Execute,
+
+ @SerializedName("tokenLogin")
+ TokenLogin,
+
+ @SerializedName("tokenLogin")
+ Clicked;
+}
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClient.java b/src/main/java/de/torui/coflsky/websocket/WSClient.java
new file mode 100644
index 0000000..dac8ae5
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/websocket/WSClient.java
@@ -0,0 +1,68 @@
+package de.torui.coflsky.websocket;
+import java.net.URI;
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.java_websocket.client.WebSocketClient;
+import org.java_websocket.handshake.ServerHandshake;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import de.torui.coflsky.core.Command;
+
+
+public class WSClient extends WebSocketClient{
+
+ private static Gson gson;
+
+ public static WSClient Instancce;
+
+
+ static {
+ gson = new GsonBuilder()/*.setFieldNamingStrategy(new FieldNamingStrategy() {
+ @Override
+ public String translateName(Field f) {
+
+ String name = f.getName();
+ char firstChar = name.charAt(0);
+ return Character.toLowerCase(firstChar) + name.substring(1);
+ }
+ })*/.create();
+ }
+
+ public WSClient(URI serverUri) {
+ super(serverUri);
+
+ }
+
+ @Override
+ public void onOpen(ServerHandshake handshakedata) {
+
+ }
+
+ @Override
+ public void onMessage(String message) {
+ System.out.println(message);
+
+ Command cmd = gson.fromJson(message, Command.class);
+
+
+ System.out.println(cmd);
+ }
+
+ @Override
+ public void onClose(int code, String reason, boolean remote) {
+ System.out.printf("code: %n reason:%s remote:%b", code, reason,remote);
+ }
+
+ @Override
+ public void onError(Exception ex) {
+ ex.printStackTrace();
+ }
+
+ public void SendCommand(Command command) {
+
+ }
+
+}