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
---
build.gradle.kts | 5 ++
.../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 +-
10 files changed, 114 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
diff --git a/build.gradle.kts b/build.gradle.kts
index 27245ec..4cb1101 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -213,6 +213,10 @@ tasks {
exclude("mcmod.info")
}
}
+ if (!name.contains("sourcesjar", ignoreCase = true) || !name.contains("dokka", ignoreCase = true)) {
+ exclude("**/**_Test.**")
+ exclude("**/**_Test$**.**")
+ }
}
named("shadowJar") {
archiveClassifier.set("dev")
@@ -246,6 +250,7 @@ tasks {
dokkaSourceSets {
configureEach {
jdkVersion.set(8)
+ //reportUndocumented.set(true)
}
}
doLast {
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
From ce370c8e2768383b57212fccd4018f92f88b8847 Mon Sep 17 00:00:00 2001
From: Wyvest <45589059+Wyvest@users.noreply.github.com>
Date: Sat, 28 May 2022 23:49:16 +0700
Subject: static abuse
---
.../java/cc/polyfrost/oneconfig/OneConfig.java | 2 +-
.../oneconfig/utils/commands/CommandManager.java | 43 +++++++++++-----------
2 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
index 6f579a3..1efa8ef 100644
--- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java
@@ -49,7 +49,7 @@ public class OneConfig {
public void onFMLInitialization(net.minecraftforge.fml.common.event.FMLInitializationEvent event) {
BlurHandler.INSTANCE.load();
testConfig = new TestConfig();
- CommandManager.registerCommand(new OneConfigCommand());
+ CommandManager.INSTANCE.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/utils/commands/CommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java
index a4e2569..f168b8f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java
@@ -21,17 +21,30 @@ import java.util.stream.Collectors;
* @see Command
*/
public class CommandManager {
- private static final HashMap, ArgumentParser>> parsers = new HashMap<>();
+ public static final CommandManager INSTANCE = new CommandManager();
+ private final HashMap, ArgumentParser>> parsers = new HashMap<>();
private static final String NOT_FOUND_TEXT = "Command not found! Type /@ROOT_COMMAND@ help for help.";
private static final String METHOD_RUN_ERROR = "Error while running @ROOT_COMMAND@ method! Please report this to the developer.";
+ private CommandManager() {
+ addParser(new StringParser());
+ addParser(new IntegerParser());
+ addParser(new IntegerParser(), int.class);
+ addParser(new DoubleParser());
+ addParser(new DoubleParser(), double.class);
+ addParser(new FloatParser());
+ addParser(new FloatParser(), float.class);
+ addParser(new BooleanParser());
+ addParser(new BooleanParser(), boolean.class);
+ }
+
/**
* Adds a parser to the parsers map.
*
* @param parser The parser to add.
* @param clazz The class of the parser.
*/
- public static void addParser(ArgumentParser> parser, Class> clazz) {
+ public void addParser(ArgumentParser> parser, Class> clazz) {
parsers.put(clazz, parser);
}
@@ -39,28 +52,16 @@ public class CommandManager {
* Adds a parser to the parsers map.
* @param parser The parser to add.
*/
- public static void addParser(ArgumentParser> parser) {
+ public void addParser(ArgumentParser> parser) {
addParser(parser, parser.typeClass);
}
- static {
- addParser(new StringParser());
- addParser(new IntegerParser());
- addParser(new IntegerParser(), int.class);
- addParser(new DoubleParser());
- addParser(new DoubleParser(), double.class);
- addParser(new FloatParser());
- addParser(new FloatParser(), float.class);
- addParser(new BooleanParser());
- addParser(new BooleanParser(), boolean.class);
- }
-
/**
* Registers the provided command.
*
* @param command The command to register.
*/
- public static void registerCommand(Object command) {
+ public void registerCommand(Object command) {
Class> clazz = command.getClass();
if (clazz.isAnnotationPresent(Command.class)) {
final Command annotation = clazz.getAnnotation(Command.class);
@@ -122,7 +123,7 @@ public class CommandManager {
}
}
- private static String sendHelpCommand(InternalCommand root) {
+ private String sendHelpCommand(InternalCommand root) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.GOLD.toString() + "Help for " + ChatColor.BOLD + root.name + ChatColor.RESET + ChatColor.GOLD + ":\n");
builder.append("\n");
@@ -139,7 +140,7 @@ public class CommandManager {
return builder.toString();
}
- private static void runThroughCommandsHelp(String append, InternalCommand command, StringBuilder builder) {
+ private void runThroughCommandsHelp(String append, InternalCommand command, StringBuilder builder) {
for (InternalCommand.InternalCommandInvoker invoker : command.invokers) {
builder.append("\n" + ChatColor.GOLD + "/" + append + " " + command.name);
for (Parameter parameter : invoker.method.getParameters()) {
@@ -158,7 +159,7 @@ public class CommandManager {
}
}
- private static String runThroughCommands(InternalCommand command, int layer, String[] args) {
+ private String runThroughCommands(InternalCommand command, int layer, String[] args) {
int newLayer = layer + 1;
if (command.isEqual(args[layer]) && !command.invokers.isEmpty()) {
Set invokers = command.invokers.stream().filter(invoker -> newLayer == args.length - invoker.parameterTypes.length).sorted(Comparator.comparingInt((a) -> a.method.getAnnotation(Main.class).priority())).collect(Collectors.toSet());
@@ -189,7 +190,7 @@ public class CommandManager {
return NOT_FOUND_TEXT;
}
- private static String tryInvoker(InternalCommand.InternalCommandInvoker invoker, int newLayer, String[] args) {
+ private String tryInvoker(InternalCommand.InternalCommandInvoker invoker, int newLayer, String[] args) {
try {
ArrayList