aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman / Nea <roman.graef@gmail.com>2022-05-31 20:53:26 +0200
committerGitHub <noreply@github.com>2022-05-31 20:53:26 +0200
commitdfdc2d9519556dfec528ab9d1732cdf32aab0639 (patch)
tree6f046db7b581f40b2deedd202ceaf98ba9ec2567 /src
parenta6546a1abe954b394c40be58d73d6fb03d93709e (diff)
downloadNotEnoughUpdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.tar.gz
NotEnoughUpdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.tar.bz2
NotEnoughUpdates-dfdc2d9519556dfec528ab9d1732cdf32aab0639.zip
Move repository related configuration to GUI. (#151)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java90
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java (renamed from src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ReloadRepoCommand.java)16
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java (renamed from src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ResetRepoCommand.java)9
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/repo/RepoModeCommand.java60
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java1
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/GUIClientPlayer.java13
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/NameModifier.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java49
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiData.java87
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiKey.java15
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java12
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java34
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java2
25 files changed, 251 insertions, 197 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index b28aace6..ea92a670 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -35,10 +35,8 @@ import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.FileUtils;
import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
import javax.net.ssl.HttpsURLConnection;
-import javax.swing.*;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -55,6 +53,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
@@ -109,10 +108,6 @@ public class NEUManager {
private final Map<String, ItemStack> itemstackCache = new HashMap<>();
- private static String GIT_COMMITS_URL;
-
- // TODO: private final Map<String, NeuItem>
-
private final Set<NeuRecipe> recipes = new HashSet<>();
private final HashMap<String, Set<NeuRecipe>> recipesMap = new HashMap<>();
private final HashMap<String, Set<NeuRecipe>> usagesMap = new HashMap<>();
@@ -136,8 +131,6 @@ public class NEUManager {
this.craftingOverlay = new CraftingOverlay(this);
this.katSitterOverlay = new KatSitterOverlay();
- GIT_COMMITS_URL = neu.config.hidden.repoCommitsURL;
-
gson = new GsonBuilder().setPrettyPrinting().create();
this.repoLocation = new File(configLocation, "repo");
@@ -200,7 +193,7 @@ public class NEUManager {
JsonObject currentCommitJSON = getJsonFromFile(new File(configLocation, "currentCommit.json"));
latestRepoCommit = null;
- try (Reader inReader = new InputStreamReader(new URL(GIT_COMMITS_URL).openStream())) {
+ try (Reader inReader = new InputStreamReader(new URL(neu.config.apiData.getCommitApiUrl()).openStream())) {
JsonObject commits = gson.fromJson(inReader, JsonObject.class);
latestRepoCommit = commits.get("sha").getAsString();
} catch (Exception e) {
@@ -216,8 +209,6 @@ public class NEUManager {
Utils.recursiveDelete(repoLocation);
repoLocation.mkdirs();
- String dlUrl = neu.config.hidden.repoURL;
-
File itemsZip = new File(repoLocation, "neu-items-master.zip");
try {
itemsZip.createNewFile();
@@ -225,7 +216,7 @@ public class NEUManager {
return false;
}
- URL url = new URL(dlUrl);
+ URL url = new URL(neu.config.apiData.getDownloadUrl(latestRepoCommit));
URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(15000);
urlConnection.setReadTimeout(30000);
@@ -238,7 +229,6 @@ public class NEUManager {
return false;
}
-
unzipIgnoreFirstFolder(itemsZip.getAbsolutePath(), repoLocation.getAbsolutePath());
if (currentCommitJSON == null || !currentCommitJSON.get("sha").getAsString().equals(latestRepoCommit)) {
@@ -261,10 +251,8 @@ public class NEUManager {
* downloading of new/updated files. This then calls the "loadItem" method for every item in the local repository.
*/
public void loadItemInformation() {
- if (NotEnoughUpdates.INSTANCE.config.hidden.autoupdate) {
- fetchRepository().thenAccept(i -> {
- reloadRepository();
- });
+ if (NotEnoughUpdates.INSTANCE.config.apiData.autoupdate) {
+ fetchRepository().thenRun(this::reloadRepository);
} else {
reloadRepository();
}
@@ -1485,26 +1473,64 @@ public class NEUManager {
}
}
- public void reloadRepository() {
+ public CompletableFuture<List<String>> userFacingRepositoryReload() {
+ String lastCommit = NotEnoughUpdates.INSTANCE.manager.latestRepoCommit;
+ NotEnoughUpdates.INSTANCE.manager.resetRepo();
+ return NotEnoughUpdates.INSTANCE.manager
+ .fetchRepository()
+ .thenCompose(ignored -> NotEnoughUpdates.INSTANCE.manager.reloadRepository())
+ .<List<String>>thenApply(ignored -> {
+ String newCommitHash = NotEnoughUpdates.INSTANCE.manager.latestRepoCommit;
+ String newCommitShortHash = (newCommitHash == null ? "MISSING" : newCommitHash.substring(0, 7));
+ return Arrays.asList(
+ "§aRepository reloaded.",
+ (lastCommit == null
+ ? "§eYou downloaded the repository version §b" + newCommitShortHash + "§e."
+ : "§eYou updated your repository from §b" + lastCommit.substring(0, 7) + "§e to §b" +
+ newCommitShortHash + "§e."
+ )
+ );
+ })
+ .exceptionally(ex -> {
+ ex.printStackTrace();
+ return Arrays.asList(
+ "§cRepository not fully reloaded.",
+ "§cThere was an error reloading your repository.",
+ "§cThis might be caused by an outdated version of neu",
+ "§c(or by not using the dangerous repository if you are using a prerelease of neu).",
+ "§aYour repository will still work, but is in a suboptimal state.",
+ "§eJoin §bdiscord.gg/moulberry §efor help."
+ );
+ });
+ }
+
+ public CompletableFuture<Void> reloadRepository() {
+ CompletableFuture<Void> comp = new CompletableFuture<>();
Minecraft.getMinecraft().addScheduledTask(() -> {
- File items = new File(repoLocation, "items");
- if (items.exists()) {
- recipes.clear();
- recipesMap.clear();
- usagesMap.clear();
-
- File[] itemFiles = new File(repoLocation, "items").listFiles();
- if (itemFiles != null) {
- for (File f : itemFiles) {
- String internalname = f.getName().substring(0, f.getName().length() - 5);
- loadItem(internalname);
+ try {
+ File items = new File(repoLocation, "items");
+ if (items.exists()) {
+ recipes.clear();
+ recipesMap.clear();
+ usagesMap.clear();
+
+ File[] itemFiles = new File(repoLocation, "items").listFiles();
+ if (itemFiles != null) {
+ for (File f : itemFiles) {
+ String internalname = f.getName().substring(0, f.getName().length() - 5);
+ loadItem(internalname);
+ }
}
}
- }
- new RepositoryReloadEvent(repoLocation, !hasBeenLoadedBefore).post();
- hasBeenLoadedBefore = true;
+ new RepositoryReloadEvent(repoLocation, !hasBeenLoadedBefore).post();
+ hasBeenLoadedBefore = true;
+ comp.complete(null);
+ } catch (Exception e) {
+ comp.completeExceptionally(e);
+ }
});
+ return comp;
}
public ItemStack createItem(String internalname) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index d7b6db4b..b8651867 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -1135,7 +1135,7 @@ public class NEUOverlay extends Gui {
}
if (internalname.get() != null) {
if (itemstack.get() != null) {
- if (NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing && Keyboard.getEventCharacter() == 'k') {
+ if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing && Keyboard.getEventCharacter() == 'k') {
Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(
internalname.get(),
manager.getJsonForItem(itemstack.get())
@@ -1159,7 +1159,7 @@ public class NEUOverlay extends Gui {
Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(
manager.jsonToStack(item));
}
- } else if (NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing &&
+ } else if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing &&
Keyboard.getEventCharacter() == 'k') {
Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(internalname.get(), item));
return true;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
index 77499d59..cac89e77 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
@@ -208,6 +208,11 @@ public class NotEnoughUpdates {
if (config == null) {
config = new NEUConfig();
saveConfig();
+ } else {
+ if (config.apiKey != null && config.apiKey.apiKey != null) {
+ config.apiData.apiKey = config.apiKey.apiKey;
+ config.apiKey = null;
+ }
}
MinecraftForge.EVENT_BUS.register(this);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
index cb2f06d6..80d2bca9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
@@ -183,8 +183,8 @@ public class APIManager {
customAH.tick();
long currentTime = System.currentTimeMillis();
if (NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse &&
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey != null &&
- !NotEnoughUpdates.INSTANCE.config.apiKey.apiKey.isEmpty()) {
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey != null &&
+ !NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty()) {
if (currentTime - lastAuctionUpdate > 60 * 1000) {
lastAuctionUpdate = currentTime;
updatePageTick();
@@ -675,7 +675,7 @@ public class APIManager {
public void updateBazaar() {
manager.hypixelApi.getHypixelApiAsync(
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey,
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey,
"skyblock/bazaar",
new HashMap<>(),
(jsonObject) -> {
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 5c2bf5c0..ea401eb7 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
@@ -14,9 +14,6 @@ import io.github.moulberry.notenoughupdates.commands.profile.CataCommand;
import io.github.moulberry.notenoughupdates.commands.profile.PeekCommand;
import io.github.moulberry.notenoughupdates.commands.profile.PvCommand;
import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand;
-import io.github.moulberry.notenoughupdates.commands.repo.ReloadRepoCommand;
-import io.github.moulberry.notenoughupdates.commands.repo.RepoModeCommand;
-import io.github.moulberry.notenoughupdates.commands.repo.ResetRepoCommand;
import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls;
import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour;
import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor;
@@ -41,11 +38,8 @@ public class Commands {
ClientCommandHandler.instance.registerCommand(new DevTestCommand());
ClientCommandHandler.instance.registerCommand(new NullzeeSphereCommand());
ClientCommandHandler.instance.registerCommand(new DiagCommand());
-
- // Repo Commands
- ClientCommandHandler.instance.registerCommand(new ResetRepoCommand());
- ClientCommandHandler.instance.registerCommand(new RepoModeCommand());
ClientCommandHandler.instance.registerCommand(new ReloadRepoCommand());
+ ClientCommandHandler.instance.registerCommand(new ResetRepoCommand());
// Profile Commands
ClientCommandHandler.instance.registerCommand(new PeekCommand());
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ReloadRepoCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java
index 7e58088f..40db245a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ReloadRepoCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ReloadRepoCommand.java
@@ -1,15 +1,10 @@
-package io.github.moulberry.notenoughupdates.commands.repo;
+package io.github.moulberry.notenoughupdates.commands.dev;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
-import io.github.moulberry.notenoughupdates.options.NEUConfig;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
+import net.minecraft.util.ChatComponentText;
public class ReloadRepoCommand extends ClientCommandBase {
@@ -19,10 +14,7 @@ public class ReloadRepoCommand extends ClientCommandBase {
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
- if (args.length > 1 && args[0].equals("fetch")) {
- NotEnoughUpdates.INSTANCE.manager.fetchRepository();
- } else {
- NotEnoughUpdates.INSTANCE.manager.reloadRepository();
- }
+ NotEnoughUpdates.INSTANCE.manager.reloadRepository();
+ sender.addChatMessage(new ChatComponentText("§e[NEU] Reloaded repository."));
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ResetRepoCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java
index b9a0d7cd..9e8363fb 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/ResetRepoCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/ResetRepoCommand.java
@@ -1,9 +1,10 @@
-package io.github.moulberry.notenoughupdates.commands.repo;
+package io.github.moulberry.notenoughupdates.commands.dev;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
public class ResetRepoCommand extends ClientCommandBase {
@@ -13,6 +14,10 @@ public class ResetRepoCommand extends ClientCommandBase {
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
- NotEnoughUpdates.INSTANCE.manager.resetRepo();
+ NotEnoughUpdates.INSTANCE.manager
+ .userFacingRepositoryReload()
+ .thenAccept(strings ->
+ strings.forEach(line ->
+ sender.addChatMessage(new ChatComponentText("§e[NEU] " + line))));
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java
index 38eafe39..c7b6e887 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/StatsCommand.java
@@ -146,7 +146,7 @@ public class StatsCommand extends ClientCommandBase {
builder.append("Loaded Mods", String.valueOf(activeModCount));
builder.append("Forge", ForgeVersion.getVersion());
builder.category("Neu Settings");
- builder.append("API Key", NotEnoughUpdates.INSTANCE.config.apiKey.apiKey.isEmpty() ? "FALSE" : "TRUE");
+ builder.append("API Key", NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty() ? "FALSE" : "TRUE");
builder.append("On Skyblock", NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() ? "TRUE" : "FALSE");
builder.append(
"Mod Version",
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java
index 0b2c155e..69d114ca 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java
@@ -21,8 +21,8 @@ public class AhCommand extends ClientCommandBase {
if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED +
"You must be on Skyblock to use this feature."));
- } else if (NotEnoughUpdates.INSTANCE.config.apiKey.apiKey == null ||
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey.trim().isEmpty()) {
+ } else if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null ||
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED +
"Can't open NeuAH, apikey is not set. Run /api new and put the result in settings."));
} else {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java
index 371db394..fe441ad6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java
@@ -23,8 +23,8 @@ public class ViewProfileCommand extends ClientCommandBase {
"Some parts of the profile viewer do not work with OF Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."));
}
- if (NotEnoughUpdates.INSTANCE.config.apiKey.apiKey == null ||
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey.trim().isEmpty()) {
+ if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null ||
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED +
"Can't view profile, apikey is not set. Run /api new and put the result in settings."));
} else if (args.length == 0) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/RepoModeCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/RepoModeCommand.java
deleted file mode 100644
index 7e5312fb..00000000
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/repo/RepoModeCommand.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package io.github.moulberry.notenoughupdates.commands.repo;
-
-import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
-import net.minecraft.client.Minecraft;
-import net.minecraft.command.CommandException;
-import net.minecraft.command.ICommandSender;
-import net.minecraft.event.ClickEvent;
-import net.minecraft.util.ChatComponentText;
-import net.minecraft.util.ChatStyle;
-
-public class RepoModeCommand extends ClientCommandBase {
-
- public RepoModeCommand() {
- super("neurepomode");
- }
-
- @Override
- public void processCommand(ICommandSender sender, String[] args) throws CommandException {
- if (args.length == 1 && args[0].equalsIgnoreCase("toggle")) {
- NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev;
- NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing =
- !NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing;
- Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("\u00a75Toggled NEU repo dev mode."));
- } else if (args.length >= 2 && args[0].equalsIgnoreCase("setrepourl")) {
- String githubUser = "Moulberry";
- String githubRepo = "NotEnoughUpdates-REPO";
- String githubBranch = "master";
- if (!args[1].equalsIgnoreCase("reset")) {
- githubUser = args[1];
- if (args.length >= 3) {
- githubRepo = args[2];
- }
- if (args.length >= 4) {
- githubBranch = args[3];
- }
- }
- NotEnoughUpdates.INSTANCE.config.hidden.repoURL =
- "https://github.com/" + githubUser + "/" + githubRepo + "/archive/" + githubBranch + ".zip";
- NotEnoughUpdates.INSTANCE.config.hidden.repoCommitsURL =
- "https://api.github.com/repos/" + githubUser + "/" + githubRepo + "/commits/" + githubBranch;
- Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
- "\u00a75Set NEU repo URL to " + NotEnoughUpdates.INSTANCE.config.hidden.repoURL +
- "\n\u00a75Set NEU repo commits URL to " + NotEnoughUpdates.INSTANCE.config.hidden.repoCommitsURL));
- Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("\u00a75Run <")
- .appendSibling(new ChatComponentText("/neureloadrepo fetch").setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(
- ClickEvent.Action.SUGGEST_COMMAND, "/neureloadrepo fetch"))))
- .appendSibling(new ChatComponentText("\u00a75> to redownload your repo.")));
-
- } else if (args.length == 1 && args[0].equalsIgnoreCase("autoupdate")) {
- NotEnoughUpdates.INSTANCE.config.hidden.autoupdate = !NotEnoughUpdates.INSTANCE.config.hidden.autoupdate;
- Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("\u00a75Toggled repo auto-updating" + (NotEnoughUpdates.INSTANCE.config.hidden.autoupdate ? "on" : "off")));
- } else {
- Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("\u00a7cUsage:" +
- "\n\u00a75/neurepomode <toggle> Toggles on/off dev mode and item editing." +
- "\n\u00a75/neurepomode <setRepoURL> <githubuser> [reponame] [branch] Sets the repo URL for downloading from." +
- "\n\u00a75/neurepomode <autoupdate> Toggles on/off auto-updating the repo"));
- }
- }
-}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java
index 6a5164a2..e4f0b3da 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java
@@ -145,7 +145,7 @@ public class ChatListener {
.substring("Your profile was changed to: ".length())
.split(" ")[0].trim());
} else if (unformatted.startsWith("Your new API key is ")) {
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey = unformatted.substring("Your new API key is ".length()).substring(
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey = unformatted.substring("Your new API key is ".length()).substring(
0,
36
);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
index 4823f5c5..fcba864c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -1390,7 +1390,7 @@ public class RenderListener {
event.setCanceled(true);
}
}
- if (NotEnoughUpdates.INSTANCE.config.hidden.dev && NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing &&
+ if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing &&
Minecraft.getMinecraft().theWorld != null && Keyboard.getEventKey() == Keyboard.KEY_N &&
Keyboard.getEventKeyState()) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
@@ -1447,7 +1447,7 @@ public class RenderListener {
System.out.println(essenceJson);
}
}
- if (NotEnoughUpdates.INSTANCE.config.hidden.dev && NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing &&
+ if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing &&
Minecraft.getMinecraft().theWorld != null && Keyboard.getEventKey() == Keyboard.KEY_O &&
Keyboard.getEventKeyState()) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java
index 130f6ee7..78d035ac 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/EntityViewer.java
@@ -79,6 +79,7 @@ public class EntityViewer extends GuiScreen {
put("invisible", new InvisibleModifier());
put("age", new AgeModifier());
put("horse", new HorseModifier());
+ put("name", new NameModifier());
}};
public int guiLeft = 0;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/GUIClientPlayer.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/GUIClientPlayer.java
index bbff2db1..db20a684 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/GUIClientPlayer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/GUIClientPlayer.java
@@ -33,7 +33,18 @@ public class GUIClientPlayer extends AbstractClientPlayer {
}
};
- @Override
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
protected NetworkPlayerInfo getPlayerInfo() {
return playerInfo;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/NameModifier.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/NameModifier.java
new file mode 100644
index 00000000..9978882d
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/entityviewer/NameModifier.java
@@ -0,0 +1,15 @@
+package io.github.moulberry.notenoughupdates.miscfeatures.entityviewer;
+
+import com.google.gson.JsonObject;
+import net.minecraft.entity.EntityLivingBase;
+
+public class NameModifier extends EntityViewerModifier {
+ @Override
+ public EntityLivingBase applyModifier(EntityLivingBase base, JsonObject info) {
+ if (base instanceof GUIClientPlayer) {
+ ((GUIClientPlayer) base).setName(info.get("name").getAsString());
+ }
+ base.setCustomNameTag(info.get("name").getAsString());
+ return base;
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
index 5ed990a4..d9cc77e3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
@@ -17,7 +17,7 @@ import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag;
import io.github.moulberry.notenoughupdates.options.seperateSections.AHGraph;
import io.github.moulberry.notenoughupdates.options.seperateSections.AHTweaks;
import io.github.moulberry.notenoughupdates.options.seperateSections.AccessoryBag;
-import io.github.moulberry.notenoughupdates.options.seperateSections.ApiKey;
+import io.github.moulberry.notenoughupdates.options.seperateSections.ApiData;
import io.github.moulberry.notenoughupdates.options.seperateSections.Calendar;
import io.github.moulberry.notenoughupdates.options.seperateSections.CustomArmour;
import io.github.moulberry.notenoughupdates.options.seperateSections.DungeonMapConfig;
@@ -46,6 +46,7 @@ import io.github.moulberry.notenoughupdates.options.seperateSections.TradeMenu;
import io.github.moulberry.notenoughupdates.overlays.MiningOverlay;
import io.github.moulberry.notenoughupdates.overlays.OverlayManager;
import io.github.moulberry.notenoughupdates.overlays.TextOverlay;
+import io.github.moulberry.notenoughupdates.util.NotificationHandler;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
@@ -155,6 +156,29 @@ public class NEUConfig extends Config {
case 21:
NotEnoughUpdates.INSTANCE.overlay.updateSearch();
return;
+ case 22:
+ NotEnoughUpdates.INSTANCE.manager
+ .userFacingRepositoryReload()
+ .thenAccept(strings ->
+ NotificationHandler.displayNotification(strings, true, true));
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ return;
+ case 23:
+ NotEnoughUpdates.INSTANCE.config.apiData.repoUser = "NotEnoughUpdates";
+ NotEnoughUpdates.INSTANCE.config.apiData.repoName = "NotEnoughUpdates-REPO";
+ NotEnoughUpdates.INSTANCE.config.apiData.repoBranch = "master";
+ NotEnoughUpdates.INSTANCE.openGui =
+ new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config, "apis"));
+ return;
+ case 24:
+ NotEnoughUpdates.INSTANCE.config.apiData.repoUser = "NotEnoughUpdates";
+ NotEnoughUpdates.INSTANCE.config.apiData.repoName = "NotEnoughUpdates-REPO";
+ NotEnoughUpdates.INSTANCE.config.apiData.repoBranch = "dangerous";
+ NotEnoughUpdates.INSTANCE.openGui =
+ new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config, "apis"));
+ return;
+ default:
+ System.err.printf("Unknown runnableId = %d in category %s%n", runnableId, activeConfigCategory);
}
}
@@ -349,10 +373,19 @@ public class NEUConfig extends Config {
@Expose
@Category(
- name = "Api Key",
- desc = "Api Key"
+ name = "Apis",
+ desc = "Api Data"
)
- public ApiKey apiKey = new ApiKey();
+ public ApiData apiData = new ApiData();
+
+ @Expose
+ public LegacyApiKey apiKey = null;
+
+ public static class LegacyApiKey {
+ // Blame Ironmoon for this (still better than my idea tho)
+ @Expose
+ public String apiKey = null;
+ }
@Expose
public Hidden hidden = new Hidden();
@@ -371,12 +404,8 @@ public class NEUConfig extends Config {
@Expose
public EnumSet<NEUDebugFlag> debugFlags = EnumSet.noneOf(NEUDebugFlag.class);
@Expose
- public boolean enableItemEditing = false;
- @Expose
public boolean cacheRenderedItempane = true;
@Expose
- public boolean autoupdate = true;
- @Expose
public String overlaySearchBar = "";
@Expose
public String overlayQuickCommand = "";
@@ -402,10 +431,6 @@ public class NEUConfig extends Config {
public ArrayList<String> quickCommands = createDefaultQuickCommands();
@Expose
public ArrayList<String> enchantColours = createDefaultEnchantColours();
- @Expose
- public String repoURL = "https://github.com/Moulberry/NotEnoughUpdates-REPO/archive/master.zip";
- @Expose
- public String repoCommitsURL = "https://api.github.com/repos/Moulberry/NotEnoughUpdates-REPO/commits/master";
@Expose
public boolean firstTimeSearchFocus = true;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiData.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiData.java
new file mode 100644
index 00000000..6121e189
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiData.java
@@ -0,0 +1,87 @@
+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.ConfigEditorText;
+import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption;
+
+public class ApiData {
+ @Expose
+ @ConfigOption(
+ name = "Api Key",
+ desc = "Hypixel api key\nYou can run §a/api new§r to autofill this value."
+ )
+ @ConfigEditorText
+ public String apiKey = "";
+
+ @ConfigEditorAccordion(id = 0)
+ @ConfigOption(name = "Repository", desc = "")
+ public boolean repository = false;
+
+ @Expose
+ @ConfigOption(name = "Automatically Update Repository", desc = "Update the repository on every startup")
+ @ConfigEditorBoolean()
+ @ConfigAccordionId(id = 0)
+ public boolean autoupdate = true;
+
+ @ConfigAccordionId(id = 0)
+ @ConfigOption(name = "Update Repository now", desc = "Refresh your repository")
+ @ConfigEditorButton(runnableId = 22, buttonText = "Update")
+ public int updateRepositoryButton = 0;
+
+ @ConfigEditorAccordion(id = 1)
+ @ConfigAccordionId(id = 0)
+ @ConfigOption(name = "Repository Location", desc = "")
+ public boolean repositoryLocation = false;
+
+ @ConfigAccordionId(id = 1)
+ @ConfigOption(name = "Use default repository", desc = "The latest, most up to date item list for the official NEU releases.")
+ @ConfigEditorButton(runnableId = 23, buttonText = "Reset")
+ public int setRepositoryToDefaultButton = 0;
+
+ @ConfigAccordionId(id = 1)
+ @ConfigOption(name = "Use dangerous Repository", desc = "The latest, most up to date item list for the NEU prereleases.\n§4Use §lonly§r§4 with the prereleases.")
+ @ConfigEditorButton(runnableId = 24, buttonText = "Use")
+ public int setRepositoryToDangerousButton = 0;
+
+ @Expose
+ @ConfigAccordionId(id = 1)
+ @ConfigOption(name = "Repository User", desc = "Repository User")
+ @ConfigEditorText
+ public String repoUser = "NotEnoughUpdates";
+
+ @Expose
+ @ConfigAccordionId(id = 1)
+ @ConfigOption(name = "Repository Name", desc = "Repository Name")
+ @ConfigEditorText
+ public String repoName = "NotEnoughUpdates-REPO";
+
+ @Expose
+ @ConfigAccordionId(id = 1)
+ @ConfigOption(name = "Repository Branch", desc = "Repository Branch")
+ @ConfigEditorText
+ public String repoBranch = "master";
+
+ @Expose
+ @ConfigAccordionId(id = 0)
+ @ConfigOption(name = "Edit Mode", desc = "Enables you to edit items in the item list.\n§4Recommended for repository maintainers only.\n§4§lRemember: §rTurn off auto update as well")
+ @ConfigEditorBoolean
+ public boolean repositoryEditing = false;
+
+ @Expose
+ @ConfigOption(name = "Lowestbin API", desc = "§4Do §lNOT §r§4change this, unless you know exactly what you are doing\n§fDefault: §amoulberry.codes")
+ @ConfigEditorText
+ public String moulberryCodesApi = "moulberry.codes";
+
+ public String getCommitApiUrl() {
+ return String.format("https://api.github.com/repos/%s/%s/commits/%s", repoUser, repoName, repoBranch);
+ }
+
+ public String getDownloadUrl(String commitId) {
+ return String.format("https://github.com/%s/%s/archive/%s.zip", repoUser, repoName, commitId);
+ }
+
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiKey.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiKey.java
deleted file mode 100644
index 5567365c..00000000
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ApiKey.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package io.github.moulberry.notenoughupdates.options.seperateSections;
-
-import com.google.gson.annotations.Expose;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorText;
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption;
-
-public class ApiKey {
- @Expose
- @ConfigOption(
- name = "Api Key",
- desc = "Hypixel api key"
- )
- @ConfigEditorText
- public String apiKey = "";
-}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java
index 444e7087..0d03f297 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BingoPage.java
@@ -280,7 +280,7 @@ public class BingoPage {
HashMap<String, String> args = new HashMap<>();
NotEnoughUpdates.INSTANCE.manager.hypixelApi.getHypixelApiAsync(
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey,
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey,
"resources/skyblock/bingo",
args,
jsonObject -> {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
index 39c12e54..95acb7d8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
@@ -312,7 +312,7 @@ public class ProfileViewer {
HashMap<String, String> args = new HashMap<>();
NotEnoughUpdates.INSTANCE.manager.hypixelApi.getHypixelApiAsync(
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey,
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey,
"resources/skyblock/collections",
args,
jsonObject -> {
@@ -331,7 +331,7 @@ public class ProfileViewer {
String nameF = name.toLowerCase();
HashMap<String, String> args = new HashMap<>();
args.put("name", "" + nameF);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "player",
+ manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiData.apiKey, "player",
args, jsonObject -> {
if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()
&& jsonObject.get("player").isJsonObject()) {
@@ -474,7 +474,7 @@ public class ProfileViewer {
HashMap<String, String> args = new HashMap<>();
args.put("uuid", "" + uuid);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "status",
+ manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiData.apiKey, "status",
args, jsonObject -> {
if (jsonObject == null) return;
@@ -500,7 +500,7 @@ public class ProfileViewer {
HashMap<String, String> args = new HashMap<>();
args.put("uuid", "" + uuid);
NotEnoughUpdates.INSTANCE.manager.hypixelApi.getHypixelApiAsync(
- NotEnoughUpdates.INSTANCE.config.apiKey.apiKey,
+ NotEnoughUpdates.INSTANCE.config.apiData.apiKey,
"skyblock/bingo",
args,
jsonObject -> {
@@ -657,7 +657,7 @@ public class ProfileViewer {
HashMap<String, String> args = new HashMap<>();
args.put("uuid", "" + uuid);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/profiles",
+ manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiData.apiKey, "skyblock/profiles",
args, jsonObject -> {
updatingPlayerInfoState.set(false);
@@ -720,7 +720,7 @@ public class ProfileViewer {
HashMap<String, String> args = new HashMap<>();
args.put("player", "" + uuid);
- manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "guild",
+ manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiData.apiKey, "guild",
args, jsonObject -> {
updatingGuildInfoState.set(false);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java
index b7d4a321..3e3b06b1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/RecipeGenerator.java
@@ -48,7 +48,7 @@ public class RecipeGenerator {
@SubscribeEvent
public void onTick(TickEvent event) {
- if (!neu.config.hidden.enableItemEditing) return;
+ if (!neu.config.apiData.repositoryEditing) return;
GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (currentScreen == null) return;
if (!(currentScreen instanceof GuiChest)) return;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java
index 7258fe9f..800c025a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java
@@ -141,7 +141,7 @@ public class HotmInformation {
public synchronized void requestUpdate(boolean force) {
if (updateTask.isDone() || force) {
updateTask = neu.manager.hypixelApi.getHypixelApiAsync(
- neu.config.apiKey.apiKey,
+ neu.config.apiData.apiKey,
"skyblock/profiles",
new HashMap<String, String>() {{
put("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""));
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
index 37de9ed8..937a0ab8 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HypixelApi.java
@@ -21,14 +21,8 @@ import java.util.function.Consumer;
import java.util.zip.GZIPInputStream;
public class HypixelApi {
- private static final int FAILS_BEFORE_SWITCH = 3;
private final Gson gson = new Gson();
private final ExecutorService es = Executors.newFixedThreadPool(3);
- private final String[] myApiURLs = {"https://moulberry.codes/"};
- //, "http://moulberry.codes/", "http://51.79.51.21/"};//, "http://51.75.78.252/" };
- private final Integer[] myApiSuccesses = {0, 0, 0, 0};
- private int currentUrl = 0;
- private long lastPrimaryUrl = 0;
public CompletableFuture<JsonObject> getHypixelApiAsync(String apiKey, String method, HashMap<String, String> args) {
return getApiAsync(generateApiUrl(apiKey, method, args));
@@ -55,29 +49,7 @@ public class HypixelApi {
}
private String getMyApiURL() {
- if (currentUrl == 0) {
- lastPrimaryUrl = System.currentTimeMillis();
- } else if (System.currentTimeMillis() - lastPrimaryUrl > 1000 * 60 * 30) { //Try switch back to main url after 30m
- currentUrl = 0;
- }
-
- myApiSuccesses[currentUrl] = Math.min(FAILS_BEFORE_SWITCH, myApiSuccesses[currentUrl] + 1);
- return myApiURLs[currentUrl];
- }
-
- private void myApiError(int index) {
- myApiSuccesses[index] = myApiSuccesses[index] - 2;
-
- if (myApiSuccesses[index] < 0) {
- myApiSuccesses[index] = 0;
-
- if (index == currentUrl) {
- currentUrl++;
- if (currentUrl >= myApiURLs.length) {
- currentUrl = 0;
- }
- }
- }
+ return String.format("https://%s/", NotEnoughUpdates.INSTANCE.config.apiData.moulberryCodesApi);
}
public CompletableFuture<JsonObject> getApiAsync(String urlS) {
@@ -104,14 +76,12 @@ public class HypixelApi {
public void getMyApiAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
es.submit(() -> {
- int current = currentUrl;
try {
consumer.accept(getApiSync(getMyApiURL() + urlS));
} catch (Exception e) {
if (NotEnoughUpdates.INSTANCE.config.hidden.dev) {
e.printStackTrace();
}
- myApiError(current);
error.run();
}
});
@@ -119,11 +89,9 @@ public class HypixelApi {
public void getMyApiGZIPAsync(String urlS, Consumer<JsonObject> consumer, Runnable error) {
es.submit(() -> {
- int current = currentUrl;
try {
consumer.accept(getApiGZIPSync(getMyApiURL() + urlS));
} catch (Exception e) {
- myApiError(current);
error.run();
}
});
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java
index b4193c88..5ee1dda1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java
@@ -30,7 +30,7 @@ public class JsonUtils {
String name,
Function<? super JsonElement, ? extends T> mapper
) {
- if (!rootObject.has(name)) {
+ if (rootObject == null || !rootObject.has(name)) {
return Collections.emptyList();
}
JsonElement jsonElement = rootObject.get(name);