aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-11 10:30:06 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-11 10:30:06 +0200
commit1ab7422957a76158883e0449ed593ac216c9ef80 (patch)
treeeb3bb5434a1b860941f85d2fdb543264d094f2de
parentd888d6b7358226792bf0cedbe67c7bb26204983f (diff)
parentf3aac4876936dc58e6251bffae4a203d7b964051 (diff)
downloadOneConfig-1ab7422957a76158883e0449ed593ac216c9ef80.tar.gz
OneConfig-1ab7422957a76158883e0449ed593ac216c9ef80.tar.bz2
OneConfig-1ab7422957a76158883e0449ed593ac216c9ef80.zip
Merge branch 'master' of github.com:Polyfrost/OneConfig
-rw-r--r--build.gradle.kts50
-rw-r--r--gradle.properties6
-rw-r--r--settings.gradle.kts2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/EventManager.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/package-info.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java36
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java337
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Optional.java12
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java9
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java12
-rw-r--r--src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/DSLs.kt2
-rw-r--r--src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt2
-rw-r--r--src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt2
36 files changed, 388 insertions, 204 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 43b495a..e9d942f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import gg.essential.gradle.util.RelocationTransform.Companion.registerRelocationAttribute
import gg.essential.gradle.util.noServerRunConfigs
+import gg.essential.gradle.util.prebundle
plugins {
kotlin("jvm")
@@ -59,6 +61,15 @@ repositories {
maven("https://repo.polyfrost.cc/releases")
}
+val relocated = registerRelocationAttribute("relocate") {
+ relocate("gg.essential", "cc.polyfrost.oneconfig.libs")
+ relocate("me.kbrewster", "cc.polyfrost.oneconfig.libs")
+}
+
+val shadeRelocated: Configuration by configurations.creating {
+ attributes { attribute(relocated, true) }
+}
+
val shade: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}
@@ -94,25 +105,33 @@ dependencies {
isTransitive = false
}
- shade("gg.essential:universalcraft-$platform:211") {
+ shadeRelocated("gg.essential:universalcraft-$platform:211") {
isTransitive = false
}
- shade("com.github.KevinPriv:keventbus:c52e0a2ea0") {
+ shadeRelocated("com.github.KevinPriv:keventbus:c52e0a2ea0") {
isTransitive = false
}
// for other mods and universalcraft
- shade("org.jetbrains.kotlin:kotlin-stdlib:1.6.21")
- shade("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21")
- shade("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21")
- shade("org.jetbrains.kotlin:kotlin-reflect:1.6.21")
- shade("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
- shade("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1")
- shade("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.1")
- shade("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.3.3")
- shade("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.3.3")
- shade("org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:1.3.3")
+ val kotlinVersion: String by project
+ val coroutinesVersion: String by project
+ val serializationVersion: String by project
+ val atomicfuVersion: String by project
+ val datetimeVersion: String by project
+ shade("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
+ shade("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
+ shade("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion")
+ shade("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
+
+ shade("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:$serializationVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$serializationVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:$serializationVersion")
+ shade("org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion")
+ shade("org.jetbrains.kotlinx:kotlinx-datetime-jvm:$datetimeVersion")
shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
isTransitive = false
@@ -135,6 +154,7 @@ dependencies {
lwjglNative("org.lwjgl:lwjgl-tinyfd:3.3.1:natives-macos")
lwjglNative("org.lwjgl:lwjgl-nanovg:3.3.1:natives-macos")
shade(lwjglJar.get().outputs.files)
+ shade(prebundle(shadeRelocated))
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.21")
}
@@ -186,6 +206,9 @@ tasks {
exclude("fabric.mod.json")
if (project.platform.isLegacyForge) {
exclude("mods.toml")
+ exclude("META-INF/versions/**")
+ exclude("**/module-info.class")
+ exclude("**/package-info.class")
} else {
exclude("mcmod.info")
}
@@ -199,9 +222,6 @@ tasks {
archiveClassifier.set("dev")
configurations = listOf(shade, lwjglNative)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
-
- relocate("gg.essential", "cc.polyfrost.oneconfig.libs")
- relocate("me.kbrewster", "cc.polyfrost.oneconfig.libs")
}
remapJar {
input.set(shadowJar.get().archiveFile)
diff --git a/gradle.properties b/gradle.properties
index 2d80be3..8471818 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -10,3 +10,9 @@ org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.jvmargs=-Xmx2G
+
+kotlinVersion=1.7.0
+coroutinesVersion=1.6.2
+serializationVersion=1.3.3
+atomicfuVersion=0.17.3
+datetimeVersion=0.3.3 \ No newline at end of file
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 4995b5d..da56434 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -6,7 +6,7 @@ pluginManagement {
maven("https://maven.architectury.dev/")
}
plugins {
- val egtVersion = "0.1.7"
+ val egtVersion = "0.1.10"
id("gg.essential.multi-version.root") version egtVersion
}
resolutionStrategy {
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
index d455411..d62247c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.config.core;
-import gg.essential.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import java.util.ArrayList;
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
index 05bb196..8492806 100644
--- a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.events;
-import me.kbrewster.eventbus.EventBus;
-import me.kbrewster.eventbus.invokers.LMFInvoker;
+import cc.polyfrost.oneconfig.libs.eventbus.EventBus;
+import cc.polyfrost.oneconfig.libs.eventbus.invokers.LMFInvoker;
/**
* Manages all events from OneConfig.
@@ -10,13 +10,9 @@ public final class EventManager {
/**
* The instance of the {@link EventManager}.
*/
- private static final EventManager INSTANCE = new EventManager();
+ public static final EventManager INSTANCE = new EventManager();
private final EventBus eventBus = new EventBus(new LMFInvoker(), Throwable::printStackTrace);
- public static EventManager getEventManager() {
- return INSTANCE;
- }
-
private EventManager() {
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index 13174ab..939bbaa 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -4,9 +4,9 @@ import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.hud.BasicHud;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.renderer.RenderManager;
-import gg.essential.universal.UKeyboard;
-import gg.essential.universal.UMatrixStack;
-import gg.essential.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 07a60ee..3172336 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -17,10 +17,10 @@ import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
-import gg.essential.universal.UKeyboard;
-import gg.essential.universal.UMatrixStack;
-import gg.essential.universal.UResolution;
-import gg.essential.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.input.Mouse;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
index 893d628..e5d187f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -14,7 +14,7 @@ import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
import cc.polyfrost.oneconfig.utils.color.ColorUtils;
-import gg.essential.universal.wrappers.UPlayer;
+import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.ModMetadata;
import org.jetbrains.annotations.NotNull;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
index 5c239c0..b7d1a68 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
@@ -10,7 +10,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
-import gg.essential.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import java.lang.reflect.Field;
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
index 559b2b2..a43b969 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
@@ -10,7 +10,7 @@ import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.MathUtils;
import cc.polyfrost.oneconfig.utils.TextUtils;
-import gg.essential.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
index 29c6d89..738ed21 100644
--- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
+++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.hud;
import cc.polyfrost.oneconfig.renderer.RenderManager;
-import gg.essential.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import java.util.List;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index 389e200..b3c6823 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -58,8 +58,8 @@ public class OneConfig {
GuiUtils.getDeltaTime(); // called to make sure static initializer is called
BlurHandler.INSTANCE.load();
CommandManager.INSTANCE.registerCommand(OneConfigCommand.class);
- EventManager.getEventManager().register(new HudCore());
- EventManager.getEventManager().register(HypixelUtils.INSTANCE);
+ EventManager.INSTANCE.register(new HudCore());
+ EventManager.INSTANCE.register(HypixelUtils.INSTANCE);
reloadModsList();
initialized = true;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
index d248df8..4aa94d9 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java
@@ -6,9 +6,9 @@ import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor;
-import gg.essential.universal.UMinecraft;
-import gg.essential.universal.UScreen;
-import me.kbrewster.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.shader.Shader;
@@ -43,7 +43,7 @@ public class BlurHandler {
* Simply initializes the blur mod so events are properly handled by forge.
*/
public void load() {
- EventManager.getEventManager().register(this);
+ EventManager.INSTANCE.register(this);
}
@Subscribe
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
index 7c92799..04a5e69 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java
@@ -2,8 +2,8 @@ package cc.polyfrost.oneconfig.internal.hud;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
import cc.polyfrost.oneconfig.hud.BasicHud;
-import gg.essential.universal.UResolution;
-import me.kbrewster.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import java.util.ArrayList;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java
index 8422e1e..f08d37e 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java
@@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class GuiIngameForgeMixin {
@Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) {
- EventManager.getEventManager().post(new HudRenderEvent(partialTicks));
+ EventManager.INSTANCE.post(new HudRenderEvent(partialTicks));
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
index 6456cf9..8a28bed 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java
@@ -27,28 +27,28 @@ public class MinecraftMixin {
@Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onInit(CallbackInfo ci) {
- EventManager.getEventManager().post(new InitializationEvent());
+ EventManager.INSTANCE.post(new InitializationEvent());
OneConfig.init();
}
@Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickStart(F)V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onRenderTickStart(CallbackInfo ci) {
- EventManager.getEventManager().post(new RenderEvent(Stage.START, timer.renderPartialTicks));
+ EventManager.INSTANCE.post(new RenderEvent(Stage.START, timer.renderPartialTicks));
}
@Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickEnd(F)V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onRenderTickEnd(CallbackInfo ci) {
- EventManager.getEventManager().post(new RenderEvent(Stage.END, timer.renderPartialTicks));
+ EventManager.INSTANCE.post(new RenderEvent(Stage.END, timer.renderPartialTicks));
}
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPreClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onClientTickStart(CallbackInfo ci) {
- EventManager.getEventManager().post(new TickEvent(Stage.START));
+ EventManager.INSTANCE.post(new TickEvent(Stage.START));
}
@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPostClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true)
private void onClientTickEnd(CallbackInfo ci) {
- EventManager.getEventManager().post(new TickEvent(Stage.END));
+ EventManager.INSTANCE.post(new TickEvent(Stage.END));
}
@ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false), remap = true)
@@ -56,7 +56,7 @@ public class MinecraftMixin {
if (a instanceof GuiOpenEvent) {
GuiOpenEvent forgeEvent = (GuiOpenEvent) a;
ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.gui);
- EventManager.getEventManager().post(event);
+ EventManager.INSTANCE.post(event);
if (event.isCancelled) {
forgeEvent.setCanceled(true);
}
@@ -67,11 +67,11 @@ public class MinecraftMixin {
@Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER))
private void onNonDeltaTickTimerUpdate(CallbackInfo ci) {
- EventManager.getEventManager().post(new TimerUpdateEvent(timer, false));
+ EventManager.INSTANCE.post(new TimerUpdateEvent(timer, false));
}
@Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;updateTimer()V", shift = At.Shift.AFTER, ordinal = 1))
private void onDeltaTickTimerUpdate(CallbackInfo ci) {
- EventManager.getEventManager().post(new TimerUpdateEvent(timer, true));
+ EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true));
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java
index 0673c77..877d540 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java
@@ -17,7 +17,7 @@ public class NetHandlerPlayClientMixin {
@Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true)
private void onSendPacket(Packet<?> p_147297_1_, CallbackInfo ci) {
SendPacketEvent event = new SendPacketEvent(p_147297_1_);
- EventManager.getEventManager().post(event);
+ EventManager.INSTANCE.post(event);
if (event.isCancelled) {
ci.cancel();
}
@@ -27,7 +27,7 @@ public class NetHandlerPlayClientMixin {
private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) {
if (packetIn.getType() == 0) {
ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent());
- EventManager.getEventManager().post(event);
+ EventManager.INSTANCE.post(event);
if (event.isCancelled) {
ci.cancel();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java
index 89346f6..51988f2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java
@@ -15,7 +15,7 @@ public class NetworkManagerMixin {
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
private void onReceivePacket(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) {
ReceivePacketEvent event = new ReceivePacketEvent(p_channelRead0_2_);
- EventManager.getEventManager().post(event);
+ EventManager.INSTANCE.post(event);
if (event.isCancelled) {
ci.cancel();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java
index 5e9b1bc..d1fce6a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java
@@ -16,6 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class WorldClientMixin {
@Inject(method = "<init>", at = @At("RETURN"))
private void onWorldLoad(NetHandlerPlayClient p_i45063_1_, WorldSettings p_i45063_2_, int p_i45063_3_, EnumDifficulty p_i45063_4_, Profiler p_i45063_5_, CallbackInfo ci) {
- EventManager.getEventManager().post(new WorldLoadEvent());
+ EventManager.INSTANCE.post(new WorldLoadEvent());
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/package-info.java b/src/main/java/cc/polyfrost/oneconfig/internal/package-info.java
new file mode 100644
index 0000000..4a8a6a5
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/package-info.java
@@ -0,0 +1,6 @@
+/**
+ * The package where all internal OneConfig shenanigans go on.
+ * This package is hidden from devs and is subject to change at any time with no warning.
+ * <p><b>It is recommended you do not interact with this package in any way.</b></p>
+ */
+package cc.polyfrost.oneconfig.internal; \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
index 7ab39e0..765a595 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
@@ -10,9 +10,9 @@ import cc.polyfrost.oneconfig.internal.assets.Images;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
-import gg.essential.universal.UGraphics;
-import gg.essential.universal.UMinecraft;
-import gg.essential.universal.UResolution;
+import cc.polyfrost.oneconfig.libs.universal.UGraphics;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.shader.Framebuffer;
import org.lwjgl.nanovg.NVGColor;
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java
index 31a503b..33ed5b7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java
@@ -4,20 +4,20 @@ 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;
-import gg.essential.universal.UChat;
+import cc.polyfrost.oneconfig.libs.universal.UChat;
-@Command(value = "test", aliases = {"t"})
+@Command(value = "test", aliases = {"t"}, description = "Description of the test command")
public class TestCommand_Test {
- @Main
+ @Main(description = "The main command.")
private static void main() { // /test
UChat.chat("Main command");
}
- @SubCommand(value = "subcommand", aliases = {"s"})
+ @SubCommand(value = "subcommand", aliases = {"s"}, description = "Subcommand 1.")
private static class TestSubCommand {
- @Main(priority = 999)
+ @Main(priority = 999, description = "Description of method")
private static void main(int a, float b, @Name("named c") String c) { // /test subcommand <a> <b> <c>
UChat.chat("Integer main: " + a + " " + b + " " + c);
}
@@ -32,8 +32,32 @@ public class TestCommand_Test {
@Main
private static void main(String a, String b, @Name("named c") String c) { // /test subcommand subsubcommand <a> <b> <c>
- UChat.chat(a + " " + b + " " + c);
+ joinAndChat(a, b, c);
}
}
}
+
+ @SubCommand(value = "subcommand2", aliases = {"s2"})
+ private static class TestSubCommand2 {
+ @Main
+ private static void main(boolean a, boolean b, boolean c, boolean d, boolean e, boolean f, int hgshrs, boolean jrwjhrw) {
+ joinAndChat(a, b, c, d, e, f, hgshrs, jrwjhrw);
+ }
+ }
+
+ @SubCommand(value = "subcommand3", aliases = {"s3"})
+ private static class TestSubCommand3 {
+ @Main
+ private static void main() {
+ UChat.chat("subcommand 3");
+ }
+ }
+
+ private static void joinAndChat(Object... stuff) {
+ StringBuilder builder = new StringBuilder();
+ for (Object thing : stuff) {
+ builder.append(thing).append(" ");
+ }
+ UChat.chat(builder.toString().trim());
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
index 8279353..54b2728 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java
@@ -7,7 +7,7 @@ import cc.polyfrost.oneconfig.config.data.*;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator;
-import gg.essential.universal.UKeyboard;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class TestConfig_Test extends Config {
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java
index 5ad95c7..12a8735 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java
@@ -2,8 +2,8 @@ package cc.polyfrost.oneconfig.test;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
-import gg.essential.universal.UMatrixStack;
-import gg.essential.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
index 7ec5ee5..0f50a33 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java
@@ -1,14 +1,14 @@
package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
-import gg.essential.universal.UResolution;
+import cc.polyfrost.oneconfig.libs.universal.UResolution;
import org.lwjgl.input.Mouse;
/**
* Various utility methods for input.
* <p>
* All values returned from this class are not scaled to Minecraft's GUI scale.
- * For scaled values, see {@link gg.essential.universal.UMouse}.
+ * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}.
* </p>
*/
public final class InputUtils {
@@ -78,7 +78,7 @@ public final class InputUtils {
* Gets the current mouse X position.
* <p>
* All values returned from this class are not scaled to Minecraft's GUI scale.
- * For scaled values, see {@link gg.essential.universal.UMouse}.
+ * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}.
* </p>
*
* @return the current mouse X position
@@ -92,7 +92,7 @@ public final class InputUtils {
* Gets the current mouse Y position.
* <p>
* All values returned from this class are not scaled to Minecraft's GUI scale.
- * For scaled values, see {@link gg.essential.universal.UMouse}.
+ * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}.
* </p>
*
* @return the current mouse Y position
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
index 5578e1e..b99d096 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/NetworkUtils.java
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.utils;
import com.google.gson.JsonElement;
-import gg.essential.universal.UDesktop;
+import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import org.apache.commons.io.IOUtils;
import java.io.*;
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
index 6cda00c..b51ee85 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java
@@ -3,7 +3,7 @@ package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.events.event.TickEvent;
-import me.kbrewster.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
/**
* Schedules a Runnable to be called after a certain amount of ticks.
@@ -13,7 +13,7 @@ public class TickDelay {
private int delay;
public TickDelay(Runnable functionName, int ticks) {
- EventManager.getEventManager().register(this);
+ EventManager.INSTANCE.register(this);
delay = ticks;
function = functionName;
}
@@ -24,7 +24,7 @@ public class TickDelay {
// Delay expired
if (delay < 1) {
function.run();
- EventManager.getEventManager().unregister(this);
+ EventManager.INSTANCE.unregister(this);
}
delay--;
}
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 32bbf5d..004f427 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java
@@ -1,15 +1,17 @@
package cc.polyfrost.oneconfig.utils.commands;
-import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
-import cc.polyfrost.oneconfig.utils.commands.annotations.Greedy;
-import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
-import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand;
+import cc.polyfrost.oneconfig.utils.commands.annotations.*;
import cc.polyfrost.oneconfig.utils.commands.arguments.*;
-import gg.essential.universal.ChatColor;
-import gg.essential.universal.UChat;
+import cc.polyfrost.oneconfig.libs.universal.ChatColor;
+import cc.polyfrost.oneconfig.libs.universal.UChat;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
+import net.minecraft.util.BlockPos;
import net.minecraftforge.client.ClientCommandHandler;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -25,19 +27,20 @@ import java.util.*;
public class CommandManager {
public static final CommandManager INSTANCE = new CommandManager();
private static final String NOT_FOUND_TEXT = "Command not found! Type /@ROOT_COMMAND@ help for help.";
+ private static final String TOO_MANY_PARAMETERS = "There were too many / little parameters for this command! 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 final HashMap<Class<?>, ArgumentParser<?>> parsers = new HashMap<>();
private CommandManager() {
addParser(new StringParser());
addParser(new IntegerParser());
- addParser(new IntegerParser(), int.class);
+ addParser(new IntegerParser(), Integer.TYPE);
addParser(new DoubleParser());
- addParser(new DoubleParser(), double.class);
+ addParser(new DoubleParser(), Double.TYPE);
addParser(new FloatParser());
- addParser(new FloatParser(), float.class);
+ addParser(new FloatParser(), Float.TYPE);
addParser(new BooleanParser());
- addParser(new BooleanParser(), boolean.class);
+ addParser(new BooleanParser(), Boolean.TYPE);
}
/**
@@ -89,62 +92,7 @@ public class CommandManager {
@Override
public void processCommand(ICommandSender sender, String[] args) {
- if (args.length == 0) {
- if (!root.invokers.isEmpty()) {
- try {
- root.invokers.get(0).method.invoke(null);
- } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException |
- ExceptionInInitializerError e) {
- e.printStackTrace();
- UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR);
- }
- }
- } else {
- if (annotation.helpCommand() && args[0].equalsIgnoreCase("help")) {
- //UChat.chat(sendHelpCommand(root));
- } else {
- List<InternalCommand.InternalCommandInvoker> commands = new ArrayList<>();
- int depth = 0;
- for (InternalCommand command : root.children) {
- int newDepth = loopThroughCommands(commands, 0, command, args, true);
- if (newDepth != -1) {
- depth = newDepth;
- break;
- }
- }
- System.out.println(depth);
- System.out.println(commands);
- if (commands.isEmpty()) {
- UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + NOT_FOUND_TEXT.replace("@ROOT_COMMAND@", annotation.value()));
- } else {
- List<CustomError> errors = new ArrayList<>();
- for (InternalCommand.InternalCommandInvoker invoker : commands) {
- try {
- List<Object> params = getParametersForInvoker(invoker, depth, args);
- if (params.size() == 1) {
- Object first = params.get(0);
- if (first instanceof CustomError) {
- errors.add((CustomError) first);
- continue;
- }
- }
- invoker.method.invoke(null, params.toArray());
- return;
- } catch (Exception e) {
- e.printStackTrace();
- UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR);
- return;
- }
- }
- if (!errors.isEmpty()) {
- UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + "Multiple errors occurred:");
- for (CustomError error : errors) {
- UChat.chat(" " + ChatColor.RED + ChatColor.BOLD + error.message);
- }
- }
- }
- }
- }
+ handleCommand(root, annotation, args);
}
@Override
@@ -152,36 +100,157 @@ public class CommandManager {
return -1;
}
- /*/
@Override
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
- List<InternalCommand.InternalCommandInvoker> commands = new ArrayList<>();
- int depth = 0;
- for (InternalCommand command : root.children) {
- int newDepth = loopThroughCommands(commands, 0, command, args, false);
- if (newDepth != -1) {
- depth = newDepth;
- break;
+ return handleTabCompletion(root, annotation, args);
+ }
+ });
+ }
+ }
+
+ private void handleCommand(InternalCommand root, Command annotation, String[] args) {
+ if (args.length == 0) {
+ if (!root.invokers.isEmpty()) {
+ try {
+ root.invokers.get(0).method.invoke(null);
+ } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException |
+ ExceptionInInitializerError e) {
+ e.printStackTrace();
+ UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR);
+ }
+ }
+ } else {
+ if (annotation.helpCommand() && args[0].equalsIgnoreCase("help")) {
+ UChat.chat(sendHelpCommand(root));
+ } else {
+ List<InternalCommand.InternalCommandInvoker> commands = new ArrayList<>();
+ int depth = 0;
+ for (InternalCommand command : root.children) {
+ int newDepth = loopThroughCommands(commands, 0, command, args);
+ if (newDepth != -1) {
+ depth = newDepth;
+ break;
+ }
+ }
+ if (commands.isEmpty()) {
+ if (depth == -2) {
+ UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + TOO_MANY_PARAMETERS.replace("@ROOT_COMMAND@", annotation.value()));
+ } else {
+ UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + NOT_FOUND_TEXT.replace("@ROOT_COMMAND@", annotation.value()));
+ }
+ } else {
+ List<CustomError> errors = new ArrayList<>();
+ for (InternalCommand.InternalCommandInvoker invoker : commands) {
+ try {
+ List<Object> params = getParametersForInvoker(invoker, depth, args);
+ if (params.size() == 1) {
+ Object first = params.get(0);
+ if (first instanceof CustomError) {
+ errors.add((CustomError) first);
+ continue;
+ }
+ }
+ invoker.method.invoke(null, params.toArray());
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR);
+ return;
+ }
+ }
+ //noinspection ConstantConditions
+ if (!errors.isEmpty()) {
+ UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + "Multiple errors occurred:");
+ for (CustomError error : errors) {
+ UChat.chat(" " + ChatColor.RED + ChatColor.BOLD + error.message);
}
}
- System.out.println(depth);
- System.out.println(commands);
- if (!commands.isEmpty()) {
- for (InternalCommand.InternalCommandInvoker invoker : commands) {
- try {
- List<Object> params = getParametersForInvoker(invoker, depth, args);
- invoker.method.invoke(null, params.toArray());
- return;
- } catch (Exception ignored) {
+ }
+ }
+ }
+ }
+ private List<String> handleTabCompletion(InternalCommand root, Command annotation, String[] args) {
+ try {
+ Set<Pair<InternalCommand.InternalCommandInvoker, Integer>> commands = new HashSet<>();
+ for (InternalCommand command : root.children) {
+ loopThroughCommandsTab(commands, 0, command, args);
+ }
+ if (!commands.isEmpty() || annotation.helpCommand()) {
+ List<Triple<InternalCommand.InternalCommandInvoker, Integer, Integer>> validCommands = new ArrayList<>(); // command, depth, and all processed params
+ for (Pair<InternalCommand.InternalCommandInvoker, Integer> pair : commands) {
+ InternalCommand.InternalCommandInvoker invoker = pair.getLeft();
+ int depth = pair.getRight();
+ int currentParam = 0;
+ boolean failed = false;
+ while (args.length - depth > 1) {
+ Parameter param = invoker.method.getParameters()[currentParam];
+ if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.parameterTypes.length) {
+ failed = true;
+ break;
+ }
+ ArgumentParser<?> parser = parsers.get(param.getType());
+ if (parser == null) {
+ failed = true;
+ break;
+ }
+ try {
+ Arguments arguments = new Arguments(Arrays.copyOfRange(args, depth, args.length), param.isAnnotationPresent(Greedy.class));
+ if (parser.parse(arguments) != null) {
+ depth += arguments.getPosition();
+ currentParam++;
+ } else {
+ failed = true;
+ break;
}
+ } catch (Exception e) {
+ failed = true;
+ break;
}
}
+ if (!failed) {
+ validCommands.add(new ImmutableTriple<>(pair.getLeft(), depth, currentParam));
+ }
}
+ if (!validCommands.isEmpty() || annotation.helpCommand()) {
+ Set<String> completions = new HashSet<>();
+ for (Triple<InternalCommand.InternalCommandInvoker, Integer, Integer> valid : validCommands) {
+ if (valid.getMiddle() == args.length) {
+ completions.add(valid.getLeft().name);
+ completions.addAll(Arrays.asList(valid.getLeft().aliases));
+ continue;
+ }
+ if (valid.getRight() + 1 > valid.getLeft().parameterTypes.length) continue;
+ Parameter param = valid.getLeft().method.getParameters()[valid.getRight()];
+ if (param.isAnnotationPresent(Greedy.class) && valid.getRight() + 1 != valid.getLeft().parameterTypes.length) {
+ continue;
+ }
+ ArgumentParser<?> parser = parsers.get(param.getType());
+ if (parser == null) {
+ continue;
+ }
+ try {
+ Arguments arguments = new Arguments(Arrays.copyOfRange(args, valid.getMiddle(), args.length), param.isAnnotationPresent(Greedy.class));
+ List<String> possibleCompletions = parser.complete(arguments, param);
+ if (possibleCompletions != null) {
+ completions.addAll(possibleCompletions);
+ }
+ } catch (Exception ignored) {
+
+ }
+ }
+ if (args.length == 1 && annotation.helpCommand()) {
+ if ("help".startsWith(args[0].toLowerCase(Locale.ENGLISH))) {
+ completions.add("help");
+ }
+ }
+ return new ArrayList<>(completions);
+ }
+ }
+ } catch (Exception ignored) {
- */
- });
}
+ return null;
}
private List<Object> getParametersForInvoker(InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) {
@@ -190,7 +259,7 @@ public class CommandManager {
int currentParam = 0;
while (processed < args.length) {
Parameter param = invoker.method.getParameters()[currentParam];
- if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.method.getParameterCount()) {
+ if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.parameterTypes.length) {
return Collections.singletonList(new CustomError("Parsing failed: Greedy parameter must be the last one."));
}
ArgumentParser<?> parser = parsers.get(param.getType());
@@ -218,36 +287,98 @@ public class CommandManager {
return parameters;
}
- private int loopThroughCommands(List<InternalCommand.InternalCommandInvoker> commands, int depth, InternalCommand command, String[] args, boolean checkParams) {
+ private int loopThroughCommands(List<InternalCommand.InternalCommandInvoker> commands, int depth, InternalCommand command, String[] args) {
int nextDepth = depth + 1;
- if (command.isEqual(args[depth])) {
+ boolean thatOneSpecialError = false;
+ if (command.isValid(args[depth], false)) {
for (InternalCommand child : command.children) {
- if (args.length > nextDepth && child.isEqual(args[nextDepth])) {
- int result = loopThroughCommands(commands, nextDepth, child, args, checkParams);
- if (result != -1) {
+ if (args.length > nextDepth && child.isValid(args[nextDepth], false)) {
+ int result = loopThroughCommands(commands, nextDepth, child, args);
+ if (result > -1) {
return result;
+ } else if (result == -2) {
+ thatOneSpecialError = true;
}
}
}
boolean added = false;
for (InternalCommand.InternalCommandInvoker invoker : command.invokers) {
- if (!checkParams || args.length - nextDepth == invoker.method.getParameterCount()) {
+ if (args.length - nextDepth == invoker.parameterTypes.length) {
commands.add(invoker);
added = true;
+ } else {
+ thatOneSpecialError = true;
}
}
if (added) {
return nextDepth;
}
- } else {
- for (InternalCommand child : command.children) {
- int childDepth = loopThroughCommands(commands, nextDepth, child, args, checkParams);
- if (childDepth != -1) {
- return childDepth;
+ }
+ return thatOneSpecialError ? -2 : -1;
+ }
+
+ private void loopThroughCommandsTab(Set<Pair<InternalCommand.InternalCommandInvoker, Integer>> commands, int depth, InternalCommand command, String[] args) {
+ int nextDepth = depth + 1;
+ if (command.isValid(args[depth], args.length == nextDepth)) {
+ if (args.length != nextDepth) {
+ for (InternalCommand child : command.children) {
+ if (child.isValid(args[nextDepth], args.length == nextDepth + 1)) {
+ loopThroughCommandsTab(commands, nextDepth, child, args);
+ }
}
}
+ for (InternalCommand.InternalCommandInvoker invoker : command.invokers) {
+ commands.add(new ImmutablePair<>(invoker, nextDepth));
+ }
+ }
+ }
+
+ //TODO: someone make the help command actually look nice lmao
+ private String sendHelpCommand(InternalCommand root) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n");
+ if (!root.description.isEmpty()) {
+ builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description);
+ }
+ for (InternalCommand command : root.children) {
+ runThroughCommandsHelp(root.name, command, builder);
+ }
+ builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD);
+ int index = 0;
+ for (String alias : root.aliases) {
+ ++index;
+ builder.append(alias).append(index < root.aliases.length ? ", " : "");
+ }
+ builder.append("\n");
+ return builder.toString();
+ }
+
+ private void runThroughCommandsHelp(String append, InternalCommand command, StringBuilder builder) {
+ if (!command.invokers.isEmpty()) {
+ Class<?> declaringClass = command.invokers.get(0).method.getDeclaringClass();
+ if (declaringClass.isAnnotationPresent(SubCommand.class)) {
+ String description = declaringClass.getAnnotation(SubCommand.class).description();
+ if (!description.isEmpty()) {
+ builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description);
+ }
+ }
+ }
+ for (InternalCommand.InternalCommandInvoker invoker : command.invokers) {
+ builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name);
+ for (Parameter parameter : invoker.method.getParameters()) {
+ String name = parameter.getName();
+ if (parameter.isAnnotationPresent(Name.class)) {
+ name = parameter.getAnnotation(Name.class).value();
+ }
+ builder.append(" <").append(name).append(">");
+ }
+ if (!command.description.trim().isEmpty()) {
+ builder.append(": ").append(ChatColor.BOLD).append(command.description);
+ }
+ }
+ for (InternalCommand subCommand : command.children) {
+ runThroughCommandsHelp(append + " " + command.name, subCommand, builder);
}
- return -1;
}
private void addToInvokers(Class<?>[] classes, InternalCommand parent) {
@@ -289,12 +420,15 @@ public class CommandManager {
this.parent = parent;
}
- public boolean isEqual(String name) {
- if (this.name.equals(name)) {
+ public boolean isValid(String name, boolean tabCompletion) {
+ String lowerCaseName = this.name.toLowerCase(Locale.ENGLISH);
+ String lowerCaseOtherName = name.toLowerCase(Locale.ENGLISH);
+ if (!tabCompletion ? lowerCaseName.equals(lowerCaseOtherName) : lowerCaseName.startsWith(lowerCaseOtherName)) {
return true;
} else {
for (String alias : aliases) {
- if (alias.equals(name)) {
+ String lowerCaseAlias = alias.toLowerCase(Locale.ENGLISH);
+ if (!tabCompletion ? lowerCaseAlias.equals(lowerCaseOtherName) : lowerCaseAlias.startsWith(lowerCaseOtherName)) {
return true;
}
}
@@ -345,3 +479,4 @@ public class CommandManager {
}
}
}
+
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Optional.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Optional.java
deleted file mode 100644
index 4dbe8b5..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Optional.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package cc.polyfrost.oneconfig.utils.commands.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.PARAMETER})
-public @interface Optional {
-
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
index 7411cbe..ede83fb 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/BooleanParser.java
@@ -13,7 +13,14 @@ public class BooleanParser extends ArgumentParser<Boolean> {
@Override
public @Nullable Boolean parse(Arguments arguments) {
- return Boolean.parseBoolean(arguments.poll());
+ String next = arguments.poll();
+ if (next.equalsIgnoreCase("true")) {
+ return true;
+ } else if (next.equalsIgnoreCase("false")) {
+ return false;
+ } else {
+ return null;
+ }
}
@Override
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java
index c80814f..d7b3bea 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java
@@ -4,9 +4,9 @@ import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.RenderEvent;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.utils.TickDelay;
-import gg.essential.universal.UMinecraft;
-import gg.essential.universal.UScreen;
-import me.kbrewster.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import net.minecraft.client.gui.GuiScreen;
/**
@@ -17,7 +17,7 @@ public final class GuiUtils {
private static long deltaTime = 17L;
static {
- EventManager.getEventManager().register(new GuiUtils());
+ EventManager.INSTANCE.register(new GuiUtils());
}
/**
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java
index c06f6f3..7459224 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java
@@ -2,8 +2,8 @@ package cc.polyfrost.oneconfig.utils.gui;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.utils.InputUtils;
-import gg.essential.universal.UMatrixStack;
-import gg.essential.universal.UScreen;
+import cc.polyfrost.oneconfig.libs.universal.UMatrixStack;
+import cc.polyfrost.oneconfig.libs.universal.UScreen;
import net.minecraft.client.gui.GuiScreen;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Mouse;
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
index 36dc46c..df5211b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java
@@ -8,11 +8,11 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import gg.essential.universal.UChat;
-import gg.essential.universal.UMinecraft;
-import gg.essential.universal.wrappers.UPlayer;
-import gg.essential.universal.wrappers.message.UTextComponent;
-import me.kbrewster.eventbus.Subscribe;
+import cc.polyfrost.oneconfig.libs.universal.UChat;
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
+import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer;
+import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent;
+import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@@ -123,7 +123,7 @@ public class HypixelUtils {
previousLocraw = parsed;
inGame = true; // If your gamemode does not return "lobby", boolean inGame is true.
}
- EventManager.getEventManager().post(new LocrawEvent(locraw));
+ EventManager.INSTANCE.post(new LocrawEvent(locraw));
event.isCancelled = true;
}
} catch (Exception ex) {
diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/DSLs.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/DSLs.kt
index cd0596e..c8c18e4 100644
--- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/DSLs.kt
+++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/DSLs.kt
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.utils.dsl
-import gg.essential.universal.UMinecraft
+import cc.polyfrost.oneconfig.libs.universal.UMinecraft
/**
* Gets the current [net.minecraft.client.Minecraft] instance.
diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt
index 7ce6c93..4e8bca8 100644
--- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt
+++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/NetworkUtilsDSL.kt
@@ -1,7 +1,7 @@
package cc.polyfrost.oneconfig.utils.dsl
import cc.polyfrost.oneconfig.utils.NetworkUtils
-import gg.essential.universal.UDesktop
+import cc.polyfrost.oneconfig.libs.universal.UDesktop
import java.io.File
/**
diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt
index 0000fc1..21c33f0 100644
--- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt
+++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt
@@ -42,6 +42,8 @@ fun nanoVG(mcScaling: Boolean = false, block: VG.() -> Unit) = RenderManager.set
)
}
+fun nanoVG(context: Long, block: VG.() -> Unit) = block.invoke(VG(context))
+
fun Long.drawRect(x: Number, y: Number, width: Number, height: Number, color: Int, bypassOneConfig: Boolean = false) =
if (bypassOneConfig) {