aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLulonaut <lulonaut@lulonaut.tech>2023-10-06 15:44:59 +0200
committerGitHub <noreply@github.com>2023-10-06 15:44:59 +0200
commit810a25eec4e6712acee145526d3017dd118b8492 (patch)
tree9dadcb47bb4d51d5329e48b40899458b104f1de1 /src
parentebdc4df69093d29c3334537f9267374773464a30 (diff)
downloadNotEnoughUpdates-810a25eec4e6712acee145526d3017dd118b8492.tar.gz
NotEnoughUpdates-810a25eec4e6712acee145526d3017dd118b8492.tar.bz2
NotEnoughUpdates-810a25eec4e6712acee145526d3017dd118b8492.zip
Remove legacy API keys from the code base (#862)
Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java7
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java63
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/ApiData.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java29
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt1
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SetKeyCommand.kt43
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt43
7 files changed, 8 insertions, 186 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
index f81331ea..268fddd5 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 NotEnoughUpdates contributors
+ * Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
@@ -228,11 +228,6 @@ public class NotEnoughUpdates {
config = new NEUConfig();
saveConfig();
} else {
- if (config.apiKey != null && config.apiKey.apiKey != null) {
- config.apiData.apiKey = config.apiKey.apiKey;
- config.apiKey = null;
- }
-
//add the trophy fishing tab to the config
if (config.profileViewer.pageLayout.size() == 8) {
config.profileViewer.pageLayout.add(8);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
index ed275c7a..6f488107 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 NotEnoughUpdates contributors
+ * Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
@@ -22,7 +22,6 @@ package io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.ApiData;
@@ -31,12 +30,11 @@ import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
+import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.item.ItemStack;
-import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
-import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.util.ArrayList;
import java.util.HashMap;
@@ -46,50 +44,20 @@ import java.util.Map;
public class MinionHelperApiLoader {
private final MinionHelperManager manager;
- private boolean dirty = true;
private boolean collectionApiEnabled = true;
- private boolean ignoreWorldSwitches = false;
+ @Getter
private boolean readyToUse = false;
+ @Getter
private ApiData apiData = null;
+ @Getter
private boolean notifyNoCollectionApi = false;
- private long lastLoaded = 0;
+ @Getter
private boolean invalidApiKey = true;
public MinionHelperApiLoader(MinionHelperManager manager) {
this.manager = manager;
}
- @SubscribeEvent
- public void onWorldLoad(WorldEvent.Load event) {
- if (ignoreWorldSwitches) return;
-
- setDirty();
- }
-
- @SubscribeEvent
- public void onTick(TickEvent.ClientTickEvent event) {
- if (Minecraft.getMinecraft().thePlayer == null) return;
- if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return;
- if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return;
- if (dirty && "Crafted Minions".equals(Utils.getOpenChestName())) {
- load();
- } else {
- if (System.currentTimeMillis() > lastLoaded + 60_000 * 3) {
- dirty = true;
- }
- }
- }
-
- private void load() {
- lastLoaded = System.currentTimeMillis();
-
- dirty = false;
- String uuid = getUuid();
- if (uuid == null) return;
-
- NotEnoughUpdates.INSTANCE.manager.apiUtils.updateProfileData(uuid);
- }
-
private String getUuid() {
EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer;
if (thePlayer == null) return null;
@@ -254,30 +222,18 @@ public class MinionHelperApiLoader {
}
public void setDirty() {
- dirty = true;
readyToUse = false;
}
public void prepareProfileSwitch() {
- ignoreWorldSwitches = true;
readyToUse = false;
}
public void onProfileSwitch() {
apiData = null;
- setDirty();
- ignoreWorldSwitches = false;
collectionApiEnabled = true;
}
- public boolean isReadyToUse() {
- return readyToUse;
- }
-
- public ApiData getApiData() {
- return apiData;
- }
-
public boolean isCollectionApiDisabled() {
return apiData != null && apiData.isCollectionApiDisabled();
}
@@ -290,11 +246,4 @@ public class MinionHelperApiLoader {
this.notifyNoCollectionApi = notifyNoCollectionApi;
}
- public boolean isNotifyNoCollectionApi() {
- return notifyNoCollectionApi;
- }
-
- public boolean isInvalidApiKey() {
- return invalidApiKey;
- }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/ApiData.java b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/ApiData.java
index 2266f9e4..f081c231 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/ApiData.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/ApiData.java
@@ -37,14 +37,6 @@ public class ApiData {
@ConfigEditorBoolean
public boolean apiDataUnlocked = false;
- @Expose
- @ConfigOption(
- name = "Api Key",
- desc = "Hypixel API key."
- )
- @ConfigEditorText
- public String apiKey = "";
-
@ConfigEditorAccordion(id = 0)
@ConfigOption(name = "Repository", desc = "")
public boolean repository = false;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
index 9611f197..5f436eb6 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
@@ -23,9 +23,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent;
import io.github.moulberry.notenoughupdates.util.kotlin.KotlinTypeAdapterFactory;
-import net.minecraft.client.Minecraft;
import org.apache.commons.io.IOUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
@@ -104,25 +102,6 @@ public class ApiUtil {
}
}
- public void updateProfileData() {
- updateProfileData(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""));
- }
-
- public void updateProfileData(String playerUuid) {
- if (true) return;
- if (!updateTasks.getOrDefault(playerUuid, CompletableFuture.completedFuture(null)).isDone()) return;
-
- String uuid = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "");
- updateTasks.put(playerUuid, newHypixelApiRequest("skyblock/profiles")
- .queryArgument("uuid", uuid)
- .requestJson()
- .handle((jsonObject, throwable) -> {
- new ProfileDataLoadedEvent(uuid, jsonObject).post();
- return null;
- }));
-
- }
-
public static class Request {
private final List<NameValuePair> queryArguments = new ArrayList<>();
@@ -291,7 +270,7 @@ public class ApiUtil {
}
}, executorService).handle((obj, t) -> {
if (t != null) {
- System.err.println(ErrorUtil.printStackTraceWithoutApiKey(t));
+ t.printStackTrace();
}
return obj;
});
@@ -320,12 +299,6 @@ public class ApiUtil {
return new Request();
}
- @Deprecated
- public Request newHypixelApiRequest(String apiPath) {
- return newAnonymousHypixelApiRequest(apiPath)
- .queryArgument("key", NotEnoughUpdates.INSTANCE.config.apiData.apiKey);
- }
-
public Request newAnonymousHypixelApiRequest(String apiPath) {
return new Request()
.url("https://api.hypixel.net/" + apiPath);
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
index 771da58c..d5b91b9d 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
@@ -167,7 +167,6 @@ class NEUStatsCommand {
builder.append("Forge", ForgeVersion.getVersion())
builder.append("Optifine", if (FMLClientHandler.instance().hasOptifine()) "TRUE" else "FALSE")
builder.category("Neu Settings")
- builder.append("API Key", if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty()) "FALSE" else "TRUE")
builder.append("On SkyBlock", if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) "TRUE" else "FALSE")
builder.append(
"Mod Version",
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SetKeyCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SetKeyCommand.kt
deleted file mode 100644
index 1a0ccbf5..00000000
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/SetKeyCommand.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2023 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 com.mojang.brigadier.arguments.StringArgumentType.string
-import io.github.moulberry.notenoughupdates.NotEnoughUpdates
-import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
-import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
-import io.github.moulberry.notenoughupdates.util.brigadier.*
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-
-@NEUAutoSubscribe
-class SetKeyCommand {
- @SubscribeEvent
- fun onCommands(event: RegisterBrigadierCommandEvent) {
- event.command("neusetkey") {
- thenArgument("key", string()) { key ->
- thenExecute {
- NotEnoughUpdates.INSTANCE.config.apiData.apiKey = this[key]
- reply("Set your key to ${this[key]}")
-
- }
- }.withHelp("Set your API key found at https://developer.hypixel.net/")
- }
- }
-}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt
deleted file mode 100644
index f849a40d..00000000
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/ErrorUtil.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2023 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 io.github.moulberry.notenoughupdates.NotEnoughUpdates
-import java.io.ByteArrayOutputStream
-import java.io.PrintStream
-import java.nio.charset.StandardCharsets
-
-object ErrorUtil {
- @JvmStatic
- fun printCensoredStackTrace(e: Throwable, toCensor: List<String>): String {
- val baos = ByteArrayOutputStream()
- e.printStackTrace(PrintStream(baos, true, StandardCharsets.UTF_8.name()))
- var string = String(baos.toByteArray(), StandardCharsets.UTF_8)
- toCensor.forEach {
- string = string.replace(it, "*".repeat(it.length))
- }
- return string
- }
-
- @JvmStatic
- fun printStackTraceWithoutApiKey(e: Throwable): String {
- return printCensoredStackTrace(e, listOf(NotEnoughUpdates.INSTANCE.config.apiData.apiKey))
- }
-}