Skip to content

Commit

Permalink
commands-v2 port, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrm-en committed Oct 25, 2022
1 parent 90da780 commit cb0946c
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 125 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-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')

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/cc/woverflow/hytils/HytilsReborn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,10 +50,10 @@ public class HousingVisitCommand {

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

//FIXME
@Main
private void handle(@Description("Player Name") EntityPlayer player) {
if (usernameRegex.matcher(player.getName()).matches()) {
playerName = player.getName();
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/cc/woverflow/hytils/command/HytilsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.");
}
}
}
Expand All @@ -103,37 +104,37 @@ 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.");
return;
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <player> <time>");
}

@Main
private void handle(@Description("Player Name") EntityPlayer playerName, @Description("Time") @Greedy String time) {
Multithreading.runAsync(() -> {
try {
long millis = addMillis(time.replace(",", "").replace(" ", ""));
json.addProperty(playerName.name, millis + new Date().getTime());
json.addProperty(playerName.getName(), millis + new Date().getTime());
try {
FileUtils.writeStringToFile(file, json.toString(), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
UChat.say("/ignore add " + playerName.name);
HytilsReborn.INSTANCE.sendMessage("&r&aSuccessfully ignored &r&6&l" + playerName.name + "&r&a for &r&e&l" + time + "&r&a. The ignore will be removed after the specified period.");
UChat.say("/ignore add " + playerName.getName());
HytilsReborn.INSTANCE.sendMessage("&r&aSuccessfully ignored &r&6&l" + playerName.getName() + "&r&a for &r&e&l" + time + "&r&a. The ignore will be removed after the specified period.");
} catch (Exception e) {
e.printStackTrace();
HytilsReborn.INSTANCE.sendMessage("&cAn error has occured and the user has not been ignored.");
Expand All @@ -99,21 +104,21 @@ private void handle(@Description("Player Name") PlayerName playerName, @Descript
}

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

@SubCommand(description = "Removes a player from the ignore list.")
private void remove(@Description("Player Name") PlayerName playerName) {
json.remove(playerName.name);
private void remove(@Description("Player Name") EntityPlayer playerName) {
json.remove(playerName.getName());
Multithreading.runAsync(() -> {
try {
FileUtils.writeStringToFile(file, json.toString(), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
});
UChat.say("/ignore remove " + playerName.name);
UChat.say("/ignore remove " + playerName.getName());
}

private static void initialize() {
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/cc/woverflow/hytils/command/PlayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
package cc.woverflow.hytils.command;


import cc.polyfrost.oneconfig.libs.universal.ChatColor;
import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
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.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.GameName;
Expand All @@ -43,22 +47,31 @@
public class PlayCommand {
private static Map<String, String> games = new HashMap<>();

static {
public static void init() {
Multithreading.runAsync(() -> {
try {
String url = "https://data.woverflow.cc/games.json";
String content = NetworkUtils.getString(url);
Type stringStringMap = new TypeToken<HashMap<String, String>>() {
}.getType();
games = new Gson().fromJson(content, stringStringMap);
Minecraft.getMinecraft().addScheduledTask(() -> CommandManager.INSTANCE.addParser(new GameNameParser(games)));
} catch (JsonSyntaxException e) {
HytilsReborn.INSTANCE.getLogger().error("Failed to fetch /play game list.", e);
}

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

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

@Main
private void play(GameName game) {
boolean autocompletePlayCommands = HytilsConfig.autocompletePlayCommands;
if (!HypixelUtils.INSTANCE.isHypixel()) {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/cc/woverflow/hytils/command/SilentRemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@

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.commands.annotations.SubCommand;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.PlayerName;
import net.minecraft.entity.player.EntityPlayer;

import java.util.Set;

@Command("silentremove")
public class SilentRemoveCommand {

//FIXME
@/*Main*/
SubCommand(description = "Adds or removes a player from the silent list")
private void player(PlayerName player) {
String name = player.name;
@Main
public void handle() {
UChat.chat(ChatColor.RED + "Usage: /silentremove <add/list> <player>");
UChat.chat(ChatColor.RED + " or: /silentremove <player>");
}

@Main(description = "Adds or removes a player from the silent list")
private void player(EntityPlayer player) {
String name = player.getName();
final Set<String> silentUsers = HytilsReborn.INSTANCE.getSilentRemoval().getSilentUsers();
if (silentUsers.contains(name)) {
silentUsers.remove(name);
Expand All @@ -44,6 +51,11 @@ private void player(PlayerName player) {
HytilsReborn.INSTANCE.sendMessage("&aAdded &e" + name + " &ato the removal queue.");
}

@SubCommand(description = "Adds a player to the silent list")
private void add(EntityPlayer entityPlayer) {
player(entityPlayer);
}

@SubCommand(description = "Clears the silent removal queue.")
private void clear() {
final Set<String> silentUsers = HytilsReborn.INSTANCE.getSilentRemoval().getSilentUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import cc.polyfrost.oneconfig.utils.commands.annotations.Description;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.woverflow.hytils.HytilsReborn;
import cc.woverflow.hytils.command.parser.PlayerName;
import com.google.common.collect.Sets;
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 @@ -52,13 +52,13 @@ public class SkyblockVisitCommand {

@Main
private void handle() {
UChat.say(EnumChatFormatting.RED + "Usage: /skyblockvisit <username>");
UChat.chat(EnumChatFormatting.RED + "Usage: /skyblockvisit <username>");
}

//FIXME: @Main
private void handle(@Description("Player Name") PlayerName player) {
if (usernameRegex.matcher(player.name).matches()) {
playerName = player.name;
@Main
private void handle(@Description("Player Name") EntityPlayer player) {
if (usernameRegex.matcher(player.getName()).matches()) {
playerName = player.getName();
if (SKYBLOCK_IN_ALL_LANGUAGES.contains(EnumChatFormatting.getTextWithoutFormattingCodes(Minecraft.getMinecraft().theWorld
.getScoreboard().getObjectiveInDisplaySlot(1).getDisplayName().split(" ")[0]))) {
visit(0);
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/cc/woverflow/hytils/command/parser/PlayerName.java

This file was deleted.

Loading

0 comments on commit cb0946c

Please sign in to comment.