From ec42965f3fef18b62e9890d90b34dbae5c8c47af Mon Sep 17 00:00:00 2001 From: NK Date: Tue, 14 Feb 2023 18:00:07 +0000 Subject: [PATCH] add more things --- src/main/java/me/night0721/lilase/Main.java | 34 +++++------ .../java/me/night0721/lilase/utils/Utils.java | 3 + .../lilase/utils/ah/AuctionHouse.java | 57 +++++++++++++++---- .../me/night0721/lilase/utils/ah/States.java | 7 +++ 4 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 src/main/java/me/night0721/lilase/utils/ah/States.java diff --git a/src/main/java/me/night0721/lilase/Main.java b/src/main/java/me/night0721/lilase/Main.java index 244e508..5160e42 100644 --- a/src/main/java/me/night0721/lilase/Main.java +++ b/src/main/java/me/night0721/lilase/Main.java @@ -4,6 +4,7 @@ import com.mojang.realmsclient.gui.ChatFormatting; import me.night0721.lilase.events.PacketReceivedEvent; 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; @@ -23,7 +24,7 @@ import org.lwjgl.input.Keyboard; import java.util.ArrayList; import java.util.Arrays; -@Mod(modid = Main.MODID, name = Main.MOD_NAME, version = Main.VERSION, acceptedMinecraftVersions="[1.8.9]") +@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"; @@ -31,12 +32,11 @@ public class Main { public static final String VERSION = "1.0.0"; static int tickAmount; + static long lastAction; + public static States clickState; static Minecraft mc = Minecraft.getMinecraft(); static KeyBinding[] keyBindings = new KeyBinding[3]; - static ArrayList interactables = new ArrayList<>(Arrays.asList(Blocks.acacia_door, Blocks.anvil, Blocks.beacon, Blocks.bed, Blocks.birch_door, Blocks.brewing_stand, Blocks.command_block, Blocks.crafting_table, Blocks.chest, Blocks.dark_oak_door, - Blocks.daylight_detector, Blocks.daylight_detector_inverted, Blocks.dispenser, Blocks.dropper, Blocks.enchanting_table, Blocks.ender_chest, Blocks.furnace, Blocks.hopper, Blocks.jungle_door, Blocks.lever, - Blocks.noteblock, Blocks.powered_comparator, Blocks.unpowered_comparator, Blocks.powered_repeater, Blocks.unpowered_repeater, Blocks.standing_sign, Blocks.wall_sign, Blocks.trapdoor, Blocks.trapped_chest, Blocks.wooden_button, - Blocks.stone_button, Blocks.oak_door, Blocks.skull)); + static ArrayList interactables = new ArrayList<>(Arrays.asList(Blocks.acacia_door, Blocks.anvil, Blocks.beacon, Blocks.bed, Blocks.birch_door, Blocks.brewing_stand, Blocks.command_block, Blocks.crafting_table, Blocks.chest, Blocks.dark_oak_door, Blocks.daylight_detector, Blocks.daylight_detector_inverted, Blocks.dispenser, Blocks.dropper, Blocks.enchanting_table, Blocks.ender_chest, Blocks.furnace, Blocks.hopper, Blocks.jungle_door, Blocks.lever, Blocks.noteblock, Blocks.powered_comparator, Blocks.unpowered_comparator, Blocks.powered_repeater, Blocks.unpowered_repeater, Blocks.standing_sign, Blocks.wall_sign, Blocks.trapdoor, Blocks.trapped_chest, Blocks.wooden_button, Blocks.stone_button, Blocks.oak_door, Blocks.skull)); @Mod.EventHandler public void init(FMLInitializationEvent event) { @@ -72,6 +72,18 @@ public class Main { 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); + break; + + case OPEN: + lastAction = System.currentTimeMillis(); + AuctionHouse.sendAuction(); + clickState = States.CLICK; + } + } @SubscribeEvent @@ -80,16 +92,6 @@ public class Main { if (!message.contains(":")) { if (message.equals("Myrap opened a WITHER door!")) { Utils.addTitle("&aMyr opened a door"); - } else if (message.equals("SpideySb opened a WITHER door!")) { - Utils.addTitle("&aSpidey opened a door"); - } else if (message.endsWith("Myrap has obtained Wither Key!")) { - Utils.addTitle("&aMyr has picked up the key"); - } else if (message.endsWith("SpideySb has obtained Wither Key!")) { - Utils.addTitle("&aSpidey has picked up the key"); - } else if (message.endsWith("Myrap has obtained Blood Key!")) { - Utils.addTitle("&aMyr has picked up the key"); - } else if (message.endsWith("SpideySb has obtained Blood Key!")) { - Utils.addTitle("&aSpidey has picked up the key"); } } event.message = new ChatComponentText(event.message.getFormattedText().replace("§bCo-op > ", "§zCo-op > ")); @@ -102,4 +104,4 @@ public class Main { mc.getNetHandler().getNetworkManager().sendPacket(new C0DPacketCloseWindow(((S2DPacketOpenWindow) event.packet).getWindowId())); } } -} +} \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/utils/Utils.java b/src/main/java/me/night0721/lilase/utils/Utils.java index 959061e..da802d1 100644 --- a/src/main/java/me/night0721/lilase/utils/Utils.java +++ b/src/main/java/me/night0721/lilase/utils/Utils.java @@ -44,4 +44,7 @@ public class Utils { 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)); } + public static void sendServerMessage(String message) { + Minecraft.getMinecraft().thePlayer.sendChatMessage(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 index e2f39e7..6206b03 100644 --- a/src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java +++ b/src/main/java/me/night0721/lilase/utils/ah/AuctionHouse.java @@ -1,12 +1,17 @@ package me.night0721.lilase.utils.ah; import me.night0721.lilase.utils.Utils; +import net.minecraft.client.Minecraft; import okhttp3.*; 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.nio.charset.StandardCharsets; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; @@ -16,19 +21,22 @@ 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 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("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.MISC, 1000, ItemTier.UNCOMMON)); Utils.sendMessage("AuctionHouse is now running"); - // run getItem every 8 seconds= new Thread(() -> { while (true) { try { @@ -151,12 +159,22 @@ public class AuctionHouse { 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); - Utils.sendMessage("Auction House:" + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!"); + uuid = auction.getString("uuid"); + message_toSend = "Auction House: " + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!"; + clickState = States.OPEN; + Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer); + + 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), @@ -202,11 +220,28 @@ public class AuctionHouse { private void sendMessage(JSONObject data) throws IOException, JSONException { String DISCORD_WEBHOOK = "https://discord.com/api/webhooks/979502673093079071/p539WaqjEwiUWqCXLSBAcfDY-EhmF2RU9ZzjCKW_8jtFMuldJQwCdOFMPsT0U3VhfdBH"; - Request request = new Request.Builder() - .url(DISCORD_WEBHOOK) - .post(RequestBody.create(data.toString(), MediaType.get("application/json"))) - .addHeader("Content-Type", "application/json") - .build(); - client.newCall(request).execute(); + + 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(StandardCharsets.UTF_8)); + stream.flush(); + stream.close(); + + connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream + connection.disconnect(); + + + // Request request = new Request.Builder() + // .url(DISCORD_WEBHOOK) + // .post(RequestBody.create(data.toString(), MediaType.get("application/json"))) + // .addHeader("Content-Type", "application/json") + //.build(); + //client.newCall(request).execute(); } } \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/utils/ah/States.java b/src/main/java/me/night0721/lilase/utils/ah/States.java new file mode 100644 index 0000000..6825260 --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/ah/States.java @@ -0,0 +1,7 @@ +package me.night0721.lilase.utils.ah; + +public enum States { + OPEN, + //CLOSE, + CLICK +} \ No newline at end of file