aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2022-08-26 13:24:35 +0200
committerGitHub <noreply@github.com>2022-08-26 21:24:35 +1000
commitdfd2f6b05bce74d7feb5d28e7a388dbb871ecf6a (patch)
tree001913c4f1dd391831da26e4398f75e6731c88e1 /src/main/java/io
parentc3845685bbb3a2a7fde25476eed0f788e038dc93 (diff)
downloadNotEnoughUpdates-dfd2f6b05bce74d7feb5d28e7a388dbb871ecf6a.tar.gz
NotEnoughUpdates-dfd2f6b05bce74d7feb5d28e7a388dbb871ecf6a.tar.bz2
NotEnoughUpdates-dfd2f6b05bce74d7feb5d28e7a388dbb871ecf6a.zip
Of course you have pronouns in pv (#234)
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java72
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java94
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java11
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ProfileViewer.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java294
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java17
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java169
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoader.java55
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoaderImpl.java59
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java37
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/PronounDB.java221
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java19
14 files changed, 904 insertions, 176 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java
new file mode 100644
index 00000000..d997d980
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * For storage of compile-time configuration flags
+ */
+public class BuildFlags {
+
+ private static final Properties properties = new Properties();
+
+ static {
+ try {
+ properties.load(BuildFlags.class.getResourceAsStream("/buildflags.properties"));
+ } catch (IOException | NullPointerException e) {
+ System.out.println("Failed to load build properties: " + e);
+ }
+ }
+
+ private static boolean getBuildFlag(String flag) {
+ return Boolean.parseBoolean(properties.getProperty("neu.buildflags." + flag));
+ }
+
+ public static Map<String, Boolean> getAllFlags() {
+ return Holder.ALL_FLAGS;
+ }
+
+ public static final boolean ENABLE_PRONOUNS_IN_PV_BY_DEFAULT = getBuildFlag("pronouns");
+
+ private static class Holder {
+ static Map<String, Boolean> ALL_FLAGS = new HashMap<>();
+
+ static {
+ for (Field declaredField : BuildFlags.class.getDeclaredFields()) {
+ if (Boolean.TYPE.equals(declaredField.getType())
+ && (declaredField.getModifiers() & Modifier.STATIC) != 0) {
+ try {
+ declaredField.setAccessible(true);
+ ALL_FLAGS.put(declaredField.getName(), (Boolean) declaredField.get(null));
+ } catch (IllegalAccessException | ClassCastException | SecurityException e) {
+ System.err.println("Failed to access BuildFlag: " + e);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
index 917185ab..fcb2aaf9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
@@ -42,6 +42,7 @@ import io.github.moulberry.notenoughupdates.commands.misc.CalculatorCommand;
import io.github.moulberry.notenoughupdates.commands.misc.CalendarCommand;
import io.github.moulberry.notenoughupdates.commands.misc.CosmeticsCommand;
import io.github.moulberry.notenoughupdates.commands.misc.CustomizeCommand;
+import io.github.moulberry.notenoughupdates.commands.misc.PronounsCommand;
import io.github.moulberry.notenoughupdates.commands.misc.UpdateCommand;
import io.github.moulberry.notenoughupdates.commands.profile.CataCommand;
import io.github.moulberry.notenoughupdates.commands.profile.PeekCommand;
@@ -97,6 +98,7 @@ public class Commands {
ClientCommandHandler.instance.registerCommand(new CalculatorCommand());
ClientCommandHandler.instance.registerCommand(new CalendarCommand());
ClientCommandHandler.instance.registerCommand(new UpdateCommand(NotEnoughUpdates.INSTANCE));
+ ClientCommandHandler.instance.registerCommand(new PronounsCommand());
// Fairy Soul Commands
ClientCommandHandler.instance.registerCommand(new FairySouls.FairySoulsCommand());
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
index 7cca9d3b..fdf59bb0 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
@@ -19,6 +19,7 @@
package io.github.moulberry.notenoughupdates.commands.dev;
+import io.github.moulberry.notenoughupdates.BuildFlags;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor;
@@ -27,6 +28,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Custom
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone;
import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph;
+import io.github.moulberry.notenoughupdates.util.PronounDB;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@@ -40,6 +42,7 @@ import net.minecraftforge.common.MinecraftForge;
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
public class DevTestCommand extends ClientCommandBase {
@@ -118,6 +121,14 @@ public class DevTestCommand extends ClientCommandBase {
" with the mode " +
gamemode));
}
+ if (args.length >= 1 && args[0].equalsIgnoreCase("buildflags")) {
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
+ "BuildFlags: \n" +
+ BuildFlags.getAllFlags().entrySet().stream()
+ .map(it -> " + " + it.getKey() + " - " + it.getValue())
+ .collect(Collectors.joining("\n"))));
+ return;
+ }
if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) {
if (args.length == 1) {
NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar();
@@ -163,6 +174,10 @@ public class DevTestCommand extends ClientCommandBase {
"I would never search"));
return;
}
+ if (args.length == 1 && args[0].equalsIgnoreCase("bluehair")) {
+ PronounDB.test();
+ return;
+ }
if (args.length == 2 && args[0].equalsIgnoreCase("openGui")) {
try {
NotEnoughUpdates.INSTANCE.openGui = (GuiScreen) Class.forName(args[1]).newInstance();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java
new file mode 100644
index 00000000..6d0ee88d
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.commands.misc;
+
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
+import io.github.moulberry.notenoughupdates.util.MinecraftExecutor;
+import io.github.moulberry.notenoughupdates.util.PronounDB;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.entity.EntityPlayerSP;
+import net.minecraft.client.gui.GuiNewChat;
+import net.minecraft.command.CommandException;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
+
+import java.util.Optional;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+public class PronounsCommand extends ClientCommandBase {
+ public PronounsCommand() {
+ super("neupronouns");
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender sender) {
+ return "/neupronouns <username> [platform]";
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) throws CommandException {
+ switch (args.length) {
+ case 1:
+ fetchPronouns("minecraft", args[0]);
+ break;
+ case 2:
+ fetchPronouns(args[1], args[0]);
+ break;
+ default:
+ sender.addChatMessage(new ChatComponentText("§4" + getCommandUsage(sender)));
+ }
+ }
+
+ private void fetchPronouns(String platform, String user) {
+ GuiNewChat nc = Minecraft.getMinecraft().ingameGUI.getChatGUI();
+ int id = new Random().nextInt();
+ nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] Fetching Pronouns..."), id);
+
+ CompletableFuture<Optional<PronounDB.PronounChoice>> pronouns;
+ if ("minecraft".equals(platform)) {
+ CompletableFuture<UUID> c = new CompletableFuture<>();
+ NotEnoughUpdates.profileViewer.getPlayerUUID(user, uuidString -> {
+ if (uuidString == null) {
+ c.completeExceptionally(new NullPointerException());
+ } else {
+ c.complete(Utils.parseDashlessUUID(uuidString));
+ }
+ });
+ pronouns = c.thenApplyAsync(PronounDB::getPronounsFor);
+ } else {
+ pronouns = CompletableFuture.supplyAsync(() -> PronounDB.getPronounsFor(platform, user));
+ }
+ pronouns.handleAsync((pronounChoice, throwable) -> {
+ if (throwable != null || !pronounChoice.isPresent()) {
+ nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] §4Failed to fetch pronouns."), id);
+ return null;
+ }
+ PronounDB.PronounChoice betterPronounChoice = pronounChoice.get();
+ nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] Pronouns for §b" + user + " §eon §b" + platform + "§e:"), id);
+ betterPronounChoice.render().forEach(it -> nc.printChatMessage(new ChatComponentText("§e[NEU] §a" + it)));
+ return null;
+ }, MinecraftExecutor.INSTANCE);
+
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java
index d52f9ba1..ecb4cd8b 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/StringUtils.java
@@ -23,6 +23,9 @@ import com.google.common.collect.Sets;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Set;
public class StringUtils {
@@ -63,4 +66,12 @@ public class StringUtils {
str = str.replace(",", "");
return Integer.parseInt(str);
}
+
+ public static String urlEncode(String something) {
+ try {
+ return URLEncoder.encode(something, StandardCharsets.UTF_8.name());
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e); // UTF 8 should always be present
+ }
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ProfileViewer.java
index ee1abf46..673e1015 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ProfileViewer.java
@@ -20,7 +20,12 @@
package io.github.moulberry.notenoughupdates.options.seperateSections;
import com.google.gson.annotations.Expose;
-import io.github.moulberry.notenoughupdates.core.config.annotations.*;
+import io.github.moulberry.notenoughupdates.BuildFlags;
+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.ConfigEditorDraggableList;
+import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorFSR;
+import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption;
import java.util.ArrayList;
import java.util.Arrays;
@@ -81,4 +86,12 @@ public class ProfileViewer {
)
@ConfigEditorBoolean
public boolean alwaysShowBingoTab = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Show Pronouns in /pv",
+ desc = "Shows the pronouns of a player in /pv. Data sourced from pronoundb.org"
+ )
+ @ConfigEditorBoolean
+ public boolean showPronounsInPv = BuildFlags.ENABLE_PRONOUNS_IN_PV_BY_DEFAULT;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java
index 30ffcdd9..dcbcb9e4 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java
@@ -19,8 +19,6 @@
package io.github.moulberry.notenoughupdates.profileviewer;
-import static io.github.moulberry.notenoughupdates.util.Utils.roundToNearestInt;
-
import com.google.common.base.Splitter;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -30,17 +28,9 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.profileviewer.weight.lily.LilyWeight;
import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight;
import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.PronounDB;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadPoolExecutor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.client.gui.FontRenderer;
@@ -63,6 +53,19 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import static io.github.moulberry.notenoughupdates.util.Utils.roundToNearestInt;
+
public class BasicPage extends GuiProfileViewerPage {
private static final ResourceLocation pv_basic = new ResourceLocation("notenoughupdates:pv_basic.png");
@@ -117,7 +120,8 @@ public class BasicPage extends GuiProfileViewerPage {
String panoramaIdentifier = "day";
if (SBInfo.getInstance().currentTimeDate != null) {
- if (SBInfo.getInstance().currentTimeDate.getHours() <= 6 || SBInfo.getInstance().currentTimeDate.getHours() >= 20) {
+ if (SBInfo.getInstance().currentTimeDate.getHours() <= 6 ||
+ SBInfo.getInstance().currentTimeDate.getHours() >= 20) {
panoramaIdentifier = "night";
}
}
@@ -133,19 +137,36 @@ public class BasicPage extends GuiProfileViewerPage {
Panorama.getPanoramasForLocation(location == null ? "unknown" : location, panoramaIdentifier)
);
+ if (Utils.isWithinRect(mouseX, mouseY, guiLeft + 23, guiTop + 44, 81, 108)) {
+ Optional<PronounDB.PronounChoice> pronounChoice =
+ GuiProfileViewer.pronouns
+ .peekValue()
+ .flatMap(it -> it); // Flatten: First optional is whether it loaded, second optional is whether it was successful
+ if (pronounChoice.isPresent()) {
+ PronounDB.PronounChoice pronouns = pronounChoice.get();
+ if (pronouns.isConsciousChoice()) {
+ getInstance().tooltipToDisplay = pronouns.render();
+ }
+ }
+ }
+
Minecraft.getMinecraft().getTextureManager().bindTexture(pv_basic);
Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST);
if (entityPlayer != null && profile.getHypixelProfile() != null) {
String playerName = null;
if (profile.getHypixelProfile().has("prefix")) {
- playerName = Utils.getElementAsString(profile.getHypixelProfile().get("prefix"), "") + " " + entityPlayer.getName();
+ playerName = Utils.getElementAsString(profile.getHypixelProfile().get("prefix"), "") + " " +
+ entityPlayer.getName();
} else {
String rank = Utils.getElementAsString(
profile.getHypixelProfile().get("rank"),
Utils.getElementAsString(profile.getHypixelProfile().get("newPackageRank"), "NONE")
);
- String monthlyPackageRank = Utils.getElementAsString(profile.getHypixelProfile().get("monthlyPackageRank"), "NONE");
+ String monthlyPackageRank = Utils.getElementAsString(
+ profile.getHypixelProfile().get("monthlyPackageRank"),
+ "NONE"
+ );
if (!rank.equals("YOUTUBER") && !monthlyPackageRank.equals("NONE")) {
rank = monthlyPackageRank;
}
@@ -191,7 +212,13 @@ public class BasicPage extends GuiProfileViewerPage {
int x = guiLeft + 63;
int y = guiTop + 54;
- GuiScreen.drawRect(x - halfRankPrefixLen - 1, y - 1, x + halfRankPrefixLen + 1, y + 8, new Color(0, 0, 0, 64).getRGB());
+ GuiScreen.drawRect(
+ x - halfRankPrefixLen - 1,
+ y - 1,
+ x + halfRankPrefixLen + 1,
+ y + 8,
+ new Color(0, 0, 0, 64).getRGB()
+ );
fr.drawString(playerName, x - halfRankPrefixLen, y, 0, true);
}
@@ -200,7 +227,8 @@ public class BasicPage extends GuiProfileViewerPage {
long networth = profile.getNetWorth(profileId);
if (networth > 0) {
Utils.drawStringCentered(
- EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format(networth),
+ EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(networth),
fr,
guiLeft + 63,
guiTop + 38,
@@ -211,31 +239,38 @@ public class BasicPage extends GuiProfileViewerPage {
double networthInCookies =
(
networth /
- NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo("BOOSTER_COOKIE").get("avg_buy").getAsDouble()
+ NotEnoughUpdates.INSTANCE.manager.auctionManager
+ .getBazaarInfo("BOOSTER_COOKIE")
+ .get("avg_buy")
+ .getAsDouble()
);
String networthIRLMoney = Long.toString(Math.round(((networthInCookies * 325) / 675) * 4.99));
if (
mouseX > guiLeft + 8 &&
- mouseX < guiLeft + 8 + fr.getStringWidth("Net Worth: " + GuiProfileViewer.numberFormat.format(networth))
+ mouseX < guiLeft + 8 + fr.getStringWidth("Net Worth: " + GuiProfileViewer.numberFormat.format(networth))
) {
if (mouseY > guiTop + 32 && mouseY < guiTop + 32 + fr.FONT_HEIGHT) {
getInstance().tooltipToDisplay = new ArrayList<>();
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Net worth in IRL money: " +
- EnumChatFormatting.DARK_GREEN +
- "$" +
- EnumChatFormatting.GOLD +
- networthIRLMoney
+ "Net worth in IRL money: " +
+ EnumChatFormatting.DARK_GREEN +
+ "$" +
+ EnumChatFormatting.GOLD +
+ networthIRLMoney
);
getInstance().tooltipToDisplay.add("");
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "This is calculated using the current");
- getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "price of booster cookies on bazaar and the price");
- getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "for cookies using gems, then the price of gems");
- getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "is where we get the amount of IRL money you");
- getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "theoretically have on skyblock in net worth.");
+ getInstance().tooltipToDisplay.add(
+ EnumChatFormatting.RED + "price of booster cookies on bazaar and the price");
+ getInstance().tooltipToDisplay.add(
+ EnumChatFormatting.RED + "for cookies using gems, then the price of gems");
+ getInstance().tooltipToDisplay.add(
+ EnumChatFormatting.RED + "is where we get the amount of IRL money you");
+ getInstance().tooltipToDisplay.add(
+ EnumChatFormatting.RED + "theoretically have on skyblock in net worth.");
} else {
getInstance().tooltipToDisplay.add(EnumChatFormatting.GRAY + "[SHIFT for Info]");
}
@@ -245,7 +280,8 @@ public class BasicPage extends GuiProfileViewerPage {
}
}
}
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
}
if (status != null) {
@@ -261,9 +297,17 @@ public class BasicPage extends GuiProfileViewerPage {
NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("POTATO_CROWN")
);
potato_crown.addEnchantment(Enchantment.unbreaking, 1656638942); // this number may be useful
- Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(new ItemStack(Items.potato), guiLeft + 35, guiTop + 160);
+ Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(
+ new ItemStack(Items.potato),
+ guiLeft + 35,
+ guiTop + 160
+ );
Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(potato_crown, guiLeft + 50, guiTop + 162);
- Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(new ItemStack(Items.potato), guiLeft + 63, guiTop + 160);
+ Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(
+ new ItemStack(Items.potato),
+ guiLeft + 63,
+ guiTop + 160
+ );
} else if (online) {
locationStr = NotEnoughUpdates.INSTANCE.navigation.getNameForAreaModeOrUnknown(location);
}
@@ -370,7 +414,8 @@ public class BasicPage extends GuiProfileViewerPage {
},
false
);
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
}
GlStateManager.color(1, 1, 1, 1);
@@ -388,9 +433,9 @@ public class BasicPage extends GuiProfileViewerPage {
int x = guiLeft + 20;
float y =
guiTop +
- 82 +
- 15 *
- (float) Math.sin(((getInstance().currentTime - getInstance().startTime) / 800f) % (2 * Math.PI));
+ 82 +
+ 15 *
+ (float) Math.sin(((getInstance().currentTime - getInstance().startTime) / 800f) % (2 * Math.PI));
GlStateManager.translate(x, y, 0);
ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item, false);
@@ -410,7 +455,14 @@ public class BasicPage extends GuiProfileViewerPage {
}
}
if (entityPlayer != null) {
- drawEntityOnScreen(guiLeft + 63, guiTop + 128 + 7, 36, guiLeft + 63 - mouseX, guiTop + 129 - mouseY, entityPlayer);
+ drawEntityOnScreen(
+ guiLeft + 63,
+ guiTop + 128 + 7,
+ 36,
+ guiLeft + 63 - mouseX,
+ guiTop + 129 - mouseY,
+ entityPlayer
+ );
}
PlayerStats.Stats stats = profile.getStats(profileId);
@@ -426,7 +478,12 @@ public class BasicPage extends GuiProfileViewerPage {
GlStateManager.color(1, 1, 1, 1);
GlStateManager.enableBlend();
- GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GL14.glBlendFuncSeparate(
+ GL11.GL_SRC_ALPHA,
+ GL11.GL_ONE_MINUS_SRC_ALPHA,
+ GL11.GL_ONE,
+ GL11.GL_ONE_MINUS_SRC_ALPHA
+ );
Utils.renderAlignedString(
statNamePretty,
EnumChatFormatting.WHITE.toString() + val,
@@ -445,49 +502,49 @@ public class BasicPage extends GuiProfileViewerPage {
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GRAY +
- "Base " +
- split.get(1) +
- ": " +
- EnumChatFormatting.GREEN +
- base +
- " " +
- split.get(0)
+ "Base " +
+ split.get(1) +
+ ": " +
+ EnumChatFormatting.GREEN +
+ base +
+ " " +
+ split.get(0)
);
int passive = Math.round(profile.getPassiveStats(profileId).get(statName) - baseStats.get(statName));
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GRAY +
- "Passive " +
- split.get(1) +
- " Bonus: +" +
- EnumChatFormatting.YELLOW +
- passive +
- " " +
- split.get(0)
+ "Passive " +
+ split.get(1) +
+ " Bonus: +" +
+ EnumChatFormatting.YELLOW +
+ passive +
+ " " +
+ split.get(0)
);
int itemBonus = Math.round(stats.get(statName) - profile.getPassiveStats(profileId).get(statName));
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GRAY +
- "Item " +
- split.get(1) +
- " Bonus: +" +
- EnumChatFormatting.DARK_PURPLE +
- itemBonus +
- " " +
- split.get(0)
+ "Item " +
+ split.get(1) +
+ " Bonus: +" +
+ EnumChatFormatting.DARK_PURPLE +
+ itemBonus +
+ " " +
+ split.get(0)
);
int finalStat = Math.round(stats.get(statName));
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GRAY +
- "Final " +
- split.get(1) +
- ": +" +
- EnumChatFormatting.RED +
- finalStat +
- " " +
- split.get(0)
+ "Final " +
+ split.get(1) +
+ ": +" +
+ EnumChatFormatting.RED +
+ finalStat +
+ " " +
+ split.get(0)
);
}
}
@@ -551,17 +608,18 @@ public class BasicPage extends GuiProfileViewerPage {
getInstance().tooltipToDisplay = new ArrayList<>();
getInstance().tooltipToDisplay.add(skillName);
if (skyblockInfo.get(entry.getKey()).maxed) {
- getInstance().tooltipToDisplay.add(EnumChatFormatting.GRAY + "Progress: " + EnumChatFormatting.GOLD + "MAXED!");
+ getInstance().tooltipToDisplay.add(
+ EnumChatFormatting.GRAY + "Progress: " + EnumChatFormatting.GOLD + "MAXED!");
} else {
int maxXp = (int) skyblockInfo.get(entry.getKey()).maxXpForLevel;
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GRAY +
- "Progress: " +
- EnumChatFormatting.DARK_PURPLE +
- GuiProfileViewer.shortNumberFormat(Math.round((level % 1) * maxXp), 0) +
- "/" +
- GuiProfileViewer.shortNumberFormat(maxXp, 0)
+ "Progress: " +
+ EnumChatFormatting.DARK_PURPLE +
+ GuiProfileViewer.shortNumberFormat(Math.round((level % 1) * maxXp), 0) +
+ "/" +
+ GuiProfileViewer.shortNumberFormat(maxXp, 0)
);
}
String totalXpS = GuiProfileViewer.numberFormat.format((int) skyblockInfo.get(entry.getKey()).totalXp);
@@ -605,23 +663,29 @@ public class BasicPage extends GuiProfileViewerPage {
return (
uuidStr.substring(0, 8) +
- "-" +
- uuidStr.substring(8, 12) +
- "-" +
- uuidStr.substring(12, 16) +
- "-" +
- uuidStr.substring(16, 20) +
- "-" +
- uuidStr.substring(20, 32)
+ "-" +
+ uuidStr.substring(8, 12) +
+ "-" +
+ uuidStr.substring(12, 16) +
+ "-" +
+ uuidStr.substring(16, 20) +
+ "-" +
+ uuidStr.substring(20, 32)
);
}
- private void renderWeight(int mouseX, int mouseY, Map<String, ProfileViewer.Level> skyblockInfo, JsonObject profileInfo) {
+ private void renderWeight(
+ int mouseX,
+ int mouseY,
+ Map<String, ProfileViewer.Level> skyblockInfo,
+ JsonObject profileInfo
+ ) {
if (skyblockInfo == null) {
return;
}
- if (Constants.WEIGHT == null || Utils.getElement(Constants.WEIGHT, "lily.skills.overall") == null || !Utils.getElement(Constants.WEIGHT, "lily.skills.overall").isJsonPrimitive()) {
+ if (Constants.WEIGHT == null || Utils.getElement(Constants.WEIGHT, "lily.skills.overall") == null ||
+ !Utils.getElement(Constants.WEIGHT, "lily.skills.overall").isJsonPrimitive()) {
Utils.showOutdatedRepoNotification();
return;
}
@@ -635,9 +699,9 @@ public class BasicPage extends GuiProfileViewerPage {
Utils.drawStringCentered(
EnumChatFormatting.GREEN +
- "Senither Weight: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())),
+ "Senither Weight: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw())),
fr,
guiLeft + 63,
guiTop + 18,
@@ -646,7 +710,8 @@ public class BasicPage extends GuiProfileViewerPage {
);
int textWidth = fr.getStringWidth(
- "Senither Weight: " + GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw()))
+ "Senither Weight: " +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getTotalWeight().getRaw()))
);
if (mouseX > guiLeft + 63 - textWidth / 2 && mouseX < guiLeft + 63 + textWidth / 2) {
if (mouseY > guiTop + 12 && mouseY < guiTop + 12 + fr.FONT_HEIGHT) {
@@ -654,34 +719,40 @@ public class BasicPage extends GuiProfileViewerPage {
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Skills: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getSkillsWeight().getWeightStruct().getRaw()))
+ "Skills: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight
+ .getSkillsWeight()
+ .getWeightStruct()
+ .getRaw()))
);
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Slayer: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight.getSlayerWeight().getWeightStruct().getRaw()))
+ "Slayer: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(senitherWeight
+ .getSlayerWeight()
+ .getWeightStruct()
+ .getRaw()))
);
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Dungeons: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(
- roundToNearestInt(senitherWeight.getDungeonsWeight().getWeightStruct().getRaw())
- )
+ "Dungeons: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(
+ roundToNearestInt(senitherWeight.getDungeonsWeight().getWeightStruct().getRaw())
+ )
);
}
}
Utils.drawStringCentered(
EnumChatFormatting.GREEN +
- "Lily Weight: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())),
+ "Lily Weight: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getTotalWeight().getRaw())),
fr,
guiLeft + 63,
guiTop + 28,
@@ -698,23 +769,32 @@ public class BasicPage extends GuiProfileViewerPage {
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Skills: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getSkillsWeight().getWeightStruct().getRaw()))
+ "Skills: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight
+ .getSkillsWeight()
+ .getWeightStruct()
+ .getRaw()))
);
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Slayer: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getSlayerWeight().getWeightStruct().getRaw()))
+ "Slayer: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight
+ .getSlayerWeight()
+ .getWeightStruct()
+ .getRaw()))
);
getInstance()
.tooltipToDisplay.add(
EnumChatFormatting.GREEN +
- "Dungeons: " +
- EnumChatFormatting.GOLD +
- GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight.getDungeonsWeight().getWeightStruct().getRaw()))
+ "Dungeons: " +
+ EnumChatFormatting.GOLD +
+ GuiProfileViewer.numberFormat.format(roundToNearestInt(lilyWeight
+ .getDungeonsWeight()
+ .getWeightStruct()
+ .getRaw()))
);
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java
index 758ea6e8..3cbd944d 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java
@@ -22,7 +22,9 @@ package io.github.moulberry.notenoughupdates.profileviewer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.PronounDB;
import io.github.moulberry.notenoughupdates.util.Utils;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -32,6 +34,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeMap;
@@ -113,9 +116,10 @@ public class ExtraPage extends GuiProfileViewerPage {
);
}
}
+ JsonObject guildInfo = profile.getGuildInformation(null);
+ boolean shouldRenderGuild = guildInfo != null && guildInfo.has("name");
{
- JsonObject guildInfo = profile.getGuildInformation(null);
- if (guildInfo != null && guildInfo.has("name")) {
+ if (shouldRenderGuild) {
Utils.renderAlignedString(
EnumChatFormatting.AQUA + "Guild",
EnumChatFormatting.WHITE + guildInfo.get("name").getAsString(),
@@ -125,6 +129,15 @@ public class ExtraPage extends GuiProfileViewerPage {
);
}
}
+ {
+ GuiProfileViewer.pronouns.peekValue().flatMap(it -> it).ifPresent(choice -> Utils.renderAlignedString(
+ EnumChatFormatting.GREEN + "Pronouns",
+ EnumChatFormatting.WHITE + String.join(" / ", choice.render()),
+ guiLeft + xStart,
+ guiTop + yStartTop + yOffset * (shouldRenderGuild ? 5 : 4),
+ 76
+ ));
+ }
float fairySouls = Utils.getElementAsFloat(Utils.getElement(profileInfo, "fairy_souls_collected"), 0);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
index 09eed1cf..59373952 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
@@ -19,7 +19,6 @@
package io.github.moulberry.notenoughupdates.profileviewer;
-import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -29,7 +28,9 @@ import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField;
import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryPage;
import io.github.moulberry.notenoughupdates.profileviewer.trophy.TrophyFishPage;
+import io.github.moulberry.notenoughupdates.util.AsyncDependencyLoader;
import io.github.moulberry.notenoughupdates.util.Constants;
+import io.github.moulberry.notenoughupdates.util.PronounDB;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityOtherPlayerMP;
@@ -53,6 +54,7 @@ import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL20;
import java.awt.*;
+import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -63,6 +65,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
public class GuiProfileViewer extends GuiScreen {
@@ -73,69 +77,72 @@ public class GuiProfileViewer extends GuiScreen {
public static final ResourceLocation pv_bingo = new ResourceLocation("notenoughupdates:pv_bingo.png");
public static final ResourceLocation pv_stranded = new ResourceLocation("notenoughupdates:pv_stranded.png");
public static final ResourceLocation pv_unknown = new ResourceLocation("notenoughupdates:pv_unknown.png");
- public static final ResourceLocation resource_packs = new ResourceLocation("minecraft:textures/gui/resource_packs.png");
+ public static final ResourceLocation resource_packs =
+ new ResourceLocation("minecraft:textures/gui/resource_packs.png");
public static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png");
- public static final HashMap<String, HashMap<String, Float>> PET_STAT_BOOSTS = new HashMap<String, HashMap<String, Float>>() {
- {
- put(
- "PET_ITEM_BIG_TEETH_COMMON",
- new HashMap<String, Float>() {
- {
- put("CRIT_CHANCE", 5f);
+ public static final HashMap<String, HashMap<String, Float>> PET_STAT_BOOSTS =
+ new HashMap<String, HashMap<String, Float>>() {
+ {
+ put(
+ "PET_ITEM_BIG_TEETH_COMMON",
+ new HashMap<String, Float>() {
+ {
+ put("CRIT_CHANCE", 5f);
+ }
}
- }
- );
- put(
- "PET_ITEM_HARDENED_SCALES_UNCOMMON",
- new HashMap<String, Float>() {
- {
- put("DEFENCE", 25f);
+ );
+ put(
+ "PET_ITEM_HARDENED_SCALES_UNCOMMON",
+ new HashMap<String, Float>() {
+ {
+ put("DEFENCE", 25f);
+ }
}
- }
- );
- put(
- "PET_ITEM_LUCKY_CLOVER",
- new HashMap<String, Float>() {
- {
- put("MAGIC_FIND", 7f);
+ );
+ put(
+ "PET_ITEM_LUCKY_CLOVER",
+ new HashMap<String, Float>() {
+ {
+ put("MAGIC_FIND", 7f);
+ }
}
- }
- );
- put(
- "PET_ITEM_SHARPENED_CLAWS_UNCOMMON",
- new HashMap<String, Float>() {
- {
- put("CRIT_DAMAGE", 15f);
+ );
+ put(
+ "PET_ITEM_SHARPENED_CLAWS_UNCOMMON",
+ new HashMap<String, Float>() {
+ {
+ put("CRIT_DAMAGE", 15f);
+ }
}
- }
- );
- }
- };
- public static final HashMap<String, HashMap<String, Float>> PET_STAT_BOOSTS_MULT = new HashMap<String, HashMap<String, Float>>() {
- {
- put(
- "PET_ITEM_IRON_CLAWS_COMMON",
- new HashMap<String, Float>() {
- {
- put("CRIT_DAMAGE", 1.4f);
- put("CRIT_CHANCE", 1.4f);
+ );
+ }
+ };
+ public static final HashMap<String, HashMap<String, Float>> PET_STAT_BOOSTS_MULT =
+ new HashMap<String, HashMap<String, Float>>() {
+ {
+ put(
+ "PET_ITEM_IRON_CLAWS_COMMON",
+ new HashMap<String, Float>() {
+ {
+ put("CRIT_DAMAGE", 1.4f);
+ put("CRIT_CHANCE", 1.4f);
+ }
}
- }
- );
- put(
- "PET_ITEM_TEXTBOOK",
- new HashMap<String, Float>() {
- {
- put("INTELLIGENCE", 2f);
+ );
+ put(
+ "PET_ITEM_TEXTBOOK",
+ new HashMap<String, Float>() {
+ {
+ put("INTELLIGENCE", 2f);
+ }
}
- }
- );
- }
- };
+ );
+ }
+ };
public static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
- private static final char[] c = new char[] { 'k', 'm', 'b', 't' };
+ private static final char[] c = new char[]{'k', 'm', 'b', 't'};
public static ProfileViewerPage currentPage = ProfileViewerPage.BASIC;
public static HashMap<String, String> MINION_RARITY_TO_NUM = new HashMap<String, String>() {
{
@@ -151,6 +158,14 @@ public class GuiProfileViewer extends GuiScreen {
private static int guiTop;
private static ProfileViewer.Profile profile;
private static String profileId = null;
+ public static AsyncDependencyLoader<Optional<PronounDB.PronounChoice>> pronouns =
+ AsyncDependencyLoader.withEqualsInvocation(
+ () ->
+ NotEnoughUpdates.INSTANCE.config.profileViewer.showPronounsInPv
+ ? Optional.ofNullable(profile).map(it -> Utils.parseDashlessUUID(it.getUuid()))
+ : Optional.<UUID>empty(),
+ uuid -> CompletableFuture.supplyAsync(() -> uuid.flatMap(PronounDB::getPronounsFor))
+ );
public final GuiElementTextField playerNameTextField;
public final GuiElementTextField inventoryTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT);
private final Map<ProfileViewerPage, GuiProfileViewerPage> pages = new HashMap<>();
@@ -268,7 +283,6 @@ public class GuiProfileViewer extends GuiScreen {
return levelObj;
}
-
public static String shortNumberFormat(double n, int iteration) {
if (n < 1000) {
if (n % 1 == 0) {
@@ -280,7 +294,10 @@ public class GuiProfileViewer extends GuiScreen {
double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) % 10 == 0;
- return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + c[iteration] : shortNumberFormat(d, iteration + 1);
+ return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + c[iteration] : shortNumberFormat(
+ d,
+ iteration + 1
+ );
}
public static int getGuiLeft() {
@@ -429,7 +446,17 @@ public class GuiProfileViewer extends GuiScreen {
//Render Open In Skycrypt button
renderBlurredBackground(width, height, guiLeft + 100 + 6 + 2, guiTop + sizeY + 3 + 2, 100 - 4, 20 - 4);
Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown);
- Utils.drawTexturedRect(guiLeft + 100 + 6, guiTop + sizeY + 3, 100, 20, 0, 100 / 200f, 0, 20 / 185f, GL11.GL_NEAREST);
+ Utils.drawTexturedRect(
+ guiLeft + 100 + 6,
+ guiTop + sizeY + 3,
+ 100,
+ 20,
+ 0,
+ 100 / 200f,
+ 0,
+ 20 / 185f,
+ GL11.GL_NEAREST
+ );
Utils.drawStringCenteredScaledMaxWidth(
"Open in Skycrypt",
Minecraft.getMinecraft().fontRendererObj,
@@ -567,7 +594,14 @@ public class GuiProfileViewer extends GuiScreen {
}
}
- Utils.drawStringCentered(str, Minecraft.getMinecraft().fontRendererObj, guiLeft + sizeX / 2f, guiTop + 101, true, 0);
+ Utils.drawStringCentered(
+ str,
+ Minecraft.getMinecraft().fontRendererObj,
+ guiLeft + sizeX / 2f,
+ guiTop + 101,
+ true,
+ 0
+ );
//This is just here to inform the player what to do
//like typing /api new or telling them to go find a psychotherapist
@@ -846,7 +880,8 @@ public class GuiProfileViewer extends GuiScreen {
Desktop desk = Desktop.getDesktop();
desk.browse(
new URI(
- "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + profileId
+ "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" +
+ profileId
)
);
Utils.playPressSound();
@@ -970,7 +1005,8 @@ public class GuiProfileViewer extends GuiScreen {
String levelStr;
String totalXpStr = null;
if (skillName.contains("Catacombs")) totalXpStr =
- EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE + numberFormat.format(levelObj.totalXp);
+ EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE +
+ numberFormat.format(levelObj.totalXp);
if (levelObj.maxed) {
levelStr = EnumChatFormatting.GOLD + "MAXED!";
} else {
@@ -1150,14 +1186,21 @@ public class GuiProfileViewer extends GuiScreen {
);
blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0);
blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height));
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
}
if (blurShaderVert == null) {
try {
- blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", blurOutputHorz, blurOutputVert);
+ blurShaderVert = new Shader(
+ Minecraft.getMinecraft().getResourceManager(),
+ "blur",
+ blurOutputHorz,
+ blurOutputVert
+ );
blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1);
blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height));
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ }
}
if (blurShaderHorz != null && blurShaderVert != null) {
if (15 != lastBgBlurFactor) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoader.java
new file mode 100644
index 00000000..37b0a187
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoader.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util;
+
+import com.google.common.base.Objects;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public interface AsyncDependencyLoader<T> {
+
+ Optional<T> peekValue();
+
+ public static <R, T> AsyncDependencyLoader<T> withObjectIdentity(
+ Supplier<R> supplier,
+ Function<R, CompletableFuture<T>> generator
+ ) {
+ return new AsyncDependencyLoaderImpl<>(supplier, generator, (a, b) -> a != b);
+ }
+
+ public static <R, T> AsyncDependencyLoader<T> withEqualsInvocation(
+ Supplier<R> supplier,
+ Function<R, CompletableFuture<T>> generator
+ ) {
+ return new AsyncDependencyLoaderImpl<>(supplier, generator, (a, b) -> !Objects.equal(a, b));
+ }
+
+ public static <R, T> AsyncDependencyLoader<T> withEqualityFunction(
+ Supplier<R> supplier,
+ Function<R, CompletableFuture<T>> generator,
+ BiFunction<R, R, Boolean> isEqual
+ ) {
+ return new AsyncDependencyLoaderImpl<>(supplier, generator, (a, b) -> !isEqual.apply(a, b));
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoaderImpl.java b/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoaderImpl.java
new file mode 100644
index 00000000..4b7f2fb8
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/AsyncDependencyLoaderImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+class AsyncDependencyLoaderImpl<R, T> implements AsyncDependencyLoader<T> {
+
+ private final Supplier<R> supplyDependency;
+ private final Function<R, CompletableFuture<T>> generator;
+ private final BiFunction<R, R, Boolean> isDifferent;
+ private volatile CompletableFuture<T> lastValue;
+ private volatile R lastDependency;
+ private volatile boolean isFirstFire = true;
+
+ @Override
+ public synchronized Optional<T> peekValue() {
+ R nextDependency = supplyDependency.get();
+ if (isFirstFire || isDifferent.apply(nextDependency, lastDependency)) {
+ isFirstFire = false;
+ if (lastValue != null)
+ lastValue.cancel(true);
+ lastValue = generator.apply(nextDependency);
+ }
+ lastDependency = nextDependency;
+ return Optional.ofNullable(lastValue.getNow(null));
+ }
+
+ AsyncDependencyLoaderImpl(
+ Supplier<R> supplyDependency,
+ Function<R, CompletableFuture<T>> generator,
+ BiFunction<R, R, Boolean> isDifferent
+ ) {
+ this.supplyDependency = supplyDependency;
+ this.generator = generator;
+ this.isDifferent = isDifferent;
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java b/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java
new file mode 100644
index 00000000..bf973b76
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/MinecraftExecutor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util;
+
+import net.minecraft.client.Minecraft;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.concurrent.Executor;
+
+public class MinecraftExecutor implements Executor {
+
+ public static MinecraftExecutor INSTANCE = new MinecraftExecutor();
+
+ private MinecraftExecutor() {}
+
+ @Override
+ public void execute(@NotNull Runnable runnable) {
+ Minecraft.getMinecraft().addScheduledTask(runnable);
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/PronounDB.java b/src/main/java/io/github/moulberry/notenoughupdates/util/PronounDB.java
new file mode 100644
index 00000000..e7286721
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/PronounDB.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.util;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.core.util.StringUtils;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class PronounDB {
+
+ static SSLContext ctx;
+
+ static {
+ try {
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(PronounDB.class.getResourceAsStream("/pronoundb.jks"), "pronoundb".toCharArray());
+ ctx = SSLContext.getInstance("TLS");
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ kmf.init(ks, null);
+ tmf.init(ks);
+ ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+ } catch (KeyStoreException | NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException |
+ IOException | CertificateException e) {
+ System.out.println("Failed to load keystore. PronounDB requests will probably not work");
+ e.printStackTrace();
+ }
+ }
+
+ private static boolean isDisabled() {
+ JsonObject disabled = Constants.DISABLE;
+ return disabled != null && disabled.has("pronoundb");
+ }
+
+ /**
+ * Returns an Optional, since JVMs can be *very* funky with KeyStore loading
+ */
+ public static Optional<JsonObject> performPronouning(String platform, String id) {
+ if (isDisabled()) return Optional.empty();
+ try {
+ URL url = new URL("https://pronoundb.org/api/v1/lookup" +
+ "?platform=" + StringUtils.urlEncode(platform) +
+ "&id=" + StringUtils.urlEncode(id));
+ HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
+ urlConnection.setSSLSocketFactory(ctx.getSocketFactory());
+ return Optional.of(NotEnoughUpdates.INSTANCE.manager.gson.fromJson(
+ new InputStreamReader(urlConnection.getInputStream()),
+ JsonObject.class
+ ));
+ } catch (ClassCastException | IOException | JsonParseException e) {
+ System.out.println("Failed to contact PronounDB: " + e);
+ return Optional.empty();
+ }
+ }
+
+ public enum Pronoun {
+ HE("he", "him", "his"),
+ IT("it", "it", "its"),
+ SHE("she", "her", "hers"),
+ THEY("they", "they", "theirs");
+
+ private final String subject;
+ private final String object;
+ private final String possessive;
+
+ Pronoun(String subject, String object, String possessive) {
+ this.subject = subject;
+ this.object = object;
+ this.possessive = possessive;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public String getObject() {
+ return object;
+ }
+
+ public String getPossessive() {
+ return possessive;
+ }
+ }
+
+ public enum PronounChoice {
+ UNSPECIFIED("unspecified", "Unspecified"),
+ HE("hh", Pronoun.HE),
+ HEIT("hi", Pronoun.HE, Pronoun.IT),
+ HESHE("hs", Pronoun.HE, Pronoun.SHE),
+ HETHEY("ht", Pronoun.HE, Pronoun.THEY),
+ ITHE("ih", Pronoun.IT, Pronoun.HE),
+ IT("ii", Pronoun.IT),
+ ITSHE("is", Pronoun.IT, Pronoun.SHE),
+ ITTHEY("it", Pronoun.IT, Pronoun.THEY),
+ SHEHE("shh", Pronoun.SHE, Pronoun.HE),
+ SHE("sh", Pronoun.SHE),
+ SHEIT("si", Pronoun.SHE, Pronoun.IT),
+ SHETHEY("st", Pronoun.SHE, Pronoun.THEY),
+ THEYHE("th", Pronoun.THEY, Pronoun.HE),
+ THEYIT("ti", Pronoun.THEY, Pronoun.IT),
+ THEYSHE("ts", Pronoun.THEY, Pronoun.SHE),
+ THEY("tt", Pronoun.THEY),
+ ANY("any", "Any pronouns"),
+ OTHER("other", "Other pronouns"),
+ ASK("ask", "Ask me my pronouns"),
+ AVOID("avoid", "Avoid pronouns, use my name");
+ private final String id;
+ private List<Pronoun> pronouns = null;
+ private String override = null;
+
+ PronounChoice(String id, String override) {
+ this.override = override;
+ this.id = id;
+ }
+
+ PronounChoice(String id, Pronoun... pronouns) {
+ this.id = id;
+ this.pronouns = Arrays.asList(pronouns);
+ }
+
+ public static Optional<PronounChoice> findPronounsForId(String id) {
+ for (PronounChoice value : values()) {
+ if (value.id.equals(id)) return Optional.of(value);
+ }
+ return Optional.empty();
+ }
+
+ public String getOverride() {
+ return override;
+ }
+
+ public List<Pronoun> getPronounsInPreferredOrder() {
+ return pronouns;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public List<String> render() {
+ if (override != null)
+ return Arrays.asList(override);
+ return pronouns
+ .stream()
+ .map(pronoun -> pronoun.getSubject() + "/" + pronoun.getObject())
+ .collect(Collectors.toList());
+ }
+
+ public boolean isConsciousChoice() {
+ return this != UNSPECIFIED;
+ }
+
+ }
+
+ public static Optional<PronounChoice> parsePronouns(JsonObject pronounObject) {
+ if (pronounObject.has("pronouns")) {
+ JsonElement pronouns = pronounObject.get("pronouns");
+ if (pronouns.isJsonPrimitive() && pronouns.getAsJsonPrimitive().isString())
+ return PronounChoice.findPronounsForId(pronouns.getAsString());
+ }
+ return Optional.empty();
+ }
+
+ public static Optional<PronounChoice> getPronounsFor(String platform, String name) {
+ return performPronouning(platform, name).flatMap(PronounDB::parsePronouns);
+ }
+
+ public static Optional<PronounChoice> getPronounsFor(UUID minecraftPlayer) {
+ return performPronouning("minecraft", minecraftPlayer.toString() /* dashed UUID */)
+ .flatMap(PronounDB::parsePronouns);
+ }
+
+ public static void test() {
+ try {
+ System.out.println("Pronouning...");
+ PronounChoice pronounsFor = getPronounsFor(UUID.fromString("842204e6-6880-487b-ae5a-0595394f9948")).get();
+ pronounsFor.render().forEach(System.out::println);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
index 5b3ea853..2267cbea 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -73,6 +73,7 @@ import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.math.BigInteger;
import java.nio.FloatBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -81,6 +82,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -1943,9 +1945,13 @@ public class Utils {
if (NotEnoughUpdates.INSTANCE.config.notifications.outdatedRepo) {
NotificationHandler.displayNotification(Lists.newArrayList(
EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "Missing repo data",
- EnumChatFormatting.RED + "Data used for many NEU features is not up to date, this should normally not be the case.",
- EnumChatFormatting.RED + "You can try " + EnumChatFormatting.BOLD + "/neuresetrepo" + EnumChatFormatting.RESET + EnumChatFormatting.RED +" and restart your game" +
- " to see if that fixes the issue.", EnumChatFormatting.RED + "If the problem persists please join " + EnumChatFormatting.BOLD + "discord.gg/moulberry" +
+ EnumChatFormatting.RED +
+ "Data used for many NEU features is not up to date, this should normally not be the case.",
+ EnumChatFormatting.RED + "You can try " + EnumChatFormatting.BOLD + "/neuresetrepo" + EnumChatFormatting.RESET +
+ EnumChatFormatting.RED + " and restart your game" +
+ " to see if that fixes the issue.",
+ EnumChatFormatting.RED + "If the problem persists please join " + EnumChatFormatting.BOLD +
+ "discord.gg/moulberry" +
EnumChatFormatting.RESET + EnumChatFormatting.RED + " and message in " + EnumChatFormatting.BOLD +
"#neu-support" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " to get support"
),
@@ -1979,6 +1985,13 @@ public class Utils {
return -1;
}
+ public static UUID parseDashlessUUID(String dashlessUuid) {
+ // From: https://stackoverflow.com/a/30760478/
+ BigInteger most = new BigInteger(dashlessUuid.substring(0, 16), 16);
+ BigInteger least = new BigInteger(dashlessUuid.substring(16, 32), 16);
+ return new UUID(most.longValue(), least.longValue());
+ }
+
public static String getOpenChestName() {
return SBInfo.getInstance().currentlyOpenChestName;
}