aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/torui/coflsky/WSCommandHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/torui/coflsky/WSCommandHandler.java')
-rw-r--r--src/main/java/de/torui/coflsky/WSCommandHandler.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java
index 9822f23..a6fa87b 100644
--- a/src/main/java/de/torui/coflsky/WSCommandHandler.java
+++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java
@@ -4,6 +4,7 @@ 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.command.ICommandManager;
import net.minecraft.entity.Entity;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.ClickEvent.Action;
@@ -15,7 +16,7 @@ import net.minecraftforge.client.ClientCommandHandler;
public class WSCommandHandler {
public static boolean HandleCommand(Command cmd, Entity sender) {
-
+ System.out.println("Handling Command=" + cmd.toString());
switch(cmd.getType()) {
case WriteToChat:
WriteToChat(cmd);
@@ -23,31 +24,44 @@ public class WSCommandHandler {
case Execute:
Execute(cmd, sender);
break;
+ default:
+ break;
}
return true;
}
private static void Execute(Command cmd, Entity sender) {
+
//Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd.getData());
- MinecraftServer.getServer().getCommandManager().executeCommand(sender, cmd.getData());
+ System.out.println("Execute: " + cmd.getData() + " sender:" + sender);
+
+ Minecraft.getMinecraft().thePlayer.sendChatMessage(cmd.getData());
+
+ //ICommandManager manager = MinecraftServer.getServer().getCommandManager();
+ //System.out.println("CommandManager: " + manager);
+ //manager.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);*/
+ //System.out.println("Executing wcmd Text=" + wcmd.Text + " OnClick=" + wcmd.OnClick);
+ if(wcmd.Text != null && wcmd.OnClick != null) {
+ IChatComponent comp = new ChatComponentText(wcmd.Text);
+
+ ChatStyle style;
+ if(wcmd.OnClick.startsWith("http")) {
+ style = new ChatStyle().setChatClickEvent(new ClickEvent(Action.OPEN_URL, wcmd.OnClick));
+ } else {
+ style = new ChatStyle().setChatClickEvent(new ClickEvent(Action.RUN_COMMAND, "/cofl callback " +wcmd.OnClick));
+ }
- IChatComponent comp = new ChatComponentText(wcmd.Text);
- ChatStyle style = new ChatStyle().setChatClickEvent(new ClickEvent(Action.RUN_COMMAND, wcmd.OnClick));
- comp.setChatStyle(style);
+
+ comp.setChatStyle(style);
+
+ Minecraft.getMinecraft().thePlayer.addChatMessage(comp);
+ }
- Minecraft.getMinecraft().thePlayer.addChatMessage(comp);
}
}