diff options
author | syeyoung <cyong06@naver.com> | 2021-05-08 17:23:08 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-05-08 17:23:08 +0900 |
commit | b34b217f44c0c5ae7e69a4d7b830a8607f5fc13a (patch) | |
tree | 6467fd8dbec016cc63b27dad05c4060e59f70d2b /src/main/java/kr/syeyoung | |
parent | 5f5e168df2abd0f168ae780d1ffeb4b7dab6c0a8 (diff) | |
download | Skyblock-Dungeons-Guide-b34b217f44c0c5ae7e69a4d7b830a8607f5fc13a.tar.gz Skyblock-Dungeons-Guide-b34b217f44c0c5ae7e69a4d7b830a8607f5fc13a.tar.bz2 Skyblock-Dungeons-Guide-b34b217f44c0c5ae7e69a4d7b830a8607f5fc13a.zip |
cosmetics.
Diffstat (limited to 'src/main/java/kr/syeyoung')
14 files changed, 623 insertions, 13 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java index c1d3e4ea..da277b2c 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java @@ -21,6 +21,7 @@ package kr.syeyoung.dungeonsguide; import com.google.common.collect.Sets; import kr.syeyoung.dungeonsguide.commands.*; import kr.syeyoung.dungeonsguide.config.Config; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; import kr.syeyoung.dungeonsguide.eventlistener.DungeonListener; import kr.syeyoung.dungeonsguide.eventlistener.FeatureListener; @@ -74,6 +75,8 @@ public class DungeonsGuide implements DGInterface, CloseListener { @Getter private StompInterface stompConnection; + @Getter + private CosmeticsManager cosmeticsManager; public DungeonsGuide(Authenticator authenticator) { this.authenticator = authenticator; @@ -96,9 +99,6 @@ public class DungeonsGuide implements DGInterface, CloseListener { try { Set<String> invalid = ReflectionHelper.getPrivateValue(LaunchClassLoader.class, (LaunchClassLoader) Main.class.getClassLoader(), "invalidClasses"); ((LaunchClassLoader) Main.class.getClassLoader()).clearNegativeEntries(Sets.newHashSet("org.slf4j.LoggerFactory")); - for (String s : invalid) { - System.out.println(s+" in invalid"); - } invalid.clear(); } catch (Throwable t) { t.printStackTrace(); @@ -138,6 +138,10 @@ public class DungeonsGuide implements DGInterface, CloseListener { Keybinds.register(); progressbar.step("Opening connection"); + + cosmeticsManager = new CosmeticsManager(); + MinecraftForge.EVENT_BUS.register(cosmeticsManager); + try { stompConnection = new StompClient(new URI(stompURL), authenticator.getToken(), this); MinecraftForge.EVENT_BUS.post(new StompConnectedEvent(stompConnection)); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/Main.java b/src/main/java/kr/syeyoung/dungeonsguide/Main.java index 10d20b2f..85323acf 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/Main.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/Main.java @@ -66,7 +66,7 @@ public class Main Authenticator authenticator = new Authenticator(progressBar); String token = null; try { - token = authenticator.authenticateAndDownload(this.getClass().getResourceAsStream("/kr/syeyoung/dungeonsguide/e.class") == null ? System.getProperty("dg.version") == null ? "latest" : System.getProperty("dg.version") : null); + token = authenticator.authenticateAndDownload(this.getClass().getResourceAsStream("/kr/syeyoung/dungeonsguide/DungeonsGuide.class") == null ? System.getProperty("dg.version") == null ? "nlatest" : System.getProperty("dg.version") : null); if (token != null) { main = this; URL.setURLStreamHandlerFactory(new DGStreamHandlerFactory(authenticator)); @@ -77,6 +77,8 @@ public class Main progressBar.step("Initializing"); this.dgInterface = new DungeonsGuide(authenticator); this.dgInterface.pre(preInitializationEvent); + while (progressBar.getStep() < progressBar.getSteps()) + progressBar.step("random-"+progressBar.getStep()); ProgressManager.pop(progressBar); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java index ff86b083..fdb4da18 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java @@ -34,6 +34,7 @@ import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.FeatureViewPl import kr.syeyoung.dungeonsguide.features.impl.party.api.ApiFetchur; import kr.syeyoung.dungeonsguide.party.PartyManager; import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; +import kr.syeyoung.dungeonsguide.stomp.*; import kr.syeyoung.dungeonsguide.utils.AhUtils; import kr.syeyoung.dungeonsguide.utils.MapUtils; import net.minecraft.client.Minecraft; @@ -357,6 +358,15 @@ public class CommandDungeonsGuide extends CommandBase { } else if (args[0].equals("purge")) { ApiFetchur.purgeCache(); sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully purged API Cache!")); + } else if (args[0].equals("send")) { + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload().header("destination", args[1]).method(StompHeader.SEND).payload(args[2])); + } else if (args[0].equals("subscribe")) { + DungeonsGuide.getDungeonsGuide().getStompConnection().subscribe(StompSubscription.builder().destination(args[1]).ackMode(StompSubscription.AckMode.AUTO).stompMessageHandler(new StompMessageHandler() { + @Override + public void handle(StompInterface stompInterface, StompPayload stompPayload) { + + } + }).build()); } else { sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg §7-§fOpens configuration gui")); sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg gui §7-§fOpens configuration gui")); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MFeature.java index 2df70b67..7e751a9c 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MFeature.java @@ -55,7 +55,7 @@ public class MFeature extends MPanel { this.config = config; this.feature = abstractFeature; - { + if (abstractFeature.isDisyllable()) { final MToggleButton mStringSelectionButton = new MToggleButton(); mStringSelectionButton.setOnToggle(new Runnable() { @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/ActiveCosmetic.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/ActiveCosmetic.java new file mode 100644 index 00000000..f00ecf06 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/ActiveCosmetic.java @@ -0,0 +1,12 @@ +package kr.syeyoung.dungeonsguide.cosmetics; + +import lombok.Data; +import java.util.UUID; + +@Data +public class ActiveCosmetic { + private UUID activityUID; + private UUID playerUID; + private UUID cosmeticData; + private String username; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticData.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticData.java new file mode 100644 index 00000000..24842a8e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticData.java @@ -0,0 +1,14 @@ +package kr.syeyoung.dungeonsguide.cosmetics; + + +import lombok.Data; + +import java.util.UUID; + +@Data +public class CosmeticData { + private UUID id; + private String cosmeticType; + private String reqPerm; + private String data; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java new file mode 100644 index 00000000..d7c8114f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/cosmetics/CosmeticsManager.java @@ -0,0 +1,288 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.cosmetics; + +import com.google.gson.JsonPrimitive; +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; +import kr.syeyoung.dungeonsguide.stomp.*; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class CosmeticsManager implements StompMessageHandler { + @Getter + private Map<UUID, CosmeticData> cosmeticDataMap = new HashMap<>(); + @Getter + private Map<UUID, ActiveCosmetic> activeCosmeticMap = new HashMap<>(); + @Getter + private Map<String, List<ActiveCosmetic>> activeCosmeticByType = new HashMap<>(); + @Getter + private Map<UUID, List<ActiveCosmetic>> activeCosmeticByPlayer = new HashMap<>(); + @Getter + private Map<String, List<ActiveCosmetic>> activeCosmeticByPlayerNameLowerCase = new HashMap<>(); + @Getter + private Set<String> perms = new HashSet<>(); + + public void requestActiveCosmetics() { + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload() + .method(StompHeader.SEND) + .header("destination", "/app/cosmetic.activelist") + ); + } + public void requestCosmeticsList() { + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload() + .method(StompHeader.SEND) + .header("destination", "/app/cosmetic.list") + ); + } + public void requestPerms() { + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload() + .method(StompHeader.SEND) + .header("destination", "/app/user.perms") + ); + } + public void setCosmetic(CosmeticData cosmetic) { + if (!perms.contains(cosmetic.getReqPerm())) return; + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload() + .method(StompHeader.SEND) + .header("destination", "/app/cosmetic.set") + .payload(cosmetic.getId().toString()) + ); + } + public void removeCosmetic(ActiveCosmetic activeCosmetic) { + DungeonsGuide.getDungeonsGuide().getStompConnection().send(new StompPayload() + .method(StompHeader.SEND) + .header("destination", "/app/cosmetic.remove") + .payload(activeCosmetic.getActivityUID().toString()) + ); + } + + @Override + public void handle(StompInterface stompInterface, StompPayload stompPayload) { + String destination = stompPayload.headers().get("destination"); + if (destination.equals("/topic/cosmetic.set")) { + JSONObject jsonObject = new JSONObject(stompPayload.payload()); + ActiveCosmetic activeCosmetic = new ActiveCosmetic(); + activeCosmetic.setActivityUID(UUID.fromString(jsonObject.getString("activityUID"))); + activeCosmetic.setPlayerUID(UUID.fromString(jsonObject.getString("playerUID"))); + activeCosmetic.setCosmeticData(UUID.fromString(jsonObject.getString("cosmeticUID"))); + activeCosmetic.setUsername(jsonObject.getString("username")); + + ActiveCosmetic previousThing = activeCosmeticMap.get(activeCosmetic.getActivityUID()); + activeCosmeticMap.put(activeCosmetic.getActivityUID(), activeCosmetic); + + CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData()); + if (cosmeticData != null) { + List<ActiveCosmetic> cosmeticsByTypeList = activeCosmeticByType.computeIfAbsent(cosmeticData.getCosmeticType(), a-> new ArrayList<>()); + cosmeticsByTypeList.add(activeCosmetic); + cosmeticsByTypeList.remove(previousThing); + } + List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayer.computeIfAbsent(activeCosmetic.getPlayerUID(), a-> new ArrayList<>()); + activeCosmetics.add(activeCosmetic); + activeCosmetics.remove(previousThing); + + activeCosmetics = activeCosmeticByPlayerNameLowerCase.computeIfAbsent(activeCosmetic.getUsername().toLowerCase(), a-> new ArrayList<>()); + activeCosmetics.add(activeCosmetic); + activeCosmetics.remove(previousThing); + + + } else if (destination.equals("/user/queue/reply/user.perms")) { + JSONArray object = new JSONArray(stompPayload.payload()); + Set<String> cache = new HashSet<>(); + for (Object o : object) { + cache.add((String) o); + } + this.perms = cache; + } else if (destination.equals("/user/queue/reply/cosmetic.activelist")) { + Map<UUID, ActiveCosmetic> activeCosmeticMap = new HashMap<>(); + JSONArray object = new JSONArray(stompPayload.payload()); + for (Object o : object) { + JSONObject jsonObject = (JSONObject) o; + ActiveCosmetic cosmeticData = new ActiveCosmetic(); + cosmeticData.setActivityUID(UUID.fromString(jsonObject.getString("activityUID"))); + cosmeticData.setPlayerUID(UUID.fromString(jsonObject.getString("playerUID"))); + cosmeticData.setCosmeticData(UUID.fromString(jsonObject.getString("cosmeticUID"))); + cosmeticData.setUsername(jsonObject.getString("username")); + + activeCosmeticMap.put(cosmeticData.getActivityUID(), cosmeticData); + } + this.activeCosmeticMap = activeCosmeticMap; + rebuildCaches(); + } else if (destination.equals("/user/queue/reply/cosmetic.list")) { + JSONArray object = new JSONArray(stompPayload.payload()); + Map<UUID, CosmeticData> newCosmeticList = new HashMap<>(); + for (Object o : object) { + JSONObject jsonObject = (JSONObject) o; + CosmeticData cosmeticData = new CosmeticData(); + cosmeticData.setCosmeticType(jsonObject.getString("cosmeticType")); + cosmeticData.setReqPerm(jsonObject.getString("reqPerm")); + cosmeticData.setData(jsonObject.getString("data")); + cosmeticData.setId(UUID.fromString(jsonObject.getString("id"))); + + newCosmeticList.put(cosmeticData.getId(), cosmeticData); + } + + cosmeticDataMap = newCosmeticList; + rebuildCaches(); + } + } + + private void rebuildCaches() { + Map<String, List<ActiveCosmetic>> activeCosmeticByType = new HashMap<>(); + Map<UUID, List<ActiveCosmetic>> activeCosmeticByPlayer = new HashMap<>(); + Map<String, List<ActiveCosmetic>> activeCosmeticByPlayerName = new HashMap<>(); + for (ActiveCosmetic value : activeCosmeticMap.values()) { + CosmeticData cosmeticData = cosmeticDataMap.get(value.getCosmeticData()); + if (cosmeticData != null) { + List<ActiveCosmetic> cosmeticsByTypeList = activeCosmeticByType.computeIfAbsent(cosmeticData.getCosmeticType(), a-> new ArrayList<>()); + cosmeticsByTypeList.add(value); + } + List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayer.computeIfAbsent(value.getPlayerUID(), a-> new ArrayList<>()); + activeCosmetics.add(value); + activeCosmetics = activeCosmeticByPlayerName.computeIfAbsent(value.getUsername().toLowerCase(), a-> new ArrayList<>()); + activeCosmetics.add(value); + } + + this.activeCosmeticByPlayerNameLowerCase = activeCosmeticByPlayerName; + this.activeCosmeticByPlayer = activeCosmeticByPlayer; + this.activeCosmeticByType = activeCosmeticByType; + } + + @SubscribeEvent + public void stompConnect(StompConnectedEvent stompConnectedEvent) { + stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder() + .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/topic/cosmetic.set").build()); + stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder() + .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/reply/user.perms").build()); + stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder() + .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/reply/cosmetic.activelist").build()); + stompConnectedEvent.getStompInterface().subscribe(StompSubscription.builder() + .stompMessageHandler(this).ackMode(StompSubscription.AckMode.AUTO).destination("/user/queue/reply/cosmetic.list").build()); + + requestCosmeticsList(); + requestActiveCosmetics(); + requestPerms(); + } + + // §9Party §8> §a[VIP§6+§a] syeyoung§f: ty + // §2Guild > §a[VIP§6+§a] syeyoung §3[Vet]§f + // §dTo §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7what§r + // §dFrom §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7?§r + // §7Rock_Bird§7§r§7: SELLING 30 DIAMOD BLOCK /p me§r + // §b[MVP§c+§b] Probutnoobgamer§f: quitting skyblock! highe + // §r§bCo-op > §a[VIP§6+§a] syeyoung§f: §rwhat§r + + public static String substitute(String str) { + str = str.replace("{HYPIXEL_RANKED_NAME}", "§.(?:\\[[a-zA-Z\\+§0-9]+\\] )?{MC_NAME}"); + str = str.replace("{HYPIXEL_RANKED_NAME_PAT}", "(§.(?:\\[[a-zA-Z\\+§0-9]+\\] )?)({MC_NAME})"); + str = str.replace("{MC_NAME}", "[a-zA-Z0-9_]+"); + str = str.replace("{ANY_COLOR}", "(?:§[a-zA-Z0-9])+"); + return str; + } + + private static final Pattern PARTY_MSG = Pattern.compile(substitute("§r§9Party §8> {HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); + private static final Pattern GUILD_MSG = Pattern.compile(substitute("§r§2Guild > {HYPIXEL_RANKED_NAME_PAT} ({ANY_COLOR}\\[.+\\]{ANY_COLOR}): (.+)")); + private static final Pattern CHAT_MSG = Pattern.compile(substitute("(?:§r)?{HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); + private static final Pattern COOP_MSG = Pattern.compile(substitute("§r§bCo-op > {HYPIXEL_RANKED_NAME_PAT}({ANY_COLOR}): (.+)")); + private static final Pattern DM_TO = Pattern.compile(substitute("§dTo §r{HYPIXEL_RANKED_NAME_PAT}§r§7: (.+)")); + private static final Pattern DM_FROM = Pattern.compile(substitute("§dFrom §r{HYPIXEL_RANKED_NAME_PAT}§r§7: (.+)")); + + + @SubscribeEvent(receiveCanceled = false, priority = EventPriority.HIGHEST) + public void onChat(ClientChatReceivedEvent clientChatReceivedEvent) { + Matcher m; + String msg = clientChatReceivedEvent.message.getFormattedText(); + boolean match = false; + String preRank = ""; + String rank = ""; + String last = ""; + String nickname = ""; + if ((m = PARTY_MSG.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = "§r§9Party §8> "; + rank = m.group(1); + last = m.group(2)+m.group(3)+": "+m.group(4); + } else if ((m = GUILD_MSG.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = "§r§2Guild > "; + rank = m.group(1); + last = m.group(2)+" "+m.group(3)+": "+m.group(4); + } else if ((m = CHAT_MSG.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = ""; + rank = m.group(1); + last = m.group(2)+m.group(3)+": "+m.group(4); + } else if ((m = COOP_MSG.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = "§r§bCo-op > "; + rank = m.group(1); + last = m.group(2)+m.group(3)+": "+m.group(4); + } else if ((m = DM_TO.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = "§dTo §r"; + rank = m.group(1); + last = m.group(2)+"§r§7: "+m.group(3); + } else if ((m = DM_FROM.matcher(msg)).matches()) { + match = true; + nickname = m.group(2); + preRank = "§dFrom §r"; + rank = m.group(1); + last = m.group(2)+"§r§7: "+m.group(3); + } + + if (!match) return; + + List<ActiveCosmetic> activeCosmetics = activeCosmeticByPlayerNameLowerCase.get(nickname.toLowerCase()); + if (activeCosmetics != null) { + CosmeticData prefix = null, color =null; + for (ActiveCosmetic activeCosmetic : activeCosmetics) { + CosmeticData cosmeticData = cosmeticDataMap.get(activeCosmetic.getCosmeticData()); + if (cosmeticData == null) continue; + if (cosmeticData.getCosmeticType().equals("prefix")) prefix = cosmeticData; + if (cosmeticData.getCosmeticType().equals("color")) color = cosmeticData; + } + + if (prefix != null) { + preRank += prefix.getData()+" "; + } + if (color != null) { + last = color.getData() + last; + } + } + + clientChatReceivedEvent.message = new ChatComponentText(preRank + rank + last); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java index 3710eff6..3429a4df 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java @@ -94,4 +94,8 @@ public abstract class AbstractFeature { }); return "base." + key ; } + + public boolean isDisyllable() { + return true; + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java index 4f859e2b..50fe1218 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java @@ -25,6 +25,8 @@ import kr.syeyoung.dungeonsguide.features.impl.advanced.FeatureRoomDebugInfo; import kr.syeyoung.dungeonsguide.features.impl.boss.*; import kr.syeyoung.dungeonsguide.features.impl.boss.terminal.FeatureSimonSaysSolver; import kr.syeyoung.dungeonsguide.features.impl.boss.terminal.FeatureTerminalSolvers; +import kr.syeyoung.dungeonsguide.features.impl.cosmetics.FeatureNicknameColor; +import kr.syeyoung.dungeonsguide.features.impl.cosmetics.FeatureNicknamePrefix; import kr.syeyoung.dungeonsguide.features.impl.dungeon.*; import kr.syeyoung.dungeonsguide.features.impl.etc.*; import kr.syeyoung.dungeonsguide.features.impl.etc.ability.FeatureAbilityCooldown; @@ -152,4 +154,7 @@ public class FeatureRegistry { public static final SimpleFeature SECRET_NEXT_KEY = register(new SimpleFeature("Secret", "Auto browse next secret upon pressing a key", "Auto browse the best next secret when you press key.\nChange key at your key settings (Settings -> Controls)", "secret.keyfornext", false)); public static final SimpleFeature SECRET_TOGGLE_KEY = register(new SimpleFeature("Secret", "Press a key to toggle pathfind lines", "A key for toggling pathfound line visibility.\nChange key at your key settings (Settings -> Controls)", "secret.togglePathfind")); public static final SimpleFeature SECRET_FREEZE_LINES = register(new FeatureFreezePathfind()); + + public static final FeatureNicknamePrefix COSMETIC_PREFIX = register(new FeatureNicknamePrefix()); + public static final FeatureNicknameColor COSMETIC_NICKNAMECOLOR = register(new FeatureNicknameColor()); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknameColor.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknameColor.java new file mode 100644 index 00000000..02bad9f1 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknameColor.java @@ -0,0 +1,49 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.features.impl.cosmetics; + +import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.features.FeatureParameter; +import kr.syeyoung.dungeonsguide.features.SimpleFeature; + +public class FeatureNicknameColor extends SimpleFeature { + public FeatureNicknameColor() { + super("Cosmetics", "Nickname Color", "Click on Edit to choose nickname color cosmetic", "cosmetic.nickname"); + this.parameters.put("dummy", new FeatureParameter("dummy", "dummy", "dummy", "dummy", "string")); + } + + @Override + public String getEditRoute(final GuiConfig config) { + ConfigPanelCreator.map.put("base." + getKey() , () -> new PrefixSelectorGUI(config, "color", new String[] { + "§9Party §8> §r§a[RANK§6+§a] %prefix%%name%§f: TEST", + "§2Guild > §r§a[RANK§6+§a] %prefix%%name% §3[Vet]§f: TEST", + "§dTo §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", + "§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", + "§r§b[RANK§c+§b] %prefix%%name%§f: TEST", + "§r§bCo-op > §r§a[RANK§6+§a] %prefix%%name%§f: §rTEST§r" + })); + return "base." + getKey(); + } + + @Override + public boolean isDisyllable() { + return false; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknamePrefix.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknamePrefix.java new file mode 100644 index 00000000..5ffcc26b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/FeatureNicknamePrefix.java @@ -0,0 +1,57 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.features.impl.cosmetics; + +import com.google.common.base.Supplier; +import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.config.guiconfig.PanelDefaultParameterConfig; +import kr.syeyoung.dungeonsguide.features.FeatureParameter; +import kr.syeyoung.dungeonsguide.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.DataRendererEditor; +import kr.syeyoung.dungeonsguide.features.impl.party.playerpreview.FeatureViewPlayerOnJoin; +import kr.syeyoung.dungeonsguide.gui.MPanel; + +import java.util.Arrays; +import java.util.Collections; + +public class FeatureNicknamePrefix extends SimpleFeature { + public FeatureNicknamePrefix() { + super("Cosmetics", "Nickname Prefix", "Click on Edit to choose prefix cosmetic", "cosmetic.prefix"); + this.parameters.put("dummy", new FeatureParameter("dummy", "dummy", "dummy", "dummy", "string")); + } + + @Override + public String getEditRoute(final GuiConfig config) { + ConfigPanelCreator.map.put("base." + getKey() , () -> new PrefixSelectorGUI(config, "prefix", new String[] { + "§9Party §8> §r%prefix% §a[RANK§6+§a] %name%§f: TEST", + "§2Guild > §r%prefix% §a[RANK§6+§a] %name% §3[Vet]§f: TEST", + "§dTo §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", + "§dFrom §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", + "§r%prefix% §b[RANK§c+§b] %name%§f: TEST", + "§r§bCo-op > §r%prefix% §a[RANK§6+§a] %name%§f: §rTEST§r" + })); + return "base." + getKey(); + } + + @Override + public boolean isDisyllable() { + return false; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/PrefixSelectorGUI.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/PrefixSelectorGUI.java new file mode 100644 index 00000000..dd0dc387 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/cosmetics/PrefixSelectorGUI.java @@ -0,0 +1,163 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.features.impl.cosmetics; + +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig; +import kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +public class PrefixSelectorGUI extends MPanel { + private GuiConfig config; + private String cosmeticType; + + public PrefixSelectorGUI(GuiConfig config, String cosmeticType, String[] previews) { + this.config = config; + this.cosmeticType = cosmeticType; + this.previews = previews; + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData != null && cosmeticData.getCosmeticType().equals(cosmeticType)) { + selected = cosmeticData; + return; + } + } + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + } + + private CosmeticData selected; + // §9Party §8> §a[VIP§6+§a] syeyoung§f: ty + // §2Guild > §a[VIP§6+§a] syeyoung §3[Vet]§f + // §dTo §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7what§r + // §dFrom §r§a[VIP§r§6+§r§a] SlashSlayer§r§7: §r§7?§r + // §7Rock_Bird§7§r§7: SELLING 30 DIAMOD BLOCK /p me§r + // §b[MVP§c+§b] Probutnoobgamer§f: quitting skyblock! highe + // §r§bCo-op > §a[VIP§6+§a] syeyoung§f: §rwhat§r + String[] previews; + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + + Set<UUID> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()).stream().map(ActiveCosmetic::getCosmeticData).collect(Collectors.toSet()); + + + + GlStateManager.translate(0,2,0); + Gui.drawRect(0,0,getBounds().width, getBounds().height-2, 0xFF444444); + Gui.drawRect(5,5,265, getBounds().height-7, 0xFF222222); + Gui.drawRect(6,17,264, getBounds().height-8, 0xFF555555); + fr.drawString("Preview", (270 - fr.getStringWidth("Preview")) / 2, 7, 0xFFFFFFFF); + + { + String prefix = selected != null ? selected.getData() : "[DG]"; + GlStateManager.pushMatrix(); + GlStateManager.translate(6,17,0); + for (int i = 0; i < previews.length; i++) { + fr.drawString(previews[i].replace("%name%", Minecraft.getMinecraft().getSession().getUsername()).replace("%prefix%", prefix), 0, i*fr.FONT_HEIGHT, -1); + } + GlStateManager.popMatrix(); + } + { + GlStateManager.pushMatrix(); + GlStateManager.translate(270,17,0); + int relX = relMousex0 - 270, relY = relMousey0 - 19; + int cnt = 0; + for (CosmeticData value : cosmeticsManager.getCosmeticDataMap().values()) { + if (value.getCosmeticType().equals(cosmeticType)) { + Gui.drawRect(0,0,220, fr.FONT_HEIGHT+3, 0xFF222222); + Gui.drawRect(1,1, 219, fr.FONT_HEIGHT+2, 0xFF555555); + fr.drawString(value.getData(), 2, 2, -1); + Gui.drawRect(120,1,160, fr.FONT_HEIGHT+2, new Rectangle(120,cnt * (fr.FONT_HEIGHT+4) + 2,40,fr.FONT_HEIGHT+1).contains(relX, relY) ? 0xFF859DF0 : 0xFF7289da); + fr.drawString("TEST", (280-fr.getStringWidth("TEST"))/2, 2, -1); + + if (cosmeticsManager.getPerms().contains(value.getReqPerm())) { + Gui.drawRect(161,1,219, fr.FONT_HEIGHT+2, new Rectangle(161,cnt * (fr.FONT_HEIGHT+4) + 2,58,fr.FONT_HEIGHT+1).contains(relX, relY) ? 0xFF859DF0 : 0xFF7289da); + + if (activeCosmeticList.contains(value.getId())) { + fr.drawString("UNSELECT", (381 - fr.getStringWidth("UNSELECT")) / 2, 2, -1); + } else { + fr.drawString("SELECT", (381 - fr.getStringWidth("SELECT")) / 2, 2, -1); + } + } else { + Gui.drawRect(161,1,219, fr.FONT_HEIGHT+2, 0xFFFF3333); + fr.drawString("Locked", (381 - fr.getStringWidth("Locked")) / 2, 2, -1); + } + GlStateManager.translate(0,fr.FONT_HEIGHT+4, 0); + + cnt++; + } + } + GlStateManager.popMatrix(); + } + } + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + + int relX = relMouseX - 270, relY = relMouseY - 19; + int cnt = 0; + + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + + for (CosmeticData value : cosmeticsManager.getCosmeticDataMap().values()) { + if (value.getCosmeticType().equals(cosmeticType)) { + if (new Rectangle(120,cnt * (fr.FONT_HEIGHT+4) + 2,40,fr.FONT_HEIGHT+1).contains(relX, relY)) { + selected = value; + return; + } + if (new Rectangle(161,cnt * (fr.FONT_HEIGHT+4) + 2,58,fr.FONT_HEIGHT+1).contains(relX, relY) && cosmeticsManager.getPerms().contains(value.getReqPerm())) { + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + if (activeCosmetic.getCosmeticData().equals(value.getId())) { + cosmeticsManager.removeCosmetic(activeCosmetic); + return; + } + } + cosmeticsManager.setCosmetic(value); + selected = value; + } + + cnt++; + } + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/APIKey.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/APIKey.java index 96562f02..a0f681a1 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/APIKey.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/party/APIKey.java @@ -31,7 +31,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent; public class APIKey extends SimpleFeature implements ChatListenerGlobal { public APIKey() { - super("Party Kicker", "API KEY", "Set api key. Disabling this feature does nothing","partykicker.apikey"); + super("Party Kicker", "API KEY", "Sets api key","partykicker.apikey"); parameters.put("apikey", new FeatureParameter<String>("apikey", "API Key", "API key", "","string")); } @@ -49,6 +49,10 @@ public class APIKey extends SimpleFeature implements ChatListenerGlobal { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fAutomatically Configured Hypixel API Key")); this.<String>getParameter("apikey").setValue(apiKeys); } + } + @Override + public boolean isDisyllable() { + return false; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/url/DGConnection.java b/src/main/java/kr/syeyoung/dungeonsguide/url/DGConnection.java index 2fb35638..725abab9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/url/DGConnection.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/url/DGConnection.java @@ -37,13 +37,11 @@ public class DGConnection extends URLConnection { } @Override public InputStream getInputStream() throws IOException { - if (authenticator != null) { - String path = url.getPath().substring(1); - if (!authenticator.getResources().containsKey(path)) throw new FileNotFoundException(); - return new ByteArrayInputStream(authenticator.getResources().get(path)); - } else if (url.getPath().contains("roomdata")){ - return DGConnection.class.getResourceAsStream(url.getPath()); - } + if (authenticator != null) { + String path = url.getPath().substring(1); + if (!authenticator.getResources().containsKey(path)) throw new FileNotFoundException(); + return new ByteArrayInputStream(authenticator.getResources().get(path)); + } throw new FileNotFoundException(); } } |