diff options
Diffstat (limited to 'src/main/java/de/torui/coflsky/WSCommandHandler.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/WSCommandHandler.java | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java index ef15381..5427364 100644 --- a/src/main/java/de/torui/coflsky/WSCommandHandler.java +++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java @@ -1,16 +1,16 @@ package de.torui.coflsky; +import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import de.torui.coflsky.commands.Command; import de.torui.coflsky.commands.CommandType; import de.torui.coflsky.commands.JsonStringCommand; -import de.torui.coflsky.commands.models.ChatMessageData; -import de.torui.coflsky.commands.models.FlipData; -import de.torui.coflsky.commands.models.SoundData; +import de.torui.coflsky.commands.RawCommand; +import de.torui.coflsky.commands.models.*; import de.torui.coflsky.configuration.ConfigurationManager; -import de.torui.coflsky.commands.models.TimerData; import de.torui.coflsky.handlers.EventRegistry; +import de.torui.coflsky.utils.FileUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.SoundHandler; @@ -23,11 +23,18 @@ import net.minecraft.util.ChatStyle; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.ForgeModContainer; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; + +import java.io.File; public class WSCommandHandler { public static transient String lastOnClickEvent; public static FlipHandler flipHandler = new FlipHandler(); + private static final ModListData modListData = new ModListData(); + private static final Gson gson = new Gson(); public static boolean HandleCommand(JsonStringCommand cmd, Entity sender) { // Entity sender = Minecraft.getMinecraft().thePlayer; @@ -54,6 +61,9 @@ public class WSCommandHandler { case Countdown: StartTimer(cmd.GetAs(new TypeToken<TimerData>() {})); break; + case GetMods: + getMods(); + break; default: break; } @@ -61,6 +71,30 @@ public class WSCommandHandler { return true; } + public static void cacheMods(){ + File modFolder = new File(Minecraft.getMinecraft().mcDataDir, "mods"); + for(File mods : modFolder.listFiles()){ + modListData.addFilename(mods.getName()); + try { + modListData.addFileHashes(FileUtils.getMD5Checksum(mods)); + } catch (Exception exception){ + // Highly less likely to happen unless something goes wrong + exception.printStackTrace(); + } + } + + for(ModContainer mod : Loader.instance().getModList()){ + modListData.addModname(mod.getName()); + modListData.addModname(mod.getModId()); + } + } + + private static void getMods(){ + // the Cofl server has asked for an mod list now let's respond with all the info + CoflSky.Wrapper.SendMessage(new RawCommand("foundMods",gson.toJson(modListData))); + } + + private static void Flip(Command<FlipData> cmd) { //handle chat message ChatMessageData[] messages = cmd.getData().Messages; |