package io.github.moulberry.notenoughupdates; import com.google.common.collect.Sets; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.authlib.Agent; import com.mojang.authlib.exceptions.AuthenticationException; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.commands.SimpleCommand; import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; import io.github.moulberry.notenoughupdates.gamemodes.GuiGamemodes; import io.github.moulberry.notenoughupdates.gamemodes.SBGamemodes; import io.github.moulberry.notenoughupdates.infopanes.CollectionLogInfoPane; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; import io.github.moulberry.notenoughupdates.questing.GuiQuestLine; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.settings.KeyBinding; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.*; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.translate.UnicodeUnescaper; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.Proxy; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @Mod(modid = NotEnoughUpdates.MODID, version = NotEnoughUpdates.VERSION, clientSideOnly = true) public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; public static final String VERSION = "1.2-REL"; public static NotEnoughUpdates INSTANCE = null; public NEUManager manager; public NEUOverlay overlay; private static final long CHAT_MSG_COOLDOWN = 200; private long lastChatMessage = 0; private long secondLastChatMessage = 0; private String currChatMessage = null; //Stolen from Biscut and used for detecting whether in skyblock private static final Set SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK","\u7A7A\u5C9B\u751F\u5B58"); private GuiScreen openGui = null; SimpleCommand collectionLogCommand = new SimpleCommand("neucl", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(!OpenGlHelper.isFramebufferEnabled()) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This feature requires FBOs to work. Try disabling Optifine's 'Fast Render'.")); } else { if(!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) { openGui = new GuiInventory(Minecraft.getMinecraft().thePlayer); } overlay.displayInformationPane(new CollectionLogInfoPane(overlay, manager)); } } }); SimpleCommand itemRenameCommand = new SimpleCommand("neurename", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(args.length == 0) { args = new String[]{"help"}; } String heldUUID = manager.getUUIDForItem(Minecraft.getMinecraft().thePlayer.getHeldItem()); switch(args[0].toLowerCase()) { case "clearall": manager.itemRenameJson = new JsonObject(); manager.saveItemRenameConfig(); sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[NEU] Cleared custom name for all items")); break; case "clear": if(heldUUID == null) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Can't clear rename - no UUID")); return; } manager.itemRenameJson.remove(heldUUID); manager.saveItemRenameConfig(); sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[NEU] Cleared custom name for held item")); break; case "copyuuid": if(heldUUID == null) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Can't clear rename - no UUID")); return; } StringSelection selection = new StringSelection(heldUUID); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[NEU] UUID copied to clipboard")); break; case "uuid": if(heldUUID == null) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Can't get UUID - no UUID")); return; } ChatStyle style = new ChatStyle(); style.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(EnumChatFormatting.GRAY+"Click to copy to clipboard"))); style.setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "neurename copyuuid")); ChatComponentText text = new ChatComponentText(EnumChatFormatting.YELLOW+"[NEU] The UUID of your currently held item is: " + EnumChatFormatting.GREEN + heldUUID); text.setChatStyle(style); sender.addChatMessage(text); break; case "set": if(heldUUID == null) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Can't rename item - no UUID")); return; } if(args.length == 1) { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[NEU] Usage: /neurename set [name...]")); return; } StringBuilder sb = new StringBuilder(); for(int i=1; i petRarityToColourMap = new HashMap<>(); static { petRarityToColourMap.put("UNKNOWN", EnumChatFormatting.RED.toString()); petRarityToColourMap.put("COMMON", EnumChatFormatting.WHITE.toString()); petRarityToColourMap.put("UNCOMMON", EnumChatFormatting.GREEN.toString()); petRarityToColourMap.put("RARE", EnumChatFormatting.BLUE.toString()); petRarityToColourMap.put("EPIC", EnumChatFormatting.DARK_PURPLE.toString()); petRarityToColourMap.put("LEGENDARY", EnumChatFormatting.GOLD.toString()); } ScheduledExecutorService peekCommandExecutorService = null; SimpleCommand peekCommand = new SimpleCommand("peek", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(args.length == 0) { sender.addChatMessage(new ChatComponentText( EnumChatFormatting.RED+"[PEEK] Usage: /peek (username)")); return; } int id = new Random().nextInt(Integer.MAX_VALUE/2)+Integer.MAX_VALUE/2; Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.YELLOW+"[PEEK] Getting player information..."), id); profileViewer.getProfileByName(args[0], profile -> { if (profile == null) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.RED+"[PEEK] Unknown player or api is down."), id); } else { profile.resetCache(); if(peekCommandExecutorService == null || peekCommandExecutorService.isShutdown()) { peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); } else { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( EnumChatFormatting.RED+"[PEEK] New peek command run, cancelling old one.")); peekCommandExecutorService.shutdownNow(); peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); } Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.YELLOW+"[PEEK] Getting player skyblock profiles..."), id); long startTime = System.currentTimeMillis(); peekCommandExecutorService.schedule(new Runnable() { public void run() { if(System.currentTimeMillis() - startTime > 10*1000) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( EnumChatFormatting.RED+"[PEEK] Getting profile info took too long, aborting."), id); return; } String g = EnumChatFormatting.GRAY.toString(); JsonObject profileInfo = profile.getProfileInformation(null); if(profileInfo != null) { float overallScore = 0; boolean isMe = args[0].equalsIgnoreCase("moulberry"); PlayerStats.Stats stats = profile.getStats(null); JsonObject skill = profile.getSkillInfo(null); Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText(EnumChatFormatting.GREEN+" "+ EnumChatFormatting.STRIKETHROUGH+"-=-" +EnumChatFormatting.RESET+EnumChatFormatting.GREEN+" "+ Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), args[0]) + "'s Info " + EnumChatFormatting.STRIKETHROUGH+"-=-"), id); if(skill == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW+"Skills api disabled!")); } else { float totalSkillLVL = 0; float totalSkillCount = 0; for(Map.Entry entry : skill.entrySet()) { if(entry.getKey().startsWith("level_skill")) { if(entry.getKey().contains("runecrafting")) continue; if(entry.getKey().contains("carpentry")) continue; totalSkillLVL += entry.getValue().getAsFloat(); totalSkillCount++; } } float combat = Utils.getElementAsFloat(skill.get("level_skill_combat"), 0); float zombie = Utils.getElementAsFloat(skill.get("level_slayer_zombie"), 0); float spider = Utils.getElementAsFloat(skill.get("level_slayer_spider"), 0); float wolf = Utils.getElementAsFloat(skill.get("level_slayer_wolf"), 0); float avgSkillLVL = totalSkillLVL/totalSkillCount; if(isMe) { avgSkillLVL = 6; combat = 4; zombie = 2; spider = 1; wolf = 2; } EnumChatFormatting combatPrefix = combat>20?(combat>35?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting zombiePrefix = zombie>3?(zombie>6?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting spiderPrefix = spider>3?(spider>6?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting wolfPrefix = wolf>3?(wolf>6?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting avgPrefix = avgSkillLVL>20?(avgSkillLVL>35?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; overallScore += combat*combat/2000f; overallScore += zombie*zombie/81f; overallScore += spider*spider/81f; overallScore += wolf*wolf/81f; overallScore += avgSkillLVL/20f; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g+"Combat: "+combatPrefix+(int)Math.floor(combat) +g+" - AVG Skill: " + avgPrefix+(int)Math.floor(avgSkillLVL))); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g+"Slayer: "+zombiePrefix+(int)Math.floor(zombie)+g+"-"+ spiderPrefix+(int)Math.floor(spider)+g+"-"+wolfPrefix+(int)Math.floor(wolf))); } if(stats == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( EnumChatFormatting.YELLOW+"Skills, collection and/or inventory apis disabled!")); } else { int health = (int)stats.get("health"); int defence = (int)stats.get("defence"); int strength = (int)stats.get("strength"); int intelligence = (int)stats.get("intelligence"); EnumChatFormatting healthPrefix = health>800?(health>1600?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting defencePrefix = defence>200?(defence>600?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting strengthPrefix = strength>100?(strength>300?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; EnumChatFormatting intelligencePrefix = intelligence>300?(intelligence>900?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g+"Stats : "+healthPrefix+health+EnumChatFormatting.RED+"\u2764 "+ defencePrefix+defence+EnumChatFormatting.GREEN+"\u2748 "+ strengthPrefix+strength+EnumChatFormatting.RED+"\u2741 "+ intelligencePrefix+intelligence+EnumChatFormatting.AQUA+"\u270e ")); } float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), -1); float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); EnumChatFormatting moneyPrefix = (bankBalance+purseBalance)>10*1000*1000? ((bankBalance+purseBalance)>50*1000*1000?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g+"Purse : "+moneyPrefix+Utils.shortNumberFormat(purseBalance, 0) + g+" - Bank: " + (bankBalance == -1 ? EnumChatFormatting.YELLOW+"Disabled" : moneyPrefix+ (isMe?"4.8b":Utils.shortNumberFormat(bankBalance, 0))))); long networth = profile.getNetWorth(null); if(networth > 0) { EnumChatFormatting moneyPrefix2 = networth>50*1000*1000? (networth>200*1000*1000?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( g+"Networth : "+moneyPrefix2+Utils.shortNumberFormat(networth, 0))); } if(networth == -1) networth = (long)(bankBalance+purseBalance); overallScore += Math.min(2, networth/(100f*1000*1000)); String activePet = Utils.getElementAsString(Utils.getElement(profile.getPetsInfo(null), "active_pet.type"), "None Active"); String activePetTier = Utils.getElementAsString(Utils.getElement(profile.getPetsInfo(null), "active_pet.tier"), "UNKNOWN"); String col = petRarityToColourMap.get(activePetTier); if(col == null) col = EnumChatFormatting.LIGHT_PURPLE.toString(); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(g+"Pet : " + col + WordUtils.capitalizeFully(activePet.replace("_", " ")))); String overall = "Skywars Main"; if(isMe) { overall = Utils.chromaString("Literally the best player to exist"); } else if(overallScore < 5 && (bankBalance+purseBalance) > 500*1000*1000) { overall = EnumChatFormatting.GOLD+"Bill Gates"; } else if(overallScore > 9) { overall = Utils.chromaString("Didn't even think this score was possible"); } else if(overallScore > 8) { overall = Utils.chromaString("Mentally unstable"); } else if(overallScore > 7) { overall = EnumChatFormatting.GOLD+"Why though 0.0"; } else if(overallScore > 5.5) { overall = EnumChatFormatting.GOLD+"Bro stop playing"; } else if(overallScore > 4) { overall = EnumChatFormatting.GREEN+"Kinda sweaty"; } else if(overallScore > 3) { overall = EnumChatFormatting.YELLOW+"Alright I guess"; } else if(overallScore > 2) { overall = EnumChatFormatting.YELLOW+"Ender Non"; } else if(overallScore > 1) { overall = EnumChatFormatting.RED+"Played Skyblock"; } Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(g+"Overall score: " + overall + g + " (" + Math.round(overallScore*10)/10f + ")")); peekCommandExecutorService.shutdownNow(); } else { peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); } } }, 200, TimeUnit.MILLISECONDS); } }); } }, new SimpleCommand.TabCompleteRunnable() { @Override public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { if (args.length != 1) return null; String lastArg = args[args.length - 1]; List playerMatches = new ArrayList<>(); for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { String playerName = player.getName(); if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { playerMatches.add(playerName); } } return playerMatches; } }); public static ProfileViewer profileViewer; SimpleCommand.ProcessCommandRunnable viewProfileRunnable = new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(Loader.isModLoaded("optifine") && new File(Minecraft.getMinecraft().mcDataDir, "optionsof.txt").exists()) { try(InputStream in = new FileInputStream(new File(Minecraft.getMinecraft().mcDataDir, "optionsof.txt"))) { BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); String line; while((line = reader.readLine()) != null) { if(line.contains("ofFastRender:true")) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This feature is incompatible with OF Fast Render. Go to Video > Performance to disable it.")); return; } } } catch(Exception e) { } } if (manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Can't view profile, apikey is not set. Run /api new and put the result in settings.")); } else if (args.length == 0) { profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { if(profile == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Invalid player name/api key. Maybe api is down? Try /api new.")); } else { profile.resetCache(); openGui = new GuiProfileViewer(profile); } }); } else if (args.length > 1) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many arguments. Usage: /neuprofile [name]")); } else { profileViewer.getProfileByName(args[0], profile -> { if(profile == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Invalid player name/api key. Maybe api is down? Try /api new.")); } else { profile.resetCache(); openGui = new GuiProfileViewer(profile); } }); } } }; SimpleCommand viewProfileCommand = new SimpleCommand("neuprofile", viewProfileRunnable, new SimpleCommand.TabCompleteRunnable() { @Override public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { if(args.length != 1) return null; String lastArg = args[args.length-1]; List playerMatches = new ArrayList<>(); for(EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { String playerName = player.getName(); if(playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { playerMatches.add(playerName); } } return playerMatches; } }); SimpleCommand viewProfileShortCommand = new SimpleCommand("pv", new SimpleCommand.ProcessCommandRunnable() { @Override public void processCommand(ICommandSender sender, String[] args) { if(!isOnSkyblock()) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/pv " + StringUtils.join(args, " ")); } else { viewProfileRunnable.processCommand(sender, args); } } }, new SimpleCommand.TabCompleteRunnable() { @Override public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { if (args.length != 1) return null; String lastArg = args[args.length - 1]; List playerMatches = new ArrayList<>(); for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { String playerName = player.getName(); if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { playerMatches.add(playerName); } } return playerMatches; } }); SimpleCommand viewProfileShort2Command = new SimpleCommand("vp", new SimpleCommand.ProcessCommandRunnable() { @Override public void processCommand(ICommandSender sender, String[] args) { if(!isOnSkyblock()) { Minecraft.getMinecraft().thePlayer.sendChatMessage("/vp " + StringUtils.join(args, " ")); } else { viewProfileRunnable.processCommand(sender, args); } } }, new SimpleCommand.TabCompleteRunnable() { @Override public List tabComplete(ICommandSender sender, String[] args, BlockPos pos) { if (args.length != 1) return null; String lastArg = args[args.length - 1]; List playerMatches = new ArrayList<>(); for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { String playerName = player.getName(); if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { playerMatches.add(playerName); } } return playerMatches; } }); SimpleCommand linksCommand = new SimpleCommand("neulinks", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { File repo = manager.repoLocation; if(repo.exists()) { File updateJson = new File(repo, "update.json"); try { JsonObject update = manager.getJsonFromFile(updateJson); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); displayLinks(update); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); } catch (Exception ignored) { } } } }); SimpleCommand overlayPlacementsCommand = new SimpleCommand("neuoverlay", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { openGui = new NEUOverlayPlacements(); } }); SimpleCommand tutorialCommand = new SimpleCommand("neututorial", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { openGui = new HelpGUI(); } }); SimpleCommand cosmeticsCommand = new SimpleCommand("neucosmetics", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { openGui = new GuiCosmetics(); } }); SimpleCommand neuAhCommand = new SimpleCommand("neuah", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { if(!hasSkyblockScoreboard()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "You must be on Skyblock to use this feature.")); } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings.")); } else { openGui = new CustomAHGui(); manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); manager.auctionManager.customAH.clearSearch(); manager.auctionManager.customAH.updateSearch(); } } }); /** * Instantiates NEUIo, NEUManager and NEUOverlay instances. Registers keybinds and adds a shutdown hook to clear tmp folder. * @param event */ @EventHandler public void preinit(FMLPreInitializationEvent event) { INSTANCE = this; MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(CapeManager.getInstance()); MinecraftForge.EVENT_BUS.register(new SBGamemodes()); MinecraftForge.EVENT_BUS.register(CustomItemEffects.INSTANCE); File f = new File(event.getModConfigurationDirectory(), "notenoughupdates"); f.mkdirs(); ClientCommandHandler.instance.registerCommand(collectionLogCommand); ClientCommandHandler.instance.registerCommand(cosmeticsCommand); ClientCommandHandler.instance.registerCommand(linksCommand); ClientCommandHandler.instance.registerCommand(gamemodesCommand); ClientCommandHandler.instance.registerCommand(resetRepoCommand); ClientCommandHandler.instance.registerCommand(itemRenameCommand); ClientCommandHandler.instance.registerCommand(viewProfileCommand); ClientCommandHandler.instance.registerCommand(viewProfileShortCommand); ClientCommandHandler.instance.registerCommand(viewProfileShort2Command); ClientCommandHandler.instance.registerCommand(peekCommand); ClientCommandHandler.instance.registerCommand(tutorialCommand); ClientCommandHandler.instance.registerCommand(overlayPlacementsCommand); ClientCommandHandler.instance.registerCommand(enchantColourCommand); ClientCommandHandler.instance.registerCommand(neuAhCommand); manager = new NEUManager(this, f); manager.loadItemInformation(); overlay = new NEUOverlay(manager); profileViewer = new ProfileViewer(manager); for(KeyBinding kb : manager.keybinds) { ClientRegistry.registerKeyBinding(kb); } Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { File tmp = new File(f, "tmp"); if(tmp.exists()) { for(File tmpFile : tmp.listFiles()) { tmpFile.delete(); } tmp.delete(); } manager.saveConfig(); } catch(IOException e) {} })); //TODO: login code. Ignore this, used for testing. try { Field field = Minecraft.class.getDeclaredField("session"); YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()) .createUserAuthentication(Agent.MINECRAFT); auth.setUsername("james.jenour@protonmail.com"); JPasswordField pf = new JPasswordField(); JOptionPane.showConfirmDialog(null, pf, "Enter password:", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE); auth.setPassword(new String(pf.getPassword())); System.out.print("Attempting login..."); auth.logIn(); Session session = new Session(auth.getSelectedProfile().getName(), auth.getSelectedProfile().getId().toString().replace("-", ""), auth.getAuthenticatedToken(), auth.getUserType().getName()); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setAccessible(true); field.set(Minecraft.getMinecraft(), session); } catch (NoSuchFieldException | AuthenticationException | IllegalAccessException e) { } } /** * If the last chat messages was sent >200ms ago, sends the message. * If the last chat message was sent <200 ago, will cache the message for #onTick to handle. */ public void sendChatMessage(String message) { if(System.currentTimeMillis() - lastChatMessage > CHAT_MSG_COOLDOWN) { secondLastChatMessage = lastChatMessage; lastChatMessage = System.currentTimeMillis(); Minecraft.getMinecraft().thePlayer.sendChatMessage(message); currChatMessage = null; } else { currChatMessage = message; } } public void displayLinks(JsonObject update) { String discord_link = update.get("discord_link").getAsString(); String youtube_link = update.get("youtube_link").getAsString(); String update_link = update.get("update_link").getAsString(); String github_link = update.get("github_link").getAsString(); String other_text = update.get("other_text").getAsString(); String other_link = update.get("other_link").getAsString(); ChatComponentText other = null; if(other_text.length() > 0) { other = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.BLUE+other_text+EnumChatFormatting.GRAY+"]"); other.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, other_link)); } ChatComponentText links = new ChatComponentText(""); ChatComponentText separator = new ChatComponentText( EnumChatFormatting.GRAY+EnumChatFormatting.BOLD.toString()+EnumChatFormatting.STRIKETHROUGH+(other==null?"---":"--")); ChatComponentText discord = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.BLUE+"Discord"+EnumChatFormatting.GRAY+"]"); discord.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, discord_link)); ChatComponentText youtube = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.RED+"YouTube"+EnumChatFormatting.GRAY+"]"); youtube.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, youtube_link)); ChatComponentText release = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.GREEN+"Release"+EnumChatFormatting.GRAY+"]"); release.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, update_link)); ChatComponentText github = new ChatComponentText(EnumChatFormatting.GRAY+"["+EnumChatFormatting.DARK_PURPLE+"GitHub"+EnumChatFormatting.GRAY+"]"); github.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, github_link)); links.appendSibling(separator); links.appendSibling(discord); links.appendSibling(separator); links.appendSibling(youtube); links.appendSibling(separator); links.appendSibling(release); links.appendSibling(separator); links.appendSibling(github); links.appendSibling(separator); if(other != null) { links.appendSibling(other); links.appendSibling(separator); } Minecraft.getMinecraft().thePlayer.addChatMessage(links); } @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.START) return; long currentTime = System.currentTimeMillis(); if (openGui != null) { if(Minecraft.getMinecraft().thePlayer.openContainer != null) { Minecraft.getMinecraft().thePlayer.closeScreen(); } Minecraft.getMinecraft().displayGuiScreen(openGui); openGui = null; } if(currChatMessage != null && currentTime - lastChatMessage > CHAT_MSG_COOLDOWN) { lastChatMessage = currentTime; Minecraft.getMinecraft().thePlayer.sendChatMessage(currChatMessage); currChatMessage = null; } } public boolean isOnSkyblock() { if(!manager.config.onlyShowOnSkyblock.value) return true; return hasSkyblockScoreboard(); } private boolean hasSkyblockScoreboard; public boolean hasSkyblockScoreboard() { return hasSkyblockScoreboard; } //Stolen from Biscut's SkyblockAddons public void updateSkyblockScoreboard() { Minecraft mc = Minecraft.getMinecraft(); if (mc != null && mc.theWorld != null) { Scoreboard scoreboard = mc.theWorld.getScoreboard(); ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1); if (sidebarObjective != null) { String objectiveName = sidebarObjective.getDisplayName().replaceAll("(?i)\\u00A7.", ""); for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { if (objectiveName.startsWith(skyblock)) { hasSkyblockScoreboard = true; return; } } } } hasSkyblockScoreboard = false; } }