still doesn't send, but can auto buy now

This commit is contained in:
NK 2023-02-20 11:01:20 +00:00
parent 9a39c4cd26
commit ac3dd01f06
4 changed files with 25 additions and 19 deletions

View file

@ -30,9 +30,9 @@ public class Main {
public static final String VERSION = "1.0.0"; public static final String VERSION = "1.0.0";
static int tickAmount; static int tickAmount;
private AuctionHouse auctionHouse; private AuctionHouse auctionHouse;
static Minecraft mc = Minecraft.getMinecraft(); static final Minecraft mc = Minecraft.getMinecraft();
static KeyBinding[] keyBindings = new KeyBinding[3]; static final KeyBinding[] keyBindings = new KeyBinding[3];
static ArrayList<Block> 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 final ArrayList<Block> 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 @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
@ -75,8 +75,9 @@ public class Main {
public void onChat(ClientChatReceivedEvent event) { public void onChat(ClientChatReceivedEvent event) {
String message = event.message.getUnformattedText(); String message = event.message.getUnformattedText();
if (!message.contains(":")) { if (!message.contains(":")) {
if (message.equals("Claiming BIN auction...")) { if (message.equals("You didn't participate in this auction!")) {
Utils.addTitle("&aBought BIN Auction"); System.out.println("Failed to buy item, closing the menu");
mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, 49, 0, 0, mc.thePlayer); // Close the window as could not buy
} }
} }
} }

View file

@ -26,7 +26,7 @@ public class AuctionHouse {
private static long lastAction; private static long lastAction;
private Thread thread; private Thread thread;
private Boolean open = false; private Boolean open = false;
private DiscordWebhook webhook; private final DiscordWebhook webhook;
private final List<Item> items = new ArrayList<>(); private final List<Item> items = new ArrayList<>();
private final List<String> posted = new ArrayList<>(); private final List<String> posted = new ArrayList<>();
public static States clickState = States.NONE; public static States clickState = States.NONE;
@ -50,7 +50,7 @@ public class AuctionHouse {
connection.setReadTimeout(5000); connection.setReadTimeout(5000);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine; String inputLine;
StringBuffer content = new StringBuffer(); StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
content.append(inputLine); content.append(inputLine);
} }
@ -69,7 +69,7 @@ public class AuctionHouse {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine; String inputLine;
StringBuffer content = new StringBuffer(); StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) { while ((inputLine = in.readLine()) != null) {
content.append(inputLine); content.append(inputLine);
} }
@ -117,6 +117,7 @@ public class AuctionHouse {
Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE); Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(auction.getString("item_lore")); Matcher matcher = pattern.matcher(auction.getString("item_lore"));
String updated = matcher.replaceAll(""); String updated = matcher.replaceAll("");
System.out.println(updated);
webhook.addEmbed( webhook.addEmbed(
new DiscordWebhook.EmbedObject() new DiscordWebhook.EmbedObject()
.setTitle("Item Is On Low Price") .setTitle("Item Is On Low Price")
@ -186,7 +187,7 @@ public class AuctionHouse {
public void toggleAuction() { public void toggleAuction() {
if (open) { if (open) {
Utils.sendMessage("Stopped Auction House"); Utils.sendMessage("Stopped Auction House");
thread.stop(); thread.interrupt();
open = false; open = false;
} else { } else {
Utils.sendMessage("Started Auction House"); Utils.sendMessage("Started Auction House");
@ -199,7 +200,7 @@ public class AuctionHouse {
} }
} }
}); });
thread.run(); //You didn't participate in this auction! thread.start();
open = true; open = true;
} }
} }
@ -250,10 +251,10 @@ enum ItemType {
} }
class Item { class Item {
public String query; public final String query;
public ItemType type; public final ItemType type;
public Integer price; public final Integer price;
public ItemTier tier; public final ItemTier tier;
public Item(String query, ItemType type, Integer price, ItemTier tier) { public Item(String query, ItemType type, Integer price, ItemTier tier) {
this.query = query; this.query = query;

View file

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
@ -139,12 +140,12 @@ public class DiscordWebhook {
URL url = new URL(this.url); URL url = new URL(this.url);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.addRequestProperty("Content-Type", "application/json"); connection.addRequestProperty("Content-Type", "application/json");
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11");
connection.setDoOutput(true); connection.setDoOutput(true);
connection.setRequestMethod("POST"); connection.setRequestMethod("POST");
System.out.println(json);
OutputStream stream = connection.getOutputStream(); OutputStream stream = connection.getOutputStream();
stream.write(json.toString().getBytes()); stream.write(json.toString().getBytes(StandardCharsets.UTF_8));
stream.flush(); stream.flush();
stream.close(); stream.close();

View file

@ -10,6 +10,7 @@ import java.util.List;
public class Utils { public class Utils {
public static boolean inDungeon; public static boolean inDungeon;
public static boolean inHub;
public static String translateAlternateColorCodes(String text) { public static String translateAlternateColorCodes(String text) {
char[] b = text.toCharArray(); char[] b = text.toCharArray();
@ -46,16 +47,18 @@ public class Utils {
List<String> scoreboard = ScoreboardUtils.getSidebarLines(); List<String> scoreboard = ScoreboardUtils.getSidebarLines();
for (String s : scoreboard) { for (String s : scoreboard) {
String sCleaned = ScoreboardUtils.cleanSB(s); String sCleaned = ScoreboardUtils.cleanSB(s);
if (sCleaned.contains("Hub")) { if (sCleaned.contains("Forest") || sCleaned.contains("Village") || sCleaned.contains("Farm") || sCleaned.contains("Mountain") || sCleaned.contains("Wilderness") || sCleaned.contains("Community Center") || sCleaned.contains("Graveyard")) {
inDungeon = false; inHub = true;
return; return;
} }
} }
inDungeon = true; inDungeon = true;
} }
public static void sendMessage(String message) { 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)); 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) { public static void sendServerMessage(String message) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(message); Minecraft.getMinecraft().thePlayer.sendChatMessage(message);
} }