diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/Config.java | 12 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java | 1 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java | 2 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/e.java | 10 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java (renamed from src/main/java/kr/syeyoung/dungeonsguide/EventListener.java) | 10 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java | 106 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java | 131 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java | 29 |
8 files changed, 291 insertions, 10 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/Config.java b/src/main/java/kr/syeyoung/dungeonsguide/Config.java index 03bd2396..eec433f9 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/Config.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/Config.java @@ -6,8 +6,9 @@ import net.minecraftforge.common.config.Property; public class Config { public static Configuration configuration; - public static final String CATEGORY_ADVANCED = "advanced"; - public static final String CATEGORY_PUZZLE_SOLVER = "solver"; + public static final String CATEGORY_ADVANCED = "Advanced"; + public static final String CATEGORY_PUZZLE_SOLVER = "Solver"; + public static final String CATEGORY_QOL = "Tooltips"; public static boolean DEBUG = true; @@ -22,6 +23,10 @@ public class Config { public static boolean solver_creeper; public static boolean solver_teleport; + + public static boolean itemtooltip_dungeonstat; + public static boolean itemtooltip_price; + public static void syncConfig(boolean load) { // Gets called from preInit try { // Load config @@ -40,7 +45,8 @@ public class Config { solver_waterpuzzle = configuration.get(Config.CATEGORY_PUZZLE_SOLVER, "water", "true", "Water puzzle solver", Property.Type.BOOLEAN).getBoolean(); solver_box = configuration.get(Config.CATEGORY_PUZZLE_SOLVER, "box", "true", "Box puzzle solver", Property.Type.BOOLEAN).getBoolean(); - + itemtooltip_dungeonstat = configuration.get(Config.CATEGORY_QOL, "dungeonstat", "true", "Show what floor dungeon item was obtained", Property.Type.BOOLEAN).getBoolean(); + itemtooltip_price = configuration.get(Config.CATEGORY_QOL, "price", "true", "Show prices of any item", Property.Type.BOOLEAN).getBoolean(); DEBUG = configuration.get(Config.CATEGORY_ADVANCED, "debug","false", "Enable debug mode", Property.Type.BOOLEAN).getBoolean(); // Comment } catch (Exception e) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java index 3b951c89..bda98879 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java @@ -71,6 +71,7 @@ public class SkyblockStatus { for (String skyblock : SKYBLOCK_IN_ALL_LANGUAGES) { if (objectiveName.startsWith(skyblock)) { skyblockFound = true; + isOnSkyblock = true; break; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java index 83427c14..05cd57d6 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java @@ -12,7 +12,7 @@ import java.util.UUID; @Getter @Setter public class DungeonRoomInfo implements Serializable { - private static final long serialVersionUID = 42L; + private static final long serialVersionUID = -8291811286448196640L; public DungeonRoomInfo(short shape, byte color) { this.uuid = UUID.randomUUID(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index 80440e36..8cd34154 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -2,14 +2,15 @@ package kr.syeyoung.dungeonsguide; import kr.syeyoung.dungeonsguide.commands.*; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import kr.syeyoung.dungeonsguide.eventlistener.DungeonListener; +import kr.syeyoung.dungeonsguide.eventlistener.ItemGuiListener; +import kr.syeyoung.dungeonsguide.utils.AhUtils; import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.commons.io.IOUtils; @@ -49,11 +50,14 @@ public class e implements c { dungeonsGuide = this; skyblockStatus = new SkyblockStatus(); - MinecraftForge.EVENT_BUS.register(new EventListener()); + MinecraftForge.EVENT_BUS.register(new DungeonListener()); + MinecraftForge.EVENT_BUS.register(new ItemGuiListener()); CommandDungeonsGuide commandDungeonsGuide; ClientCommandHandler.instance.registerCommand(commandDungeonsGuide = new CommandDungeonsGuide()); MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); + AhUtils.registerTimer(); + try { DungeonRoomInfoRegistry.loadAll(configDir); } catch (BadPaddingException e) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java index 8b7273c5..118626f5 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java @@ -1,8 +1,12 @@ -package kr.syeyoung.dungeonsguide; +package kr.syeyoung.dungeonsguide.eventlistener; +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.Keybinds; +import kr.syeyoung.dungeonsguide.SkyblockStatus; import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.e; import kr.syeyoung.dungeonsguide.roomedit.EditingContext; import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet; import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit; @@ -29,7 +33,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import java.awt.*; -public class EventListener { +public class DungeonListener { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent e) { try { @@ -204,7 +208,7 @@ public class EventListener { @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent keyInputEvent) { - if (Config.DEBUG &&Keybinds.editingSession.isKeyDown() ){ + if (Config.DEBUG && Keybinds.editingSession.isKeyDown() ){ EditingContext ec = EditingContext.getEditingContext(); if (ec == null) { DungeonContext context = e.getDungeonsGuide().getSkyblockStatus().getContext(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java new file mode 100644 index 00000000..829513bf --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/ItemGuiListener.java @@ -0,0 +1,106 @@ +package kr.syeyoung.dungeonsguide.eventlistener; + +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.utils.AhUtils; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.*; + +public class ItemGuiListener { + @SubscribeEvent + public void dungeonTooltip(ItemTooltipEvent event) { + if (!e.getDungeonsGuide().getSkyblockStatus().isOnSkyblock()) return; + if (!Config.itemtooltip_dungeonstat) return; + + ItemStack hoveredItem = event.itemStack; + NBTTagCompound compound = hoveredItem.getTagCompound(); + if (compound == null) + return; + if (!compound.hasKey("ExtraAttributes")) + return; + NBTTagCompound nbtTagCompound = compound.getCompoundTag("ExtraAttributes"); + + int floor = nbtTagCompound.getInteger("item_tier"); + int percentage = nbtTagCompound.getInteger("baseStatBoostPercentage"); + + if (nbtTagCompound.hasKey("item_tier")) + event.toolTip.add("§7Obtained in: §c"+(floor == 0 ? "Entrance" : "Floor "+floor)); + if (nbtTagCompound.hasKey("baseStatBoostPercentage")) + event.toolTip.add("§7Stat Percentage: §"+(percentage == 50 ? "6§l":"c")+(percentage * 2)+"%"); + } + @SubscribeEvent + public void priceTooltip(ItemTooltipEvent event) { + if (!e.getDungeonsGuide().getSkyblockStatus().isOnSkyblock()) return; + if (!Config.itemtooltip_price) return; + + ItemStack hoveredItem = event.itemStack; + NBTTagCompound compound = hoveredItem.getTagCompound(); + if (compound == null) + return; + if (!compound.hasKey("ExtraAttributes")) + return; + final String id = compound.getCompoundTag("ExtraAttributes").getString("id"); + if (id.equals("ENCHANTED_BOOK")) { + final NBTTagCompound enchants = compound.getCompoundTag("ExtraAttributes").getCompoundTag("enchantments"); + Set<String> keys = enchants.getKeySet(); + Set<String> actualKeys = new TreeSet<String>(new Comparator<String>() { + public int compare(String o1, String o2) { + String id2 = id + "::" + o1 + "-" + enchants.getInteger(o1); + AhUtils.AuctionData auctionData = AhUtils.auctions.get(id2); + int price1 = (auctionData == null) ? 0 : ((Integer)auctionData.prices.first()).intValue(); + String id3 = id + "::" + o2 + "-" + enchants.getInteger(o2); + AhUtils.AuctionData auctionData2 = AhUtils.auctions.get(id3); + int price2 = (auctionData2 == null) ? 0 : ((Integer)auctionData2.prices.first()).intValue(); + return (compare2(price1, price2) == 0) ? o1.compareTo(o2) : compare2(price1, price2); + } + + public int compare2(int y, int x) { + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); + actualKeys.addAll(keys); + int totalLowestPrice = 0; + int totalHighestPrice = 0; + int iterations = 0; + for (String key : actualKeys) { + iterations++; + String id2 = id + "::" + key + "-" + enchants.getInteger(key); + AhUtils.AuctionData auctionData = AhUtils.auctions.get(id2); + if (auctionData == null) { + if (iterations < 10) + event.toolTip.add("§f"+ key + " " + enchants.getInteger(key) + "§7: §cn/a"); + continue; + } + if (iterations < 10) + event.toolTip.add("§f"+ key + " " + enchants.getInteger(key) + "§7: §e"+ TextUtils.format((Integer) auctionData.prices.first()) + " §7to§e "+ TextUtils.format(auctionData.prices.last())); + totalLowestPrice += auctionData.prices.first(); + totalHighestPrice += auctionData.prices.last(); + } + if (iterations >= 10) + event.toolTip.add("§7"+ (iterations - 10) + " more enchants... "); + event.toolTip.add("§fTotal§7 §e:"+ TextUtils.format(totalLowestPrice) + " §7to§e "+ TextUtils.format(totalHighestPrice)); + } else { + AhUtils.AuctionData auctionData = AhUtils.auctions.get(id); + event.toolTip.add(""); + if (auctionData == null) { + event.toolTip.add("§fLowest ah §7: §cn/a"); + event.toolTip.add("§fHighest ah §7: §cn/a"); + event.toolTip.add("§fBazaar sell price §7: §cn/a"); + event.toolTip.add("§fBazaar buy price §7: §cn/a"); + } else { + event.toolTip.add("§fLowest ah §7: " + ((auctionData.prices.size() != 0) ? ("§e"+ TextUtils.format(auctionData.prices.first().intValue())) : "§cn/a")); + event.toolTip.add("§fHighest ah §7: " + ((auctionData.prices.size() != 0) ? ("§e"+ TextUtils.format((auctionData.prices.last()).intValue())) : "§cn/a")); + event.toolTip.add("§fBazaar sell price §7: " + ((auctionData.sellPrice == -1) ? "§cn/a": ("§e"+ TextUtils.format(auctionData.sellPrice)))); + event.toolTip.add("§fBazaar buy price §7: " + ((auctionData.buyPrice == -1) ? "§cn/a": ("§e"+ TextUtils.format(auctionData.buyPrice)))); + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java new file mode 100644 index 00000000..1f7644bc --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java @@ -0,0 +1,131 @@ +package kr.syeyoung.dungeonsguide.utils; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.Timer; +import java.util.TimerTask; +import java.util.TreeSet; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; + +public class AhUtils { + public static volatile Map<String, AuctionData> auctions = new HashMap<String, AuctionData>(); + + private static Map<String, AuctionData> semi_auctions = new HashMap<String, AuctionData>(); + + public static Timer timer = new Timer(); + + public static int totalAuctions = 0; + + public static void registerTimer() { + timer.schedule(new TimerTask() { + public void run() { + AhUtils.loadAuctions(); + } + }, 0L, 1800000L); + } + + public static void loadAuctions() { + try { + int i = 0; + do { + + } while (loadPage(i++)); + loadBazaar(); + auctions = semi_auctions; + semi_auctions = new HashMap<String, AuctionData>(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void loadBazaar() throws IOException { + System.out.println("Fetching bazaar data"); + URL url = new URL("https://api.hypixel.net/skyblock/bazaar"); + InputStreamReader reader = new InputStreamReader(url.openStream()); + JsonObject object = (JsonObject)(new JsonParser()).parse(reader); + boolean success = object.get("success").getAsBoolean(); + if (!success) + return; + JsonObject element = object.getAsJsonObject("products"); + for (Map.Entry<String, JsonElement> product : (Iterable<Map.Entry<String, JsonElement>>)element.entrySet()) { + String id = product.getKey(); + AuctionData auctionData = semi_auctions.get(id); + boolean notexisted = (auctionData == null); + if (notexisted) + auctionData = new AuctionData(id); + auctionData.sellPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("sellPrice").getAsInt(); + auctionData.buyPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("buyPrice").getAsInt(); + if (notexisted) + semi_auctions.put(id, auctionData); + } + } + + public static boolean loadPage(int page) throws IOException { + System.out.println("Fetching page " + page + " of auctions"); + URL url = new URL("https://api.hypixel.net/skyblock/auctions?page=" + page); + InputStreamReader reader = new InputStreamReader(url.openStream()); + JsonObject object = (JsonObject)(new JsonParser()).parse(reader); + boolean success = object.get("success").getAsBoolean(); + if (!success) + return false; + int maxPage = object.get("totalPages").getAsInt(); + int totalAuctions = object.get("totalAuctions").getAsInt(); + System.out.println("Fetched page " + page + "/" + maxPage + " of auctions! (" + totalAuctions + " total)"); + JsonArray array = object.get("auctions").getAsJsonArray(); + for (JsonElement element2 : array) { + JsonObject element = element2.getAsJsonObject(); + JsonElement isBin = element.get("bin"); + if (isBin == null || !isBin.getAsBoolean()) + continue; + byte[] itemData = Base64.decode(element.get("item_bytes").getAsString().replace("\\u003d", "=")); + NBTTagCompound nbtTagCompound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(itemData)); + NBTTagCompound acutalItem = (NBTTagCompound)nbtTagCompound.getTagList("i", 10).get(0); + NBTTagCompound attributes = acutalItem.getCompoundTag("tag").getCompoundTag("ExtraAttributes"); + String id = attributes.getString("id"); + if (id.equals("ENCHANTED_BOOK")) { + NBTTagCompound enchants = attributes.getCompoundTag("enchantments"); + Set<String> keys = enchants.getKeySet(); + if (keys.size() != 1) + continue; + String ench = keys.iterator().next(); + int lv = enchants.getInteger(ench); + id = id + "::" + ench + "-" + lv; + } + AuctionData auctionData = semi_auctions.get(id); + boolean notexisted = (auctionData == null); + if (notexisted) + auctionData = new AuctionData(id); + auctionData.prices.add(element.get("starting_bid").getAsInt()); + if (notexisted) + semi_auctions.put(id, auctionData); + } + return (page < maxPage); + } + + public static class AuctionData { + public String id; + + public SortedSet<Integer> prices; + + public int sellPrice = -1; + + public int buyPrice = -1; + + public AuctionData(String id) { + this.id = id; + this.prices = new TreeSet<Integer>(); + } + } +}
\ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java index d56584c3..300cf6ba 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/TextUtils.java @@ -2,6 +2,8 @@ package kr.syeyoung.dungeonsguide.utils; import java.text.DecimalFormat; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.regex.Pattern; public class TextUtils { @@ -33,4 +35,31 @@ public class TextUtils { return stringBuilder.toString(); } + + + private static final TreeMap<Long, String> suffixes = new TreeMap<Long, String>(); + + static { + suffixes.put(1000L, "k"); + suffixes.put(1000000L, "m"); + suffixes.put(1000000000L, "b"); + } + + public static String format(long value) { +// return String.valueOf(value); + + if (value == Long.MIN_VALUE) + return format(-9223372036854775807L); + if (value < 0L) + return "-" + format(-value); + if (value < 1000L) + return Long.toString(value); + Map.Entry<Long, String> e = suffixes.floorEntry(value); + Long divideBy = e.getKey(); + String suffix = e.getValue(); + long truncated = value * 10 / divideBy ; + boolean hasDecimal = (truncated < 100L && (truncated / 10.0D) != (truncated / 10L)); + return hasDecimal ? ((truncated / 10.0D) + suffix) : ((truncated / 10L) + suffix); + } + }
\ No newline at end of file |