Skip to content

Commit

Permalink
misc: update to new command api (part 1, broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrm-en committed Oct 24, 2022
1 parent fea945c commit 90da780
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 261 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9")
forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9")

compileOnly('cc.polyfrost:oneconfig-1.8.9-forge:0.1.0-alpha92')
compileOnly('cc.polyfrost:oneconfig-1.8.9-forge:0.1.0-alpha108')
include('cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-alpha+')
compileOnly('org.spongepowered:mixin:0.7.11-SNAPSHOT')

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 10 additions & 8 deletions src/main/java/cc/woverflow/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,23 @@ public class HytilsReborn {

@Mod.EventHandler
public void onFMLPreInitialization(FMLPreInitializationEvent event) {
if (!modDir.exists()) modDir.mkdirs();
if (!modDir.exists() && !modDir.mkdirs()) {
throw new RuntimeException("Failed to create mod directory! Please report this https://polyfrost.cc/discord");
}
}

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
config = new HytilsConfig();

CommandManager.INSTANCE.addParser(new PlayerNameParser());
CommandManager.INSTANCE.registerCommand(HousingVisitCommand.class);
CommandManager.INSTANCE.registerCommand(HytilsCommand.class);
CommandManager.INSTANCE.registerCommand(IgnoreTemporaryCommand.class);
CommandManager.INSTANCE.registerCommand(LimboCommand.class);
CommandManager.INSTANCE.registerCommand(PlayCommand.class);
CommandManager.INSTANCE.registerCommand(SilentRemoveCommand.class);
CommandManager.INSTANCE.registerCommand(SkyblockVisitCommand.class);
CommandManager.INSTANCE.registerCommand(new HousingVisitCommand());
CommandManager.INSTANCE.registerCommand(new HytilsCommand());
CommandManager.INSTANCE.registerCommand(new IgnoreTemporaryCommand());
CommandManager.INSTANCE.registerCommand(new LimboCommand());
CommandManager.INSTANCE.registerCommand(new PlayCommand());
CommandManager.INSTANCE.registerCommand(new SilentRemoveCommand());
CommandManager.INSTANCE.registerCommand(new SkyblockVisitCommand());

CosmeticsHandler.INSTANCE.initialize();
PatternHandler.INSTANCE.initialize();
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/cc/woverflow/hytils/command/HousingVisitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package cc.woverflow.hytils.command;

import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
import cc.polyfrost.oneconfig.utils.commands.annotations.Description;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.polyfrost.oneconfig.utils.commands.annotations.Name;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.PlayerName;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
Expand All @@ -47,9 +48,14 @@ public class HousingVisitCommand {
protected static String playerName = "";

@Main
private static void handle(@Name("Player Name") PlayerName player) {
if (usernameRegex.matcher(player.name).matches()) {
playerName = player.name;
private void handle() {
UChat.say(EnumChatFormatting.RED + "Usage: /housingvisit <username>");
}

//FIXME
private void handle(@Description("Player Name") EntityPlayer player) {
if (usernameRegex.matcher(player.getName()).matches()) {
playerName = player.getName();

// if we are in the housing lobby, just immediately run the /visit command
if ("HOUSING".equals(EnumChatFormatting.getTextWithoutFormattingCodes(Minecraft.getMinecraft().theWorld.getScoreboard().getObjectiveInDisplaySlot(1).getDisplayName()))) {
Expand All @@ -63,13 +69,13 @@ private static void handle(@Name("Player Name") PlayerName player) {
}
}

private static void visit(final long time) {
private void visit(final long time) {
if (playerName != null) {
Multithreading.schedule(() -> HytilsReborn.INSTANCE.getCommandQueue().queue("/visit " + playerName), time, TimeUnit.MILLISECONDS); // at 300ms you can be nearly certain that nothing important will be null
}
}

private static class HousingVisitHook {
private class HousingVisitHook {
@SubscribeEvent
public void onHousingLobbyJoin(final WorldEvent.Load event) {
MinecraftForge.EVENT_BUS.unregister(this);
Expand Down
226 changes: 98 additions & 128 deletions src/main/java/cc/woverflow/hytils/command/HytilsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import cc.polyfrost.oneconfig.utils.Notifications;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
import cc.polyfrost.oneconfig.utils.commands.annotations.Description;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.polyfrost.oneconfig.utils.commands.annotations.Name;
import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.*;
Expand All @@ -36,158 +36,128 @@

@Command(value = "hytils", aliases = {"hytilities", "hytilsreborn", "hytilitiesreborn", "hytil"})
public class HytilsCommand {

static {
CommandManager.INSTANCE.addParser(new GEXPTypeParser());
CommandManager.INSTANCE.addParser(new WinstreakTypeParser());
}

@Main
private static void handleDefault() {
private void handleDefault() {
HytilsReborn.INSTANCE.getConfig().openGui();
}

@SubCommand("gexp")
private static class GEXPCommand {
@Main
private static void getGEXP() {
getGEXP(null, null);
}

@Main
private static void getGEXP(@Name("username") PlayerName username) {
getGEXP(username, null);
}

@SuppressWarnings("SameParameterValue")
@Main
private static void getGEXP(@Name("username") @Nullable PlayerName username, @Name("type") @Nullable GEXPType type) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelAPIUtils.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 (username != null) {
if (type == null) {
if (HypixelAPIUtils.getGEXP(username.name)) {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, username.name + " currently has " + HypixelAPIUtils.gexp + " guild EXP.");
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s GEXP.");
}
} else {
switch (type) {
case DAILY:
if (HypixelAPIUtils.getGEXP(username.name)) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
username.name + " currently has " + HypixelAPIUtils.gexp + " daily guild EXP."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s daily GEXP.");
}
case WEEKLY:
if (HypixelAPIUtils.getWeeklyGEXP(username.name)) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
username.name + " currently has " + HypixelAPIUtils.gexp + " weekly guild EXP."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s weekly GEXP.");
}
}
}
} else {
if (HypixelAPIUtils.getGEXP()) {
@SubCommand(description = "Shows your guild experience", aliases = {"guildexp", "guildexperience"})
@SuppressWarnings("SameParameterValue")
private void gexp(@Description("username") @Nullable PlayerName username, @Description("type") @Nullable GEXPType type) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelAPIUtils.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 (username != null) {
if (type == null) {
if (HypixelAPIUtils.getGEXP(username.name)) {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "You currently have " + HypixelAPIUtils.gexp + " guild EXP.");
.send(HytilsReborn.MOD_NAME, username.name + " currently has " + HypixelAPIUtils.gexp + " guild EXP.");
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get your GEXP.");
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s GEXP.");
}
} else {
switch (type) {
case DAILY:
if (HypixelAPIUtils.getGEXP(username.name)) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
username.name + " currently has " + HypixelAPIUtils.gexp + " daily guild EXP."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s daily GEXP.");
}
case WEEKLY:
if (HypixelAPIUtils.getWeeklyGEXP(username.name)) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
username.name + " currently has " + HypixelAPIUtils.gexp + " weekly guild EXP."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s weekly GEXP.");
}
}
}
} else {
if (HypixelAPIUtils.getGEXP()) {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "You currently have " + HypixelAPIUtils.gexp + " guild EXP.");
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get your GEXP.");
}
});
}
}
});
}

@SubCommand("winstreak")
private static class WinStreakCommand {
@Main
private static void getWinStreak() {
getWinStreak(null, null);
}

@Main
private static void getWinStreak(@Name("username") PlayerName username) {
getWinStreak(username, null);
}

@SuppressWarnings("SameParameterValue")
@Main
private static void getWinStreak(@Name("username") @Nullable PlayerName player, @Name("type") @Nullable WinstreakType gamemode) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelAPIUtils.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.name, gamemode.name())) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak in " + gamemode.name().toLowerCase(Locale.ENGLISH) + "."
);
} else {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
"There was a problem trying to get " + player.name + "'s winstreak in $gamemode."
);
}
@SubCommand(description = "Shows your winstreak", aliases = {"winstreak", "ws"})
@SuppressWarnings("SameParameterValue")
private void winstreak(@Description("username") @Nullable PlayerName player, @Description("type") @Nullable WinstreakType gamemode) {
Multithreading.runAsync(() -> {
if (HytilsConfig.apiKey.isEmpty() || !HypixelAPIUtils.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.name, gamemode.name())) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak in " + gamemode.name().toLowerCase(Locale.ENGLISH) + "."
);
} else {
if (HypixelAPIUtils.getWinstreak(player.name)) {
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.name + "'s winstreak.");
}
Notifications.INSTANCE
.send(
HytilsReborn.MOD_NAME,
"There was a problem trying to get " + player.name + "'s winstreak in $gamemode."
);
}
} else {
if (HypixelAPIUtils.getWinstreak()) {
if (HypixelAPIUtils.getWinstreak(player.name)) {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "You currently have a " + HypixelAPIUtils.winstreak + " winstreak.");
.send(
HytilsReborn.MOD_NAME,
player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak."
);
} else {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get your winstreak.");
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.name + "'s winstreak.");
}
}
});
}
}

@SubCommand("setkey")
private static class SetKeyCommand {
@Main
private static void setKey(@Name("API Key") String apiKey) {
Multithreading.runAsync(() -> {
if (HypixelAPIUtils.isValidKey(apiKey)) {
HytilsConfig.apiKey = apiKey;
HytilsReborn.INSTANCE.getConfig().save();
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.GREEN + "Saved API key successfully!");
} else {
if (HypixelAPIUtils.getWinstreak()) {
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "You currently have a " + HypixelAPIUtils.winstreak + " winstreak.");
} else {
HytilsReborn.INSTANCE.sendMessage(EnumChatFormatting.RED + "Invalid API key! Please try again.");
Notifications.INSTANCE
.send(HytilsReborn.MOD_NAME, "There was a problem trying to get your winstreak.");
}
});
}
}
});
}

@SubCommand(description = "Sets your API key.", aliases = "setkey")
private static void key(@Description("API Key") String apiKey) {
Multithreading.runAsync(() -> {
if (HypixelAPIUtils.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.");
}
});
}
}
Loading

0 comments on commit 90da780

Please sign in to comment.