From 9a39c4cd26c9ea492e0e0ddceb7ae3a6d5fea23e Mon Sep 17 00:00:00 2001 From: NK Date: Mon, 20 Feb 2023 00:40:18 +0000 Subject: [PATCH] should be working, but doesn't send shit --- build.gradle | 149 +++++---- src/main/java/me/night0721/lilase/Main.java | 39 +-- .../night0721/lilase/utils/AuctionHouse.java | 264 ++++++++++++++++ .../night0721/lilase/utils/ConfigUtils.java | 179 +++++++++++ .../lilase/utils/DiscordWebhook.java | 47 ++- .../java/me/night0721/lilase/utils/Utils.java | 12 + .../lilase/utils/ah/AuctionHouse.java | 284 ------------------ .../me/night0721/lilase/utils/ah/Item.java | 15 - .../me/night0721/lilase/utils/ah/States.java | 9 - 9 files changed, 576 insertions(+), 422 deletions(-) create mode 100644 src/main/java/me/night0721/lilase/utils/AuctionHouse.java create mode 100644 src/main/java/me/night0721/lilase/utils/ConfigUtils.java delete mode 100644 src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java delete mode 100644 src/main/java/me/night0721/lilase/utils/ah/Item.java delete mode 100644 src/main/java/me/night0721/lilase/utils/ah/States.java diff --git a/build.gradle b/build.gradle index 136b186..c382de2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,105 +1,140 @@ -plugins { - id 'net.minecraftforge.gradle.forge' version 'FG_2.1-SNAPSHOT' - id 'com.github.johnrengelman.shadow' version '6.1.0' - id 'org.spongepowered.mixin' version '0.6-SNAPSHOT' +buildscript { + ext.kotlin_version = "1.6.10" + repositories { + jcenter() + maven { + name = "forge" + url = "https://files.minecraftforge.net/maven" + } + maven { url "https://jitpack.io" } + maven { url "https://repo.spongepowered.org/repository/maven-public/" } + } + dependencies { + classpath "com.github.Skytils:ForgeGradle:41dfce0a70" + classpath "com.github.jengelman.gradle.plugins:shadow:6.1.0" + classpath "com.github.debuggingss:MixinGradle:0.6-SNAPSHOT" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } } +apply plugin: "kotlin" +apply plugin: "net.minecraftforge.gradle.forge" +apply plugin: "com.github.johnrengelman.shadow" +apply plugin: "org.spongepowered.mixin" version = "1.0.0" group = "me.night0721.lilase" archivesBaseName = "Lilase" sourceCompatibility = 1.8 - -sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' -} - -repositories { - mavenCentral() - maven { url 'https://jitpack.io/' } - maven { url 'https://repo.spongepowered.org/repository/maven-public/' } - maven { url "https://repo.sk1er.club/repository/maven-public" } - maven { url "https://repo.sk1er.club/repository/maven-releases/" } -} +compileJava.options.encoding = "UTF-8" +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.VERSION_1_8 minecraft { - version = '1.8.9-11.15.1.2318-1.8.9' - runDir = 'run' - mappings = 'stable_22' + version = "1.8.9-11.15.1.2318-1.8.9" + runDir = "run" + mappings = "stable_22" makeObfSourceJar = false - replace '@VERSION@': project.version + + replace "@VERSION@": project.version + clientRunArgs += ["--tweakClass gg.essential.loader.stage0.EssentialSetupTweaker", "--mixin mixins.night0721.json"] } configurations { - packageLib - configurations.implementation.extendsFrom(configurations.packageLib) + include + implementation.extendsFrom(include) +} + +repositories { + mavenCentral() + maven { url "https://jitpack.io/" } + maven { url "https://repo.spongepowered.org/repository/maven-public/" } + maven { url "https://repo.sk1er.club/repository/maven-public" } + maven { url "https://repo.sk1er.club/repository/maven-releases/" } + maven { url "https://storehouse.okaeri.eu/repository/maven-public/" } } dependencies { - packageLib("gg.essential:loader-launchwrapper:1.1.3") - implementation("gg.essential:essential-1.8.9-forge:2581") - implementation("com.squareup.okhttp3:okhttp:4.10.0") - implementation("org.json:json:20220924") - annotationProcessor('org.spongepowered:mixin:0.7.11-SNAPSHOT') - implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { - transitive = false - } - shadow "org.json:json:20220924" - shadow "com.squareup.okhttp3:okhttp:4.10.0" + compileOnly("gg.essential:essential-1.8.9-forge:2581") + include("gg.essential:loader-launchwrapper:1.1.3") + implementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") + annotationProcessor("org.spongepowered:mixin:0.7.11-SNAPSHOT") + include("org.apache.commons:commons-collections4:4.4") + implementation("org.projectlombok:lombok:1.18.24") + annotationProcessor("org.projectlombok:lombok:1.18.24") + include("org.joml:joml:1.10.5") + include "org.json:json:20220924" + + include(fileTree(dir: "libs", include: "*.jar")) + implementation(fileTree(dir: "libs", include: "*.jar")) } mixin { disableRefMapWarning = true defaultObfuscationEnv searge - add sourceSets.main, 'mixins.night0721.refmap.json' + add sourceSets.main, "mixins.night0721.refmap.json" } jar { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - - manifest.attributes( - 'FMLCorePluginContainsFMLMod': true, + manifest.attributes("FMLCorePluginContainsFMLMod": true, "FMLCorePlugin": "me.night0721.lilase.mixins.MixinLoader", - 'ForceLoadAsMod': true, - 'MixinConfigs': 'mixins.night0721.json', - 'ModSide': 'CLIENT', - 'TweakClass': 'gg.essential.loader.stage0.EssentialSetupTweaker', - 'TweakOrder': '0' - ) + "ForceLoadAsMod": true, + "MixinConfigs": "mixins.night0721.json", + "ModSide": "CLIENT", + "TweakClass": "gg.essential.loader.stage0.EssentialSetupTweaker", + "TweakOrder": "0") enabled = false } -shadowJar { - archiveFileName = jar.archiveFileName - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - configurations = [project.configurations.runtimeClasspath] +sourceJar { + enabled = false } +shadowJar { + archiveClassifier.set("") + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + configurations = [project.configurations.include] + exclude "LICENSE.md" + exclude "pack.mcmeta" + exclude "dummyThing" + exclude "**/module-info.class" + exclude "*.so" + exclude "*.dylib" + exclude "*.dll" + exclude "*.jnilib" + exclude "ibxm/**" + exclude "com/jcraft/**" + exclude "org/lwjgl/**" + exclude "net/java/**" + + exclude "META-INF/proguard/**" + exclude "META-INF/maven/**" + exclude "META-INF/versions/**" + exclude "META-INF/com.android.tools/**" + + exclude "fabric.mod.json" +} +tasks.reobfJar.dependsOn tasks.shadowJar reobf { shadowJar { - classpath = project.configurations.compileClasspath + classpath = sourceSets.main.compileClasspath } } processResources { - inputs.property 'version', project.version - inputs.property 'mcversion', project.minecraft.version + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - expand 'version': project.version, 'mcversion': project.minecraft.version + include "mcmod.info" + expand "version": project.version, "mcversion": project.minecraft.version } from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' + exclude "mcmod.info" } } sourceSets { main { output.resourcesDir = java.outputDir } } - -tasks.reobfJar.dependsOn(shadowJar) \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/Main.java b/src/main/java/me/night0721/lilase/Main.java index 2041f38..260c110 100644 --- a/src/main/java/me/night0721/lilase/Main.java +++ b/src/main/java/me/night0721/lilase/Main.java @@ -2,16 +2,15 @@ package me.night0721.lilase; import com.mojang.realmsclient.gui.ChatFormatting; import me.night0721.lilase.events.PacketReceivedEvent; +import me.night0721.lilase.utils.AuctionHouse; +import me.night0721.lilase.utils.ConfigUtils; import me.night0721.lilase.utils.Utils; -import me.night0721.lilase.utils.ah.AuctionHouse; -import me.night0721.lilase.utils.ah.States; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraft.init.Blocks; import net.minecraft.network.play.client.C0DPacketCloseWindow; import net.minecraft.network.play.server.S2DPacketOpenWindow; -import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -26,14 +25,10 @@ import java.util.Arrays; @Mod(modid = Main.MODID, name = Main.MOD_NAME, version = Main.VERSION, acceptedMinecraftVersions = "[1.8.9]") public class Main { - public static final String MOD_NAME = "Lilase"; public static final String MODID = "Lilase"; public static final String VERSION = "1.0.0"; - static int tickAmount; - static long lastAction; - public static States clickState = States.NONE; private AuctionHouse auctionHouse; static Minecraft mc = Minecraft.getMinecraft(); static KeyBinding[] keyBindings = new KeyBinding[3]; @@ -55,7 +50,8 @@ public class Main { public void onTick(TickEvent.ClientTickEvent event) { if (mc.thePlayer == null || event.phase != TickEvent.Phase.START) return; tickAmount++; - + ConfigUtils.init(); + ConfigUtils.reloadConfig(); if (keyBindings[0].isKeyDown()) { if (mc.objectMouseOver.getBlockPos() == null) return; Block block = mc.theWorld.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock(); @@ -72,38 +68,17 @@ public class Main { if (tickAmount % 20 == 0) { Utils.checkForDungeon(); } - - switch (clickState) { - case CLICK: - if (System.currentTimeMillis() - lastAction < 500) return; - Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer); - lastAction = System.currentTimeMillis(); - clickState = States.CONFIRM; - break; - case CONFIRM: - if (System.currentTimeMillis() - lastAction < 500) return; - Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 11, 0, 0, Minecraft.getMinecraft().thePlayer); - clickState = States.NONE; - break; - case OPEN: - AuctionHouse.sendAuction(); - lastAction = System.currentTimeMillis(); - clickState = States.CLICK; - case NONE: - break; - } - + AuctionHouse.switchStates(); } @SubscribeEvent public void onChat(ClientChatReceivedEvent event) { String message = event.message.getUnformattedText(); if (!message.contains(":")) { - if (message.equals("Myrap opened a WITHER door!")) { - Utils.addTitle("&aMyr opened a door"); + if (message.equals("Claiming BIN auction...")) { + Utils.addTitle("&aBought BIN Auction"); } } - event.message = new ChatComponentText(event.message.getFormattedText().replace("§bCo-op > ", "§zCo-op > ")); } @SubscribeEvent diff --git a/src/main/java/me/night0721/lilase/utils/AuctionHouse.java b/src/main/java/me/night0721/lilase/utils/AuctionHouse.java new file mode 100644 index 0000000..495e3dd --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/AuctionHouse.java @@ -0,0 +1,264 @@ +package me.night0721.lilase.utils; + +import net.minecraft.client.Minecraft; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import javax.net.ssl.HttpsURLConnection; +import java.awt.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class AuctionHouse { + private static String uuid; + private static String message_toSend; + private static long lastAction; + private Thread thread; + private Boolean open = false; + private DiscordWebhook webhook; + private final List items = new ArrayList<>(); + private final List posted = new ArrayList<>(); + public static States clickState = States.NONE; + + public AuctionHouse() { + // items.add(new Item("Livid Dagger", ItemType.WEAPON, 8000000, ItemTier.LEGENDARY)); + // items.add(new Item("Aspect of the Void", ItemType.WEAPON, 8000000, ItemTier.EPIC)); + // items.add(new Item("Bal", ItemType.MISC, 10000000, ItemTier.EPIC)); + items.add(new Item(" ", ItemType.ANY, 1000, ItemTier.ANY)); + webhook = new DiscordWebhook(ConfigUtils.getString("main", "Webhook")); + webhook.setUsername("Lilase - Auction House"); + webhook.setAvatarUrl("https://wallpapercave.com/wp/wp2412537.jpg"); + } + + private JSONObject getHypixelData(String player) throws IOException, JSONException { + URL url = new URL("https://api.hypixel.net/player?key=" + ConfigUtils.getString("main", "APIKey") + "&uuid=" + player); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + connection.disconnect(); + return new JSONObject(content.toString()); + } + + private void getItem() throws IOException, JSONException { + URL url = new URL("https://api.hypixel.net/skyblock/auctions"); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + int status = connection.getResponseCode(); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + connection.disconnect(); + if (status != 200) return; + JSONObject data = new JSONObject(content.toString()); + JSONArray auctions = data.getJSONArray("auctions"); + for (int i = 0; i < auctions.length(); i++) { + JSONObject auction = auctions.getJSONObject(i); + for (Item item : items) { + String lore = " "; + ItemType type = item.type; + switch (item.query) { + case "Bal": + lore = "Made of Lava"; + break; + case "Squid": + lore = "More Ink"; + break; + case "Monkey": + lore = "Treeborn"; + break; + case "Ocelot": + lore = "Tree Hugger"; + break; + case "Dolphin": + lore = "Echolocation"; + break; + case "Flying Fish": + lore = "Water Bender"; + break; + } + + if (!auction.getString("item_name").toLowerCase().contains(item.query.toLowerCase())) break; + if (!auction.getString("item_lore").contains(lore)) break; + if (auction.getInt("starting_bid") > item.price) break; + if (item.tier != ItemTier.ANY) if (!auction.getString("tier").equals(item.tier.name())) break; + if (type != ItemType.ANY) if (!auction.getString("category").equals(type.lowercase)) break; + if (!auction.getBoolean("bin")) break; + if (!posted.contains(auction.getString("uuid"))) { + posted.add(auction.getString("uuid")); + NumberFormat format = NumberFormat.getInstance(Locale.US); + JSONObject profile = getHypixelData(auction.getString("auctioneer")); + Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE); + Matcher matcher = pattern.matcher(auction.getString("item_lore")); + String updated = matcher.replaceAll(""); + webhook.addEmbed( + new DiscordWebhook.EmbedObject() + .setTitle("Item Is On Low Price") + .setAuthor("night0721", "https://github.com/night0721", "https://avatars.githubusercontent.com/u/77528305?v=4") + .setDescription(updated) + .addField("Item", auction.getString("item_name"), true) + .addField("Price", format.format(auction.getInt("starting_bid")) + " coins", true) + .addField("Seller", profile.getJSONObject("player").getString("displayname"), true) + .addField("Started for", toDuration(System.currentTimeMillis() - auction.getLong("start")), true) + .addField("Ends in", getTimeSinceDate(auction.getLong("end") - System.currentTimeMillis()), true) + .setUrl("https://www.brandonfowler.me/skyblockah/?uuid=" + auction.getString("uuid")) + .setColor(Color.decode("#003153")) + ); + webhook.setContent(auction.getString("item_name") + " is sale at " + format.format(auction.getInt("starting_bid")) + "!\n`" + "/viewauction " + auction.getString("uuid") + "`"); + new Thread(() -> { + try { + webhook.execute(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + uuid = auction.getString("uuid"); + message_toSend = "Auction House: " + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!"; + clickState = States.OPEN; + return; + } + } + } + } + + public static void sendAuction() { + Utils.sendServerMessage("/viewauction " + uuid); + Utils.sendMessage(message_toSend); + } + + public final List times = Arrays.asList(TimeUnit.DAYS.toMillis(365), TimeUnit.DAYS.toMillis(30), TimeUnit.DAYS.toMillis(1), TimeUnit.HOURS.toMillis(1), TimeUnit.MINUTES.toMillis(1), TimeUnit.SECONDS.toMillis(1)); + public final List timesString = Arrays.asList("year", "month", "day", "hour", "minute", "second"); + + public String toDuration(long duration) { + + StringBuilder res = new StringBuilder(); + for (int i = 0; i < times.size(); i++) { + Long current = times.get(i); + long temp = duration / current; + if (temp > 0) { + res.append(temp).append(" ").append(timesString.get(i)).append(temp != 1 ? "s" : "").append(" ago"); + break; + } + } + if ("".equals(res.toString())) return "0 seconds ago"; + else return res.toString(); + } + + private static String getTimeSinceDate(long timeSinceDate) { + long seconds = TimeUnit.MILLISECONDS.toSeconds(timeSinceDate); + long minutes = TimeUnit.MILLISECONDS.toMinutes(timeSinceDate); + long hours = TimeUnit.MILLISECONDS.toHours(timeSinceDate); + long days = TimeUnit.MILLISECONDS.toDays(timeSinceDate); + + if (seconds < 60) return "in " + seconds + " seconds"; + else if (minutes < 60) return "in " + minutes + " minutes"; + else if (hours < 24) return "in " + hours + " hours"; + else return "in " + days + " days"; + + } + + public void toggleAuction() { + if (open) { + Utils.sendMessage("Stopped Auction House"); + thread.stop(); + open = false; + } else { + Utils.sendMessage("Started Auction House"); + thread = new Thread(() -> { + while (true) { + try { + getItem(); + thread.sleep(TimeUnit.SECONDS.toMillis(ConfigUtils.getInt("main", "AuctionHouseDelay"))); + } catch (IOException | JSONException | InterruptedException ignore) { + } + } + }); + thread.run(); //You didn't participate in this auction! + open = true; + } + } + + public static void switchStates() { + switch (clickState) { + case CLICK: + if (System.currentTimeMillis() - lastAction < 500) return; + Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer); + lastAction = System.currentTimeMillis(); + clickState = States.CONFIRM; + break; + case CONFIRM: + if (System.currentTimeMillis() - lastAction < 500) return; + Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 11, 0, 0, Minecraft.getMinecraft().thePlayer); + clickState = States.NONE; + break; + case OPEN: + AuctionHouse.sendAuction(); + lastAction = System.currentTimeMillis(); + clickState = States.CLICK; + case NONE: + break; + } + } +} + +enum States { + OPEN, NONE, CLICK, CONFIRM +} + +enum ItemTier { + ANY, COMMON, UNCOMMON, RARE, EPIC, LEGENDARY, MYTHIC, DIVINE, SPECIAL, VERY_SPECIAL, +} + +enum ItemType { + ANY("any"), WEAPON("weapon"), ARMOR("armor"), ACCESSORIES("accessories"), CONSUMABLES("consumables"), BLOCKS("blocks"), MISC("misc"), + ; + public final String lowercase; + + public String getLowercase() { + return lowercase; + } + + ItemType(String lowercase) { + this.lowercase = lowercase; + } +} + +class Item { + public String query; + public ItemType type; + public Integer price; + public ItemTier tier; + + public Item(String query, ItemType type, Integer price, ItemTier tier) { + this.query = query; + this.type = type; + this.price = price; + this.tier = tier; + } +} \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/utils/ConfigUtils.java b/src/main/java/me/night0721/lilase/utils/ConfigUtils.java new file mode 100644 index 0000000..76226ab --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/ConfigUtils.java @@ -0,0 +1,179 @@ +package me.night0721.lilase.utils; + +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Configuration; + +import java.io.File; + +public class ConfigUtils { + public static Configuration config; + public final static String file = "config/Lilase.cfg"; + + public static void reloadConfig() { + if (!hasKey("main", "APIKey")) writeStringConfig("main", "APIKey", ""); + if (!hasKey("main", "Webhook")) writeStringConfig("main", "Webhook", ""); + if (!hasKey("main", "AuctionHouseDelay")) writeIntConfig("main", "AuctionHouseDelay", 8); + } + + public static void init() { + config = new Configuration(new File(file)); + try { + config.load(); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } + + + public static int getInt(String category, String key) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (config.getCategory(category).containsKey(key)) { + return config.get(category, key, 0).getInt(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + return 0; + } + + public static double getDouble(String category, String key) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (config.getCategory(category).containsKey(key)) { + return config.get(category, key, 0D).getDouble(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + return 0D; + } + + public static String getString(String category, String key) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (config.getCategory(category).containsKey(key)) { + return config.get(category, key, "").getString(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + return ""; + } + + public static boolean getBoolean(String category, String key) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (config.getCategory(category).containsKey(key)) { + return config.get(category, key, false).getBoolean(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + return true; + } + + public static void writeIntConfig(String category, String key, int value) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + int set = config.get(category, key, value).getInt(); + config.getCategory(category).get(key).set(value); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } + + public static void writeDoubleConfig(String category, String key, double value) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + double set = config.get(category, key, value).getDouble(); + config.getCategory(category).get(key).set(value); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } + + public static void writeStringConfig(String category, String key, String value) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + String set = config.get(category, key, value).getString(); + config.getCategory(category).get(key).set(value); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } + + public static void writeBooleanConfig(String category, String key, boolean value) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + boolean set = config.get(category, key, value).getBoolean(); + config.getCategory(category).get(key).set(value); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } + + public static boolean hasKey(String category, String key) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (!config.hasCategory(category)) return false; + return config.getCategory(category).containsKey(key); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + return false; + } + + public static void deleteCategory(String category) { + category = category.toLowerCase(); + config = new Configuration(new File(file)); + try { + config.load(); + if (config.hasCategory(category)) { + config.removeCategory(new ConfigCategory(category)); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + config.save(); + } + } +} diff --git a/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java b/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java index 642b145..77d2918 100644 --- a/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java +++ b/src/main/java/me/night0721/lilase/utils/DiscordWebhook.java @@ -1,16 +1,13 @@ package me.night0721.lilase.utils; import javax.net.ssl.HttpsURLConnection; -import java.awt.Color; +import java.awt.*; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Array; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Class used to execute Discord Webhooks with low effort @@ -22,7 +19,7 @@ public class DiscordWebhook { private String username; private String avatarUrl; private boolean tts; - private List embeds = new ArrayList<>(); + private final List embeds = new ArrayList<>(); /** * Constructs a new DiscordWebhook instance @@ -151,7 +148,7 @@ public class DiscordWebhook { stream.flush(); stream.close(); - connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream + connection.getInputStream().close(); connection.disconnect(); } @@ -165,7 +162,7 @@ public class DiscordWebhook { private Thumbnail thumbnail; private Image image; private Author author; - private List fields = new ArrayList<>(); + private final List fields = new ArrayList<>(); public String getTitle() { return title; @@ -248,9 +245,9 @@ public class DiscordWebhook { return this; } - private class Footer { - private String text; - private String iconUrl; + private static class Footer { + private final String text; + private final String iconUrl; private Footer(String text, String iconUrl) { this.text = text; @@ -266,8 +263,8 @@ public class DiscordWebhook { } } - private class Thumbnail { - private String url; + private static class Thumbnail { + private final String url; private Thumbnail(String url) { this.url = url; @@ -278,8 +275,8 @@ public class DiscordWebhook { } } - private class Image { - private String url; + private static class Image { + private final String url; private Image(String url) { this.url = url; @@ -290,10 +287,10 @@ public class DiscordWebhook { } } - private class Author { - private String name; - private String url; - private String iconUrl; + private static class Author { + private final String name; + private final String url; + private final String iconUrl; private Author(String name, String url, String iconUrl) { this.name = name; @@ -314,10 +311,10 @@ public class DiscordWebhook { } } - private class Field { - private String name; - private String value; - private boolean inline; + private static class Field { + private final String name; + private final String value; + private final boolean inline; private Field(String name, String value, boolean inline) { this.name = name; @@ -339,7 +336,7 @@ public class DiscordWebhook { } } - private class JSONObject { + private static class JSONObject { private final HashMap map = new HashMap<>(); @@ -367,7 +364,7 @@ public class DiscordWebhook { } else if (val instanceof Boolean) { builder.append(val); } else if (val instanceof JSONObject) { - builder.append(val.toString()); + builder.append(val); } else if (val.getClass().isArray()) { builder.append("["); int len = Array.getLength(val); diff --git a/src/main/java/me/night0721/lilase/utils/Utils.java b/src/main/java/me/night0721/lilase/utils/Utils.java index da802d1..df438c4 100644 --- a/src/main/java/me/night0721/lilase/utils/Utils.java +++ b/src/main/java/me/night0721/lilase/utils/Utils.java @@ -41,6 +41,18 @@ public class Utils { } inDungeon = false; } + + public static void checkInHub() { + List scoreboard = ScoreboardUtils.getSidebarLines(); + for (String s : scoreboard) { + String sCleaned = ScoreboardUtils.cleanSB(s); + if (sCleaned.contains("Hub")) { + inDungeon = false; + return; + } + } + inDungeon = true; + } public static void sendMessage(String message) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "" + EnumChatFormatting.BOLD + "Liliase" + EnumChatFormatting.RESET + EnumChatFormatting.DARK_GRAY + " » " + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + EnumChatFormatting.BOLD + message)); } diff --git a/src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java b/src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java deleted file mode 100644 index f48313d..0000000 --- a/src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java +++ /dev/null @@ -1,284 +0,0 @@ -package me.night0721.lilase.utils.ah; - -import me.night0721.lilase.utils.Utils; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import javax.net.ssl.HttpsURLConnection; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URL; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static me.night0721.lilase.Main.clickState; - -public class AuctionHouse { - private final OkHttpClient client; - private static String uuid; - private static String message_toSend; - private Thread thread; - private Boolean open = false; - private final List items = new ArrayList<>(); - private final List posted = new ArrayList<>(); - - public AuctionHouse() { - client = new OkHttpClient(); - // items.add(new Item("Livid Dagger", ItemType.WEAPON, 8000000, ItemTier.LEGENDARY)); - // items.add(new Item("Aspect of the Void", ItemType.WEAPON, 8000000, ItemTier.EPIC)); - // items.add(new Item("Bal", ItemType.MISC, 10000000, ItemTier.EPIC)); - items.add(new Item(" ", ItemType.ANY, 1000, ItemTier.ANY)); - thread = new Thread(() -> { - while (true) { - try { - getItem(); - TimeUnit.SECONDS.sleep(8); - } catch (IOException | JSONException | InterruptedException e) { - e.printStackTrace(); - } - } - }); - } - - private JSONObject getHypixelData(String player) throws IOException, JSONException { - String API_KEY = "d800be32-3abc-49bd-83a7-188573853d49"; - Request request = new Request.Builder() - .url("https://api.hypixel.net/player?key=" + API_KEY + "&uuid=" + player) - .build(); - - Response response = client.newCall(request).execute(); - if (response.code() == 200 && response.body() != null) - return new JSONObject(response.body().string()); - else - return null; - - } - - private void getItem() throws IOException, JSONException { - Request request = new Request.Builder() - .url("https://api.hypixel.net/skyblock/auctions") - .build(); - Response response = client.newCall(request).execute(); - if (response.code() != 200 || response.body() == null) return; - JSONObject data = new JSONObject(response.body().string()); - JSONArray auctions = data.getJSONArray("auctions"); - for (int i = 0; i < auctions.length(); i++) { - JSONObject auction = auctions.getJSONObject(i); - for (Item item : items) { - String lore = " "; - ItemType type = item.type; - switch (item.query) { - case "Bal": - lore = "Made of Lava"; - break; - case "Squid": - lore = "More Ink"; - break; - case "Monkey": - lore = "Treeborn"; - break; - case "Ocelot": - lore = "Tree Hugger"; - break; - case "Dolphin": - lore = "Echolocation"; - break; - case "Flying Fish": - lore = "Water Bender"; - break; - } - - if (!auction.getString("item_name").toLowerCase().contains(item.query.toLowerCase())) break; - if (!auction.getString("item_lore").contains(lore)) break; - if (item.tier != ItemTier.ANY) { - if (!auction.getString("tier").equals(item.tier.name())) break; - } - if (auction.getInt("starting_bid") > item.price) break; - if (type != ItemType.ANY) { - if (!auction.getString("category").equals(type.lowercase)) break; - } - if (!auction.getBoolean("bin")) break; - if (!posted.contains(auction.getString("uuid"))) { - posted.add(auction.getString("uuid")); - NumberFormat format = NumberFormat.getInstance(Locale.US); - JSONObject profile = getHypixelData(auction.getString("auctioneer")); - Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE); - Matcher matcher = pattern.matcher(auction.getString("item_lore")); - String updated = matcher.replaceAll(""); - JSONObject message = new JSONObject(); - JSONObject embed = new JSONObject(); - JSONObject author = new JSONObject(); - JSONObject footer = new JSONObject(); - JSONArray fields = new JSONArray(); - JSONObject item_field = new JSONObject(); - JSONObject price_field = new JSONObject(); - JSONObject seller_field = new JSONObject(); - JSONObject started_field = new JSONObject(); - JSONObject ends_field = new JSONObject(); - - author.put("name", "Ń1ght#4004"); - author.put("url", "https://github.com/night0721"); - author.put("icon_url", "https://avatars.githubusercontent.com/u/77528305?v=4"); - footer.put("text", "Made by Ń1ght#4004"); - footer.put("icon_url", "https://avatars.githubusercontent.com/u/77528305?v=4"); - item_field.put("name", "Item"); - item_field.put("value", auction.getString("item_name")); - item_field.put("inline", true); - price_field.put("name", "Price"); - price_field.put("value", format.format(auction.getInt("starting_bid"))); - price_field.put("inline", true); - seller_field.put("name", "Seller"); - assert profile != null; - seller_field.put("value", profile.getJSONObject("player").getString("displayname")); - seller_field.put("inline", true); - started_field.put("name", "Started for"); - started_field.put("value", toDuration(System.currentTimeMillis() - auction.getLong("start"))); - started_field.put("inline", true); - ends_field.put("name", "Ends in"); - ends_field.put("value", getTimeSinceDate(auction.getLong("end") - System.currentTimeMillis())); - ends_field.put("inline", true); - fields.put(item_field); - fields.put(price_field); - fields.put(seller_field); - fields.put(started_field); - fields.put(ends_field); - embed.put("color", 0x003153); - embed.put("title", "Item Is On Low Price"); - embed.put("url", "https://www.brandonfowler.me/skyblockah/?uuid=" + auction.getString("uuid")); - embed.put("description", updated); - embed.put("author", author); - embed.put("footer", footer); - embed.put("fields", fields); - message.put("username", "Skyblock AH"); - message.put("embeds", new JSONArray().put(embed)); - message.put("content", auction.getString("item_name") + " is sale at " + format.format(auction.getInt("starting_bid")) + "!\n" + "/viewauction " + auction.getString("uuid")); - sendMessage(message); - uuid = auction.getString("uuid"); - message_toSend = "Auction House: " + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!"; - clickState = States.OPEN; - return; - } - } - } - } - - public static void sendAuction() { - Utils.sendServerMessage("/viewauction " + uuid); - Utils.sendMessage(message_toSend); - } - - public final List times = Arrays.asList( - TimeUnit.DAYS.toMillis(365), - TimeUnit.DAYS.toMillis(30), - TimeUnit.DAYS.toMillis(1), - TimeUnit.HOURS.toMillis(1), - TimeUnit.MINUTES.toMillis(1), - TimeUnit.SECONDS.toMillis(1)); - public final List timesString = Arrays.asList("year", "month", "day", "hour", "minute", "second"); - - public String toDuration(long duration) { - - StringBuilder res = new StringBuilder(); - for (int i = 0; i < times.size(); i++) { - Long current = times.get(i); - long temp = duration / current; - if (temp > 0) { - res.append(temp).append(" ").append(timesString.get(i)).append(temp != 1 ? "s" : "").append(" ago"); - break; - } - } - if ("".equals(res.toString())) - return "0 seconds ago"; - else - return res.toString(); - } - - private static String getTimeSinceDate(long timeSinceDate) { - long seconds = TimeUnit.MILLISECONDS.toSeconds(timeSinceDate); - long minutes = TimeUnit.MILLISECONDS.toMinutes(timeSinceDate); - long hours = TimeUnit.MILLISECONDS.toHours(timeSinceDate); - long days = TimeUnit.MILLISECONDS.toDays(timeSinceDate); - - if (seconds < 60) - return "in " + seconds + " seconds"; - else if (minutes < 60) - return "in " + minutes + " minutes"; - else if (hours < 24) - return "in " + hours + " hours"; - else - return "in " + days + " days"; - - } - - private void sendMessage(JSONObject data) throws IOException, JSONException { - String DISCORD_WEBHOOK = "https://discord.com/api/webhooks/979502673093079071/p539WaqjEwiUWqCXLSBAcfDY-EhmF2RU9ZzjCKW_8jtFMuldJQwCdOFMPsT0U3VhfdBH"; - - URL url = new URL(DISCORD_WEBHOOK); - HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); - connection.setDoOutput(true); - connection.setRequestMethod("POST"); - - OutputStream stream = connection.getOutputStream(); - stream.write(data.toString().getBytes()); - stream.flush(); - stream.close(); - connection.getInputStream().close(); - connection.disconnect(); - } - - public void toggleAuction() { - if (open) { - Utils.sendMessage("Stopped Auction House"); - thread.stop(); - open = false; - } else { - Utils.sendMessage("Started Auction House"); - thread.run(); - open = true; - } - } -} -enum ItemTier { - ANY, - COMMON, - UNCOMMON, - RARE, - EPIC, - LEGENDARY, - MYTHIC, - DIVINE, - SPECIAL, - VERY_SPECIAL, -} - -enum ItemType { - ANY("any"), - WEAPON("weapon"), - ARMOR("armor"), - ACCESSORIES("accessories"), - CONSUMABLES("consumables"), - BLOCKS("blocks"), - MISC("misc"),; - - public final String lowercase; - - public String getLowercase() { - return lowercase; - } - - ItemType(String lowercase) { - this.lowercase = lowercase; - } -} diff --git a/src/main/java/me/night0721/lilase/utils/ah/Item.java b/src/main/java/me/night0721/lilase/utils/ah/Item.java deleted file mode 100644 index 3722848..0000000 --- a/src/main/java/me/night0721/lilase/utils/ah/Item.java +++ /dev/null @@ -1,15 +0,0 @@ -package me.night0721.lilase.utils.ah; - -public class Item { - public String query; - public ItemType type; - public Integer price; - public ItemTier tier; - - public Item(String query, ItemType type, Integer price, ItemTier tier) { - this.query = query; - this.type = type; - this.price = price; - this.tier = tier; - } -} diff --git a/src/main/java/me/night0721/lilase/utils/ah/States.java b/src/main/java/me/night0721/lilase/utils/ah/States.java deleted file mode 100644 index a986950..0000000 --- a/src/main/java/me/night0721/lilase/utils/ah/States.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.night0721.lilase.utils.ah; - -public enum States { - OPEN, - NONE, - //CLOSE, - CLICK, - CONFIRM -}