hm more fix on auction house

This commit is contained in:
NK 2023-02-18 13:55:20 +00:00
parent ec42965f3f
commit 813451d4c2
6 changed files with 475 additions and 69 deletions

View file

@ -33,7 +33,8 @@ public class Main {
static int tickAmount; static int tickAmount;
static long lastAction; static long lastAction;
public static States clickState; public static States clickState = States.NONE;
private AuctionHouse auctionHouse;
static Minecraft mc = Minecraft.getMinecraft(); static Minecraft mc = Minecraft.getMinecraft();
static KeyBinding[] keyBindings = new KeyBinding[3]; static 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 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));
@ -41,7 +42,7 @@ public class Main {
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
auctionHouse = new AuctionHouse();
keyBindings[0] = new KeyBinding("Ghost Block Bind", Keyboard.KEY_G, "Lilase"); keyBindings[0] = new KeyBinding("Ghost Block Bind", Keyboard.KEY_G, "Lilase");
keyBindings[1] = new KeyBinding("Hub", Keyboard.KEY_DIVIDE, "Lilase"); keyBindings[1] = new KeyBinding("Hub", Keyboard.KEY_DIVIDE, "Lilase");
keyBindings[2] = new KeyBinding("Auction House", Keyboard.KEY_END, "Lilase"); keyBindings[2] = new KeyBinding("Auction House", Keyboard.KEY_END, "Lilase");
@ -66,7 +67,7 @@ public class Main {
mc.thePlayer.sendChatMessage("/hub"); mc.thePlayer.sendChatMessage("/hub");
} }
if (keyBindings[2].isPressed()) { if (keyBindings[2].isPressed()) {
new AuctionHouse(); auctionHouse.toggleAuction();
} }
if (tickAmount % 20 == 0) { if (tickAmount % 20 == 0) {
Utils.checkForDungeon(); Utils.checkForDungeon();
@ -76,12 +77,20 @@ public class Main {
case CLICK: case CLICK:
if (System.currentTimeMillis() - lastAction < 500) return; if (System.currentTimeMillis() - lastAction < 500) return;
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer); Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer);
break;
case OPEN:
lastAction = System.currentTimeMillis(); 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(); AuctionHouse.sendAuction();
lastAction = System.currentTimeMillis();
clickState = States.CLICK; clickState = States.CLICK;
case NONE:
break;
} }
} }

View file

