From bf5bdf3ca643c6a28def732e9085a6c9766a8830 Mon Sep 17 00:00:00 2001 From: Florian Rinke Date: Fri, 5 Nov 2021 17:07:39 +0100 Subject: Modularized Command Infrastructure --- src/main/java/de/torui/coflsky/CoflSkyCommand.java | 8 ++-- src/main/java/de/torui/coflsky/EventRegistry.java | 10 ++-- .../java/de/torui/coflsky/WSCommandHandler.java | 53 ++++++++++------------ src/main/java/de/torui/coflsky/core/Command.java | 28 ++++++------ .../java/de/torui/coflsky/core/CommandType.java | 21 ++++++--- .../de/torui/coflsky/core/JsonStringCommand.java | 28 ++++++++++++ .../java/de/torui/coflsky/core/SoundCommand.java | 27 ----------- .../java/de/torui/coflsky/core/StringCommand.java | 38 ---------------- .../de/torui/coflsky/core/WriteToChatCommand.java | 25 ---------- .../coflsky/core/commandEntities/AuctionData.java | 30 ++++++++++++ .../core/commandEntities/ChatMessageData.java | 25 ++++++++++ .../coflsky/core/commandEntities/SoundData.java | 23 ++++++++++ .../java/de/torui/coflsky/network/WSClient.java | 10 +--- .../de/torui/coflsky/network/WSClientWrapper.java | 5 +- 14 files changed, 173 insertions(+), 158 deletions(-) create mode 100644 src/main/java/de/torui/coflsky/core/JsonStringCommand.java delete mode 100644 src/main/java/de/torui/coflsky/core/SoundCommand.java delete mode 100644 src/main/java/de/torui/coflsky/core/StringCommand.java delete mode 100644 src/main/java/de/torui/coflsky/core/WriteToChatCommand.java create mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java create mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java create mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java index e48d131..8f4e9e7 100644 --- a/src/main/java/de/torui/coflsky/CoflSkyCommand.java +++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java @@ -6,7 +6,7 @@ import java.util.List; import de.torui.coflsky.core.Command; import de.torui.coflsky.core.CommandType; -import de.torui.coflsky.core.StringCommand; +import de.torui.coflsky.core.JsonStringCommand; import de.torui.coflsky.minecraft_integration.CoflSessionManager; import de.torui.coflsky.minecraft_integration.CoflSessionManager.CoflSession; import de.torui.coflsky.network.QueryServerCommands; @@ -136,7 +136,7 @@ public class CoflSkyCommand extends CommandBase { public void CommandNotRecognized(String[] args, ICommandSender sender) { String command = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - StringCommand sc = new StringCommand(args[0], WSClient.gson.toJson(command)); + JsonStringCommand sc = new JsonStringCommand(args[0], WSClient.gson.toJson(command)); if(CoflSky.Wrapper.isRunning) { CoflSky.Wrapper.SendMessage(sc); @@ -158,8 +158,8 @@ public class CoflSkyCommand extends CommandBase { System.out.println("CallbackData: " + command); //new Thread(()->{ System.out.println("Callback: " + command); - WSCommandHandler.HandleCommand(new Command(CommandType.Execute, WSClient.gson.toJson(command)), Minecraft.getMinecraft().thePlayer); - CoflSky.Wrapper.SendMessage(new Command(CommandType.Clicked, WSClient.gson.toJson(command))); + WSCommandHandler.HandleCommand(new JsonStringCommand(CommandType.Execute, WSClient.gson.toJson(command)), Minecraft.getMinecraft().thePlayer); + CoflSky.Wrapper.SendMessage(new JsonStringCommand(CommandType.Clicked, WSClient.gson.toJson(command))); System.out.println("Sent!"); //}).start(); diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java index f47d0a1..c0b4546 100644 --- a/src/main/java/de/torui/coflsky/EventRegistry.java +++ b/src/main/java/de/torui/coflsky/EventRegistry.java @@ -1,5 +1,8 @@ package de.torui.coflsky; +import de.torui.coflsky.core.Command; +import de.torui.coflsky.core.CommandType; +import de.torui.coflsky.core.JsonStringCommand; import java.util.UUID; import net.minecraft.client.Minecraft; @@ -58,14 +61,13 @@ public class EventRegistry{ public void onEvent(KeyInputEvent event) { if(CoflSky.keyBindings[0].isPressed()) { - //System.out.println(">>>>> Key Pressed"); - + if(WSCommandHandler.lastOnClickEvent != null) { String command = WSCommandHandler.lastOnClickEvent; WSCommandHandler.lastOnClickEvent = null; - //System.out.println(">>>>> HasLastONClickEvent = " + command); - WSCommandHandler.Execute(command,Minecraft.getMinecraft().thePlayer); + WSCommandHandler.HandleCommand(new JsonStringCommand(CommandType.Execute, WSClient.gson.toJson(command)), + Minecraft.getMinecraft().thePlayer); } diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java index 7e857db..287ed09 100644 --- a/src/main/java/de/torui/coflsky/WSCommandHandler.java +++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java @@ -1,25 +1,19 @@ package de.torui.coflsky; +import com.google.gson.reflect.TypeToken; + import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.SoundCommand; -import de.torui.coflsky.core.WriteToChatCommand; +import de.torui.coflsky.core.JsonStringCommand; +import de.torui.coflsky.core.commandEntities.SoundData; +import de.torui.coflsky.core.commandEntities.ChatMessageData; import de.torui.coflsky.network.WSClient; import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.ISound; -import net.minecraft.client.audio.PositionedSound; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.audio.SoundCategory; -import net.minecraft.client.audio.SoundEventAccessorComposite; import net.minecraft.client.audio.SoundHandler; -import net.minecraft.client.audio.SoundManager; -import net.minecraft.command.ICommandManager; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.Entity; import net.minecraft.event.ClickEvent; import net.minecraft.event.ClickEvent.Action; import net.minecraft.event.HoverEvent; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.integrated.IntegratedServerCommandManager; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import net.minecraft.util.IChatComponent; @@ -28,23 +22,24 @@ import net.minecraftforge.client.ClientCommandHandler; public class WSCommandHandler { - public static String lastOnClickEvent; + public static transient String lastOnClickEvent; - public static boolean HandleCommand(Command cmd, Entity sender) { + public static boolean HandleCommand(JsonStringCommand cmd, Entity sender) { // Entity sender = Minecraft.getMinecraft().thePlayer; System.out.println("Handling Command=" + cmd.toString()); + switch (cmd.getType()) { case WriteToChat: - WriteToChat(cmd); + WriteToChat(cmd.GetAs(new TypeToken() {})); break; case Execute: - Execute(cmd, sender); + Execute(cmd.GetAs(new TypeToken() {}), sender); break; case PlaySound: - PlaySound(cmd, sender); + PlaySound(cmd.GetAs(new TypeToken() {}), sender); break; case ChatMessage: - ChatMessage(cmd); + ChatMessage(cmd.GetAs(new TypeToken() {})); break; default: break; @@ -53,9 +48,9 @@ public class WSCommandHandler { return true; } - private static void PlaySound(Command cmd, Entity sender) { - - SoundCommand sc = WSClient.gson.fromJson(cmd.getData(), SoundCommand.class); + private static void PlaySound(Command cmd, Entity sender) { + + SoundData sc = cmd.getData(); SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); @@ -66,10 +61,10 @@ public class WSCommandHandler { handler.playSound(psr); } - private static void Execute(Command cmd, Entity sender) { + private static void Execute(Command cmd, Entity sender) { System.out.println("Execute: " + cmd.getData() + " sender:" + sender); - String dummy = WSClient.gson.fromJson(cmd.getData(), String.class); - Execute(dummy,sender); + //String dummy = WSClient.gson.fromJson(cmd.getData(), String.class); + Execute(cmd.getData(),sender); } public static void Execute(String cmd, Entity sender) @@ -82,7 +77,7 @@ public class WSCommandHandler { } - private static IChatComponent CommandToChatComponent(WriteToChatCommand wcmd) { + private static IChatComponent CommandToChatComponent(ChatMessageData wcmd) { if(wcmd.OnClick != null) lastOnClickEvent = "/cofl callback " + wcmd.OnClick; if (wcmd.Text != null) { @@ -110,12 +105,12 @@ public class WSCommandHandler { return null; } - private static void ChatMessage(Command cmd) { - WriteToChatCommand[] list = WSClient.gson.fromJson(cmd.getData(), WriteToChatCommand[].class); + private static void ChatMessage(Command cmd) { + ChatMessageData[] list = cmd.getData() ;//WSClient.gson.fromJson(cmd.getData(), WriteToChatCommand[].class); IChatComponent master = new ChatComponentText(""); - for (WriteToChatCommand wcmd : list) { + for (ChatMessageData wcmd : list) { IChatComponent comp = CommandToChatComponent(wcmd); if (comp != null) master.appendSibling(comp); @@ -125,8 +120,8 @@ public class WSCommandHandler { - private static void WriteToChat(Command cmd) { - WriteToChatCommand wcmd = WSClient.gson.fromJson(cmd.getData(), WriteToChatCommand.class); + private static void WriteToChat(Command cmd) { + ChatMessageData wcmd = cmd.getData(); IChatComponent comp = CommandToChatComponent(wcmd); if (comp != null) diff --git a/src/main/java/de/torui/coflsky/core/Command.java b/src/main/java/de/torui/coflsky/core/Command.java index fc6cd13..e18c59a 100644 --- a/src/main/java/de/torui/coflsky/core/Command.java +++ b/src/main/java/de/torui/coflsky/core/Command.java @@ -2,20 +2,21 @@ package de.torui.coflsky.core; import com.google.gson.annotations.SerializedName; -public class Command { +public class Command { @SerializedName("type") private CommandType Type; @SerializedName("data") - private String data; - - public Command() {} - - public Command(CommandType type, String data) { + private T data; + + public Command() { + } + + public Command(CommandType type, T data) { super(); - this.Type = type; + Type = type; this.data = data; } - + public CommandType getType() { return Type; } @@ -24,17 +25,18 @@ public class Command { Type = type; } - public String getData() { + public T getData() { return data; } - public void setData(String data) { + + public void setData(T 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 index 67b9b93..74e8a41 100644 --- a/src/main/java/de/torui/coflsky/core/CommandType.java +++ b/src/main/java/de/torui/coflsky/core/CommandType.java @@ -5,17 +5,26 @@ import com.google.gson.annotations.SerializedName; public enum CommandType { @SerializedName("writeToChat") WriteToChat, - + @SerializedName("execute") Execute, - + @SerializedName("tokenLogin") TokenLogin, - + @SerializedName("clicked") - Clicked, + Clicked, + @SerializedName("playSound") - PlaySound, + PlaySound, + @SerializedName("chatMessage") - ChatMessage; + ChatMessage, + + @SerializedName("purchaseStart") + PurchaseStart, + + @SerializedName("purchaseConfirm") + PurchaseConfirm, + } diff --git a/src/main/java/de/torui/coflsky/core/JsonStringCommand.java b/src/main/java/de/torui/coflsky/core/JsonStringCommand.java new file mode 100644 index 0000000..9ce0cb1 --- /dev/null +++ b/src/main/java/de/torui/coflsky/core/JsonStringCommand.java @@ -0,0 +1,28 @@ +package de.torui.coflsky.core; + +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class JsonStringCommand extends Command { + + public JsonStringCommand(String type, String data) { + this.setType(CommandType.valueOf(type)); + this.setData(data); + } + + public JsonStringCommand() { + super(); + + } + + public JsonStringCommand(CommandType type, String data) { + super(type, data); + } + + public Command GetAs(TypeToken type){ + T t = new GsonBuilder().create().fromJson(this.getData(),type.getType()); + Command cmd = new Command(this.getType(), t); + + return (Command) cmd; + } +} diff --git a/src/main/java/de/torui/coflsky/core/SoundCommand.java b/src/main/java/de/torui/coflsky/core/SoundCommand.java deleted file mode 100644 index bdba82d..0000000 --- a/src/main/java/de/torui/coflsky/core/SoundCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.annotations.SerializedName; - -public class SoundCommand { - @SerializedName("name") - public String Name; - - @SerializedName("pitch") - public float Pitch; - - - - public SoundCommand() { - super(); - } - - - - public SoundCommand(String name, float pitch) { - super(); - Name = name; - Pitch = pitch; - } - - -} diff --git a/src/main/java/de/torui/coflsky/core/StringCommand.java b/src/main/java/de/torui/coflsky/core/StringCommand.java deleted file mode 100644 index 745f1ba..0000000 --- a/src/main/java/de/torui/coflsky/core/StringCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.annotations.SerializedName; - -public class StringCommand { - @SerializedName("type") - private String Type; - @SerializedName("data") - private String data; - - public StringCommand() {} - - public StringCommand(String type, String data) { - super(); - this.Type = type; - this.data = data; - } - - public String getType() { - return Type; - } - - public void setType(String 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/WriteToChatCommand.java b/src/main/java/de/torui/coflsky/core/WriteToChatCommand.java deleted file mode 100644 index b8c64bb..0000000 --- a/src/main/java/de/torui/coflsky/core/WriteToChatCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.annotations.SerializedName; - -public class WriteToChatCommand { - @SerializedName("text") - public String Text; - @SerializedName("onClick") - public String OnClick; - - @SerializedName("hover") - public String Hover; - - public WriteToChatCommand() { - - } - - public WriteToChatCommand(String text, String onClick, String hover) { - super(); - Text = text; - OnClick = onClick; - Hover = hover; - } - -} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java b/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java new file mode 100644 index 0000000..0e677b2 --- /dev/null +++ b/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java @@ -0,0 +1,30 @@ +package de.torui.coflsky.core.commandEntities; + +import com.google.gson.annotations.SerializedName; + +public class AuctionData { + @SerializedName("auctionId") + private String auctionId; + @SerializedName("itemId") + private String itemId; + public String getAuctionId() { + return auctionId; + } + public void setAuctionId(String auctionId) { + this.auctionId = auctionId; + } + public String getItemId() { + return itemId; + } + public void setItemId(String itemId) { + this.itemId = itemId; + } + public AuctionData(String auctionId, String itemId) { + super(); + this.auctionId = auctionId; + this.itemId = itemId; + } + + public AuctionData() {} + +} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java b/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java new file mode 100644 index 0000000..cfc1381 --- /dev/null +++ b/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java @@ -0,0 +1,25 @@ +package de.torui.coflsky.core.commandEntities; + +import com.google.gson.annotations.SerializedName; + +public class ChatMessageData { + @SerializedName("text") + public String Text; + @SerializedName("onClick") + public String OnClick; + + @SerializedName("hover") + public String Hover; + + public ChatMessageData() { + + } + + public ChatMessageData(String text, String onClick, String hover) { + super(); + Text = text; + OnClick = onClick; + Hover = hover; + } + +} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java b/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java new file mode 100644 index 0000000..64687ab --- /dev/null +++ b/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java @@ -0,0 +1,23 @@ +package de.torui.coflsky.core.commandEntities; + +import com.google.gson.annotations.SerializedName; + +public class SoundData { + @SerializedName("name") + public String Name; + + @SerializedName("pitch") + public float Pitch; + + public SoundData() { + super(); + } + + public SoundData(String name, float pitch) { + super(); + Name = name; + Pitch = pitch; + } + + +} diff --git a/src/main/java/de/torui/coflsky/network/WSClient.java b/src/main/java/de/torui/coflsky/network/WSClient.java index 529056b..b3f28ca 100644 --- a/src/main/java/de/torui/coflsky/network/WSClient.java +++ b/src/main/java/de/torui/coflsky/network/WSClient.java @@ -17,7 +17,7 @@ import net.minecraft.client.Minecraft; import de.torui.coflsky.CoflSky; import de.torui.coflsky.WSCommandHandler; import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.StringCommand; +import de.torui.coflsky.core.JsonStringCommand; public class WSClient extends WebSocketAdapter { @@ -112,7 +112,7 @@ public class WSClient extends WebSocketAdapter { //super.onTextMessage(websocket, text); System.out.println("Received: "+ text); - Command cmd = gson.fromJson(text, Command.class); + JsonStringCommand cmd = gson.fromJson(text, JsonStringCommand.class); //System.out.println(cmd); WSCommandHandler.HandleCommand(cmd, Minecraft.getMinecraft().thePlayer); @@ -122,12 +122,6 @@ public class WSClient extends WebSocketAdapter { String json = gson.toJson(cmd); this.socket.sendText(json); } - - public void SendCommand(StringCommand sc) { - String json = gson.toJson(sc); - this.socket.sendText(json); - } - diff --git a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java index f30d0f9..dd9d13b 100644 --- a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java +++ b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java @@ -10,7 +10,7 @@ import com.neovisionaries.ws.client.WebSocketException; import de.torui.coflsky.CoflSky; import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.StringCommand; +import de.torui.coflsky.core.JsonStringCommand; import de.torui.coflsky.minecraft_integration.PlayerDataProvider; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; @@ -141,9 +141,6 @@ public class WSClientWrapper { } - public void SendMessage(StringCommand sc) { - this.socket.SendCommand(sc); - } public String GetStatus() { return "" + isRunning + " " + -- cgit From 0e9a5837522132b946ab1568ad0485622f32a921 Mon Sep 17 00:00:00 2001 From: Florian Rinke Date: Fri, 5 Nov 2021 17:16:57 +0100 Subject: add missing import --- src/main/java/de/torui/coflsky/EventRegistry.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java index c0b4546..bb2f24f 100644 --- a/src/main/java/de/torui/coflsky/EventRegistry.java +++ b/src/main/java/de/torui/coflsky/EventRegistry.java @@ -5,6 +5,7 @@ import de.torui.coflsky.core.CommandType; import de.torui.coflsky.core.JsonStringCommand; import java.util.UUID; +import de.torui.coflsky.network.WSClient; import net.minecraft.client.Minecraft; import net.minecraft.server.MinecraftServer; import net.minecraft.server.gui.MinecraftServerGui; -- cgit From e533c7f6f9860479f5f472280d6fce8b87d8d0b8 Mon Sep 17 00:00:00 2001 From: Florian Rinke Date: Fri, 5 Nov 2021 20:17:35 +0100 Subject: rename de.torui.coflsky.core to commands in for refactor --- src/main/java/de/torui/coflsky/CoflSkyCommand.java | 6 ++-- src/main/java/de/torui/coflsky/EventRegistry.java | 6 ++-- .../java/de/torui/coflsky/WSCommandHandler.java | 8 ++--- .../java/de/torui/coflsky/commands/Command.java | 42 ++++++++++++++++++++++ .../de/torui/coflsky/commands/CommandType.java | 30 ++++++++++++++++ .../torui/coflsky/commands/JsonStringCommand.java | 28 +++++++++++++++ .../torui/coflsky/commands/models/AuctionData.java | 30 ++++++++++++++++ .../coflsky/commands/models/ChatMessageData.java | 25 +++++++++++++ .../torui/coflsky/commands/models/SoundData.java | 23 ++++++++++++ src/main/java/de/torui/coflsky/core/Command.java | 42 ---------------------- .../java/de/torui/coflsky/core/CommandType.java | 30 ---------------- .../de/torui/coflsky/core/JsonStringCommand.java | 28 --------------- .../coflsky/core/commandEntities/AuctionData.java | 30 ---------------- .../core/commandEntities/ChatMessageData.java | 25 ------------- .../coflsky/core/commandEntities/SoundData.java | 23 ------------ .../java/de/torui/coflsky/network/WSClient.java | 4 +-- .../de/torui/coflsky/network/WSClientWrapper.java | 4 +-- 17 files changed, 192 insertions(+), 192 deletions(-) create mode 100644 src/main/java/de/torui/coflsky/commands/Command.java create mode 100644 src/main/java/de/torui/coflsky/commands/CommandType.java create mode 100644 src/main/java/de/torui/coflsky/commands/JsonStringCommand.java create mode 100644 src/main/java/de/torui/coflsky/commands/models/AuctionData.java create mode 100644 src/main/java/de/torui/coflsky/commands/models/ChatMessageData.java create mode 100644 src/main/java/de/torui/coflsky/commands/models/SoundData.java delete mode 100644 src/main/java/de/torui/coflsky/core/Command.java delete mode 100644 src/main/java/de/torui/coflsky/core/CommandType.java delete mode 100644 src/main/java/de/torui/coflsky/core/JsonStringCommand.java delete mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java delete mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java delete mode 100644 src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java index 8f4e9e7..b48a3cd 100644 --- a/src/main/java/de/torui/coflsky/CoflSkyCommand.java +++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java @@ -4,9 +4,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.CommandType; -import de.torui.coflsky.core.JsonStringCommand; +import de.torui.coflsky.commands.Command; +import de.torui.coflsky.commands.CommandType; +import de.torui.coflsky.commands.JsonStringCommand; import de.torui.coflsky.minecraft_integration.CoflSessionManager; import de.torui.coflsky.minecraft_integration.CoflSessionManager.CoflSession; import de.torui.coflsky.network.QueryServerCommands; diff --git a/src/main/java/de/torui/coflsky/EventRegistry.java b/src/main/java/de/torui/coflsky/EventRegistry.java index bb2f24f..f155cfb 100644 --- a/src/main/java/de/torui/coflsky/EventRegistry.java +++ b/src/main/java/de/torui/coflsky/EventRegistry.java @@ -1,10 +1,10 @@ package de.torui.coflsky; -import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.CommandType; -import de.torui.coflsky.core.JsonStringCommand; import java.util.UUID; +import de.torui.coflsky.commands.Command; +import de.torui.coflsky.commands.CommandType; +import de.torui.coflsky.commands.JsonStringCommand; import de.torui.coflsky.network.WSClient; import net.minecraft.client.Minecraft; import net.minecraft.server.MinecraftServer; diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java index 287ed09..a06640c 100644 --- a/src/main/java/de/torui/coflsky/WSCommandHandler.java +++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java @@ -2,10 +2,10 @@ package de.torui.coflsky; import com.google.gson.reflect.TypeToken; -import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.JsonStringCommand; -import de.torui.coflsky.core.commandEntities.SoundData; -import de.torui.coflsky.core.commandEntities.ChatMessageData; +import de.torui.coflsky.commands.Command; +import de.torui.coflsky.commands.JsonStringCommand; +import de.torui.coflsky.commands.models.ChatMessageData; +import de.torui.coflsky.commands.models.SoundData; import de.torui.coflsky.network.WSClient; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; diff --git a/src/main/java/de/torui/coflsky/commands/Command.java b/src/main/java/de/torui/coflsky/commands/Command.java new file mode 100644 index 0000000..20ab8f1 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/Command.java @@ -0,0 +1,42 @@ +package de.torui.coflsky.commands; + +import com.google.gson.annotations.SerializedName; + +public class Command { + @SerializedName("type") + private CommandType Type; + @SerializedName("data") + private T data; + + public Command() { + } + + public Command(CommandType type, T data) { + super(); + Type = type; + this.data = data; + } + + public CommandType getType() { + return Type; + } + + public void setType(CommandType type) { + Type = type; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + @Override + public String toString() { + return "Command [Type=" + Type + ", data=" + data + "]"; + } + +} + diff --git a/src/main/java/de/torui/coflsky/commands/CommandType.java b/src/main/java/de/torui/coflsky/commands/CommandType.java new file mode 100644 index 0000000..3fac287 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/CommandType.java @@ -0,0 +1,30 @@ +package de.torui.coflsky.commands; + +import com.google.gson.annotations.SerializedName; + +public enum CommandType { + @SerializedName("writeToChat") + WriteToChat, + + @SerializedName("execute") + Execute, + + @SerializedName("tokenLogin") + TokenLogin, + + @SerializedName("clicked") + Clicked, + + @SerializedName("playSound") + PlaySound, + + @SerializedName("chatMessage") + ChatMessage, + + @SerializedName("purchaseStart") + PurchaseStart, + + @SerializedName("purchaseConfirm") + PurchaseConfirm, + +} diff --git a/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java new file mode 100644 index 0000000..6bc22d8 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java @@ -0,0 +1,28 @@ +package de.torui.coflsky.commands; + +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class JsonStringCommand extends Command { + + public JsonStringCommand(String type, String data) { + this.setType(CommandType.valueOf(type)); + this.setData(data); + } + + public JsonStringCommand() { + super(); + + } + + public JsonStringCommand(CommandType type, String data) { + super(type, data); + } + + public Command GetAs(TypeToken type){ + T t = new GsonBuilder().create().fromJson(this.getData(),type.getType()); + Command cmd = new Command(this.getType(), t); + + return (Command) cmd; + } +} diff --git a/src/main/java/de/torui/coflsky/commands/models/AuctionData.java b/src/main/java/de/torui/coflsky/commands/models/AuctionData.java new file mode 100644 index 0000000..ff1f705 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/models/AuctionData.java @@ -0,0 +1,30 @@ +package de.torui.coflsky.commands.models; + +import com.google.gson.annotations.SerializedName; + +public class AuctionData { + @SerializedName("auctionId") + private String auctionId; + @SerializedName("itemId") + private String itemId; + public String getAuctionId() { + return auctionId; + } + public void setAuctionId(String auctionId) { + this.auctionId = auctionId; + } + public String getItemId() { + return itemId; + } + public void setItemId(String itemId) { + this.itemId = itemId; + } + public AuctionData(String auctionId, String itemId) { + super(); + this.auctionId = auctionId; + this.itemId = itemId; + } + + public AuctionData() {} + +} diff --git a/src/main/java/de/torui/coflsky/commands/models/ChatMessageData.java b/src/main/java/de/torui/coflsky/commands/models/ChatMessageData.java new file mode 100644 index 0000000..65459c5 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/models/ChatMessageData.java @@ -0,0 +1,25 @@ +package de.torui.coflsky.commands.models; + +import com.google.gson.annotations.SerializedName; + +public class ChatMessageData { + @SerializedName("text") + public String Text; + @SerializedName("onClick") + public String OnClick; + + @SerializedName("hover") + public String Hover; + + public ChatMessageData() { + + } + + public ChatMessageData(String text, String onClick, String hover) { + super(); + Text = text; + OnClick = onClick; + Hover = hover; + } + +} diff --git a/src/main/java/de/torui/coflsky/commands/models/SoundData.java b/src/main/java/de/torui/coflsky/commands/models/SoundData.java new file mode 100644 index 0000000..5df18d3 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/models/SoundData.java @@ -0,0 +1,23 @@ +package de.torui.coflsky.commands.models; + +import com.google.gson.annotations.SerializedName; + +public class SoundData { + @SerializedName("name") + public String Name; + + @SerializedName("pitch") + public float Pitch; + + public SoundData() { + super(); + } + + public SoundData(String name, float pitch) { + super(); + Name = name; + Pitch = pitch; + } + + +} diff --git a/src/main/java/de/torui/coflsky/core/Command.java b/src/main/java/de/torui/coflsky/core/Command.java deleted file mode 100644 index e18c59a..0000000 --- a/src/main/java/de/torui/coflsky/core/Command.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.annotations.SerializedName; - -public class Command { - @SerializedName("type") - private CommandType Type; - @SerializedName("data") - private T data; - - public Command() { - } - - public Command(CommandType type, T data) { - super(); - Type = type; - this.data = data; - } - - public CommandType getType() { - return Type; - } - - public void setType(CommandType type) { - Type = type; - } - - public T getData() { - return data; - } - - public void setData(T 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 deleted file mode 100644 index 74e8a41..0000000 --- a/src/main/java/de/torui/coflsky/core/CommandType.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.annotations.SerializedName; - -public enum CommandType { - @SerializedName("writeToChat") - WriteToChat, - - @SerializedName("execute") - Execute, - - @SerializedName("tokenLogin") - TokenLogin, - - @SerializedName("clicked") - Clicked, - - @SerializedName("playSound") - PlaySound, - - @SerializedName("chatMessage") - ChatMessage, - - @SerializedName("purchaseStart") - PurchaseStart, - - @SerializedName("purchaseConfirm") - PurchaseConfirm, - -} diff --git a/src/main/java/de/torui/coflsky/core/JsonStringCommand.java b/src/main/java/de/torui/coflsky/core/JsonStringCommand.java deleted file mode 100644 index 9ce0cb1..0000000 --- a/src/main/java/de/torui/coflsky/core/JsonStringCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.torui.coflsky.core; - -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; - -public class JsonStringCommand extends Command { - - public JsonStringCommand(String type, String data) { - this.setType(CommandType.valueOf(type)); - this.setData(data); - } - - public JsonStringCommand() { - super(); - - } - - public JsonStringCommand(CommandType type, String data) { - super(type, data); - } - - public Command GetAs(TypeToken type){ - T t = new GsonBuilder().create().fromJson(this.getData(),type.getType()); - Command cmd = new Command(this.getType(), t); - - return (Command) cmd; - } -} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java b/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java deleted file mode 100644 index 0e677b2..0000000 --- a/src/main/java/de/torui/coflsky/core/commandEntities/AuctionData.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.torui.coflsky.core.commandEntities; - -import com.google.gson.annotations.SerializedName; - -public class AuctionData { - @SerializedName("auctionId") - private String auctionId; - @SerializedName("itemId") - private String itemId; - public String getAuctionId() { - return auctionId; - } - public void setAuctionId(String auctionId) { - this.auctionId = auctionId; - } - public String getItemId() { - return itemId; - } - public void setItemId(String itemId) { - this.itemId = itemId; - } - public AuctionData(String auctionId, String itemId) { - super(); - this.auctionId = auctionId; - this.itemId = itemId; - } - - public AuctionData() {} - -} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java b/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java deleted file mode 100644 index cfc1381..0000000 --- a/src/main/java/de/torui/coflsky/core/commandEntities/ChatMessageData.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.torui.coflsky.core.commandEntities; - -import com.google.gson.annotations.SerializedName; - -public class ChatMessageData { - @SerializedName("text") - public String Text; - @SerializedName("onClick") - public String OnClick; - - @SerializedName("hover") - public String Hover; - - public ChatMessageData() { - - } - - public ChatMessageData(String text, String onClick, String hover) { - super(); - Text = text; - OnClick = onClick; - Hover = hover; - } - -} diff --git a/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java b/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java deleted file mode 100644 index 64687ab..0000000 --- a/src/main/java/de/torui/coflsky/core/commandEntities/SoundData.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.torui.coflsky.core.commandEntities; - -import com.google.gson.annotations.SerializedName; - -public class SoundData { - @SerializedName("name") - public String Name; - - @SerializedName("pitch") - public float Pitch; - - public SoundData() { - super(); - } - - public SoundData(String name, float pitch) { - super(); - Name = name; - Pitch = pitch; - } - - -} diff --git a/src/main/java/de/torui/coflsky/network/WSClient.java b/src/main/java/de/torui/coflsky/network/WSClient.java index b3f28ca..cd23b30 100644 --- a/src/main/java/de/torui/coflsky/network/WSClient.java +++ b/src/main/java/de/torui/coflsky/network/WSClient.java @@ -16,8 +16,8 @@ import com.neovisionaries.ws.client.WebSocketState; import net.minecraft.client.Minecraft; import de.torui.coflsky.CoflSky; import de.torui.coflsky.WSCommandHandler; -import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.JsonStringCommand; +import de.torui.coflsky.commands.Command; +import de.torui.coflsky.commands.JsonStringCommand; public class WSClient extends WebSocketAdapter { diff --git a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java index dd9d13b..6542542 100644 --- a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java +++ b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java @@ -9,8 +9,8 @@ import java.util.UUID; import com.neovisionaries.ws.client.WebSocketException; import de.torui.coflsky.CoflSky; -import de.torui.coflsky.core.Command; -import de.torui.coflsky.core.JsonStringCommand; +import de.torui.coflsky.commands.Command; +import de.torui.coflsky.commands.JsonStringCommand; import de.torui.coflsky.minecraft_integration.PlayerDataProvider; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; -- cgit