Skip to content

Commit

Permalink
wip command stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 18, 2024
1 parent eeacc3c commit 37495f8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package org.polyfrost.hytils.command;

import net.hypixel.data.type.GameType;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Parameter;
import org.polyfrost.oneconfig.api.hypixel.v0.HypixelAPI;
import org.polyfrost.universal.ChatColor;
import org.polyfrost.universal.UChat;
import org.polyfrost.oneconfig.utils.v1.Multithreading;
Expand All @@ -28,13 +31,14 @@
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/**
* Combination command & listener, since they are both small.
*/
@Command(value = "housingvisit", aliases = "hvisit")
@Command({"housingvisit", "hvisit"})
public class HousingVisitCommand {

/**
Expand All @@ -44,13 +48,13 @@ public class HousingVisitCommand {

protected static String playerName = "";

@Main
private void handle() {
@Command
private void main() {
UChat.chat(ChatColor.RED + "Usage: /housingvisit <username>");
}

@Main(description = "Visits a player's house in Housing.")
private void main(@Description("Player Name") GameProfile player) {
@Command(description = "Visits a player's house in Housing.")
private void main(@Parameter("Player Name") GameProfile player) {
if (!HypixelUtils.INSTANCE.isHypixel()) {
UChat.chat(ChatColor.RED + "You must be on Hypixel to use this command!");
return;
Expand All @@ -59,7 +63,9 @@ private void main(@Description("Player Name") GameProfile player) {
playerName = player.getName();

// if we are in the housing lobby, just immediately run the /visit command
if (LocrawUtil.INSTANCE.getLocrawInfo() != null && LocrawUtil.INSTANCE.getLocrawInfo().getGameType() == LocrawInfo.GameType.HOUSING && !LocrawUtil.INSTANCE.isInGame()) {
HypixelAPI.Location location = HypixelAPI.getLocation();
Optional<GameType> gameType = location.getGameType();
if (gameType.isPresent() && gameType.get() == GameType.HOUSING && !location.isGame()) {
visit(0);
} else {
HytilsReborn.INSTANCE.getCommandQueue().queue("/l housing");
Expand All @@ -70,6 +76,7 @@ private void main(@Description("Player Name") GameProfile player) {
}
}

//TODO this probably wont get excluded as a command
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
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/polyfrost/hytils/command/HytilsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

package org.polyfrost.hytils.command;

import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Parameter;
import org.polyfrost.oneconfig.api.ui.v1.notifications.Notifications;
import org.polyfrost.oneconfig.utils.v1.Multithreading;
import org.polyfrost.oneconfig.utils.v1.Notifications;
import org.polyfrost.oneconfig.api.commands.v1.CommandManager;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Description;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Main;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.SubCommand;
import org.polyfrost.hytils.HytilsReborn;
import org.polyfrost.hytils.command.parser.GEXPType;
import org.polyfrost.hytils.command.parser.GEXPTypeParser;
Expand All @@ -36,21 +34,21 @@

import java.util.Locale;

@Command(value = "hytils", aliases = {"hytilities", "hytilsreborn", "hytilitiesreborn", "hytil"})
@Command({"hytils", "hytilities", "hytilsreborn", "hytilitiesreborn", "hytil"})
public class HytilsCommand {
static {
CommandManager.INSTANCE.addParser(new GEXPTypeParser());
CommandManager.INSTANCE.addParser(new WinstreakTypeParser());
CommandManager.INSTANCE.registerParser(new GEXPTypeParser());
CommandManager.INSTANCE.registerParser(new WinstreakTypeParser());
}

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

@SubCommand(description = "Shows your guild experience", aliases = {"guildexp", "guildexperience"})
@Command(value = {"guildexp", "guildexperience"}, description = "Shows your guild experience")
@SuppressWarnings("SameParameterValue")
private void gexp(@Description("username") @Nullable GameProfile player, @Description("type") @Nullable GEXPType type) {
private void gexp(@Parameter("Username") @Nullable GameProfile player, @Parameter("GEXP Type") @Nullable GEXPType type) {
Multithreading.runAsync(() -> {
if (player != null) {
if (type == null) {
Expand Down Expand Up @@ -101,9 +99,9 @@ private void gexp(@Description("username") @Nullable GameProfile player, @Descri
});
}

@SubCommand(description = "Shows your winstreak", aliases = {"winstreak", "ws"})
@Command(value = {"winstreak", "ws"}, description = "Shows your winstreak")
@SuppressWarnings("SameParameterValue")
private void winstreak(@Description("username") @Nullable GameProfile player, @Description("type") @Nullable WinstreakType gamemode) {
private void winstreak(@Parameter("Username") @Nullable GameProfile player, @Parameter("Winstreak Type") @Nullable WinstreakType gamemode) {
Multithreading.runAsync(() -> {
if (player != null) {
if (gamemode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.polyfrost.hytils.command;

import org.polyfrost.oneconfig.api.config.v1.core.ConfigUtils;
import org.polyfrost.oneconfig.api.config.v1.ConfigManager;
import org.polyfrost.universal.UChat;
import org.polyfrost.oneconfig.utils.v1.Multithreading;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.*;
Expand Down Expand Up @@ -46,7 +46,7 @@
public class IgnoreTemporaryCommand {
private static JsonObject json;
private static final JsonParser PARSER = new JsonParser();
private static final File ignoreFile = ConfigUtils.getProfileFile("tempignore.json");
private static final File ignoreFile = ConfigManager.active().getFolder().resolve("tempignore.json").toFile();
private static final Pattern regex = Pattern.compile("(\\d+)( ?)((month|day|hour|minute|second|millisecond|y|m|d|h|s)s?)", Pattern.CASE_INSENSITIVE);

static {
Expand Down Expand Up @@ -78,13 +78,8 @@ public class IgnoreTemporaryCommand {
});
}

@Main
private void handle() {
UChat.chat("Usage: /ignoretemp <player> <time>");
}

//@Main
private void handle(@Description("Player Name") GameProfile playerName, @Description("Time") @Greedy String time) {
@Command(greedy = true)
private void main(@Parameter("Player Name") GameProfile playerName, @Parameter("Time") String time) {
Multithreading.runAsync(() -> {
try {
long millis = addMillis(time.replace(",", "").replace(" ", ""));
Expand All @@ -103,13 +98,13 @@ private void handle(@Description("Player Name") GameProfile playerName, @Descrip
});
}

@SubCommand(description = "Adds a player to the ignore list for a specified amount of time.")
private void add(@Description("Player Name") GameProfile playerName, @Description("Time") @Greedy String time) {
handle(playerName, time);
@Command(description = "Adds a player to the ignore list for a specified amount of time.", greedy = true)
private void add(@Parameter("Player Name") GameProfile playerName, @Parameter("Time") String time) {
main(playerName, time);
}

@SubCommand(description = "Removes a player from the ignore list.")
private void remove(@Description("Player Name") GameProfile playerName) {
@Command(description = "Removes a player from the ignore list.")
private void remove(@Parameter("Player Name") GameProfile playerName) {
json.remove(playerName.getName());
Multithreading.runAsync(() -> {
try {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/polyfrost/hytils/command/LimboCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import org.polyfrost.universal.ChatColor;
import org.polyfrost.universal.UChat;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Main;
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;
import net.minecraft.client.Minecraft;

@Command("limbo")
public class LimboCommand {
@Main(description = "Sends you to limbo.")
@Command(description = "Sends you to limbo.")
private void main() {
if (HypixelUtils.INSTANCE.isHypixel()) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("§");
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/org/polyfrost/hytils/command/PlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.polyfrost.oneconfig.utils.v1.NetworkUtils;
import org.polyfrost.oneconfig.api.commands.v1.CommandManager;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Main;
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;
import org.polyfrost.hytils.HytilsReborn;
import org.polyfrost.hytils.command.parser.GameName;
Expand Down Expand Up @@ -59,19 +58,13 @@ public static void init() {
}

Minecraft.getMinecraft().addScheduledTask(() -> {
CommandManager.INSTANCE.addParser(new GameNameParser(games));
CommandManager.INSTANCE.registerCommand(new PlayCommand());
CommandManager.INSTANCE.registerParser(new GameNameParser(games));
CommandManager.registerCommand(new PlayCommand());
});
});
}

@Main
public void handle() {
UChat.chat(ChatColor.RED + "Usage: /play <game>");
}

@Main
private void play(GameName game) {
@Command
private void main(GameName game) {
boolean autocompletePlayCommands = HytilsConfig.autocompletePlayCommands;
if (!HypixelUtils.INSTANCE.isHypixel()) {
HytilsReborn.INSTANCE.getCommandQueue().queue("/play " + game.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@
import org.polyfrost.universal.ChatColor;
import org.polyfrost.universal.UChat;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Main;
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;
import org.polyfrost.oneconfig.api.hypixel.v1.LocrawInfo;
import org.polyfrost.oneconfig.api.hypixel.v1.LocrawUtil;
import org.polyfrost.hytils.HytilsReborn;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.cache.LocrawGamesHandler;
import org.polyfrost.hytils.handlers.lobby.limbo.LimboLimiter;

@Command(value = "requeue", aliases = "rq")
@Command({"requeue", "rq"})
public class RequeueCommand {

protected static String game = "";

@Main(description = "Requeues you into the last game you played.")
@Command(description = "Requeues you into the last game you played.")
private void main() {
LocrawInfo locraw = LocrawUtil.INSTANCE.getLocrawInfo();
LocrawInfo lastLocraw = LocrawUtil.INSTANCE.getLastLocrawInfo();
Expand Down

0 comments on commit 37495f8

Please sign in to comment.