aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java12
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java32
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java124
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java16
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java18
6 files changed, 163 insertions, 43 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index df31834f..abe0bdcf 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -23,6 +23,7 @@ import org.apache.commons.io.FileUtils;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
+import javax.net.ssl.HttpsURLConnection;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import java.io.*;
@@ -1032,11 +1033,12 @@ public class NEUManager {
} catch (IOException e) {
return null;
}
- try (
- BufferedInputStream inStream = new BufferedInputStream(new URL(
- url + "?action=raw&templates=expand").openStream());
- FileOutputStream fileOutputStream = new FileOutputStream(f)
- ) {
+ try {
+ HttpsURLConnection con = (HttpsURLConnection) new URL(url + "?action=raw&templates=expand").openConnection();
+ con.setRequestMethod("GET");
+ con.setRequestProperty("User-Agent", "NotEnoughUpdates");
+ BufferedInputStream inStream = new BufferedInputStream(con.getInputStream());
+ FileOutputStream fileOutputStream = new FileOutputStream(f);
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = inStream.read(dataBuffer, 0, 1024)) != -1) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index 5ad02f94..b7aa42d6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -751,16 +751,27 @@ public class NEUOverlay extends Gui {
public void showInfo(JsonObject item) {
if (item.has("info") && item.has("infoType")) {
JsonArray lore = item.get("info").getAsJsonArray();
- StringBuilder loreBuilder = new StringBuilder();
- for (int i = 0; i < lore.size(); i++) {
- loreBuilder.append(lore.get(i).getAsString());
- if (i != lore.size() - 1)
- loreBuilder.append("\n");
+ String infoType = item.get("infoType").getAsString();
+ String infoText = "";
+ if (infoType.equals("WIKI_URL")) {
+ for (JsonElement url : lore) {
+ infoText = url.getAsString();
+ if (
+ url.getAsString().startsWith("https://wiki.hypixel.net/") && NotEnoughUpdates.INSTANCE.config.misc.wiki == 0
+ || url.getAsString().startsWith("https://hypixel-skyblock.fandom.com/") &&
+ NotEnoughUpdates.INSTANCE.config.misc.wiki == 1) break;
+ }
+ } else {
+ StringBuilder loreBuilder = new StringBuilder();
+ for (int i = 0; i < lore.size(); i++) {
+ loreBuilder.append(lore.get(i).getAsString());
+ if (i != lore.size() - 1)
+ loreBuilder.append("\n");
+ }
+ infoText = loreBuilder.toString();
}
- String infoText = loreBuilder.toString();
String internalname = item.get("internalname").getAsString();
String name = item.get("displayname").getAsString();
- String infoType = item.get("infoType").getAsString();
displayInformationPane(new TextInfoPane(
this,
manager,
@@ -825,6 +836,10 @@ public class NEUOverlay extends Gui {
if (selectedItemGroup != null) {
int selectedX = Math.min(selectedItemGroupX, width - getBoxPadding() - 18 * selectedItemGroup.size());
if (mouseY > selectedItemGroupY + 17 && mouseY < selectedItemGroupY + 35) {
+ if (!Mouse.getEventButtonState()) {
+ Utils.pushGuiScale(-1);
+ return true; //End early if the mouse isn't pressed, but still cancel event.
+ }
for (int i = 0; i < selectedItemGroup.size(); i++) {
if (mouseX >= selectedX - 1 + 18 * i && mouseX <= selectedX + 17 + 18 * i) {
JsonObject item = selectedItemGroup.get(i);
@@ -1349,7 +1364,8 @@ public class NEUOverlay extends Gui {
} else if (getSortMode() == SORT_MODE_PET) {
return internalname.matches(petRegex) && item.get("displayname").getAsString().contains("[");
} else if (getSortMode() == SORT_MODE_TOOL) {
- return checkItemType(item.get("lore").getAsJsonArray(),
+ return checkItemType(
+ item.get("lore").getAsJsonArray(),
"SWORD",
"BOW",
"AXE",
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java
index baf88457..e4098f3e 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java
@@ -14,6 +14,7 @@ import io.github.moulberry.notenoughupdates.util.AllowEmptyHTMLTag;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture;
@@ -30,10 +31,12 @@ import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
public class HTMLInfoPane extends TextInfoPane {
private static final WikiModel wikiModel;
@@ -47,6 +50,10 @@ public class HTMLInfoPane extends TextInfoPane {
private int imageHeight = 0;
private int imageWidth = 0;
+ private float xMin = 0;
+ private int mouseOffset = 0;
+ private boolean selected = false;
+
private static boolean hasAttemptedDownload = false;
/*
@@ -61,6 +68,16 @@ public class HTMLInfoPane extends TextInfoPane {
conf.addTokenTag("infobox", new IgnoreTag("infobox"));
conf.addTokenTag("tabber", new IgnoreTag("tabber"));
conf.addTokenTag("kbd", new HTMLTag("kbd"));
+ conf.addTokenTag("td", new AllowEmptyHTMLTag("td"));
+ conf.addTokenTag("tbody", new AllowEmptyHTMLTag("tbody"));
+ conf.addTokenTag("style", new AllowEmptyHTMLTag("style"));
+ conf.addTokenTag("article", new AllowEmptyHTMLTag("article"));
+ conf.addTokenTag("section", new AllowEmptyHTMLTag("section"));
+ conf.addTokenTag("link", new AllowEmptyHTMLTag("link"));
+ conf.addTokenTag("wbr", new AllowEmptyHTMLTag("wbr"));
+ conf.addTokenTag("dl", new AllowEmptyHTMLTag("dl"));
+ conf.addTokenTag("dd", new AllowEmptyHTMLTag("dd"));
+ conf.addTokenTag("dt", new AllowEmptyHTMLTag("dt"));
wikiModel = new WikiModel(conf, "https://hypixel-skyblock.fandom.com/wiki/Special:Filepath/${image}",
"https://hypixel-skyblock.fandom.com/wiki/${title}"
) {
@@ -101,7 +118,7 @@ public class HTMLInfoPane extends TextInfoPane {
) {
return manager.getWebFile(wikiUrl).thenApply(f -> {
if (f == null) {
- return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl);
+ return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl, false);
}
StringBuilder sb = new StringBuilder();
@@ -114,9 +131,16 @@ public class HTMLInfoPane extends TextInfoPane {
sb.append(l).append("\n");
}
} catch (IOException e) {
- return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl);
+ return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl, false);
}
- return createFromWikiText(overlay, manager, name, f.getName(), sb.toString());
+ return createFromWikiText(
+ overlay,
+ manager,
+ name,
+ f.getName(),
+ sb.toString(),
+ wikiUrl.startsWith("https://wiki.hypixel.net/")
+ );
});
}
@@ -126,15 +150,37 @@ public class HTMLInfoPane extends TextInfoPane {
* a more permanent solution that can be abstracted to work with arbitrary wiki codes (eg. moulberry.github.io/
* files/neu_help.html).
*/
+
+ private static final Pattern replacePattern = Pattern.compile(
+ "<nav class=\"page-actions-menu\">.*</nav>|",
+ Pattern.DOTALL
+ );
+
public static HTMLInfoPane createFromWikiText(
NEUOverlay overlay, NEUManager manager, String name, String filename,
- String wiki
+ String wiki, boolean isOfficialWiki
) {
- String[] split = wiki.split("</infobox>");
- wiki = split[split.length - 1]; //Remove everything before infobox
- wiki = wiki.split("<span class=\"navbox-vde\">")[0]; //Remove navbox
- wiki = wiki.split("<table class=\"navbox mw-collapsible\"")[0];
- wiki = "__NOTOC__\n" + wiki; //Remove TOC
+ if (isOfficialWiki) {
+ wiki = wiki.split("<main id=\"content\" class=\"mw-body\">")[1].split("</main>")[0]; // hide top bar
+ wiki = wiki.split("<div class=\"container-navbox\">")[0]; // hide giant bottom list
+ wiki = wiki.split("<div class=\"categoryboxcontainer\">")[0]; // hide small bottom category thing
+ wiki = replacePattern.matcher(wiki).replaceAll("");
+ wiki = wiki.replaceAll(
+ "<div id=\"siteNotice\"></div><div id=\"mw-dismissablenotice-anonplace\"></div><script>.*</script>",
+ ""
+ ); // hide beta box
+ wiki = wiki.replaceAll("<h1 id=\"section_0\">.*</h1>", ""); // hide title
+ wiki = wiki.replace("src=\"/", "src=\"https://wiki.hypixel.net/");
+ wiki = wiki.replace("\uD83D\uDDF8", "✓"); // replace checkmark with one that renders
+ wiki = wiki.replace("\uD83E\uDC10", "\u27F5"); // replace left arrow with one that renders
+ wiki = wiki.replace("\uD83E\uDC12", "\u27F6"); // replace right arrow with one that renders
+ } else {
+ String[] split = wiki.split("</infobox>");
+ wiki = split[split.length - 1]; //Remove everything before infobox
+ wiki = wiki.split("<span class=\"navbox-vde\">")[0]; //Remove navbox
+ wiki = wiki.split("<table class=\"navbox mw-collapsible\"")[0];
+ wiki = "__NOTOC__\n" + wiki; //Remove TOC
+ }
try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/parsed.txt"))) {
out.println(wiki);
} catch (IOException ignored) {
@@ -143,13 +189,13 @@ public class HTMLInfoPane extends TextInfoPane {
try {
html = wikiModel.render(wiki);
} catch (IOException e) {
- return new HTMLInfoPane(overlay, manager, "error", "error", "Could not render wiki.");
+ return new HTMLInfoPane(overlay, manager, "error", "error", "Could not render wiki.", false);
}
try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/html.txt"))) {
out.println(html);
} catch (IOException ignored) {
}
- return new HTMLInfoPane(overlay, manager, name, filename, html);
+ return new HTMLInfoPane(overlay, manager, name, filename, html, isOfficialWiki);
}
private String spaceEscape(String str) {
@@ -164,7 +210,14 @@ public class HTMLInfoPane extends TextInfoPane {
* generation is done asynchronously as sometimes it can take up to 10 seconds for more
* complex webpages.
*/
- public HTMLInfoPane(NEUOverlay overlay, NEUManager manager, String name, String filename, String html) {
+ public HTMLInfoPane(
+ NEUOverlay overlay,
+ NEUManager manager,
+ String name,
+ String filename,
+ String html,
+ boolean isOfficial
+ ) {
super(overlay, manager, name, "");
this.title = name;
@@ -180,7 +233,7 @@ public class HTMLInfoPane extends TextInfoPane {
return;
}
- File cssFile = new File(manager.configLocation, "wikia.css");
+ File cssFile = new File(manager.configLocation, isOfficial ? "official-wiki.css" : "wikia.css");
File wkHtmlToImage = new File(manager.configLocation, "wkhtmltox-" + osId + "/bin/wkhtmltoimage");
//Use old binary folder
@@ -235,6 +288,15 @@ public class HTMLInfoPane extends TextInfoPane {
return;
}
+ if (!cssFile.exists() && isOfficial) {
+ try {
+ Files.copy(this.getClass().getResourceAsStream("/assets/notenoughupdates/official-wiki.css"), cssFile.toPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+
File input = new File(manager.configLocation, "tmp/input.html");
String outputFileName = filename.replaceAll("(?i)\\u00A7.", "")
.replaceAll("[^a-zA-Z0-9_\\-]", "_");
@@ -412,12 +474,23 @@ public class HTMLInfoPane extends TextInfoPane {
}
int yScroll = scrollHeight.getValue();
+ float xSize = Math.min((paneWidth - overlay.getBoxPadding() * 2f) / imageWidth * scaleF, 1);
+ float xMax = xMin + xSize;
+
float vMin = yScroll / (imageHeight / scaleF);
float vMax = (yScroll + height - overlay.getBoxPadding() * 3) / (imageHeight / scaleF);
Utils.drawTexturedRect(leftSide + overlay.getBoxPadding(), overlay.getBoxPadding() * 2, imageW,
- height - overlay.getBoxPadding() * 3,
- 0, 1, vMin, vMax
+ (height - overlay.getBoxPadding() * 3),
+ xMin, xMax, vMin, vMax
);
+ if (xSize < 1) {
+ int barX = (int) (xMin * imageW) + leftSide + overlay.getBoxPadding();
+ int barY = height - overlay.getBoxPadding() - 10;
+ int barWidth = (int) (xMax * imageW) + leftSide + overlay.getBoxPadding();
+ int barHeight = height - overlay.getBoxPadding() - 5;
+ boolean isHovered = mouseX >= barX && mouseX <= barWidth && mouseY >= barY && mouseY <= barHeight || selected;
+ Gui.drawRect(barX, barY, barWidth, barHeight, new Color(255, 255, 255, isHovered ? 150 : 100).getRGB());
+ }
} else {
scrollHeight.setValue(0);
@@ -435,6 +508,27 @@ public class HTMLInfoPane extends TextInfoPane {
@Override
public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) {
+ int paneWidth = (int) (width / 3 * overlay.getWidthMult());
+ int rightSide = (int) (width * overlay.getInfoPaneOffsetFactor());
+ int leftSide = rightSide - paneWidth;
+ int imageW = paneWidth - overlay.getBoxPadding() * 2;
+ float scaleF = IMAGE_WIDTH * ZOOM_FACTOR / (float) imageW;
+ float xSize = Math.min((paneWidth - overlay.getBoxPadding() * 2f) / imageWidth * scaleF, 1);
+ float xMax = xMin + xSize;
+ int barX = (int) (xMin * imageW) + leftSide + overlay.getBoxPadding();
+ int barY = height - overlay.getBoxPadding() - 10;
+ int barWidth = (int) (xMax * imageW) + leftSide + overlay.getBoxPadding();
+ int barHeight = height - overlay.getBoxPadding() - 5;
+ if (!mouseDown)
+ selected = false;
+ if (mouseX >= barX && mouseX <= barWidth && mouseY >= barY && mouseY <= barHeight && mouseDown || selected) {
+ if (!selected)
+ mouseOffset = mouseX - barX;
+ xMin = (mouseX - leftSide - overlay.getBoxPadding() / 2f - mouseOffset) / imageWidth * scaleF;
+ xMin = Math.max(0, xMin);
+ xMin = Math.min(xMin, 1 - xSize);
+ selected = true;
+ }
super.mouseInput(width, height, mouseX, mouseY, mouseDown);
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java
index 70d7d65b..03cb64f6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/InfoPane.java
@@ -61,10 +61,10 @@ public abstract class InfoPane extends Gui {
return HTMLInfoPane.createFromWikiUrl(overlay, manager, name, infoText);
case "WIKI":
return CompletableFuture.completedFuture(
- HTMLInfoPane.createFromWikiText(overlay, manager, name, internalName, infoText));
+ HTMLInfoPane.createFromWikiText(overlay, manager, name, internalName, infoText, false));
case "HTML":
return CompletableFuture.completedFuture(
- new HTMLInfoPane(overlay, manager, name, internalName, infoText));
+ new HTMLInfoPane(overlay, manager, name, internalName, infoText, false));
default:
return CompletableFuture.completedFuture(
new TextInfoPane(overlay, manager, name, infoText));
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java
index 3955b35f..63a08d41 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java
@@ -117,12 +117,11 @@ public class GuiPriceGraph extends GuiScreen {
Utils.drawStringCentered("Loading...", Minecraft.getMinecraft().fontRendererObj,
guiLeft + 166, guiTop + 116, false, 0xffffff00
);
- else if (dataPoints == null || dataPoints.get() == null || dataPoints.get().size() <= 1)
+ else if (dataPoints == null || dataPoints.get() == null || dataPoints.get().size() <= 1 || lowestValue == null)
Utils.drawStringCentered("No data found.", Minecraft.getMinecraft().fontRendererObj,
guiLeft + 166, guiTop + 116, false, 0xffff0000
);
else {
-
int graphColor = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor);
int graphColor2 = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor2);
Integer lowestDist = null;
@@ -399,15 +398,17 @@ public class GuiPriceGraph extends GuiScreen {
if (!file.getName().endsWith(".gz")) continue;
if (file.lastModified() <
System.currentTimeMillis() - NotEnoughUpdates.INSTANCE.config.ahGraph.dataRetention * 86400000L)
+ //noinspection ResultOfMethodCallIgnored
file.delete();
}
Date date = new Date();
Long epochSecond = date.toInstant().getEpochSecond();
File file = new File(dir, "prices_" + format.format(date) + ".gz");
HashMap<String, Data> prices = new HashMap<>();
- if (file.exists())
- prices = load(file);
- if (prices == null) return;
+ if (file.exists()) {
+ HashMap<String, Data> tempPrices = load(file);
+ if (tempPrices != null) prices = tempPrices;
+ }
for (Map.Entry<String, JsonElement> item : items.entrySet()) {
if (prices.containsKey(item.getKey())) {
if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has(
@@ -493,7 +494,10 @@ public class GuiPriceGraph extends GuiScreen {
))
) {
return GSON.fromJson(reader, type);
- } catch (Exception ignored) {
+ } catch (Exception e) {
+ System.out.println("Deleting " + file.getName() + " because it is probably corrupted.");
+ //noinspection ResultOfMethodCallIgnored
+ file.delete();
}
}
return null;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
index e872bfc0..dafbe202 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java
@@ -1,13 +1,7 @@
package io.github.moulberry.notenoughupdates.options.seperateSections;
import com.google.gson.annotations.Expose;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption;
+import io.github.moulberry.notenoughupdates.core.config.annotations.*;
public class Misc {
@Expose
@@ -147,4 +141,14 @@ public class Misc {
@ConfigEditorBoolean
public boolean disableNPCRetexturing = false;
+ @Expose
+ @ConfigOption(
+ name = "Wiki",
+ desc = "The wiki to use in the wiki renderer."
+ )
+ @ConfigEditorDropdown(values = {
+ "Hypixel",
+ "Fandom"
+ })
+ public int wiki = 0;
}