From cb0946c31ebca4a3413d78cffec9e705087f8522 Mon Sep 17 00:00:00 2001 From: xtrm Date: Tue, 25 Oct 2022 19:25:03 +0200 Subject: [PATCH] commands-v2 port, part 2 --- build.gradle | 2 +- .../cc/woverflow/hytils/HytilsReborn.java | 8 +-- .../hytils/command/HousingVisitCommand.java | 5 +- .../hytils/command/HytilsCommand.java | 37 +++++++------- .../command/IgnoreTemporaryCommand.java | 25 ++++++---- .../woverflow/hytils/command/PlayCommand.java | 19 +++++-- .../hytils/command/SilentRemoveCommand.java | 24 ++++++--- .../hytils/command/SkyblockVisitCommand.java | 12 ++--- .../hytils/command/parser/PlayerName.java | 26 ---------- .../command/parser/PlayerNameParser.java | 49 ------------------- .../hytils/config/BlockHighlightConfig.java | 2 +- 11 files changed, 84 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/cc/woverflow/hytils/command/parser/PlayerName.java delete mode 100644 src/main/java/cc/woverflow/hytils/command/parser/PlayerNameParser.java diff --git a/build.gradle b/build.gradle index 8b739d6e..3ba36dd9 100644 --- a/build.gradle +++ b/build.gradle @@ -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-alpha108') + compileOnly('cc.polyfrost:oneconfig-1.8.9-forge:0.1.0-alpha114') include('cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-alpha+') compileOnly('org.spongepowered:mixin:0.7.11-SNAPSHOT') diff --git a/src/main/java/cc/woverflow/hytils/HytilsReborn.java b/src/main/java/cc/woverflow/hytils/HytilsReborn.java index 4ec26c69..c3ec5f60 100644 --- a/src/main/java/cc/woverflow/hytils/HytilsReborn.java +++ b/src/main/java/cc/woverflow/hytils/HytilsReborn.java @@ -23,7 +23,6 @@ import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.woverflow.hytils.command.*; -import cc.woverflow.hytils.command.parser.PlayerNameParser; import cc.woverflow.hytils.config.HytilsConfig; import cc.woverflow.hytils.handlers.cache.CosmeticsHandler; import cc.woverflow.hytils.handlers.cache.HeightHandler; @@ -108,6 +107,7 @@ public class HytilsReborn { @Mod.EventHandler public void onFMLPreInitialization(FMLPreInitializationEvent event) { + if (!modDir.exists() && !modDir.mkdirs()) { throw new RuntimeException("Failed to create mod directory! Please report this https://polyfrost.cc/discord"); } @@ -117,15 +117,17 @@ public void onFMLPreInitialization(FMLPreInitializationEvent event) { public void init(FMLInitializationEvent event) { config = new HytilsConfig(); - CommandManager.INSTANCE.addParser(new PlayerNameParser()); 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()); + // We initialize it a different way because it requires the + // GameNameParser to be initialized, and that depends on networking. + PlayCommand.init(); + CosmeticsHandler.INSTANCE.initialize(); PatternHandler.INSTANCE.initialize(); HeightHandler.INSTANCE.initialize(); diff --git a/src/main/java/cc/woverflow/hytils/command/HousingVisitCommand.java b/src/main/java/cc/woverflow/hytils/command/HousingVisitCommand.java index e9d392f3..c879be1d 100644 --- a/src/main/java/cc/woverflow/hytils/command/HousingVisitCommand.java +++ b/src/main/java/cc/woverflow/hytils/command/HousingVisitCommand.java @@ -18,6 +18,7 @@ package cc.woverflow.hytils.command; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.utils.Multithreading; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; @@ -49,10 +50,10 @@ public class HousingVisitCommand { @Main private void handle() { - UChat.say(EnumChatFormatting.RED + "Usage: /housingvisit "); + UChat.chat(ChatColor.RED + "Usage: /housingvisit "); } - //FIXME + @Main private void handle(@Description("Player Name") EntityPlayer player) { if (usernameRegex.matcher(player.getName()).matches()) { playerName = player.getName(); diff --git a/src/main/java/cc/woverflow/hytils/command/HytilsCommand.java b/src/main/java/cc/woverflow/hytils/command/HytilsCommand.java index 76131675..f4239a0a 100644 --- a/src/main/java/cc/woverflow/hytils/command/HytilsCommand.java +++ b/src/main/java/cc/woverflow/hytils/command/HytilsCommand.java @@ -29,6 +29,7 @@ import cc.woverflow.hytils.command.parser.*; import cc.woverflow.hytils.config.HytilsConfig; import cc.woverflow.hytils.util.HypixelAPIUtils; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumChatFormatting; import org.jetbrains.annotations.Nullable; @@ -48,44 +49,44 @@ private void handleDefault() { @SubCommand(description = "Shows your guild experience", aliases = {"guildexp", "guildexperience"}) @SuppressWarnings("SameParameterValue") - private void gexp(@Description("username") @Nullable PlayerName username, @Description("type") @Nullable GEXPType type) { + private void gexp(@Description("username") @Nullable EntityPlayer player, @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 (player != null) { if (type == null) { - if (HypixelAPIUtils.getGEXP(username.name)) { + if (HypixelAPIUtils.getGEXP(player.getName())) { Notifications.INSTANCE - .send(HytilsReborn.MOD_NAME, username.name + " currently has " + HypixelAPIUtils.gexp + " guild EXP."); + .send(HytilsReborn.MOD_NAME, player.getName() + " currently has " + HypixelAPIUtils.gexp + " guild EXP."); } else { Notifications.INSTANCE - .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + username.name + "'s GEXP."); + .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.getName() + "'s GEXP."); } } else { switch (type) { case DAILY: - if (HypixelAPIUtils.getGEXP(username.name)) { + if (HypixelAPIUtils.getGEXP(player.getName())) { Notifications.INSTANCE .send( HytilsReborn.MOD_NAME, - username.name + " currently has " + HypixelAPIUtils.gexp + " daily guild EXP." + player.getName() + " 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."); + .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.getName() + "'s daily GEXP."); } case WEEKLY: - if (HypixelAPIUtils.getWeeklyGEXP(username.name)) { + if (HypixelAPIUtils.getWeeklyGEXP(player.getName())) { Notifications.INSTANCE .send( HytilsReborn.MOD_NAME, - username.name + " currently has " + HypixelAPIUtils.gexp + " weekly guild EXP." + player.getName() + " 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."); + .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.getName() + "'s weekly GEXP."); } } } @@ -103,7 +104,7 @@ private void gexp(@Description("username") @Nullable PlayerName username, @Descr @SubCommand(description = "Shows your winstreak", aliases = {"winstreak", "ws"}) @SuppressWarnings("SameParameterValue") - private void winstreak(@Description("username") @Nullable PlayerName player, @Description("type") @Nullable WinstreakType gamemode) { + private void winstreak(@Description("username") @Nullable EntityPlayer 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."); @@ -111,29 +112,29 @@ private void winstreak(@Description("username") @Nullable PlayerName player, @De } if (player != null) { if (gamemode != null) { - if (HypixelAPIUtils.getWinstreak(player.name, gamemode.name())) { + if (HypixelAPIUtils.getWinstreak(player.getName(), gamemode.name())) { Notifications.INSTANCE .send( HytilsReborn.MOD_NAME, - player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak in " + gamemode.name().toLowerCase(Locale.ENGLISH) + "." + player.getName() + " 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." + "There was a problem trying to get " + player.getName() + "'s winstreak in $gamemode." ); } } else { - if (HypixelAPIUtils.getWinstreak(player.name)) { + if (HypixelAPIUtils.getWinstreak(player.getName())) { Notifications.INSTANCE .send( HytilsReborn.MOD_NAME, - player.name + " currently has a " + HypixelAPIUtils.winstreak + " winstreak." + player.getName() + " currently has a " + HypixelAPIUtils.winstreak + " winstreak." ); } else { Notifications.INSTANCE - .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.name + "'s winstreak."); + .send(HytilsReborn.MOD_NAME, "There was a problem trying to get " + player.getName() + "'s winstreak."); } } } else { diff --git a/src/main/java/cc/woverflow/hytils/command/IgnoreTemporaryCommand.java b/src/main/java/cc/woverflow/hytils/command/IgnoreTemporaryCommand.java index 93840d38..07cf83e2 100644 --- a/src/main/java/cc/woverflow/hytils/command/IgnoreTemporaryCommand.java +++ b/src/main/java/cc/woverflow/hytils/command/IgnoreTemporaryCommand.java @@ -22,11 +22,11 @@ import cc.polyfrost.oneconfig.utils.Multithreading; import cc.polyfrost.oneconfig.utils.commands.annotations.*; import cc.woverflow.hytils.HytilsReborn; -import cc.woverflow.hytils.command.parser.PlayerName; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -78,19 +78,24 @@ public class IgnoreTemporaryCommand { }); } - //FIXME: @Main - private void handle(@Description("Player Name") PlayerName playerName, @Description("Time") @Greedy String time) { + @Main + private void handle() { + UChat.chat("Usage: /ignoretemp