Skip to content

Commit

Permalink
Revert "replace legacy hypixel api keys"
Browse files Browse the repository at this point in the history
This reverts commit 1dea43d.
  • Loading branch information
Wyvest committed Jul 10, 2023
1 parent 1a3de70 commit 55fb476
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 137 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.gradle.jvmargs=-Xmx2G

mod_name = Hytils Reborn
mod_id = hytils-reborn
mod_version = 1.6.0-beta5
mod_version = 1.6.0-beta4

loom.platform = forge
2 changes: 1 addition & 1 deletion src/main/java/cc/woverflow/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void postInit(FMLPostInitializationEvent event) {
isPatcher = Loader.isModLoaded("patcher");
isChatting = Loader.isModLoaded("chatting");

Multithreading.runAsync(() -> rank = HypixelAPIUtils.getRank());
Multithreading.runAsync(() -> rank = HypixelAPIUtils.getRank(Minecraft.getMinecraft().getSession().getUsername()));
}

@Mod.EventHandler
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/cc/woverflow/hytils/command/HytilsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import cc.polyfrost.oneconfig.utils.commands.annotations.Description;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.GEXPType;
import cc.woverflow.hytils.command.parser.GEXPTypeParser;
import cc.woverflow.hytils.command.parser.WinstreakType;
import cc.woverflow.hytils.command.parser.WinstreakTypeParser;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.util.HypixelAPIUtils;
import com.mojang.authlib.GameProfile;
import net.minecraft.util.EnumChatFormatting;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
Expand All @@ -52,6 +55,10 @@ private void handleDefault() {
@SuppressWarnings("SameParameterValue")
private void gexp(@Description("username") @Nullable GameProfile player, @Description("type") @Nullable GEXPType type) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelUtils.INSTANCE.isValidKey(HytilsConfig.apiKey)) {
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.RED + "You need to provide a valid API key to run this command! Type /api new to autoset a key.");
return;
}
if (player != null) {
if (type == null) {
if (HypixelAPIUtils.getGEXP(player.getName())) {
Expand Down Expand Up @@ -105,6 +112,10 @@ private void gexp(@Description("username") @Nullable GameProfile player, @Descri
@SuppressWarnings("SameParameterValue")
private void winstreak(@Description("username") @Nullable GameProfile player, @Description("type") @Nullable WinstreakType gamemode) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelUtils.INSTANCE.isValidKey(HytilsConfig.apiKey)) {
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.RED + "You need to provide a valid API key to run this command! Type /api new to autoset a key.");
return;
}
if (player != null) {
if (gamemode != null) {
if (HypixelAPIUtils.getWinstreak(player.getName(), gamemode.name())) {
Expand Down Expand Up @@ -143,4 +154,17 @@ private void winstreak(@Description("username") @Nullable GameProfile player, @D
}
});
}

@SubCommand(description = "Sets your API key.", aliases = "setkey")
private static void key(@Description("API Key") String apiKey) {
Multithreading.runAsync(() -> {
if (HypixelUtils.INSTANCE.isValidKey(apiKey)) {
HytilsConfig.apiKey = apiKey;
HytilsReborn.INSTANCE.getConfig().save();
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.GREEN + "Saved API key successfully!");
} else {
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.RED + "Invalid API key! Please try again.");
}
});
}
}
11 changes: 11 additions & 0 deletions src/main/java/cc/woverflow/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
@SuppressWarnings("unused")
public class HytilsConfig extends Config {

// API

@Text(
name = "API Key",
description = "Automatically get the API Key from /api new.",
category = "API",
secure = true
)
@HypixelKey
public static String apiKey = "";

// Automatic

@Switch(
Expand Down
Loading

0 comments on commit 55fb476

Please sign in to comment.