aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorFlorian Rinke <develop@torui.de>2021-09-13 20:38:05 +0200
committerFlorian Rinke <develop@torui.de>2021-09-13 20:38:05 +0200
commit5dc63920c5f9e6dba1754b35e3224829c36d27ba (patch)
tree086701f9766c851e7207cc3c28e672555abdf1d4 /src/main
parentf88b74485ffdf42ca2b62c72fb746082e7fc012f (diff)
downloadCOFL-5dc63920c5f9e6dba1754b35e3224829c36d27ba.tar.gz
COFL-5dc63920c5f9e6dba1754b35e3224829c36d27ba.tar.bz2
COFL-5dc63920c5f9e6dba1754b35e3224829c36d27ba.zip
made command client side
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/torui/coflsky/CoflSky.java10
-rw-r--r--src/main/java/de/torui/coflsky/CoflSkyCommand.java21
-rw-r--r--src/main/java/de/torui/coflsky/EventRegistry.java37
-rw-r--r--src/main/java/de/torui/coflsky/WSCommandHandler.java53
-rw-r--r--src/main/java/de/torui/coflsky/core/WriteToChatCommand.java18
-rw-r--r--src/main/java/de/torui/coflsky/websocket/WSClient.java2
6 files changed, 135 insertions, 6 deletions
diff --git a/src/main/java/de/torui/coflsky/CoflSky.java b/src/main/java/de/torui/coflsky/CoflSky.java
index 3ef2119..045b0fc 100644
--- a/src/main/java/de/torui/coflsky/CoflSky.java
+++ b/src/main/java/de/torui/coflsky/CoflSky.java
@@ -5,6 +5,7 @@ import java.net.URISyntaxException;
import de.torui.coflsky.websocket.WSClient;
import net.minecraft.init.Blocks;
+import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@@ -13,13 +14,14 @@ 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;
+import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = CoflSky.MODID, version = CoflSky.VERSION)
public class CoflSky
{
public static final String MODID = "CoflSky";
public static final String VERSION = "1.0";
-
+ public static WSClient WS;
@EventHandler
public void init(FMLInitializationEvent event) throws URISyntaxException
{
@@ -29,6 +31,7 @@ public class CoflSky
//new Thread(new WSClient(new URI("ws://localhost:8080"))).start();
System.out.println(">>>Started");
+ ClientCommandHandler.instance.registerCommand(new CoflSkyCommand());
MinecraftForge.EVENT_BUS.register(new EventRegistry());
}
@@ -36,7 +39,10 @@ public class CoflSky
@EventHandler
public void init(FMLServerStartingEvent event)
{
- event.registerServerCommand(new CoflSkyCommand());
+
+ if(event.getSide() == Side.CLIENT) return;
+ //event.registerServerCommand(new CoflSkyCommand());
}
}
+ \ No newline at end of file
diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java
index 1219c94..77ac4d7 100644
--- a/src/main/java/de/torui/coflsky/CoflSkyCommand.java
+++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java
@@ -1,14 +1,27 @@
package de.torui.coflsky;
+import java.util.List;
+
+import de.torui.coflsky.core.Command;
+import de.torui.coflsky.core.CommandType;
+import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
+import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import scala.actors.threadpool.Arrays;
public class CoflSkyCommand extends CommandBase {
+
+ @Override
+ public int getRequiredPermissionLevel() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
@Override
public String getCommandName() {
return "coflsky";
@@ -31,8 +44,14 @@ public class CoflSkyCommand extends CommandBase {
case "stop":
//todo: stop
break;
+ case "debug":
+ WSCommandHandler.HandleCommand(new Command(CommandType.Execute, "/say hewwo"), sender.getCommandSenderEntity());
+ WSCommandHandler.HandleCommand(new Command(CommandType.WriteToChat, "{ \"text\": \"Clickable Texts are fun\", \"onClick\": \"/give @p minecraft:apple 1\"}"), sender.getCommandSenderEntity());
+ break;
+ case "callback":
+ break;
default:
- sender.addChatMessage(new ChatComponentText("" + args[1] +"is not a valid subcommand!"));
+ sender.addChatMessage(new ChatComponentText("" + args[0] +"is not a valid subcommand!"));
return;
}
}
diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java
index 216cd2c..aa1592d 100644
--- a/src/main/java/de/torui/coflsky/EventRegistry.java
+++ b/src/main/java/de/torui/coflsky/EventRegistry.java
@@ -1,13 +1,21 @@
package de.torui.coflsky;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import de.torui.coflsky.websocket.WSClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
+import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
+import net.minecraftforge.fml.relauncher.Side;
+import net.minecraftforge.fml.relauncher.SideOnly;
public class EventRegistry{
+ @SideOnly(Side.CLIENT)
@SubscribeEvent
public void PlayerLoggedIn(PlayerLoggedInEvent plie) {
@@ -15,13 +23,26 @@ public class EventRegistry{
if(plie.player.getEntityWorld().isRemote) {
//is a server
- ServerData sd = Minecraft.getMinecraft().getCurrentServerData();
+ /*ServerData sd = Minecraft.getMinecraft().getCurrentServerData();
if(sd != null) {
System.out.println("ServerIP:= " + sd.serverIP);
} else {
System.out.println("Could not get serverdata");
}
-
+ */
+ if(CoflSky.WS == null) {
+ try {
+ String uuid = Minecraft.getMinecraft().thePlayer.getPersistentID().toString();
+ //String uuid = Minecraft.getMinecraft().thePlayer.getUUID(null)
+ CoflSky.WS = new WSClient(new URI("wss://sky-commands.coflnet.com/modsocket?uuid=" + uuid));
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Thread t = new Thread(CoflSky.WS);
+
+ }
} else {
System.out.println("World is not remote");
@@ -29,9 +50,21 @@ public class EventRegistry{
}
+ @SideOnly(Side.CLIENT)
@SubscribeEvent
public void PlayerLoggedOut(PlayerLoggedOutEvent ploe) {
System.out.println("COFLSKY disabled");
+
+ if(CoflSky.WS != null) {
+ try {
+ CoflSky.WS.closeBlocking();
+ CoflSky.WS = null;
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
}
}
diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java
new file mode 100644
index 0000000..9822f23
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java
@@ -0,0 +1,53 @@
+package de.torui.coflsky;
+
+import de.torui.coflsky.core.Command;
+import de.torui.coflsky.core.WriteToChatCommand;
+import de.torui.coflsky.websocket.WSClient;
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.Entity;
+import net.minecraft.event.ClickEvent;
+import net.minecraft.event.ClickEvent.Action;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.ChatStyle;
+import net.minecraft.util.IChatComponent;
+import net.minecraftforge.client.ClientCommandHandler;
+
+public class WSCommandHandler {
+ public static boolean HandleCommand(Command cmd, Entity sender) {
+
+ switch(cmd.getType()) {
+ case WriteToChat:
+ WriteToChat(cmd);
+ break;
+ case Execute:
+ Execute(cmd, sender);
+ break;
+ }
+
+ return true;
+ }
+
+ private static void Execute(Command cmd, Entity sender) {
+ //Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd.getData());
+ MinecraftServer.getServer().getCommandManager().executeCommand(sender, cmd.getData());
+ }
+
+ private static void WriteToChat(Command cmd) {
+ WriteToChatCommand wcmd = WSClient.gson.fromJson(cmd.getData(), WriteToChatCommand.class);
+ System.out.println("Executing wcmd Text=" + wcmd.Text + " OnClick=" + wcmd.OnClick);
+ wcmd.Text = "Hello World";
+ wcmd.OnClick = "/give @p apple 1"
+; /*String command = "tellraw @p [\"\", {\"text\":\"Hewwo World\", \"clickEvent\": {\"action\":\"run_command\", \"value\":\"/say hi\"}}]";
+ //"/tellraw @p [\"\",{\"text\":\"" + wcmd.Text + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + wcmd.OnClick + "\"}}]"
+ int result = ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command);
+ System.out.println("Sent to commandhandler with result" + result);*/
+
+
+ IChatComponent comp = new ChatComponentText(wcmd.Text);
+ ChatStyle style = new ChatStyle().setChatClickEvent(new ClickEvent(Action.RUN_COMMAND, wcmd.OnClick));
+ comp.setChatStyle(style);
+
+ Minecraft.getMinecraft().thePlayer.addChatMessage(comp);
+ }
+}
diff --git a/src/main/java/de/torui/coflsky/core/WriteToChatCommand.java b/src/main/java/de/torui/coflsky/core/WriteToChatCommand.java
new file mode 100644
index 0000000..939c386
--- /dev/null
+++ b/src/main/java/de/torui/coflsky/core/WriteToChatCommand.java
@@ -0,0 +1,18 @@
+package de.torui.coflsky.core;
+
+import com.google.gson.annotations.SerializedName;
+
+public class WriteToChatCommand {
+ @SerializedName("text")
+ public String Text;
+ @SerializedName("onClick")
+ public String OnClick;
+ public WriteToChatCommand(String text, String onClickEvent) {
+ super();
+ Text = text;
+ OnClick = onClickEvent;
+ }
+
+
+
+}
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClient.java b/src/main/java/de/torui/coflsky/websocket/WSClient.java
index dac8ae5..c26edf0 100644
--- a/src/main/java/de/torui/coflsky/websocket/WSClient.java
+++ b/src/main/java/de/torui/coflsky/websocket/WSClient.java
@@ -14,7 +14,7 @@ import de.torui.coflsky.core.Command;
public class WSClient extends WebSocketClient{
- private static Gson gson;
+ public static Gson gson;
public static WSClient Instancce;