From a112193704fce1dc704aa58a51fdf30f55f32a9c Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Sat, 28 May 2022 23:11:16 +0700 Subject: migrate OneConfigCommand to new command util make classes that end with `_Test` be excluded from non-sourcejar jars javadoc some more stuff --- .../java/cc/polyfrost/oneconfig/OneConfig.java | 18 +++--- .../oneconfig/command/OneConfigCommand.java | 69 ++++++++-------------- .../cc/polyfrost/oneconfig/init/OneConfigInit.java | 5 ++ .../cc/polyfrost/oneconfig/test/TestCommand.java | 39 ------------ .../polyfrost/oneconfig/test/TestCommand_Test.java | 39 ++++++++++++ .../cc/polyfrost/oneconfig/test/TestNanoVGGui.java | 27 --------- .../oneconfig/test/TestNanoVGGui_Test.java | 27 +++++++++ .../cc/polyfrost/oneconfig/test/package-info.java | 5 ++ .../utils/commands/annotations/Command.java | 2 +- 9 files changed, 109 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/test/package-info.java (limited to 'src/main/java/cc') diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java index c1301d3..6f579a3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java @@ -11,12 +11,10 @@ import cc.polyfrost.oneconfig.lwjgl.BlurHandler; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; -import cc.polyfrost.oneconfig.test.TestCommand; import cc.polyfrost.oneconfig.test.TestConfig; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; import net.minecraft.launchwrapper.Launch; -import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.fml.common.DummyModContainer; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; @@ -27,24 +25,23 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; +/** + * The main class of OneConfig. + */ @net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") public class OneConfig { - public static File jarFile; - public static File oneConfigDir = new File("./OneConfig"); - public static File themesDir = new File(oneConfigDir, "themes"); + public static final File oneConfigDir = new File("./OneConfig"); public static OneConfigConfig config; public static TestConfig testConfig; - public static List loadedMods = new ArrayList<>(); - public static List loadedOtherMods = new ArrayList<>(); + public static final List loadedMods = new ArrayList<>(); + public static final List loadedOtherMods = new ArrayList<>(); @net.minecraftforge.fml.common.Mod.EventHandler public void onPreFMLInit(net.minecraftforge.fml.common.event.FMLPreInitializationEvent event) { if (!Launch.blackboard.containsKey("oneconfig.initialized")) { throw new RuntimeException("OneConfig has not been initialized! Please add the OneConfig tweaker or call OneConfigInit via an ITweaker or a FMLLoadingPlugin!"); } - jarFile = event.getSourceFile(); oneConfigDir.mkdirs(); - themesDir.mkdirs(); config = new OneConfigConfig(); } @@ -52,8 +49,7 @@ public class OneConfig { public void onFMLInitialization(net.minecraftforge.fml.common.event.FMLInitializationEvent event) { BlurHandler.INSTANCE.load(); testConfig = new TestConfig(); - CommandManager.registerCommand(new TestCommand()); - ClientCommandHandler.instance.registerCommand(new OneConfigCommand()); + CommandManager.registerCommand(new OneConfigCommand()); EventManager.INSTANCE.register(new HudCore()); EventManager.INSTANCE.register(HypixelUtils.INSTANCE); RenderManager.setupAndDraw((vg) -> { diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java index 0743b54..ab2c403 100644 --- a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java @@ -2,54 +2,35 @@ package cc.polyfrost.oneconfig.command; import cc.polyfrost.oneconfig.gui.HudGui; import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.test.TestNanoVGGui; import cc.polyfrost.oneconfig.utils.GuiUtils; -import net.minecraft.command.CommandBase; -import net.minecraft.command.ICommandSender; - -import java.util.ArrayList; -import java.util.List; - -public class OneConfigCommand extends CommandBase { - - @Override - public String getCommandName() { - return "oneconfig"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "oneconfig <>"; - } - - @Override - public List getCommandAliases() { - return new ArrayList() {{ - add("oneconfig"); - add("ocfg"); - }}; +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Main; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; + +/** + * The main OneConfig command. + */ +@Command(value = "oneconfig", aliases = {"ocfg", "oneconfig"}, description = "Access the OneConfig GUI.") +public class OneConfigCommand { + + @Main + private static void main() { + GuiUtils.displayScreen(OneConfigGui.create()); } - @Override - public void processCommand(ICommandSender sender, String[] args) { - if (args.length == 0) GuiUtils.displayScreen(OneConfigGui.create()); - else { - switch (args[0]) { - case "hud": - GuiUtils.displayScreen(new HudGui()); - break; - case "lwjgl": - GuiUtils.displayScreen(new TestNanoVGGui()); - break; - case "destroy": - OneConfigGui.instanceToRestore = null; - break; - } + @SubCommand(value = "hud", description = "Open the OneConfig HUD config.") + private static class HUDSubCommand { + @Main + private static void main() { + GuiUtils.displayScreen(new HudGui()); } } - @Override - public int getRequiredPermissionLevel() { - return -1; + @SubCommand(value = "destory", description = "Destroy the cached OneConfig GUI.") + private static class DestroySubCommand { + @Main + private static void main() { + OneConfigGui.instanceToRestore = null; + } } -} +} \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java index 33b13d5..6e0bab3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java +++ b/src/main/java/cc/polyfrost/oneconfig/init/OneConfigInit.java @@ -10,6 +10,11 @@ import org.spongepowered.asm.mixin.Mixins; */ @SuppressWarnings("unused") public class OneConfigInit { + + /** + * Initializes the OneConfig mod. + * @param args The arguments passed to the mod. + */ public static void initialize(String[] args) { Launch.blackboard.put("oneconfig.initialized", true); MixinBootstrap.init(); diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java deleted file mode 100644 index 753c353..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.polyfrost.oneconfig.test; - -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.Name; -import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; - -@Command(value = "test", aliases = {"t"}) -public class TestCommand { - - @Main - private static void main() { // /test - UChat.chat("Main command"); - } - - @SubCommand(value = "subcommand", aliases = {"s"}) - private static class TestSubCommand { - - @Main(priority = 999) - private static void main(int a, float b, @Name("named c") String c) { // /test subcommand - UChat.chat("Integer main: " + a + " " + b + " " + c); - } - - @Main(priority = 10001) - private static void main(double a, double b, @Name("named c") String c) { // /test subcommand - UChat.chat("Double main: " + a + " " + b + " " + c); - } - - @SubCommand(value = "subsubcommand", aliases = {"ss"}) - private static class TestSubSubCommand { - - @Main - private static void main(String a, String b, @Name("named c") String c) { // /test subcommand subsubcommand - UChat.chat(a + " " + b + " " + c); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java new file mode 100644 index 0000000..d8c37f0 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java @@ -0,0 +1,39 @@ +package cc.polyfrost.oneconfig.test; + +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.Name; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; + +@Command(value = "test", aliases = {"t"}) +public class TestCommand_Test { + + @Main + private static void main() { // /test + UChat.chat("Main command"); + } + + @SubCommand(value = "subcommand", aliases = {"s"}) + private static class TestSubCommand { + + @Main(priority = 999) + private static void main(int a, float b, @Name("named c") String c) { // /test subcommand + UChat.chat("Integer main: " + a + " " + b + " " + c); + } + + @Main(priority = 10001) + private static void main(double a, double b, @Name("named c") String c) { // /test subcommand + UChat.chat("Double main: " + a + " " + b + " " + c); + } + + @SubCommand(value = "subsubcommand", aliases = {"ss"}) + private static class TestSubSubCommand { + + @Main + private static void main(String a, String b, @Name("named c") String c) { // /test subcommand subsubcommand + UChat.chat(a + " " + b + " " + c); + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java deleted file mode 100644 index b309429..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.polyfrost.oneconfig.test; - -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UScreen; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import org.jetbrains.annotations.NotNull; - -import java.awt.*; - -public class TestNanoVGGui extends UScreen { - - @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); - drawRect(0, 0, width, height, Color.BLACK.getRGB()); - long startTime = System.nanoTime(); - RenderManager.setupAndDraw((vg) -> { - RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB()); - RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8); - RenderManager.drawString(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.BOLD); - RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB()); - RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB()); - RenderManager.drawString(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.BOLD); - }); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java new file mode 100644 index 0000000..614d138 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java @@ -0,0 +1,27 @@ +package cc.polyfrost.oneconfig.test; + +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public class TestNanoVGGui_Test extends UScreen { + + @Override + public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); + drawRect(0, 0, width, height, Color.BLACK.getRGB()); + long startTime = System.nanoTime(); + RenderManager.setupAndDraw((vg) -> { + RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB()); + RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8); + RenderManager.drawString(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.BOLD); + RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB()); + RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB()); + RenderManager.drawString(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.BOLD); + }); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/test/package-info.java b/src/main/java/cc/polyfrost/oneconfig/test/package-info.java new file mode 100644 index 0000000..ef38b37 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/test/package-info.java @@ -0,0 +1,5 @@ +/** + * Test package for the OneConfig library. + * Classes in this package that end with {@code _Test} are excluded from actual builds. + */ +package cc.polyfrost.oneconfig.test; \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java index 7717d46..b1a4ce5 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java @@ -80,7 +80,7 @@ import java.lang.annotation.Target; * Note: if you're viewing this in IntelliJ or just see the @literal tag everywhere, please ignore that. *

* - * @see cc.polyfrost.oneconfig.test.TestCommand + * @see cc.polyfrost.oneconfig.command.OneConfigCommand * @see Main * @see CommandManager */ -- cgit