Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: /requeue command #72

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/cc/woverflow/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void init(FMLInitializationEvent event) {
CommandManager.INSTANCE.registerCommand(new HytilsCommand());
CommandManager.INSTANCE.registerCommand(new IgnoreTemporaryCommand());
CommandManager.INSTANCE.registerCommand(new LimboCommand());
CommandManager.INSTANCE.registerCommand(new RequeueCommand());
CommandManager.INSTANCE.registerCommand(new SilentRemoveCommand());
CommandManager.INSTANCE.registerCommand(new SkyblockVisitCommand());
CommandManager.INSTANCE.registerCommand(new UnblockCommand());
Expand All @@ -119,6 +120,7 @@ public void init(FMLInitializationEvent event) {
CosmeticsHandler.INSTANCE.initialize();
PatternHandler.INSTANCE.initialize();
BedLocationHandler.INSTANCE.initialize();
LocrawGamesHandler.INSTANCE.initialize();
HeightHandler.INSTANCE.initialize();

registerHandlers();
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/cc/woverflow/hytils/command/RequeueCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cc.woverflow.hytils.command;

import cc.polyfrost.oneconfig.libs.universal.ChatColor;
import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.cache.LocrawGamesHandler;
import cc.woverflow.hytils.handlers.lobby.limbo.LimboLimiter;

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

protected static String game = "";

@Main(description = "Requeues you into the last game you played.")
private void requeue() {
LocrawInfo locraw = LocrawUtil.INSTANCE.getLocrawInfo();
LocrawInfo lastLocraw = LocrawUtil.INSTANCE.getLastLocrawInfo();
if (!HypixelUtils.INSTANCE.isHypixel() || locraw == null || lastLocraw == null) {
return;
}

if (LocrawUtil.INSTANCE.isInGame()) {
switch (locraw.getGameType()) {
case HOUSING:
case SKYBLOCK:
case REPLAY:
UChat.chat(ChatColor.RED + "You must be in a valid game to use this command.");
return;
}
game = locraw.getGameMode();
} else if (!LocrawUtil.INSTANCE.isInGame() && !lastLocraw.getGameMode().equals("lobby")) {
switch (lastLocraw.getGameType()) {
case HOUSING:
case REPLAY:
UChat.chat(ChatColor.RED + "The last round has to be a valid game to use this command.");
return;
}
game = lastLocraw.getGameMode();
} else {
UChat.chat(ChatColor.RED + "The last round has to be a game to use this command.");
return;
}

String value = LocrawGamesHandler.locrawGames.get(locraw.getRawGameType().toLowerCase() + "_" + game.toLowerCase());
if (value != null) {
game = value;
}

if (HytilsConfig.limboPlayCommandHelper && LimboLimiter.inLimbo()) {
HytilsReborn.INSTANCE.getCommandQueue().queue("/lobby");
}
HytilsReborn.INSTANCE.getCommandQueue().queue("/play " + game.toLowerCase());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cc.woverflow.hytils.handlers.cache;

import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import cc.woverflow.hytils.HytilsReborn;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

public class LocrawGamesHandler {
public static LocrawGamesHandler INSTANCE = new LocrawGamesHandler();
public static Map<String, String> locrawGames = new HashMap<>();

public void initialize() {
Multithreading.runAsync(() -> {
try {
String url = "https://data.woverflow.cc/locraw_games.json";
String content = NetworkUtils.getString(url);
Type stringStringMap = new TypeToken<HashMap<String, String>>() {
}.getType();
locrawGames = new Gson().fromJson(content, stringStringMap);
} catch (JsonSyntaxException e) {
HytilsReborn.INSTANCE.getLogger().error("Failed to fetch locraw_games list.", e);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.config.HytilsConfig;
import cc.woverflow.hytils.handlers.cache.LocrawGamesHandler;
import cc.woverflow.hytils.handlers.chat.ChatReceiveModule;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

public class AutoQueue implements ChatReceiveModule {
private String command = null;
private boolean sentCommand;

/**
* We want this to activate early so that it catches the queue message.
*/
Expand All @@ -42,9 +45,6 @@ public int getPriority() {
return -11;
}

private String command = null;
private boolean sentCommand;

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (!HytilsConfig.autoQueue) {
Expand All @@ -55,7 +55,12 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
LocrawInfo locraw = getLocraw();
Matcher matcher = getLanguage().autoQueuePrefixGlobalRegex.matcher(message);
if (matcher.matches() && locraw != null) {
this.command = "/play " + locraw.getGameMode().toLowerCase(Locale.ENGLISH);
String game = locraw.getGameMode();
String value = LocrawGamesHandler.locrawGames.get(locraw.getRawGameType().toLowerCase() + "_" + game.toLowerCase());
if (value != null) {
game = value;
}
this.command = "/play " + game.toLowerCase();
}
}

Expand Down