diff options
author | nea <nea@nea.moe> | 2023-02-06 22:24:57 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-02-06 22:24:57 +0100 |
commit | faee1d0a6e1cdab67fba2a496fed440616d9e812 (patch) | |
tree | 6f2ab9154e0f522d013f84601c5634be7dbb55d0 | |
parent | 62e0919fcd091338e2d15b139d88517206c435b7 (diff) | |
download | NotEnoughUpdates-faee1d0a6e1cdab67fba2a496fed440616d9e812.tar.gz NotEnoughUpdates-faee1d0a6e1cdab67fba2a496fed440616d9e812.tar.bz2 NotEnoughUpdates-faee1d0a6e1cdab67fba2a496fed440616d9e812.zip |
profile commands
19 files changed, 664 insertions, 1018 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java index 0c8597bb..459b6b83 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java @@ -19,43 +19,19 @@ package io.github.moulberry.notenoughupdates.commands; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.misc.AhCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CalculatorCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CalendarCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CosmeticsCommand; -import io.github.moulberry.notenoughupdates.commands.misc.CustomizeCommand; -import io.github.moulberry.notenoughupdates.commands.misc.PronounsCommand; -import io.github.moulberry.notenoughupdates.commands.misc.UpdateCommand; -import io.github.moulberry.notenoughupdates.commands.profile.CataCommand; -import io.github.moulberry.notenoughupdates.commands.profile.PeekCommand; -import io.github.moulberry.notenoughupdates.commands.profile.PvCommand; -import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand; import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.fml.common.Loader; public class Commands { public Commands() { // Profile Commands - ClientCommandHandler.instance.registerCommand(new PeekCommand()); - ClientCommandHandler.instance.registerCommand(new ViewProfileCommand()); - ClientCommandHandler.instance.registerCommand(new PvCommand()); - if (!Loader.isModLoaded("skyblockextras")) ClientCommandHandler.instance.registerCommand(new CataCommand()); // Misc Commands - ClientCommandHandler.instance.registerCommand(new CosmeticsCommand()); - ClientCommandHandler.instance.registerCommand(new CustomizeCommand()); ClientCommandHandler.instance.registerCommand(new ScreenCommand("neubuttons", GuiInvButtonEditor::new)); ClientCommandHandler.instance.registerCommand(new ScreenCommand("neuec", GuiEnchantColour::new)); ClientCommandHandler.instance.registerCommand(new ScreenCommand("neuoverlay", NEUOverlayPlacements::new)); - ClientCommandHandler.instance.registerCommand(new AhCommand()); - ClientCommandHandler.instance.registerCommand(new CalculatorCommand()); - ClientCommandHandler.instance.registerCommand(new CalendarCommand()); - ClientCommandHandler.instance.registerCommand(new UpdateCommand(NotEnoughUpdates.INSTANCE)); - ClientCommandHandler.instance.registerCommand(new PronounsCommand()); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java deleted file mode 100644 index 1ca398ef..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.auction.CustomAHGui; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.StringUtils; - -public class AhCommand extends ClientCommandBase { - - public AhCommand() { - super("neuah"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - Utils.addChatMessage(EnumChatFormatting.RED + "You must be on SkyBlock to use this feature."); - } else if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || - NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Utils.addChatMessage( - EnumChatFormatting.RED + "Can't open NEU AH: an api key is not set. Run /api new and put the result in settings."); - } else { - NotEnoughUpdates.INSTANCE.openGui = new CustomAHGui(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.clearSearch(); - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.updateSearch(); - - if (args.length > 0) { - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch(StringUtils.join(args, " ")); - } else { - if (NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.saveLastSearch) { - NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch(null); - } - } - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java deleted file mode 100644 index b01f106b..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.Calculator; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public class CalculatorCommand extends ClientCommandBase { - public CalculatorCommand() { - super("neucalc"); - } - - @Override - public List<String> getCommandAliases() { - return Arrays.asList("neucalculator"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { - sender.addChatMessage(new ChatComponentText( - "\n§e[NEU] §5It's a calculator.\n" + - "§eFor Example §b/neucalc 3m*7k§e.\n" + - "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + - "§eThe \"s\" suffix acts as 64.\n" + - "§eTurn on Sign Calculator in /neu misc to also support this in sign popups and the neu search bar.\n")); - return; - } - String source = String.join(" ", args); - try { - BigDecimal calculate = Calculator.calculate(source); - DecimalFormat formatter = new DecimalFormat("#,##0.##"); - String format = formatter.format(calculate); - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.WHITE + source + " " + EnumChatFormatting.YELLOW + - "= " + EnumChatFormatting.GREEN + format - )); - } catch (Calculator.CalculatorException e) { - sender.addChatMessage(new ChatComponentText( - EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.RED + "Error during calculation: " + - e.getMessage() + "\n" + - EnumChatFormatting.WHITE + source.substring(0, e.getOffset()) + EnumChatFormatting.DARK_RED + - source.substring(e.getOffset(), e.getLength() + e.getOffset()) + EnumChatFormatting.GRAY + - source.substring(e.getLength() + e.getOffset()) - )); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java deleted file mode 100644 index 58c13474..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalendarCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; - -public class CalendarCommand extends ClientCommandBase { - - public CalendarCommand() { - super("neucalendar"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - Minecraft.getMinecraft().thePlayer.closeScreen(); - CalendarOverlay.setEnabled(true); - NotEnoughUpdates.INSTANCE.sendChatMessage("/calendar"); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java deleted file mode 100644 index bbab316e..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CosmeticsCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.EnumChatFormatting; - -public class CosmeticsCommand extends ClientCommandBase { - - public CosmeticsCommand() { - super("neucosmetics"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.notifications.doFastRenderNotif) { - Utils.addChatMessage(EnumChatFormatting.RED + - "NEU Cosmetics do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); - - } - - NotEnoughUpdates.INSTANCE.openGui = new GuiCosmetics(); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java deleted file mode 100644 index 28c2893d..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CustomizeCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.miscgui.GuiItemCustomize; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; - -import java.util.Collections; -import java.util.List; - -public class CustomizeCommand extends ClientCommandBase { - - public CustomizeCommand() { - super("neucustomize"); - } - - @Override - public List<String> getCommandAliases() { - return Collections.singletonList("neurename"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - - if (held == null) { - sender.addChatMessage(new ChatComponentText("\u00a7cYou can't customize your hand...")); - return; - } - - String heldUUID = NotEnoughUpdates.INSTANCE.manager.getUUIDForItem(held); - - if (heldUUID == null) { - sender.addChatMessage(new ChatComponentText("\u00a7cHeld item does not have a UUID, so it cannot be customized")); - return; - } - - NotEnoughUpdates.INSTANCE.openGui = new GuiItemCustomize(held, heldUUID); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java deleted file mode 100644 index 5a4f1400..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/PronounsCommand.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.util.MinecraftExecutor; -import io.github.moulberry.notenoughupdates.util.PronounDB; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -import java.util.Optional; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -public class PronounsCommand extends ClientCommandBase { - public PronounsCommand() { - super("neupronouns"); - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/neupronouns <username> [platform]"; - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - switch (args.length) { - case 1: - fetchPronouns("minecraft", args[0]); - break; - case 2: - fetchPronouns(args[1], args[0]); - break; - default: - sender.addChatMessage(new ChatComponentText("§4" + getCommandUsage(sender))); - } - } - - private void fetchPronouns(String platform, String user) { - GuiNewChat nc = Minecraft.getMinecraft().ingameGUI.getChatGUI(); - int id = new Random().nextInt(); - nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] Fetching Pronouns..."), id); - - CompletableFuture<Optional<PronounDB.PronounChoice>> pronouns; - if ("minecraft".equals(platform)) { - CompletableFuture<UUID> c = new CompletableFuture<>(); - NotEnoughUpdates.profileViewer.getPlayerUUID(user, uuidString -> { - if (uuidString == null) { - c.completeExceptionally(new NullPointerException()); - } else { - c.complete(Utils.parseDashlessUUID(uuidString)); - } - }); - pronouns = c.thenCompose(PronounDB::getPronounsFor); - } else { - pronouns = PronounDB.getPronounsFor(platform, user); - } - pronouns.handleAsync((pronounChoice, throwable) -> { - if (throwable != null || !pronounChoice.isPresent()) { - nc.printChatMessageWithOptionalDeletion(new ChatComponentText("§e[NEU] §4Failed to fetch pronouns."), id); - return null; - } - PronounDB.PronounChoice betterPronounChoice = pronounChoice.get(); - nc.printChatMessageWithOptionalDeletion(new ChatComponentText( - "§e[NEU] Pronouns for §b" + user + " §eon §b" + platform + "§e:"), id); - betterPronounChoice.render().forEach(it -> nc.printChatMessage(new ChatComponentText("§e[NEU] §a" + it))); - return null; - }, MinecraftExecutor.INSTANCE); - - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java deleted file mode 100644 index 1aeebda5..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/UpdateCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.misc; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatComponentText; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public class UpdateCommand extends ClientCommandBase { - NotEnoughUpdates neu; - - public UpdateCommand(NotEnoughUpdates neu) { - super("neuupdate"); - this.neu = neu; - } - - @Override - public List<String> getCommandAliases() { - return Arrays.asList("neuupdates", "enoughupdates"); - } - - public void displayHelp(ICommandSender sender) { - sender.addChatMessage(new ChatComponentText( - "" + - "§e[NEU] §b/neuupdate help - View help.\n" + - "§e[NEU] §b/neuupdate check - Check for updates.\n" + - "" - )); - - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if ((args.length == 1 && Objects.equals(args[0], "help")) || args.length == 0) { - displayHelp(sender); - return; - } - switch (args[0].toLowerCase().intern()) { - case "check": - neu.autoUpdater.displayUpdateMessageIfOutOfDate(); - break; - case "scheduledownload": - neu.autoUpdater.scheduleDownload(); - break; - case "updatemodes": - sender.addChatMessage(new ChatComponentText("§e[NEU] §bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files")); - break; - default: - displayHelp(sender); - - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java deleted file mode 100644 index afc47418..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/CataCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import net.minecraft.command.ICommandSender; - -public class CataCommand extends ViewProfileCommand { - - public CataCommand() { - super("cata"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - GuiProfileViewer.currentPage = GuiProfileViewer.ProfileViewerPage.DUNGEON; - super.processCommand(sender, args); - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java deleted file mode 100644 index 23852ab6..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PeekCommand.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; -import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import org.apache.commons.lang3.text.WordUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -public class PeekCommand extends ClientCommandBase { - - private ScheduledExecutorService peekCommandExecutorService = null; - private ScheduledFuture<?> peekScheduledFuture = null; - - public PeekCommand() { - super("peek"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - String name; - if (args.length == 0) { - name = Minecraft.getMinecraft().thePlayer.getName(); - } else { - name = args[0]; - } - int id = new Random().nextInt(Integer.MAX_VALUE / 2) + Integer.MAX_VALUE / 2; - - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting player information..."), id); - NotEnoughUpdates.profileViewer.getProfileByName(name, profile -> { - if (profile == null) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.RED + "[PEEK] Unknown player or the Hypixel API is down."), id); - } else { - profile.resetCache(); - - if (peekCommandExecutorService == null || peekCommandExecutorService.isTerminated()) { - peekCommandExecutorService = Executors.newSingleThreadScheduledExecutor(); - } - - if (peekScheduledFuture != null && !peekScheduledFuture.isDone()) { - Utils.addChatMessage( - EnumChatFormatting.RED + "[PEEK] New peek command was run, cancelling old one."); - peekScheduledFuture.cancel(true); - } - - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting the player's SkyBlock profile(s)..."), id); - - long startTime = System.currentTimeMillis(); - peekScheduledFuture = peekCommandExecutorService.schedule(new Runnable() { - public void run() { - if (System.currentTimeMillis() - startTime > 10 * 1000) { - Minecraft.getMinecraft().ingameGUI - .getChatGUI() - .printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.RED + "[PEEK] Getting profile info took too long, aborting."), id); - return; - } - - String g = EnumChatFormatting.GRAY.toString(); - - JsonObject profileInfo = profile.getProfileInformation(null); - if (profileInfo != null) { - float overallScore = 0; - - boolean isMe = name.equalsIgnoreCase("moulberry"); - - PlayerStats.Stats stats = profile.getStats(null); - if (stats == null) { - peekScheduledFuture = peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); - return; - } - Map<String, ProfileViewer.Level> skyblockInfo = profile.getSkyblockInfo(null); - - if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new ChatComponentText( - EnumChatFormatting.YELLOW + "[PEEK] Getting the player's Skyblock networth..."), id); - - CountDownLatch countDownLatch = new CountDownLatch(1); - - profile.getSoopyNetworth(null, () -> countDownLatch.countDown()); - - try { //Wait for async network request - countDownLatch.await(10, TimeUnit.SECONDS); - } catch (InterruptedException e) {} - - //Now it's waited for network request the data should be cached (accessed in nw section) - } - - Minecraft.getMinecraft().ingameGUI - .getChatGUI() - .printChatMessageWithOptionalDeletion(new ChatComponentText(EnumChatFormatting.GREEN + " " + - EnumChatFormatting.STRIKETHROUGH + "-=-" + EnumChatFormatting.RESET + EnumChatFormatting.GREEN + - " " + - Utils.getElementAsString(profile.getHypixelProfile().get("displayname"), name) + "'s Info " + - EnumChatFormatting.STRIKETHROUGH + "-=-"), id); - - if (skyblockInfo == null) { - Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills API disabled!"); - } else { - float totalSkillLVL = 0; - float totalSkillCount = 0; - - List<String> skills = Arrays.asList("taming", "mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy", "carpentry"); - for (String skillName : skills) { - totalSkillLVL += skyblockInfo.get(skillName).level; - totalSkillCount++; - } - - float combat = skyblockInfo.get("combat").level; - float zombie = skyblockInfo.get("zombie").level; - float spider = skyblockInfo.get("spider").level; - float wolf = skyblockInfo.get("wolf").level; - float enderman = skyblockInfo.get("enderman").level; - float blaze = skyblockInfo.get("blaze").level; - - float avgSkillLVL = totalSkillLVL / totalSkillCount; - - if (isMe) { - avgSkillLVL = 6; - combat = 4; - zombie = 2; - spider = 1; - wolf = 2; - enderman = 0; - blaze = 0; - } - - EnumChatFormatting combatPrefix = combat > 20 - ? (combat > 35 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting zombiePrefix = zombie > 3 - ? (zombie > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting spiderPrefix = spider > 3 - ? (spider > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting wolfPrefix = - wolf > 3 ? (wolf > 6 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - EnumChatFormatting endermanPrefix = enderman > 3 - ? (enderman > 6 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting blazePrefix = blaze > 3 - ? (blaze > 6 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting avgPrefix = avgSkillLVL > 20 - ? (avgSkillLVL > 35 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - overallScore += zombie * zombie / 81f; - overallScore += spider * spider / 81f; - overallScore += wolf * wolf / 81f; - overallScore += enderman * enderman / 81f; - overallScore += blaze * blaze / 81f; - overallScore += avgSkillLVL / 20f; - - int cata = (int) skyblockInfo.get("catacombs").level; - EnumChatFormatting cataPrefix = cata > 15 - ? (cata > 25 ? EnumChatFormatting.GREEN : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - overallScore += cata * cata / 2000f; - - Utils.addChatMessage(g + "Combat: " + combatPrefix + (int) Math.floor(combat) + - (cata > 0 ? g + " - Cata: " + cataPrefix + cata : "") + - g + " - AVG: " + avgPrefix + (int) Math.floor(avgSkillLVL)); - Utils.addChatMessage(g + "Slayer: " + zombiePrefix + (int) Math.floor(zombie) + g + "-" + - spiderPrefix + (int) Math.floor(spider) + g + "-" + - wolfPrefix + (int) Math.floor(wolf) + g + "-" + - endermanPrefix + (int) Math.floor(enderman) + g + "-" + - blazePrefix + (int) Math.floor(blaze)); - } - if (stats == null) { - Utils.addChatMessage(EnumChatFormatting.YELLOW + "Skills, collection and/or inventory apis disabled!"); - } else { - int health = (int) stats.get("health"); - int defence = (int) stats.get("defence"); - int strength = (int) stats.get("strength"); - int intelligence = (int) stats.get("intelligence"); - - EnumChatFormatting healthPrefix = health > 800 - ? (health > 1600 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting defencePrefix = defence > 200 - ? (defence > 600 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting strengthPrefix = strength > 100 - ? (strength > 300 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - EnumChatFormatting intelligencePrefix = intelligence > 300 - ? (intelligence > 900 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) - : EnumChatFormatting.RED; - - Utils.addChatMessage( g + "Stats : " + healthPrefix + health + EnumChatFormatting.RED + "\u2764 " + - defencePrefix + defence + EnumChatFormatting.GREEN + "\u2748 " + - strengthPrefix + strength + EnumChatFormatting.RED + "\u2741 " + - intelligencePrefix + intelligence + EnumChatFormatting.AQUA + "\u270e "); - } - float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), -1); - float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); - - long networth; - if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { - ProfileViewer.Profile.SoopyNetworthData nwData = profile.getSoopyNetworth(null, () -> {}); - if (nwData == null) { - networth = -2l; - } else { - networth = nwData.getTotal(); - } - } else { - networth = profile.getNetWorth(null); - } - - float money = Math.max(bankBalance + purseBalance, networth); - EnumChatFormatting moneyPrefix = money > 50 * 1000 * 1000 ? - (money > 200 * 1000 * 1000 - ? EnumChatFormatting.GREEN - : EnumChatFormatting.YELLOW) : EnumChatFormatting.RED; - Utils.addChatMessage( g + "Purse: " + moneyPrefix + Utils.shortNumberFormat(purseBalance, 0) + g + " - Bank: " + - (bankBalance == -1 ? EnumChatFormatting.YELLOW + "N/A" : moneyPrefix + - (isMe ? "4.8b" : Utils.shortNumberFormat(bankBalance, 0))) + - (networth > 0 ? g + " - Net: " + moneyPrefix + Utils.shortNumberFormat(networth, 0) : "")); - - overallScore += Math.min(2, money / (100f * 1000 * 1000)); - - String activePet = Utils.getElementAsString( - Utils.getElement(profile.getPetsInfo(null), "active_pet.type"), - "None Active" - ); - String activePetTier = Utils.getElementAsString(Utils.getElement( - profile.getPetsInfo(null), - "active_pet.tier" - ), "UNKNOWN"); - - String col = NotEnoughUpdates.petRarityToColourMap.get(activePetTier); - if (col == null) col = EnumChatFormatting.LIGHT_PURPLE.toString(); - - Utils.addChatMessage(g + "Pet : " + col + WordUtils.capitalizeFully(activePet.replace("_", " "))); - - String overall = "Skywars Main"; - if (isMe) { - overall = Utils.chromaString("Literally the best player to exist"); // ego much - } else if (overallScore < 5 && (bankBalance + purseBalance) > 500 * 1000 * 1000) { - overall = EnumChatFormatting.GOLD + "Bill Gates"; - } else if (overallScore > 9) { - overall = Utils.chromaString("Didn't even think this score was possible"); - } else if (overallScore > 8) { - overall = Utils.chromaString("Mentally unstable"); - } else if (overallScore > 7) { - overall = EnumChatFormatting.GOLD + "Why though 0.0"; - } else if (overallScore > 5.5) { - overall = EnumChatFormatting.GOLD + "Bro stop playing"; - } else if (overallScore > 4) { - overall = EnumChatFormatting.GREEN + "Kinda sweaty"; - } else if (overallScore > 3) { - overall = EnumChatFormatting.YELLOW + "Alright I guess"; - } else if (overallScore > 2) { - overall = EnumChatFormatting.YELLOW + "Ender Non"; - } else if (overallScore > 1) { - overall = EnumChatFormatting.RED + "Played SkyBlock"; - } - - Utils.addChatMessage(g + "Overall score: " + overall + g + " (" + Math.round(overallScore * 10) / 10f + ")"); - - peekCommandExecutorService.shutdownNow(); - } else { - peekScheduledFuture = peekCommandExecutorService.schedule(this, 200, TimeUnit.MILLISECONDS); - } - } - }, 200, TimeUnit.MILLISECONDS); - } - }); - } - - @Override - public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - if (args.length != 1) return null; - - String lastArg = args[args.length - 1]; - List<String> playerMatches = new ArrayList<>(); - for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - String playerName = player.getName(); - if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { - playerMatches.add(playerName); - } - } - return playerMatches; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java deleted file mode 100644 index 2d5c05f4..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/PvCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import net.minecraft.client.Minecraft; -import net.minecraft.command.ICommandSender; -import org.apache.commons.lang3.StringUtils; - -public class PvCommand extends ViewProfileCommand { - - public PvCommand() { - super("pv"); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - if (!NotEnoughUpdates.INSTANCE.isOnSkyblock()) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/pv " + StringUtils.join(args, " ")); - } else { - super.processCommand(sender, args); - } - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java deleted file mode 100644 index 26468e39..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/profile/ViewProfileCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. - */ - -package io.github.moulberry.notenoughupdates.commands.profile; - -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - -public class ViewProfileCommand extends ClientCommandBase { - - public static final Consumer<String[]> RUNNABLE = (args) -> { - if (!OpenGlHelper.isFramebufferEnabled()) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Some parts of the profile viewer do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it."); - - } - if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || - NotEnoughUpdates.INSTANCE.config.apiData.apiKey.trim().isEmpty()) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Can't view profile, an API key is not set. Run /api new and put the result in settings."); - } else if (args.length == 0) { - NotEnoughUpdates.profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { - if (profile == null) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Invalid player name/API key. Maybe the API is down? Try /api new."); - } else { - profile.resetCache(); - NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); - } - }); - } else if (args.length > 1) { - Utils.addChatMessage(EnumChatFormatting.RED + - "Too many arguments. Usage: /neuprofile [name]"); - } else { - NotEnoughUpdates.profileViewer.getProfileByName(args[0], profile -> { - if (profile == null) { - Utils.addChatMessage(EnumChatFormatting.RED + "Invalid player name/api key. Maybe the API is down? Try /api new."); - } else { - profile.resetCache(); - NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); - } - }); - } - }; - - public ViewProfileCommand() { - this("neuprofile"); - } - - public ViewProfileCommand(String name) { - super(name); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - RUNNABLE.accept(args); - } - - @Override - public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - if (args.length != 1) return null; - - String lastArg = args[args.length - 1]; - List<String> playerMatches = new ArrayList<>(); - for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - String playerName = player.getName(); - if (playerName.toLowerCase().startsWith(lastArg.toLowerCase())) { - playerMatches.add(playerName); - } - } - return playerMatches; - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index f15a26a7..5da0f24b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -26,7 +26,6 @@ import io.github.moulberry.notenoughupdates.NEUApi; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.auction.CustomAHGui; -import io.github.moulberry.notenoughupdates.commands.profile.ViewProfileCommand; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; @@ -1052,7 +1051,14 @@ public class RenderListener { if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String username = tag.getCompoundTag("SkullOwner").getString("Name"); Utils.playPressSound(); - ViewProfileCommand.RUNNABLE.accept(new String[]{username}); + NotEnoughUpdates.profileViewer.getProfileByName(username, profile -> { + if (profile == null) { + Utils.addChatMessage("${RED}Invalid player name/API key. Maybe the API is down? Try /api new."); + } else { + profile.resetCache(); + NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile); + } + }); } } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt new file mode 100644 index 00000000..8c15eee0 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/AhCommand.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.auction.CustomAHGui +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.RestArgumentType +import io.github.moulberry.notenoughupdates.util.brigadier.get +import io.github.moulberry.notenoughupdates.util.brigadier.reply +import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.function.Predicate + +@NEUAutoSubscribe +class AhCommand { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + val hook = event.command("neuah") { + + thenArgumentExecute("search", RestArgumentType) { search -> + if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey == null || + NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isBlank() + ) { + reply("${RED}Can't open NEU AH: an api key is not set. Run /api new and put the result in settings.") + return@thenArgumentExecute + } + NotEnoughUpdates.INSTANCE.openGui = CustomAHGui() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.lastOpen = System.currentTimeMillis() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.clearSearch() + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.updateSearch() + + val search = this[search] + + NotEnoughUpdates.INSTANCE.manager.auctionManager.customAH.setSearch( + if (search.isBlank() && NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.saveLastSearch) + null else search + ) + + } + } + hook.beforeCommand = Predicate { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) + Utils.addChatMessage("${RED}You must be on SkyBlock to use this feature.") + NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() + } + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt index 514f7be0..3b721df5 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/DungeonCommands.kt @@ -52,7 +52,7 @@ class DungeonCommands { }.withHelp("Warps to the dungeon nuts") event.command("join") { thenArgument("floor", string()) { floor -> - suggests((1..7).flatMap { listOf("f$it", "m$it") }) + suggestsList((1..7).flatMap { listOf("f$it", "m$it") }) thenExecute { val floor = this[floor] val prefix = if (floor.startsWith("m")) "master_catacombs" else "catacombs" @@ -110,8 +110,8 @@ class DungeonCommands { reply("${RED}Failed to save.") } } - } - }.withHelp("Save a colour map from an item") + }.withHelp("Save a colour map from an item") + } thenLiteral("load") { thenArgument("filename", string()) { fileName -> requiresDev() @@ -134,8 +134,8 @@ class DungeonCommands { } reply("Loaded colour map from file") } - } - }.withHelp("Load a colour map from a file") + }.withHelp("Load a colour map from a file") + } thenExecute { NotEnoughUpdates.INSTANCE.openGui = GuiDungeonMapEditor(null) } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt new file mode 100644 index 00000000..a21e39b8 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/MiscCommands.kt @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NEUManager +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay +import io.github.moulberry.notenoughupdates.miscgui.GuiItemCustomize +import io.github.moulberry.notenoughupdates.util.Calculator +import io.github.moulberry.notenoughupdates.util.Calculator.CalculatorException +import io.github.moulberry.notenoughupdates.util.MinecraftExecutor +import io.github.moulberry.notenoughupdates.util.PronounDB +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.text.DecimalFormat +import java.util.* +import java.util.concurrent.CompletableFuture + +@NEUAutoSubscribe +class MiscCommands { + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("neucalc", "neucalculator") { + thenArgumentExecute("calculation", RestArgumentType) { calculation -> + val calculation = this[calculation] + try { + val calculate = Calculator.calculate(calculation) + val formatter = DecimalFormat("#,##0.##") + val formatted = formatter.format(calculate) + reply("$WHITE$calculation $YELLOW= $GREEN$formatted") + } catch (e: CalculatorException) { + reply( + "${RED}Error during calculation: ${e.message}\n${WHITE}${calculation.substring(0, e.offset)}" + + "${DARK_RED}${calculation.substring(e.offset, e.length + e.offset)}${GRAY}" + + calculation.substring(e.length + e.offset) + ) + } + }.withHelp("Calculate an expression") + thenExecute { + reply( + "§5It's a calculator.\n" + + "§eFor Example §b/neucalc 3m*7k§e.\n" + + "§eYou can also use suffixes (k, m, b, t, s)§e.\n" + + "§eThe \"s\" suffix acts as 64.\n" + + "§eTurn on Sign Calculator in /neu misc to also support this in sign popups and the neu search bar." + ) + } + }.withHelp("Display help for NEUs calculator") + event.command("neucalendar") { + thenExecute { + Minecraft.getMinecraft().thePlayer.closeScreen() + CalendarOverlay.setEnabled(true) + NotEnoughUpdates.INSTANCE.sendChatMessage("/calendar") + } + }.withHelp("Display NEUs custom calendar overlay") + event.command("neucosmetics") { + thenExecute { + if (!OpenGlHelper.isFramebufferEnabled() && NotEnoughUpdates.INSTANCE.config.notifications.doFastRenderNotif) { + reply( + "${RED}NEU Cosmetics do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it." + ) + } + NotEnoughUpdates.INSTANCE.openGui = GuiCosmetics() + } + }.withHelp("Equip NEU cosmetics") + event.command("neucustomize", "neurename") { + thenExecute { + val held = Minecraft.getMinecraft().thePlayer.heldItem + if (held == null) { + reply("${RED}You can't customize your hand...") + return@thenExecute + } + val heldUUID = NEUManager.getUUIDForItem(held) + if (heldUUID == null) { + reply("${RED}This item does not have an UUID, so it cannot be customized.") + return@thenExecute + } + + NotEnoughUpdates.INSTANCE.openGui = GuiItemCustomize(held, heldUUID) + } + }.withHelp("Customize your items") + event.command("neupronouns", "neuliberals") { + thenArgument("platform", string()) { platform -> + suggestsList(listOf("minecraft", "discord", "twitch", "twitter", "github")) + thenArgumentExecute("user", string()) { user -> + fetchPronouns(this[platform], this[user]) + }.withHelp("Look up someones pronouns using their username on a platform") + } + thenArgumentExecute("user", string()) { user -> + fetchPronouns("minecraft", this[user]) + }.withHelp("Look up someones pronouns using their minecraft username") + } + event.command("neuupdate", "neuupdates", "enoughupdates") { + thenLiteralExecute("check") { + NotEnoughUpdates.INSTANCE.autoUpdater.displayUpdateMessageIfOutOfDate() + }.withHelp("Check for updates") + thenLiteralExecute("scheduledownload") { + NotEnoughUpdates.INSTANCE.autoUpdater.scheduleDownload() + }.withHelp("Queue a new version of NEU to be downloaded") + thenLiteralExecute("updatemodes") { + reply("§bTo ensure we do not accidentally corrupt your mod folder, we can only offer support for auto-updates on system with certain capabilities for file deletions (specifically unix systems). You can still manually update your files") + }.withHelp("Display an explanation why you cannot auto update") + } + } + + fun fetchPronouns(platform: String, user: String) { + val nc = Minecraft.getMinecraft().ingameGUI.chatGUI + val id = Random().nextInt() + nc.printChatMessageWithOptionalDeletion(ChatComponentText("§e[NEU] Fetching Pronouns..."), id) + + val pronouns = if ("minecraft" == platform) { + val c = CompletableFuture<UUID>() + NotEnoughUpdates.profileViewer.getPlayerUUID(user) { uuidString -> + if (uuidString == null) { + c.completeExceptionally(NullPointerException()) + } else { + c.complete(Utils.parseDashlessUUID(uuidString)) + } + } + c.thenCompose { minecraftPlayer -> + PronounDB.getPronounsFor(minecraftPlayer) + } + } else { + PronounDB.getPronounsFor(platform, user) + } + pronouns.handleAsync({ pronounChoice, throwable -> + if (throwable != null || !pronounChoice.isPresent) { + nc.printChatMessageWithOptionalDeletion(ChatComponentText("§e[NEU] §4Failed to fetch pronouns."), id) + return@handleAsync null + } + val betterPronounChoice = pronounChoice.get() + nc.printChatMessageWithOptionalDeletion( + ChatComponentText("§e[NEU] Pronouns for §b$user §eon §b$platform§e:"), id + ) + betterPronounChoice.render().forEach { + nc.printChatMessage(ChatComponentText("§e[NEU] §a$it")) + } + null + }, MinecraftExecutor.INSTANCE) + + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt new file mode 100644 index 00000000..61fa6029 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/PeekCommand.kt @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.util.ChatComponentText +import net.minecraft.util.EnumChatFormatting.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.apache.commons.lang3.text.WordUtils +import java.util.* +import java.util.concurrent.* + +@NEUAutoSubscribe +class PeekCommand { + + var future: Future<*>? = null + val executor = Executors.newScheduledThreadPool(1) + + fun executePeek(name: String) { + val chatGui = Minecraft.getMinecraft().ingameGUI.chatGUI + val id = Random().nextInt(Int.MAX_VALUE / 2) + Int.MAX_VALUE / 2 + fun deleteReply(text: String) { + chatGui.printChatMessageWithOptionalDeletion(ChatComponentText(text), id) + } + + deleteReply("$YELLOW[PEEK] Getting player information...") + + + NotEnoughUpdates.profileViewer.getProfileByName( + name + ) { profile: ProfileViewer.Profile? -> + if (profile == null) { + deleteReply("$RED[PEEK] Unknown player or the Hypixel API is down.") + } else { + profile.resetCache() + if (future?.isDone != true) { + Utils.addChatMessage( + "$RED[PEEK] New peek command was run, cancelling old one." + ) + future?.cancel(true) + } + deleteReply("$YELLOW[PEEK] Getting the player's SkyBlock profile(s)...") + val startTime = System.currentTimeMillis() + future = ForkJoinPool.commonPool().submit(object : Runnable { + override fun run() { + if (System.currentTimeMillis() - startTime > 10 * 1000) { + deleteReply("$RED[PEEK] Getting profile info took too long, aborting.") + return + } + val g = GRAY.toString() + val profileInfo = profile.getProfileInformation(null) + if (profileInfo == null) { + future = executor.schedule(this, 200, TimeUnit.MILLISECONDS) + return + } + var overallScore = 0f + val isMe = name.equals("moulberry", ignoreCase = true) + val stats = profile.getStats(null) + if (stats == null) { + future = executor.schedule(this, 200, TimeUnit.MILLISECONDS) + return + } + val skyblockInfo = profile.getSkyblockInfo(null) + if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { + deleteReply("$YELLOW[PEEK] Getting the player's Skyblock networth...") + val countDownLatch = CountDownLatch(1) + profile.getSoopyNetworth(null, Runnable { countDownLatch.countDown() }) + try { //Wait for async network request + countDownLatch.await(10, TimeUnit.SECONDS) + } catch (e: InterruptedException) { + } + + //Now it's waited for network request the data should be cached (accessed in nw section) + } + deleteReply( + "$GREEN $STRIKETHROUGH-=-$RESET$GREEN ${ + Utils.getElementAsString( + profile.hypixelProfile!!["displayname"], + name + ) + }'s Info $STRIKETHROUGH-=-" + ) + if (skyblockInfo == null) { + Utils.addChatMessage(YELLOW.toString() + "Skills API disabled!") + } else { + var totalSkillLVL = 0f + var totalSkillCount = 0f + val skills: List<String> = + mutableListOf( + "taming", + "mining", + "foraging", + "enchanting", + "farming", + "combat", + "fishing", + "alchemy", + "carpentry" + ) + for (skillName in skills) { + totalSkillLVL += skyblockInfo[skillName]!!.level + totalSkillCount++ + } + var combat = skyblockInfo["combat"]!!.level + var zombie = skyblockInfo["zombie"]!!.level + var spider = skyblockInfo["spider"]!!.level + var wolf = skyblockInfo["wolf"]!!.level + var enderman = skyblockInfo["enderman"]!!.level + var blaze = skyblockInfo["blaze"]!!.level + var avgSkillLVL = totalSkillLVL / totalSkillCount + if (isMe) { + avgSkillLVL = 6f + combat = 4f + zombie = 2f + spider = 1f + wolf = 2f + enderman = 0f + blaze = 0f + } + val combatPrefix = + if (combat > 20) (if (combat > 35) GREEN else YELLOW) else RED + val zombiePrefix = + if (zombie > 3) (if (zombie > 6) GREEN else YELLOW) else RED + val spiderPrefix = + if (spider > 3) (if (spider > 6) GREEN else YELLOW) else RED + val wolfPrefix = + if (wolf > 3) (if (wolf > 6) GREEN else YELLOW) else RED + val endermanPrefix = + if (enderman > 3) (if (enderman > 6) GREEN else YELLOW) else RED + val blazePrefix = + if (blaze > 3) (if (blaze > 6) GREEN else YELLOW) else RED + val avgPrefix = + if (avgSkillLVL > 20) (if (avgSkillLVL > 35) GREEN else YELLOW) else RED + overallScore += zombie * zombie / 81f + overallScore += spider * spider / 81f + overallScore += wolf * wolf / 81f + overallScore += enderman * enderman / 81f + overallScore += blaze * blaze / 81f + overallScore += avgSkillLVL / 20f + val cata = skyblockInfo["catacombs"]!!.level.toInt() + val cataPrefix = + if (cata > 15) (if (cata > 25) GREEN else YELLOW) else RED + overallScore += cata * cata / 2000f + Utils.addChatMessage( + g + "Combat: " + combatPrefix + Math.floor(combat.toDouble()) + .toInt() + + (if (cata > 0) "$g - Cata: $cataPrefix$cata" else "") + + g + " - AVG: " + avgPrefix + Math.floor(avgSkillLVL.toDouble()) + .toInt() + ) + Utils.addChatMessage( + g + "Slayer: " + zombiePrefix + Math.floor(zombie.toDouble()) + .toInt() + g + "-" + + spiderPrefix + Math.floor(spider.toDouble()) + .toInt() + g + "-" + + wolfPrefix + Math.floor(wolf.toDouble()).toInt() + g + "-" + + endermanPrefix + Math.floor(enderman.toDouble()) + .toInt() + g + "-" + + blazePrefix + Math.floor(blaze.toDouble()).toInt() + ) + } + val health = stats["health"].toInt() + val defence = stats["defence"].toInt() + val strength = stats["strength"].toInt() + val intelligence = stats["intelligence"].toInt() + val healthPrefix = + if (health > 800) (if (health > 1600) GREEN else YELLOW) else RED + val defencePrefix = + if (defence > 200) (if (defence > 600) GREEN else YELLOW) else RED + val strengthPrefix = + if (strength > 100) (if (strength > 300) GREEN else YELLOW) else RED + val intelligencePrefix = + if (intelligence > 300) (if (intelligence > 900) GREEN else YELLOW) else RED + Utils.addChatMessage( + g + "Stats : " + healthPrefix + health + RED + "\u2764 " + + defencePrefix + defence + GREEN + "\u2748 " + + strengthPrefix + strength + RED + "\u2741 " + + intelligencePrefix + intelligence + AQUA + "\u270e " + ) + val bankBalance = + Utils.getElementAsFloat( + Utils.getElement( + profileInfo, + "banking.balance" + ), -1f + ) + val purseBalance = + Utils.getElementAsFloat( + Utils.getElement( + profileInfo, + "coin_purse" + ), 0f + ) + val networth = if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth) { + val nwData = + profile.getSoopyNetworth(null, Runnable {}) + nwData?.total ?: -2L + } else { + profile.getNetWorth(null) + } + val money = + Math.max(bankBalance + purseBalance, networth.toFloat()) + val moneyPrefix = + if (money > 50 * 1000 * 1000) (if (money > 200 * 1000 * 1000) GREEN else YELLOW) else RED + Utils.addChatMessage( + g + "Purse: " + moneyPrefix + Utils.shortNumberFormat( + purseBalance.toDouble(), + 0 + ) + g + " - Bank: " + + (if (bankBalance == -1f) YELLOW.toString() + "N/A" else moneyPrefix.toString() + + if (isMe) "4.8b" else Utils.shortNumberFormat( + bankBalance.toDouble(), + 0 + )) + + if (networth > 0) "$g - Net: $moneyPrefix" + Utils.shortNumberFormat( + networth.toDouble(), + 0 + ) else "" + ) + overallScore += Math.min(2f, money / (100f * 1000 * 1000)) + val activePet = + Utils.getElementAsString( + Utils.getElement( + profile.getPetsInfo( + null + ), "active_pet.type" + ), + "None Active" + ) + val activePetTier = + Utils.getElementAsString( + Utils.getElement( + profile.getPetsInfo(null), + "active_pet.tier" + ), "UNKNOWN" + ) + var col = NotEnoughUpdates.petRarityToColourMap[activePetTier] + if (col == null) col = LIGHT_PURPLE.toString() + Utils.addChatMessage( + g + "Pet : " + col + WordUtils.capitalizeFully( + activePet.replace("_", " ") + ) + ) + var overall = "Skywars Main" + if (isMe) { + overall = + Utils.chromaString("Literally the best player to exist") // ego much + } else if (overallScore < 5 && bankBalance + purseBalance > 500 * 1000 * 1000) { + overall = GOLD.toString() + "Bill Gates" + } else if (overallScore > 9) { + overall = + Utils.chromaString("Didn't even think this score was possible") + } else if (overallScore > 8) { + overall = + Utils.chromaString("Mentally unstable") + } else if (overallScore > 7) { + overall = GOLD.toString() + "Why though 0.0" + } else if (overallScore > 5.5) { + overall = GOLD.toString() + "Bro stop playing" + } else if (overallScore > 4) { + overall = GREEN.toString() + "Kinda sweaty" + } else if (overallScore > 3) { + overall = YELLOW.toString() + "Alright I guess" + } else if (overallScore > 2) { + overall = YELLOW.toString() + "Ender Non" + } else if (overallScore > 1) { + overall = RED.toString() + "Played SkyBlock" + } + Utils.addChatMessage( + g + "Overall score: " + overall + g + " (" + Math.round( + overallScore * 10 + ) / 10f + ")" + ) + } + }) + } + } + } + + @SubscribeEvent + fun onCommand(event: RegisterBrigadierCommandEvent) { + event.command("peek") { + thenArgument("player", string()) { player -> + suggestsList { Minecraft.getMinecraft().theWorld.playerEntities.map { it.name } } + thenExecute { + executePeek(this[player]) + } + }.withHelp("Quickly glance at other peoples stats") + thenExecute { + executePeek(Minecraft.getMinecraft().thePlayer.name) + } + }.withHelp("Quickly glance at your own stats") + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt new file mode 100644 index 00000000..8a2763f7 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/ProfileViewerCommands.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.arguments.StringArgumentType.string +import com.mojang.brigadier.context.CommandContext +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.command.ICommandSender +import net.minecraft.util.EnumChatFormatting.RED +import net.minecraftforge.fml.common.Loader +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class ProfileViewerCommands { + companion object { + fun CommandContext<ICommandSender>.openPv(name: String) { + if (!OpenGlHelper.isFramebufferEnabled()) { + reply("${RED}Some parts of the profile viewer do not work with OptiFine Fast Render. Go to ESC > Options > Video Settings > Performance > Fast Render to disable it.") + } + + if (NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isNullOrBlank()) { + reply("${RED}Can't view profile, an API key is not set. Run /api new and put the result in settings.") + return + } + + NotEnoughUpdates.profileViewer.getProfileByName(name) { profile -> + if (profile == null) { + reply("${RED}Invalid player name/API key. Maybe the API is down? Try /api new.") + } else { + profile.resetCache() + NotEnoughUpdates.INSTANCE.openGui = GuiProfileViewer(profile) + } + } + } + } + + + @SubscribeEvent + fun onCommand(event: RegisterBrigadierCommandEvent) { + fun pvCommand(name: String, before: () -> Unit) { + event.command(name) { + thenExecute { + before() + openPv(Minecraft.getMinecraft().thePlayer.name) + } + thenArgument("player", string()) { player -> + suggestsList { Minecraft.getMinecraft().theWorld.playerEntities.map { it.name } } + thenExecute { + before() + openPv(this[player]) + } + }.withHelp("Open the profile viewer for a player") + }.withHelp("Open the profile viewer for yourself") + } + pvCommand("pv") {} + pvCommand("neuprofile") {} + if (!Loader.isModLoaded("skyblockextras")) + pvCommand("cata") { + GuiProfileViewer.currentPage = GuiProfileViewer.ProfileViewerPage.DUNGEON + } + + + } +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt index 1b840a07..17203a4b 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt @@ -80,15 +80,11 @@ data class TypeSafeArg<T : Any>(val name: String, val argument: ArgumentType<T>) } fun <T : ICommandSender, C : CommandContext<T>> C.reply(component: IChatComponent) { - source.addChatMessage(component) + source.addChatMessage(ChatComponentText("§e[NEU] ").appendSibling(component)) } -fun <T : ICommandSender, C : CommandContext<T>> C.reply(text: String) { - source.addChatMessage(ChatComponentText(text)) -} - -fun <T : ICommandSender, C : CommandContext<T>> C.reply(text: String, block: ChatComponentText.() -> Unit) { - source.addChatMessage(ChatComponentText(text).also(block)) +fun <T : ICommandSender, C : CommandContext<T>> C.reply(text: String, block: ChatComponentText.() -> Unit = {}) { + source.addChatMessage(ChatComponentText(text.split("\n").joinToString("\n") { "§e[NEU] $it" }).also(block)) } operator fun <T : Any, C : CommandContext<*>> C.get(arg: TypeSafeArg<T>): T { @@ -167,9 +163,13 @@ fun <T : CommandNode<DefaultSource>> T.withHelp(helpText: String): T { return this } -fun <A : Any, T : RequiredArgumentBuilder<DefaultSource, A>> T.suggests(list: List<String>) { +fun <A : Any, T : RequiredArgumentBuilder<DefaultSource, A>> T.suggestsList(list: List<String>) { + suggestsList { list } +} + +fun <A : Any, T : RequiredArgumentBuilder<DefaultSource, A>> T.suggestsList(list: () -> List<String>) { suggests { context, builder -> - list.filter { it.startsWith(builder.remaining, ignoreCase = true) } + list().filter { it.startsWith(builder.remaining, ignoreCase = true) } .forEach { builder.suggest(it) } builder.buildFuture() } |