diff --git a/build.gradle b/build.gradle index 5e0f514..1bdfb56 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { implementation fileTree(dir: 'libs', include: '*.jar') implementation "org.json:json:20210307" - implementation "gg.essential:Vigilance:123-10809-SNAPSHOT" + implementation "gg.essential:Vigilance:141-10809-SNAPSHOT" implementation "org.spongepowered:mixin:0.7.11-SNAPSHOT" annotationProcessor "org.spongepowered:mixin:0.7.11-SNAPSHOT" @@ -144,7 +144,7 @@ reobf { jar { manifest { attributes "ModSide": "CLIENT", - "FMLCorePlugin": "io.github.koxx12_dev.scc.fml.CoreMod", + "FMLCorePlugin": "io.github.koxx12dev.scc.fml.CoreMod", "FMLCorePluginContainsFMLMod": "true", "ForceLoadAsMod": true, "MixinConfigs": "mixins.scc.json", diff --git a/gradle.properties b/gradle.properties index 82c5971..1420628 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -mod_id=scc +mod_id=skyclientcosmetics mod_name=Skyclient Cosmetics -mod_version=BETA-5.3 +mod_version=BETA-6 mod_description=Cosmetics for the mod installer Skyclient! org.gradle.jvmargs=-Xmx2G \ No newline at end of file diff --git a/libs.md b/libs.md new file mode 100644 index 0000000..6661367 --- /dev/null +++ b/libs.md @@ -0,0 +1,8 @@ +# Libraries used + +| Lib | Licence | Reason | +| ------------- | ------------- | ------------- | +| [Discord game sdk4j](https://github.com/JnCrMx/discord-game-sdk4j) | MIT | Discord RPC | +| [Vigilance](https://github.com/Sk1erLLC/Vigilance) | LGPL-3.0 | Settings UI | +| [JSON](https://github.com/stleary/JSON-java) | [Custom](https://github.com/stleary/JSON-java/blob/master/LICENSE) | Do i need to explain it? | +| [Mixin](https://github.com/SpongePowered/Mixin) | MIT | Changing loading screen | \ No newline at end of file diff --git a/src/main/java/io/github/koxx12_dev/scc/Utils/HTTPstuff.java b/src/main/java/io/github/koxx12_dev/scc/Utils/HTTPstuff.java deleted file mode 100644 index b2e39c7..0000000 --- a/src/main/java/io/github/koxx12_dev/scc/Utils/HTTPstuff.java +++ /dev/null @@ -1,73 +0,0 @@ -package io.github.koxx12_dev.scc.Utils; - -import io.github.koxx12_dev.scc.SCC; -import org.json.JSONArray; -import org.json.JSONObject; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.List; -import java.util.Scanner; - -public class HTTPstuff { - - public static String request(String URL) throws IOException { - - java.net.URL url = new URL(URL); - URLConnection conn = url.openConnection(); - InputStream inputStream = conn.getInputStream(); - Scanner s = new Scanner(inputStream).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - - } - - public static void reloadTags(){ - - try { - SCC.HypixelRanks.clear(); - SCC.UUIDtags.clear(); - SCC.UUIDtagsShort.clear(); - SCC.api = HTTPstuff.getApiData(); - } catch (Exception ignored) {} - - JSONObject api = SCC.api; - - try { - JSONArray tagsIdList = api.getJSONObject("tags").names(); - JSONArray permsIdList = api.getJSONObject("perms").names(); - JSONArray HPRanks = api.getJSONArray("HpRanks"); - if (permsIdList.length() != tagsIdList.length()) { - throw new Error("Someone broke the repo\nwait for staff to fix it"); - } - for (int i = 0; i < tagsIdList.length(); i++) { - List tag = api.getJSONObject("tags").getJSONArray((String) tagsIdList.get(i)).toList(); - JSONArray perms = api.getJSONObject("perms").getJSONArray((String) tagsIdList.get(i)); - for (int j = 0; j < perms.length(); j++) { - String uuid = perms.getString(j).replaceAll("-",""); - - String name = HTTPstuff.request("https://api.mojang.com/user/profiles/"+uuid+"/names"); - JSONArray nameJson = new JSONArray(name); - String nme = (String) nameJson.getJSONObject(nameJson.length()-1).get("name"); - - SCC.UUIDtagsShort.put(nme,tag.get(1).toString().replaceAll("&","\u00A7")); - SCC.UUIDtags.put(nme,tag.get(0).toString().replaceAll("&","\u00A7")); - } - } - for (int i = 0; i < HPRanks.length(); i++) { - SCC.HypixelRanks.add(HPRanks.get(i).toString()); - } - } catch (IOException ignored) { - } - - SCC.LOGGER.debug(SCC.UUIDtags); - SCC.LOGGER.debug(SCC.UUIDtagsShort); - SCC.LOGGER.debug(SCC.HypixelRanks); - } - - public static JSONObject getApiData() throws IOException { - return new JSONObject(HTTPstuff.request("https://koxx12-dev.github.io/api/scc/tags.json")); - } - -} diff --git a/src/main/java/io/github/koxx12_dev/scc/Utils/Transformers.java b/src/main/java/io/github/koxx12_dev/scc/Utils/Transformers.java deleted file mode 100644 index b18e4e1..0000000 --- a/src/main/java/io/github/koxx12_dev/scc/Utils/Transformers.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.github.koxx12_dev.scc.Utils; - -import io.github.koxx12_dev.scc.SCC; -import net.minecraft.client.Minecraft; - -public class Transformers { - - public static String cleanMessage(String msg) { - //if null, keep null (no gain or loss of safety) - if (msg == null) - return null; - - msg = msg.replaceAll("\u00A7k","") - .replaceAll("\u00A7l","") - .replaceAll("\u00A7m","") - .replaceAll("\u00A7n","") - .replaceAll("\u00A7o","") - .replaceAll("\u00A7r","") - .replaceAll("\u00A74","") - .replaceAll("\u00A7c","") - .replaceAll("\u00A76","") - .replaceAll("\u00A7e","") - .replaceAll("\u00A72","") - .replaceAll("\u00A7a","") - .replaceAll("\u00A7b","") - .replaceAll("\u00A73","") - .replaceAll("\u00A71","") - .replaceAll("\u00A79","") - .replaceAll("\u00A7d","") - .replaceAll("\u00A75","") - .replaceAll("\u00A7f","") - .replaceAll("\u00A77","") - .replaceAll("\u00A78","") - .replaceAll("\u00A70",""); - - return msg; - } - public static String DiscordPlaceholder(String text) { - String text2 = text.replaceAll("%player%", Minecraft.getMinecraft().getSession().getUsername()); - - try{ - text2 = text2.replaceAll("%fps%", String.valueOf(Minecraft.getDebugFPS())); - } catch (Exception ignored) {} - try{ - text2 = text2.replaceAll("%shorttag%", cleanMessage(SCC.UUIDtagsShort.get(Minecraft.getMinecraft().getSession().getUsername()))); - } catch (Exception ignored) {} - try{ - text2 = text2.replaceAll("%tag%", cleanMessage(SCC.UUIDtags.get(Minecraft.getMinecraft().getSession().getUsername()))); - } catch (Exception ignored) {} - try { - text2 = text2.replaceAll("%hand%", cleanMessage(Minecraft.getMinecraft().thePlayer.getHeldItem().getDisplayName())); - } catch (NullPointerException e) { - text2 = text2.replaceAll("%hand%", "Nothing"); - } - return text2; - } -} diff --git a/src/main/java/io/github/koxx12_dev/scc/listeners/ChatListeners.java b/src/main/java/io/github/koxx12_dev/scc/listeners/ChatListeners.java deleted file mode 100644 index 0a07792..0000000 --- a/src/main/java/io/github/koxx12_dev/scc/listeners/ChatListeners.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.github.koxx12_dev.scc.listeners; - -import io.github.koxx12_dev.scc.GUI.SCCConfig; -import io.github.koxx12_dev.scc.SCC; -import io.github.koxx12_dev.scc.Utils.DetectionStuff; -import io.github.koxx12_dev.scc.Utils.Transformers; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ChatListeners { - - @SubscribeEvent - public void onChatMsg(ClientChatReceivedEvent event) { - if (SCCConfig.TagsShow && DetectionStuff.isOnHypixel()) { - - if (SCCConfig.DebugLogs) { - SCC.LOGGER.info(event.message.getFormattedText() + " , " + Transformers.cleanMessage(event.message.getUnformattedText())); - SCC.LOGGER.info(Arrays.toString(event.message.getFormattedText().split(" ")) + " , " + Arrays.toString(Transformers.cleanMessage(event.message.getUnformattedText()).split(" "))); - } - - List msgAsList = new ArrayList<>(Arrays.asList(event.message.getFormattedText().split(" "))); - List cleanMsgAsList = new ArrayList<>(Arrays.asList(Transformers.cleanMessage(event.message.getUnformattedText()).split(" "))); - - - for (int i = 0; i < (cleanMsgAsList.toArray().length-1); i++) { - - String val = cleanMsgAsList.get(i); - String valClean = cleanMsgAsList.get(i).replaceAll(",","").replaceAll(":",""); - if (SCC.HypixelRanks.contains(val)) { - - - int j = (i+1); - try { - - String val2; - - if (!SCCConfig.ShortenTags) { - val2 = SCC.UUIDtags.get(cleanMsgAsList.get(j).replaceAll(":","")); - } else { - val2 = SCC.UUIDtagsShort.get(cleanMsgAsList.get(j).replaceAll(":","")); - } - - if (val2 != null) { - msgAsList.add(i,val2); - event.message = new ChatComponentText(String.join(" ", msgAsList)); - } else { - SCC.LOGGER.debug(cleanMsgAsList.get(j).replaceAll(":","") + " doesnt have a tag"); - } - } catch (Exception e) { - SCC.LOGGER.debug(cleanMsgAsList.get(j).replaceAll(":","") + " doesnt have a tag"); - } - break; - } else if(SCC.UUIDtags.containsKey(valClean) && val.contains(":")) { - - String val2; - - if (!SCCConfig.ShortenTags) { - val2 = SCC.UUIDtags.get(valClean); - } else { - val2 = SCC.UUIDtagsShort.get(valClean); - } - - msgAsList.add(i,val2); - - event.message = new ChatComponentText(String.join(" ", msgAsList)); - - break; - - } - - } - - - - } - if (SCCConfig.DebugTags) { - try { - SCC.LOGGER.debug(event.message = new ChatComponentText(SCC.UUIDtags.get(Minecraft.getMinecraft().getSession().getUsername()))); - } catch (Exception e) { - SCC.LOGGER.debug(Minecraft.getMinecraft().getSession().getUsername() + " doesnt have a tag"); - } - - } - } -} diff --git a/src/main/java/io/github/koxx12_dev/scc/listeners/PlayerListeners.java b/src/main/java/io/github/koxx12_dev/scc/listeners/PlayerListeners.java deleted file mode 100644 index 7666194..0000000 --- a/src/main/java/io/github/koxx12_dev/scc/listeners/PlayerListeners.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.koxx12_dev.scc.listeners; - -import io.github.koxx12_dev.scc.GUI.SCCConfig; -import io.github.koxx12_dev.scc.SCC; -import io.github.koxx12_dev.scc.threads.JoinThread; -import net.minecraft.client.Minecraft; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent; - -public class PlayerListeners { - - @SubscribeEvent - public void onPlayerLoggedIn(FMLNetworkEvent.ClientConnectedToServerEvent event) { - - Thread joinThread = new JoinThread(); - joinThread.start(); - - } - - @SubscribeEvent - public void onNameFormat(PlayerEvent.NameFormat event) { - if (SCCConfig.DebugDisplayTags) { - event.displayname = SCC.UUIDtags.get(Minecraft.getMinecraft().getSession().getUsername()); - } - - if (SCCConfig.DisplayTags) { - if (SCC.UUIDtags.containsKey(event.displayname)) { - String tag; - - if (SCCConfig.ShortenTags) { - tag = SCC.UUIDtagsShort.get(event.displayname); - } else { - tag = SCC.UUIDtags.get(event.displayname); - } - event.displayname = tag + " " + event.displayname; - } - } - } - -} diff --git a/src/main/java/io/github/koxx12_dev/scc/threads/JoinThread.java b/src/main/java/io/github/koxx12_dev/scc/threads/JoinThread.java deleted file mode 100644 index 5c7ed7f..0000000 --- a/src/main/java/io/github/koxx12_dev/scc/threads/JoinThread.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.koxx12_dev.scc.threads; - -import io.github.koxx12_dev.scc.GUI.SCCConfig; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -public class JoinThread extends Thread { - - public void run() { - - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - if (SCCConfig.JoinMessage) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA +"Looks like you are using Skyclient Cosmetics for the first time\n"+ EnumChatFormatting.AQUA +"Use /scc to get started!")); - SCCConfig.JoinMessage = false; - } - - } - -} diff --git a/src/main/java/io/github/koxx12_dev/scc/SCC.java b/src/main/java/io/github/koxx12dev/scc/SkyclientCosmetics.java similarity index 63% rename from src/main/java/io/github/koxx12_dev/scc/SCC.java rename to src/main/java/io/github/koxx12dev/scc/SkyclientCosmetics.java index 69aefa6..b212f95 100644 --- a/src/main/java/io/github/koxx12_dev/scc/SCC.java +++ b/src/main/java/io/github/koxx12dev/scc/SkyclientCosmetics.java @@ -1,13 +1,14 @@ -package io.github.koxx12_dev.scc; +package io.github.koxx12dev.scc; import de.jcm.discordgamesdk.Core; -import io.github.koxx12_dev.scc.Commands.MainCommand; -import io.github.koxx12_dev.scc.GUI.SCCConfig; -import io.github.koxx12_dev.scc.Utils.HTTPstuff; -import io.github.koxx12_dev.scc.Utils.RPC; -import io.github.koxx12_dev.scc.listeners.ChatListeners; -import io.github.koxx12_dev.scc.listeners.GuiListners; -import io.github.koxx12_dev.scc.listeners.PlayerListeners; +import io.github.koxx12dev.scc.Utils.Cache; +import io.github.koxx12dev.scc.commands.MainCommand; +import io.github.koxx12dev.scc.gui.Settings; +import io.github.koxx12dev.scc.Utils.Requests; +import io.github.koxx12dev.scc.Utils.RPC; +import io.github.koxx12dev.scc.listeners.ChatListeners; +import io.github.koxx12dev.scc.listeners.GuiListners; +import io.github.koxx12dev.scc.listeners.PlayerListeners; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.client.ClientCommandHandler; @@ -26,41 +27,43 @@ import java.util.HashMap; import java.util.List; -@Mod(modid = SCC.MOD_ID, name = SCC.MOD_NAME, version = SCC.MOD_VERSION, clientSideOnly = true) -public class SCC { +@Mod(modid = SkyclientCosmetics.MOD_ID, name = SkyclientCosmetics.MOD_NAME, version = SkyclientCosmetics.MOD_VERSION, clientSideOnly = true) +public class SkyclientCosmetics { public static final String MOD_NAME = "${GRADLE_MOD_NAME}"; public static final String MOD_ID = "${GRADLE_MOD_ID}"; public static final String MOD_VERSION = "${GRADLE_MOD_VERSION}"; -public static boolean RPCRunning = false; +public static boolean rpcRunning = false; -public static boolean RPCon = false; +public static boolean rpcOn = false; public static GuiScreen displayScreen; -public static List HypixelRanks = new ArrayList<>(); +public static List hypixelRanks = new ArrayList<>(); -public static SCCConfig config; +public static Settings config; -public static HashMap UUIDtags = new HashMap<>(); - -public static HashMap UUIDtagsShort = new HashMap<>(); +public static HashMap> uuidTags = new HashMap<>(); public static JSONObject api; -public static Core RPCcore; +public static Core rpcCore; -public static String PartyID = RPC.generateID(); +public static String partyID = RPC.generateID(); public static Logger LOGGER; +public static String rankColor; + @Mod.EventHandler public void onPreInit(FMLPreInitializationEvent event) throws IOException { + Cache.setup(); + LOGGER = event.getModLog(); - api = HTTPstuff.getApiData(); + api = Requests.getApiData(); /* if ((boolean)api.get("whitelist")) { String UUID = Minecraft.getMinecraft().getSession().getPlayerID(); @@ -80,7 +83,7 @@ public void onInit(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new PlayerListeners()); MinecraftForge.EVENT_BUS.register(new GuiListners()); - RPC.INSTANCE.RPCManager(); + RPC.INSTANCE.rpcManager(); MinecraftForge.EVENT_BUS.register(RPC.INSTANCE); @@ -89,7 +92,7 @@ public void onInit(FMLInitializationEvent event) { } @Mod.EventHandler -public void onPostInit(FMLPostInitializationEvent event) { +public void onPostInit(FMLPostInitializationEvent event) throws IOException { // $USER = The username of the currently logged in user. // Simply prints out Hello, $USER. /* @@ -99,28 +102,28 @@ public void onPostInit(FMLPostInitializationEvent event) { })); - SCC.LOGGER.info(Arrays.toString(new File(Minecraft.getMinecraft().mcDataDir, "mods").list())); + SkyclientCosmetics.LOGGER.info(Arrays.toString(new File(Minecraft.getMinecraft().mcDataDir, "mods").list())); //throw new Error("fuck sbe https://github.com/MicrocontrollersDev/Alternatives/blob/1e409e056e3e14ca874a2368c045de96787e8cbd/SkyblockExtras.md"); } */ - - HTTPstuff.reloadTags(); - config = new SCCConfig(); + Requests.reloadTags(); + config = new Settings(); config.preload(); + Requests.setRankColor(); } @SubscribeEvent -public void onTick(TickEvent.ClientTickEvent event) { +public void onTick(TickEvent.ClientTickEvent event) throws IOException { if (event.phase != TickEvent.Phase.START) return; if (displayScreen != null) { Minecraft.getMinecraft().displayGuiScreen(displayScreen); displayScreen = null; } - if (SCCConfig.reloadTags) { - HTTPstuff.reloadTags(); - SCCConfig.reloadTags = false; + if (Settings.reloadTags) { + Requests.reloadTags(); + Settings.reloadTags = false; } } } diff --git a/src/main/java/io/github/koxx12dev/scc/Utils/Cache.java b/src/main/java/io/github/koxx12dev/scc/Utils/Cache.java new file mode 100644 index 0000000..43f1c13 --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/Utils/Cache.java @@ -0,0 +1,107 @@ +package io.github.koxx12dev.scc.Utils; + +import net.minecraft.client.Minecraft; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.*; +import java.time.Instant; +import java.util.Base64; +import java.util.Calendar; +import java.util.Date; +import java.util.Scanner; + +public class Cache { + + public static File mcConfigDir = new File(Minecraft.getMinecraft().mcDataDir,"config"); + + public static File sccConfigDir = new File(mcConfigDir,"SkyClientCosmetics"); + + public static File sccCacheFile = new File(sccConfigDir,"SCC-Cache.txt"); + + public static JSONObject tempCache = new JSONObject(); + + public static void setup() throws IOException { + + if (!sccConfigDir.exists()) { + sccConfigDir.mkdir(); + } + + if (!sccCacheFile.exists()) { + sccCacheFile.createNewFile(); + } else { + loadCache(); + } + + } + + public static String getData(String uuid) throws IOException { + + if (!tempCache.has("timestamp")) { + updateTimestamp(true); + } + + if (!tempCache.has(uuid) || tempCache.getLong("timestamp") > Instant.now().toEpochMilli()) { + + String name = Requests.request("https://api.mojang.com/user/profiles/" + uuid + "/names"); + JSONArray nameJson = new JSONArray(name); + String nme = (String) nameJson.getJSONObject(nameJson.length() - 1).get("name"); + + tempCache.put(uuid,nme); + //SkyclientCosmetics.LOGGER.info("PUT {} AS {} TO CACHE",uuid,nme); + } + + return tempCache.get(uuid).toString(); + } + + public static void saveCache() throws IOException { + + String b64json = Base64.getEncoder().encodeToString(tempCache.toString().getBytes()); + + FileWriter fileWriter = new FileWriter(sccCacheFile); + PrintWriter printWriter = new PrintWriter(fileWriter); + printWriter.print(b64json); + printWriter.close(); + + } + + public static void loadCache() throws FileNotFoundException { + Scanner reader = new Scanner(sccCacheFile); + if (reader.hasNextLine()) { + String data = reader.nextLine(); + reader.close(); + byte[] bytes = Base64.getDecoder().decode(data); + tempCache = new JSONObject(new String(bytes)); + } + + } + + public static void updateTimestamp() { + + if (tempCache.getLong("timestamp") > Instant.now().toEpochMilli()) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(Date.from(Instant.now())); + calendar.add(Calendar.HOUR_OF_DAY, 48); + long timestamp = calendar.getTimeInMillis() / 1000; + + tempCache.put("timestamp", timestamp); + + //SkyclientCosmetics.LOGGER.info("UPDATED CACHE TIMESTAMP"); + + } + } + + public static void updateTimestamp(boolean force) { + if (force) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(Date.from(Instant.now())); + calendar.add(Calendar.HOUR_OF_DAY, 48); + long timestamp = calendar.getTimeInMillis() / 1000; + + tempCache.put("timestamp", timestamp); + + //SkyclientCosmetics.LOGGER.info("UPDATED CACHE TIMESTAMP"); + } + } + +} diff --git a/src/main/java/io/github/koxx12dev/scc/Utils/Chat.java b/src/main/java/io/github/koxx12dev/scc/Utils/Chat.java new file mode 100644 index 0000000..0ee860d --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/Utils/Chat.java @@ -0,0 +1,13 @@ +package io.github.koxx12dev.scc.Utils; + +import gg.essential.universal.ChatColor; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; + +public class Chat { + + public static void sendMessagePrivate(String message) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(ChatColor.DARK_GREEN+"["+ChatColor.AQUA+"SkyClien"+ChatColor.DARK_AQUA+"'"+ChatColor.AQUA+"t Cosmetics"+ChatColor.DARK_GREEN+"]"+ChatColor.WHITE+": "+ChatColor.RESET+message)); + } + +} diff --git a/src/main/java/io/github/koxx12_dev/scc/Utils/DownloadSDK.java b/src/main/java/io/github/koxx12dev/scc/Utils/DownloadSDK.java similarity index 98% rename from src/main/java/io/github/koxx12_dev/scc/Utils/DownloadSDK.java rename to src/main/java/io/github/koxx12dev/scc/Utils/DownloadSDK.java index 3756d57..4ccb70e 100644 --- a/src/main/java/io/github/koxx12_dev/scc/Utils/DownloadSDK.java +++ b/src/main/java/io/github/koxx12dev/scc/Utils/DownloadSDK.java @@ -1,4 +1,4 @@ -package io.github.koxx12_dev.scc.Utils; +package io.github.koxx12dev.scc.Utils; import java.io.BufferedInputStream; import java.io.File; diff --git a/src/main/java/io/github/koxx12_dev/scc/Utils/RPC.java b/src/main/java/io/github/koxx12dev/scc/Utils/RPC.java similarity index 70% rename from src/main/java/io/github/koxx12_dev/scc/Utils/RPC.java rename to src/main/java/io/github/koxx12dev/scc/Utils/RPC.java index b30726f..e2bc23f 100644 --- a/src/main/java/io/github/koxx12_dev/scc/Utils/RPC.java +++ b/src/main/java/io/github/koxx12dev/scc/Utils/RPC.java @@ -1,12 +1,12 @@ -package io.github.koxx12_dev.scc.Utils; +package io.github.koxx12dev.scc.Utils; import de.jcm.discordgamesdk.Core; import de.jcm.discordgamesdk.CreateParams; import de.jcm.discordgamesdk.DiscordEventAdapter; import de.jcm.discordgamesdk.GameSDKException; import de.jcm.discordgamesdk.activity.Activity; -import io.github.koxx12_dev.scc.GUI.SCCConfig; -import io.github.koxx12_dev.scc.SCC; +import io.github.koxx12dev.scc.SkyclientCosmetics; +import io.github.koxx12dev.scc.gui.Settings; import java.io.File; import java.io.IOException; @@ -21,9 +21,9 @@ public class RPC extends Thread { private static Instant timestamp = Instant.now(); - public void RPCManager() { - if (!SCC.RPCRunning) { - SCC.RPCRunning = true; + public void rpcManager() { + if (!SkyclientCosmetics.rpcRunning) { + SkyclientCosmetics.rpcRunning = true; trd.start(); } } @@ -51,24 +51,24 @@ public void run() { @Override public void onActivityJoin(String secret) { - SCC.LOGGER.info(""); + SkyclientCosmetics.LOGGER.info(""); } }); try(Core core = new Core(params)) { // Run callbacks forever - SCC.RPCcore = core; + SkyclientCosmetics.rpcCore = core; - while(SCC.RPCRunning) { + while(SkyclientCosmetics.rpcRunning) { try { core.runCallbacks(); } catch (GameSDKException e) { - System.out.println("FAILED TO LAUNCH RPC"); - SCC.RPCRunning = false; + SkyclientCosmetics.LOGGER.warn("FAILED TO LAUNCH RPC"); + SkyclientCosmetics.rpcRunning = false; } try { - if (SCC.RPCRunning) { + if (SkyclientCosmetics.rpcRunning) { Thread.sleep(16); } @@ -76,17 +76,17 @@ public void onActivityJoin(String secret) catch(InterruptedException e) { e.printStackTrace(); } - if (!SCCConfig.RPC && SCC.RPCon && SCC.RPCRunning) { + if (!Settings.rpc && SkyclientCosmetics.rpcOn && SkyclientCosmetics.rpcRunning) { core.activityManager().clearActivity(); - SCC.RPCon = false; - } else if(SCCConfig.RPC && SCC.RPCRunning) { - RPC.update(SCC.RPCcore); + SkyclientCosmetics.rpcOn = false; + } else if(Settings.rpc && SkyclientCosmetics.rpcRunning) { + RPC.update(SkyclientCosmetics.rpcCore); } } } catch (GameSDKException e) { - System.out.println("FAILED TO LAUNCH RPC"); - SCC.RPCRunning = false; + SkyclientCosmetics.LOGGER.warn("FAILED TO LAUNCH RPC"); + SkyclientCosmetics.rpcRunning = false; } } } @@ -101,8 +101,8 @@ public void onActivityJoin(String secret) public static void update(Core core) { try(Activity activity = new Activity()) { - String LineOne = Transformers.DiscordPlaceholder(SCCConfig.RPCLineOne); - String LineTwo = Transformers.DiscordPlaceholder(SCCConfig.RPCLineTwo); + String LineOne = Transformers.discordPlaceholder(Settings.rpcLineOne); + String LineTwo = Transformers.discordPlaceholder(Settings.rpcLineTwo); if (!LineOne.equals("") && LineOne.length() >= 2 && LineOne.length() <= 127) { activity.setDetails(LineOne); @@ -117,19 +117,19 @@ public static void update(Core core) { //activity.party().size().setMaxSize(4); //activity.party().size().setCurrentSize(1); - if (SCCConfig.BadSbeMode) { + if (Settings.sbeBadMode) { activity.assets().setLargeImage("nosbe"); } else { activity.assets().setLargeImage("skyclienticon"); } - activity.assets().setLargeText(Transformers.DiscordPlaceholder(SCCConfig.RPCImgText)); + activity.assets().setLargeText(Transformers.discordPlaceholder(Settings.rpcImgText)); - //activity.party().setID(SCC.PartyID); + //activity.party().setID(SkyclientCosmetics.PartyID); //activity.secrets().setJoinSecret("Secret"); core.activityManager().updateActivity(activity); - SCC.RPCon = true; + SkyclientCosmetics.rpcOn = true; } } diff --git a/src/main/java/io/github/koxx12dev/scc/Utils/Requests.java b/src/main/java/io/github/koxx12dev/scc/Utils/Requests.java new file mode 100644 index 0000000..838df34 --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/Utils/Requests.java @@ -0,0 +1,128 @@ +package io.github.koxx12dev.scc.Utils; + +import gg.essential.universal.ChatColor; +import io.github.koxx12dev.scc.SkyclientCosmetics; +import io.github.koxx12dev.scc.gui.Settings; +import net.minecraft.client.Minecraft; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class Requests { + + public static String request(String URL) throws IOException { + + java.net.URL url = new URL(URL); + URLConnection conn = url.openConnection(); + InputStream inputStream = conn.getInputStream(); + Scanner s = new Scanner(inputStream).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + + } + + public static void reloadTags() throws IOException { + + try { + SkyclientCosmetics.hypixelRanks.clear(); + SkyclientCosmetics.uuidTags.clear(); + SkyclientCosmetics.api = Requests.getApiData(); + } catch (Exception ignored) { + } + + JSONObject api = SkyclientCosmetics.api; + + try { + JSONArray tagsIdList = api.getJSONObject("tags").names(); + JSONArray permsIdList = api.getJSONObject("perms").names(); + JSONArray HPRanks = api.getJSONArray("HpRanks"); + if (permsIdList.length() != tagsIdList.length()) { + throw new Error("Someone broke the repo\nwait for staff to fix it"); + } + for (int i = 0; i < tagsIdList.length(); i++) { + List tag = api.getJSONObject("tags").getJSONArray((String) tagsIdList.get(i)).toList(); + JSONArray perms = api.getJSONObject("perms").getJSONArray((String) tagsIdList.get(i)); + for (int j = 0; j < perms.length(); j++) { + String uuid = perms.getString(j).replaceAll("-", ""); + + String nme = Cache.getData(uuid); + + List tmp = new ArrayList<>(); + + tmp.add(tag.get(0).toString().replaceAll("&", "\u00A7")); + tmp.add(tag.get(1).toString().replaceAll("&", "\u00A7")); + + SkyclientCosmetics.uuidTags.put(nme, tmp); + } + } + for (int i = 0; i < HPRanks.length(); i++) { + SkyclientCosmetics.hypixelRanks.add(HPRanks.get(i).toString()); + } + } catch (IOException ignored) { + } + + SkyclientCosmetics.LOGGER.debug(SkyclientCosmetics.uuidTags); + SkyclientCosmetics.LOGGER.debug(SkyclientCosmetics.hypixelRanks); + Cache.updateTimestamp(); + Cache.saveCache(); + } + + public static JSONObject getApiData() throws IOException { + return new JSONObject(Requests.request("https://koxx12-dev.github.io/api/scc/tags.json")); + } + + public static void setRankColor() { + try { + JSONObject response = new JSONObject(request("https://api.hypixel.net/player?key=" + Settings.hpApiKey + "&uuid=" + Minecraft.getMinecraft().getSession().getPlayerID())); + String rank; + if (response.getBoolean("success")) { + try { + rank = response.getJSONObject("player").get("rank").toString(); + } catch (Exception e) { + try { + try { + rank = response.getJSONObject("player").get("newPackageRank").toString(); + } catch (Exception ee) { + rank = response.getJSONObject("player").get("packageRank").toString(); + } + } catch (Exception eee) { + rank = response.getJSONObject("player").get("monthlyPackageRank").toString(); + } + } + + if (rank.equals("NONE") || rank.equals("NORMAL")) { + SkyclientCosmetics.rankColor = ""; + } else { + System.out.println("TEST: " + rank); + switch (rank) { + case "YOUTUBER": + SkyclientCosmetics.rankColor = ChatColor.RED.toString(); + break; + case "VIP": + case "VIP_PLUS": + SkyclientCosmetics.rankColor = ChatColor.GREEN.toString(); + break; + case "MVP": + case "MVP_PLUS": + SkyclientCosmetics.rankColor = ChatColor.AQUA.toString(); + break; + case "SUPERSTAR": + SkyclientCosmetics.rankColor = ChatColor.GOLD.toString(); + break; + } + } + } else { + throw new IOException("Getting rank color failed"); + } + } catch (Exception e) { + SkyclientCosmetics.rankColor = ""; + } + } + +} diff --git a/src/main/java/io/github/koxx12_dev/scc/Utils/DetectionStuff.java b/src/main/java/io/github/koxx12dev/scc/Utils/ServerDetection.java similarity index 85% rename from src/main/java/io/github/koxx12_dev/scc/Utils/DetectionStuff.java rename to src/main/java/io/github/koxx12dev/scc/Utils/ServerDetection.java index 8364454..765e82d 100644 --- a/src/main/java/io/github/koxx12_dev/scc/Utils/DetectionStuff.java +++ b/src/main/java/io/github/koxx12dev/scc/Utils/ServerDetection.java @@ -1,8 +1,8 @@ -package io.github.koxx12_dev.scc.Utils; +package io.github.koxx12dev.scc.Utils; import net.minecraft.client.Minecraft; -public class DetectionStuff { +public class ServerDetection { /* Code stolen from skytils diff --git a/src/main/java/io/github/koxx12dev/scc/Utils/Tag.java b/src/main/java/io/github/koxx12dev/scc/Utils/Tag.java new file mode 100644 index 0000000..bf08fee --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/Utils/Tag.java @@ -0,0 +1,19 @@ +package io.github.koxx12dev.scc.Utils; + +import io.github.koxx12dev.scc.gui.Settings; + +public class Tag { + + public static boolean isShortTagsOnBoolean() { + return Settings.shortenTags; + } + + public static int isShortTagsOnInt() { + if (Settings.shortenTags) { + return 1; + } else { + return 0; + } + } + +} diff --git a/src/main/java/io/github/koxx12dev/scc/Utils/Transformers.java b/src/main/java/io/github/koxx12dev/scc/Utils/Transformers.java new file mode 100644 index 0000000..8967d6f --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/Utils/Transformers.java @@ -0,0 +1,77 @@ +package io.github.koxx12dev.scc.Utils; + +import io.github.koxx12dev.scc.SkyclientCosmetics; +import net.minecraft.client.Minecraft; +import org.apache.commons.lang3.ArrayUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Transformers { + + public static String cleanMessage(String msg) { + //if null, keep null (no gain or loss of safety) + if (msg == null) + return null; + + List chars = new ArrayList<>(Arrays.asList(ArrayUtils.toObject(msg.toCharArray()))); + // For each character in the String + // add it to the List + for (int i = 0; i < chars.toArray().length; i++) { + if (chars.get(i) == '\u00A7') { + chars.remove(i); + chars.remove(i); + } + } + + StringBuilder builder = new StringBuilder(chars.size()); + + for(Character ch: chars) + { + builder.append(ch); + } + + return builder.toString().replaceAll("\u00A7b",""); + } + public static String discordPlaceholder(String text) { + + List txt = new ArrayList<>(Arrays.asList(text.split("%"))); + + for (int i = 0; i < txt.toArray().length; i++) { + switch (txt.get(i)) { + case "player": + try { + txt.set(i,Minecraft.getMinecraft().getSession().getUsername()); + } catch (Exception ignored) {} + break; + case "fps": + try { + txt.set(i,String.valueOf(Minecraft.getDebugFPS())); + } catch (Exception ignored) { + txt.set(i,"0"); + } + break; + case "hand" : + try { + txt.set(i,cleanMessage(Minecraft.getMinecraft().thePlayer.getHeldItem().getDisplayName())); + } catch (Exception ignored) { + txt.set(i,"Nothing"); + } + break; + case "shorttag": + try { + txt.set(i,cleanMessage(SkyclientCosmetics.uuidTags.get(Minecraft.getMinecraft().getSession().getUsername()).get(1))); + } catch (Exception ignored) {} + break; + case "tag": + try { + txt.set(i,cleanMessage(SkyclientCosmetics.uuidTags.get(Minecraft.getMinecraft().getSession().getUsername()).get(0))); + } catch (Exception ignored) {} + break; + } + } + + return String.join("", txt); + } +} diff --git a/src/main/java/io/github/koxx12_dev/scc/Commands/MainCommand.java b/src/main/java/io/github/koxx12dev/scc/commands/MainCommand.java similarity index 67% rename from src/main/java/io/github/koxx12_dev/scc/Commands/MainCommand.java rename to src/main/java/io/github/koxx12dev/scc/commands/MainCommand.java index d4495c3..2e69212 100644 --- a/src/main/java/io/github/koxx12_dev/scc/Commands/MainCommand.java +++ b/src/main/java/io/github/koxx12dev/scc/commands/MainCommand.java @@ -1,13 +1,14 @@ -package io.github.koxx12_dev.scc.Commands; +package io.github.koxx12dev.scc.commands; -import io.github.koxx12_dev.scc.SCC; -import io.github.koxx12_dev.scc.Utils.HTTPstuff; +import io.github.koxx12dev.scc.SkyclientCosmetics; +import io.github.koxx12dev.scc.Utils.Requests; import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import java.io.IOException; + public class MainCommand extends CommandBase { @Override public String getCommandName() { @@ -20,11 +21,16 @@ public String getCommandUsage(ICommandSender sender) { } @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { + public void processCommand(ICommandSender sender, String[] args) { if (args.length != 1) { - SCC.displayScreen = SCC.config.gui(); + SkyclientCosmetics.displayScreen = SkyclientCosmetics.config.gui(); } else if (args[0].equalsIgnoreCase("reload")) { - HTTPstuff.reloadTags(); + try { + Requests.reloadTags(); + } catch (IOException e) { + e.printStackTrace(); + } + Requests.setRankColor(); } else { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+"Unknown command\n"+EnumChatFormatting.RED+"\"/scc\" for config gui\n"+EnumChatFormatting.RED+"\"/scc reload\" to reload tags")); } diff --git a/src/main/java/io/github/koxx12_dev/scc/fml/CoreMod.java b/src/main/java/io/github/koxx12dev/scc/fml/CoreMod.java similarity index 97% rename from src/main/java/io/github/koxx12_dev/scc/fml/CoreMod.java rename to src/main/java/io/github/koxx12dev/scc/fml/CoreMod.java index 80ead11..2c5da16 100644 --- a/src/main/java/io/github/koxx12_dev/scc/fml/CoreMod.java +++ b/src/main/java/io/github/koxx12dev/scc/fml/CoreMod.java @@ -1,4 +1,4 @@ -package io.github.koxx12_dev.scc.fml; +package io.github.koxx12dev.scc.fml; import net.minecraftforge.fml.relauncher.CoreModManager; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; diff --git a/src/main/java/io/github/koxx12_dev/scc/GUI/SCCConfig.java b/src/main/java/io/github/koxx12dev/scc/gui/Settings.java similarity index 54% rename from src/main/java/io/github/koxx12_dev/scc/GUI/SCCConfig.java rename to src/main/java/io/github/koxx12dev/scc/gui/Settings.java index 41cc4ac..17e1e8c 100644 --- a/src/main/java/io/github/koxx12_dev/scc/GUI/SCCConfig.java +++ b/src/main/java/io/github/koxx12dev/scc/gui/Settings.java @@ -1,83 +1,88 @@ -package io.github.koxx12_dev.scc.GUI; +package io.github.koxx12dev.scc.gui; import gg.essential.vigilance.Vigilant; import gg.essential.vigilance.data.Property; import gg.essential.vigilance.data.PropertyType; -import io.github.koxx12_dev.scc.SCC; +import io.github.koxx12dev.scc.SkyclientCosmetics; import java.io.File; -public class SCCConfig extends Vigilant { +public class Settings extends Vigilant { @Property(type = PropertyType.SWITCH, name = "Show Debug Options", description = "SHOWS DEBUG STUFF USELESS FOR EVERYONE BUT ME -koxx12", category = "DEBUG", subcategory = "DEBUG") - public static boolean ShowDebug = false; + public static boolean showDebug = false; @Property(type = PropertyType.SWITCH, name = "Show custom tags", description = "Show all custom tags in new messages", category = "Main", subcategory = "Tags") - public static boolean TagsShow = true; + public static boolean showTags = true; @Property(type = PropertyType.SWITCH, name = "Shorten custom tag", description = "Shortens all custom tags in new messages", category = "Main", subcategory = "Tags") - public static boolean ShortenTags = false; + public static boolean shortenTags = false; @Property(type = PropertyType.CHECKBOX, name = "Reload Tags", description = "Reloads custom tags", category = "Main", subcategory = "Tags") public static boolean reloadTags = false; @Property(type = PropertyType.SWITCH, name = "Debug Tags", description = "Replaces every message with your tag", category = "DEBUG", subcategory = "DEBUG") - public static boolean DebugTags = false; + public static boolean debugTags = false; @Property(type = PropertyType.SWITCH, name = "Debug Display Tags", description = "Changes player names to your tag", category = "DEBUG", subcategory = "DEBUG") - public static boolean DebugDisplayTags = false; + public static boolean debugDisplayTags = false; @Property(type = PropertyType.SWITCH, name = "Show Debug info in the logs", description = "Spams your logs as fuck", category = "DEBUG", subcategory = "DEBUG") - public static boolean DebugLogs = false; + public static boolean debugLogs = false; @Property(type = PropertyType.TEXT, name = "Discord RPC Second Line", description = "Allows you to set second line of the Discord RPC", category = "Main", subcategory = "RPC") - public static String RPCLineTwo = "SBE bad"; + public static String rpcLineTwo = "SBE bad"; @Property(type = PropertyType.TEXT, name = "Discord RPC First Line", description = "Allows you to set the first line of the Discord RPC", category = "Main", subcategory = "RPC") - public static String RPCLineOne = "%player% is very cool"; + public static String rpcLineOne = "%player% is very cool"; @Property(type = PropertyType.TEXT, name = "Discord RPC Img Text", description = "Allows you to set text of the img", category = "Main", subcategory = "RPC") - public static String RPCImgText = "SkyClient is cool"; + public static String rpcImgText = "SkyClient is cool"; @Property(type = PropertyType.SWITCH, name = "Discord RPC", description = "Enables Discord RPC", category = "Main", subcategory = "RPC") - public static boolean RPC = true; + public static boolean rpc = true; @Property(type = PropertyType.CHECKBOX, name = "First time message", description = "Get \"First time message\" when u join next time", category = "Main", subcategory = "Other") - public static boolean JoinMessage = true; + public static boolean joinMessage = true; @Property(type = PropertyType.SWITCH, name = "Sbe sucks Mode", description = "Do i need to explain this?", category = "Main", subcategory = "RPC") - public static boolean BadSbeMode = false; + public static boolean sbeBadMode = false; @Property(type = PropertyType.SWITCH, name = "Tags in Display Names", description = "Shows tags above player names (May crash)", category = "Main", subcategory = "Tags") - public static boolean DisplayTags = false; + public static boolean displayTags = false; - //@Property(type = PropertyType.TEXT, name = "Skyclient Cosmetics API key", description = "SCC Api key is used for every feature of this mod", category = "Main", subcategory = "Main", protectedText = true) + @Property(type = PropertyType.TEXT, name = "Hypixel API key", description = "Hypixel API key used for requests", category = "Main", subcategory = "Hypixel", protectedText = true) + public static String hpApiKey = ""; + + @Property(type = PropertyType.SWITCH, name = "Display Name fix", description = "Fixes your display name display names (only useful is you use patcher)", category = "Fixes", subcategory = "Main") + public static boolean displanameFix = false; + + //@Property(type = PropertyType.TEXT, name = "Skyclient Cosmetics API key", description = "SkyclientCosmetics Api key is used for every feature of this mod", category = "Main", subcategory = "Main", protectedText = true) //public static String SCCApiKey = ""; - public SCCConfig() { + public Settings() { super(new File("./config/skyclientcosmetics.toml")); initialize(); - addDependency("DebugTags","ShowDebug"); - addDependency("DebugDisplayTags","ShowDebug"); - addDependency("DebugLogs","ShowDebug"); - - addDependency("BadSbeMode","RPC"); - addDependency("RPCLineTwo","RPC"); - addDependency("RPCLineOne","RPC"); - addDependency("RPCImgText","RPC"); + addDependency("debugTags","showDebug"); + addDependency("debugDisplayTags","showDebug"); + addDependency("debugLogs","showDebug"); - addDependency("ShortenTags","TagsShow"); - addDependency("reloadTags","TagsShow"); - addDependency("DisplayTags","TagsShow"); + addDependency("sbeBadMode","rpc"); + addDependency("rpcLineTwo","rpc"); + addDependency("rpcLineOne","rpc"); + addDependency("rpcImgText","rpc"); - hidePropertyIf("BadSbeMode",() -> !SCC.RPCRunning); - hidePropertyIf("RPCLineTwo",() -> !SCC.RPCRunning); - hidePropertyIf("RPCLineOne",() -> !SCC.RPCRunning); - hidePropertyIf("RPCImgText",() -> !SCC.RPCRunning); - hidePropertyIf("RPC",() -> !SCC.RPCRunning); + addDependency("shortenTags","showTags"); + addDependency("reloadTags","showTags"); + addDependency("displayTags","showTags"); + hidePropertyIf("sbeBadMode",() -> !SkyclientCosmetics.rpcRunning); + hidePropertyIf("rpcLineTwo",() -> !SkyclientCosmetics.rpcRunning); + hidePropertyIf("rpcLineOne",() -> !SkyclientCosmetics.rpcRunning); + hidePropertyIf("rpcImgText",() -> !SkyclientCosmetics.rpcRunning); + hidePropertyIf("rpc",() -> !SkyclientCosmetics.rpcRunning); } } diff --git a/src/main/java/io/github/koxx12dev/scc/listeners/ChatListeners.java b/src/main/java/io/github/koxx12dev/scc/listeners/ChatListeners.java new file mode 100644 index 0000000..530099d --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/listeners/ChatListeners.java @@ -0,0 +1,99 @@ +package io.github.koxx12dev.scc.listeners; + +import gg.essential.universal.ChatColor; +import io.github.koxx12dev.scc.SkyclientCosmetics; +import io.github.koxx12dev.scc.Utils.*; +import io.github.koxx12dev.scc.gui.Settings; +import net.minecraft.client.Minecraft; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.json.JSONObject; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ChatListeners { + + @SubscribeEvent + public void onChatMsgTags(ClientChatReceivedEvent event) { + + if (Settings.showTags && ServerDetection.isOnHypixel()) { + try { + JSONObject msg = new JSONObject(IChatComponent.Serializer.componentToJson(event.message)); + + String name = msg.getJSONArray("extra").getJSONObject(0).get("text").toString(); + + List nameParsed = new ArrayList<>(Arrays.asList(name.split(" "))); + + String[] nameParsedClean = Transformers.cleanMessage(name).split(" "); + if (Settings.debugLogs) { + SkyclientCosmetics.LOGGER.debug(msg); + } + for (int i = 0; i < nameParsedClean.length; i++) { + String current = (String) Array.get(nameParsedClean, i); + if (Settings.debugLogs) { + SkyclientCosmetics.LOGGER.debug(current + " , " + i); + } + int j = i; + if (SkyclientCosmetics.uuidTags.containsKey(current.replace(":", ""))) { + if (current.contains(":")) { + + if (i != 0) { + if (SkyclientCosmetics.hypixelRanks.contains(Array.get(nameParsedClean, i - 1))) { + j = i - 1; + } + } + nameParsed.add(j, SkyclientCosmetics.uuidTags.get(current.replace(":", "")).get(Tag.isShortTagsOnInt())); + + msg.getJSONArray("extra").getJSONObject(0).put("text", String.join(" ", nameParsed) + " "); + event.message = IChatComponent.Serializer.jsonToComponent(msg.toString()); + } else if (msg.getJSONArray("extra").getJSONObject(1).get("text").toString().contains(":")) { + + String color = ChatColor.valueOf(msg.getJSONArray("extra").getJSONObject(0).get("color").toString().toUpperCase()).toString(); + + if (i != 0) { + if (SkyclientCosmetics.hypixelRanks.contains(Array.get(nameParsedClean, i - 1))) { + j = i - 1; + } + } + nameParsed.add(j, SkyclientCosmetics.uuidTags.get(current.replace(":", "")).get(Tag.isShortTagsOnInt()) + color); + + msg.getJSONArray("extra").getJSONObject(0).put("text", String.join(" ", nameParsed)); + event.message = IChatComponent.Serializer.jsonToComponent(msg.toString()); + } + } + } + } catch (Exception ignored) {} + } + + } + + @SubscribeEvent + public void onChatMsgHpApi(ClientChatReceivedEvent event) { + String msg = Transformers.cleanMessage(event.message.getUnformattedText()); + if (msg.contains("Your new API key is ")) { + String key = msg.replace("Your new API key is ",""); + SkyclientCosmetics.LOGGER.info(key); + Chat.sendMessagePrivate(ChatColor.GREEN+"Checking API key"); + try { + JSONObject response = new JSONObject(Requests.request("https://api.hypixel.net/key?key=" + key)); + + if (response.getBoolean("success") && response.getJSONObject("record").get("owner").toString().replaceAll("-", "").equals(Minecraft.getMinecraft().getSession().getPlayerID())) { + Chat.sendMessagePrivate(ChatColor.GREEN+"Verified API key!"); + Settings.hpApiKey = key; + } else { + Chat.sendMessagePrivate(ChatColor.RED+"Couldn't verify \""+key+"\" as a API key"); + } + + } catch (Exception e) { + Chat.sendMessagePrivate(ChatColor.RED+"\""+key+"\" is not a valid API key"); + } + + } + + } + +} diff --git a/src/main/java/io/github/koxx12_dev/scc/listeners/GuiListners.java b/src/main/java/io/github/koxx12dev/scc/listeners/GuiListners.java similarity index 81% rename from src/main/java/io/github/koxx12_dev/scc/listeners/GuiListners.java rename to src/main/java/io/github/koxx12dev/scc/listeners/GuiListners.java index 46937ed..3ee708a 100644 --- a/src/main/java/io/github/koxx12_dev/scc/listeners/GuiListners.java +++ b/src/main/java/io/github/koxx12dev/scc/listeners/GuiListners.java @@ -1,6 +1,6 @@ -package io.github.koxx12_dev.scc.listeners; +package io.github.koxx12dev.scc.listeners; -import io.github.koxx12_dev.scc.SCC; +import io.github.koxx12dev.scc.SkyclientCosmetics; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiIngameMenu; import net.minecraftforge.client.event.GuiScreenEvent; @@ -22,7 +22,7 @@ public void onGuiInitPost(GuiScreenEvent.InitGuiEvent.Post event) { @SubscribeEvent public void onGuiAction(GuiScreenEvent.ActionPerformedEvent.Post event) { if (event.gui instanceof GuiIngameMenu && event.button.id == 2666487) { - SCC.displayScreen = SCC.config.gui(); + SkyclientCosmetics.displayScreen = SkyclientCosmetics.config.gui(); } } diff --git a/src/main/java/io/github/koxx12dev/scc/listeners/PlayerListeners.java b/src/main/java/io/github/koxx12dev/scc/listeners/PlayerListeners.java new file mode 100644 index 0000000..774d76e --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/listeners/PlayerListeners.java @@ -0,0 +1,43 @@ +package io.github.koxx12dev.scc.listeners; + +import io.github.koxx12dev.scc.SkyclientCosmetics; +import io.github.koxx12dev.scc.Utils.Tag; +import io.github.koxx12dev.scc.gui.Settings; +import io.github.koxx12dev.scc.threads.JoinThread; +import net.minecraft.client.Minecraft; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; + +public class PlayerListeners { + + @SubscribeEvent + public void onPlayerLoggedIn(FMLNetworkEvent.ClientConnectedToServerEvent event) { + + Thread joinThread = new JoinThread(); + joinThread.start(); + + } + + @SubscribeEvent + public void onNameFormat(PlayerEvent.NameFormat event) { + if (Settings.debugDisplayTags) { + event.displayname = SkyclientCosmetics.uuidTags.get(Minecraft.getMinecraft().getSession().getUsername()).get(0); + } + + if (Settings.displayTags) { + if (SkyclientCosmetics.uuidTags.containsKey(event.displayname)) { + String tag; + + tag = SkyclientCosmetics.uuidTags.get(event.displayname).get(Tag.isShortTagsOnInt()); + + if (Minecraft.getMinecraft().getSession().getUsername().equals(event.displayname) && Settings.displanameFix) { + event.displayname = tag + SkyclientCosmetics.rankColor + " " + event.displayname; + } else { + event.displayname = tag + " " + event.displayname; + } + } + } + } + +} diff --git a/src/main/java/io/github/koxx12_dev/scc/mixins/forge/MixinSplashProgress.java b/src/main/java/io/github/koxx12dev/scc/mixins/forge/MixinSplashProgress.java similarity index 92% rename from src/main/java/io/github/koxx12_dev/scc/mixins/forge/MixinSplashProgress.java rename to src/main/java/io/github/koxx12dev/scc/mixins/forge/MixinSplashProgress.java index ef4b3d9..a6f79b9 100644 --- a/src/main/java/io/github/koxx12_dev/scc/mixins/forge/MixinSplashProgress.java +++ b/src/main/java/io/github/koxx12dev/scc/mixins/forge/MixinSplashProgress.java @@ -1,4 +1,4 @@ -package io.github.koxx12_dev.scc.mixins.forge; +package io.github.koxx12dev.scc.mixins.forge; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.client.SplashProgress; diff --git a/src/main/java/io/github/koxx12dev/scc/threads/JoinThread.java b/src/main/java/io/github/koxx12dev/scc/threads/JoinThread.java new file mode 100644 index 0000000..ba9bd81 --- /dev/null +++ b/src/main/java/io/github/koxx12dev/scc/threads/JoinThread.java @@ -0,0 +1,23 @@ +package io.github.koxx12dev.scc.threads; + +import io.github.koxx12dev.scc.Utils.Chat; +import io.github.koxx12dev.scc.gui.Settings; +import net.minecraft.util.EnumChatFormatting; + +public class JoinThread extends Thread { + + public void run() { + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (Settings.joinMessage) { + Chat.sendMessagePrivate(EnumChatFormatting.AQUA +"Looks like you are using Skyclient Cosmetics for the first time\n"+ EnumChatFormatting.AQUA +"Use /scc to get started!\n"+ EnumChatFormatting.AQUA +"Use \"/api new\" to set hypixel API key!"); + Settings.joinMessage = false; + } + + } + +} diff --git a/src/main/resources/mixins.scc.json b/src/main/resources/mixins.scc.json index 3e521b1..946b753 100644 --- a/src/main/resources/mixins.scc.json +++ b/src/main/resources/mixins.scc.json @@ -2,7 +2,7 @@ "compatibilityLevel": "JAVA_8", "minVersion": "0.7", "priority": 2147483647, - "package": "io.github.koxx12_dev.scc.mixins", + "package": "io.github.koxx12dev.scc.mixins", "refmap": "mixins.scc.refmap.json", "mixins": [ "forge.MixinSplashProgress"