@ -0,0 +1,391 @@
package me.night0721.lilase.utils;
import javax.net.ssl.HttpsURLConnection;
import java.awt.Color;
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;
/**
* Class used to execute Discord Webhooks with low effort
*/
public class DiscordWebhook {
private final String url;
private String content;
private String username;
private String avatarUrl;
private boolean tts;
private List<EmbedObject> embeds = new ArrayList<>();
/**
* Constructs a new DiscordWebhook instance
*
* @param url The webhook URL obtained in Discord
*/
public DiscordWebhook(String url) {
this.url = url;
}
public void setContent(String content) {
this.content = content;
}
public void setUsername(String username) {
this.username = username;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public void setTts(boolean tts) {
this.tts = tts;
}
public void addEmbed(EmbedObject embed) {
this.embeds.add(embed);
}
public void execute() throws IOException {
if (this.content == null && this.embeds.isEmpty()) {
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
}
JSONObject json = new JSONObject();
json.put("content", this.content);
json.put("username", this.username);
json.put("avatar_url", this.avatarUrl);
json.put("tts", this.tts);
if (!this.embeds.isEmpty()) {
List<JSONObject> embedObjects = new ArrayList<>();
for (EmbedObject embed : this.embeds) {
JSONObject jsonEmbed = new JSONObject();
jsonEmbed.put("title", embed.getTitle());
jsonEmbed.put("description", embed.getDescription());
jsonEmbed.put("url", embed.getUrl());
if (embed.getColor() != null) {
Color color = embed.getColor();
int rgb = color.getRed();
rgb = (rgb << 8) + color.getGreen();
rgb = (rgb << 8) + color.getBlue();
jsonEmbed.put("color", rgb);
}
EmbedObject.Footer footer = embed.getFooter();
EmbedObject.Image image = embed.getImage();
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
EmbedObject.Author author = embed.getAuthor();
List<EmbedObject.Field> fields = embed.getFields();
if (footer != null) {
JSONObject jsonFooter = new JSONObject();
jsonFooter.put("text", footer.getText());
jsonFooter.put("icon_url", footer.getIconUrl());
jsonEmbed.put("footer", jsonFooter);
}
if (image != null) {
JSONObject jsonImage = new JSONObject();
jsonImage.put("url", image.getUrl());
jsonEmbed.put("image", jsonImage);
}
if (thumbnail != null) {
JSONObject jsonThumbnail = new JSONObject();
jsonThumbnail.put("url", thumbnail.getUrl());
jsonEmbed.put("thumbnail", jsonThumbnail);
}
if (author != null) {
JSONObject jsonAuthor = new JSONObject();
jsonAuthor.put("name", author.getName());
jsonAuthor.put("url", author.getUrl());
jsonAuthor.put("icon_url", author.getIconUrl());
jsonEmbed.put("author", jsonAuthor);
}
List<JSONObject> jsonFields = new ArrayList<>();
for (EmbedObject.Field field : fields) {
JSONObject jsonField = new JSONObject();
jsonField.put("name", field.getName());
jsonField.put("value", field.getValue());
jsonField.put("inline", field.isInline());
jsonFields.add(jsonField);
}
jsonEmbed.put("fields", jsonFields.toArray());
embedObjects.add(jsonEmbed);
}
json.put("embeds", embedObjects.toArray());
}
URL url = new URL(this.url);
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(json.toString().getBytes());
stream.flush();
stream.close();
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
connection.disconnect();
}
public static class EmbedObject {
private String title;
private String description;
private String url;
private Color color;
private Footer footer;
private Thumbnail thumbnail;
private Image image;
private Author author;
private List<Field> fields = new ArrayList<>();
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getUrl() {
return url;
}
public Color getColor() {
return color;
}
public Footer getFooter() {
return footer;
}
public Thumbnail getThumbnail() {
return thumbnail;
}
public Image getImage() {
return image;
}
public Author getAuthor() {
return author;
}
public List<Field> getFields() {
return fields;
}
public EmbedObject setTitle(String title) {
this.title = title;
return this;
}
public EmbedObject setDescription(String description) {
this.description = description;
return this;
}
public EmbedObject setUrl(String url) {
this.url = url;
return this;
}
public EmbedObject setColor(Color color) {
this.color = color;
return this;
}
public EmbedObject setFooter(String text, String icon) {
this.footer = new Footer(text, icon);
return this;
}
public EmbedObject setThumbnail(String url) {
this.thumbnail = new Thumbnail(url);
return this;
}
public EmbedObject setImage(String url) {
this.image = new Image(url);
return this;
}
public EmbedObject setAuthor(String name, String url, String icon) {
this.author = new Author(name, url, icon);
return this;
}
public EmbedObject addField(String name, String value, boolean inline) {
this.fields.add(new Field(name, value, inline));
return this;
}
private class Footer {
private String text;
private String iconUrl;
private Footer(String text, String iconUrl) {
this.text = text;
this.iconUrl = iconUrl;
}
private String getText() {
return text;
}
private String getIconUrl() {
return iconUrl;
}
}
private class Thumbnail {
private String url;
private Thumbnail(String url) {
this.url = url;
}
private String getUrl() {
return url;
}
}
private class Image {
private String url;
private Image(String url) {
this.url = url;
}
private String getUrl() {
return url;
}
}
private class Author {
private String name;
private String url;
private String iconUrl;
private Author(String name, String url, String iconUrl) {
this.name = name;
this.url = url;
this.iconUrl = iconUrl;
}
private String getName() {
return name;
}
private String getUrl() {
return url;
}
private String getIconUrl() {
return iconUrl;
}
}
private class Field {
private String name;
private String value;
private boolean inline;
private Field(String name, String value, boolean inline) {
this.name = name;
this.value = value;
this.inline = inline;
}
private String getName() {
return name;
}
private String getValue() {
return value;
}
private boolean isInline() {
return inline;
}
}
}
private class JSONObject {
private final HashMap<String, Object> map = new HashMap<>();
void put(String key, Object value) {
if (value != null) {
map.put(key, value);
}
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
builder.append("{");
int i = 0;
for (Map.Entry<String, Object> entry : entrySet) {
Object val = entry.getValue();
builder.append(quote(entry.getKey())).append(":");
if (val instanceof String) {
builder.append(quote(String.valueOf(val)));
} else if (val instanceof Integer) {
builder.append(Integer.valueOf(String.valueOf(val)));
} else if (val instanceof Boolean) {
builder.append(val);
} else if (val instanceof JSONObject) {
builder.append(val.toString());
} else if (val.getClass().isArray()) {
builder.append("[");
int len = Array.getLength(val);
for (int j = 0; j < len; j++) {
builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
}
builder.append("]");
}
builder.append(++i == entrySet.size() ? "}" : ",");
}
return builder.toString();
}
private String quote(String string) {
return "\"" + string + "\"";
}
}
}

View file

@ -1,8 +1,9 @@
package me.night0721.lilase.utils.ah; package me.night0721.lilase.utils.ah;
import me.night0721.lilase.utils.Utils; import me.night0721.lilase.utils.Utils;
import net.minecraft.client.Minecraft; import okhttp3.OkHttpClient;
import okhttp3.*; import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -11,7 +12,6 @@ import javax.net.ssl.HttpsURLConnection;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -27,6 +27,8 @@ public class AuctionHouse {
private final OkHttpClient client; private final OkHttpClient client;
private static String uuid; private static String uuid;
private static String message_toSend; private static String message_toSend;
private Thread thread;
private Boolean open = false;
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<>();
@ -35,9 +37,8 @@ public class AuctionHouse {
// items.add(new Item("Livid Dagger", ItemType.WEAPON, 8000000, ItemTier.LEGENDARY)); // 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("Aspect of the Void", ItemType.WEAPON, 8000000, ItemTier.EPIC));
// items.add(new Item("Bal", ItemType.MISC, 10000000, ItemTier.EPIC)); // items.add(new Item("Bal", ItemType.MISC, 10000000, ItemTier.EPIC));
items.add(new Item(" ", ItemType.MISC, 1000, ItemTier.UNCOMMON)); items.add(new Item(" ", ItemType.ANY, 1000, ItemTier.ANY));
Utils.sendMessage("AuctionHouse is now running"); thread = new Thread(() -> {
new Thread(() -> {
while (true) { while (true) {
try { try {
getItem(); getItem();
@ -46,7 +47,7 @@ public class AuctionHouse {
e.printStackTrace(); e.printStackTrace();
} }
} }
}).start(); });
} }
private JSONObject getHypixelData(String player) throws IOException, JSONException { private JSONObject getHypixelData(String player) throws IOException, JSONException {
@ -99,12 +100,16 @@ public class AuctionHouse {
if (!auction.getString("item_name").toLowerCase().contains(item.query.toLowerCase())) break; if (!auction.getString("item_name").toLowerCase().contains(item.query.toLowerCase())) break;
if (!auction.getString("item_lore").contains(lore)) 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.getString("tier").equals(item.tier.name())) break;
}
if (auction.getInt("starting_bid") > item.price) break; if (auction.getInt("starting_bid") > item.price) break;
if (type != ItemType.ANY) {
if (!auction.getString("category").equals(type.lowercase)) break; if (!auction.getString("category").equals(type.lowercase)) break;
}
if (!auction.getBoolean("bin")) break; if (!auction.getBoolean("bin")) break;
if (!posted.contains(auction.getString("item_uuid"))) { if (!posted.contains(auction.getString("uuid"))) {
posted.add(auction.getString("item_uuid")); posted.add(auction.getString("uuid"));
NumberFormat format = NumberFormat.getInstance(Locale.US); NumberFormat format = NumberFormat.getInstance(Locale.US);
JSONObject profile = getHypixelData(auction.getString("auctioneer")); JSONObject profile = getHypixelData(auction.getString("auctioneer"));
Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE); Pattern pattern = Pattern.compile("§[0-9a-z]", Pattern.MULTILINE);
@ -150,7 +155,6 @@ public class AuctionHouse {
embed.put("color", 0x003153); embed.put("color", 0x003153);
embed.put("title", "Item Is On Low Price"); embed.put("title", "Item Is On Low Price");
embed.put("url", "https://www.brandonfowler.me/skyblockah/?uuid=" + auction.getString("uuid")); embed.put("url", "https://www.brandonfowler.me/skyblockah/?uuid=" + auction.getString("uuid"));
embed.put("timestamp", System.currentTimeMillis() / 1000);
embed.put("description", updated); embed.put("description", updated);
embed.put("author", author); embed.put("author", author);
embed.put("footer", footer); embed.put("footer", footer);
@ -162,8 +166,6 @@ public class AuctionHouse {
uuid = auction.getString("uuid"); uuid = auction.getString("uuid");
message_toSend = "Auction House: " + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!"; message_toSend = "Auction House: " + auction.getString("item_name") + " is sale for " + format.format(auction.getInt("starting_bid")) + "!";
clickState = States.OPEN; clickState = States.OPEN;
Minecraft.getMinecraft().playerController.windowClick(Minecraft.getMinecraft().thePlayer.openContainer.windowId, 31, 0, 0, Minecraft.getMinecraft().thePlayer);
return; return;
} }
} }
@ -229,19 +231,54 @@ public class AuctionHouse {
connection.setRequestMethod("POST"); connection.setRequestMethod("POST");
OutputStream stream = connection.getOutputStream(); OutputStream stream = connection.getOutputStream();
stream.write(data.toString().getBytes(StandardCharsets.UTF_8)); stream.write(data.toString().getBytes());
stream.flush(); stream.flush();
stream.close(); stream.close();
connection.getInputStream().close();
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
connection.disconnect(); connection.disconnect();
}
public void toggleAuction() {
// Request request = new Request.Builder() if (open) {
// .url(DISCORD_WEBHOOK) Utils.sendMessage("Stopped Auction House");
// .post(RequestBody.create(data.toString(), MediaType.get("application/json"))) thread.stop();
// .addHeader("Content-Type", "application/json") open = false;
//.build(); } else {
//client.newCall(request).execute(); 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;
} }
} }

View file

@ -1,13 +0,0 @@
package me.night0721.lilase.utils.ah;
public enum ItemTier {
COMMON,
UNCOMMON,
RARE,
EPIC,
LEGENDARY,
MYTHIC,
DIVINE,
SPECIAL,
VERY_SPECIAL,
}

View file

@ -1,20 +0,0 @@
package me.night0721.lilase.utils.ah;
public enum ItemType {
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;
}
}

View file

@ -2,6 +2,8 @@ package me.night0721.lilase.utils.ah;
public enum States { public enum States {
OPEN, OPEN,
NONE,
//CLOSE, //CLOSE,
CLICK CLICK,
CONFIRM
} }