diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-05 10:39:49 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-05 10:39:49 +0100 |
commit | 17826161c67f6adf5976d7993ac0a229193e2eb6 (patch) | |
tree | f4172013d2db0986f0bb123040be1dc5b5823b3d /src/main/java | |
parent | 087f5404658a1543834f16a89e3436f8399297f6 (diff) | |
parent | 72c024213e7c61411ce12f6032f8ef0659408c3a (diff) | |
download | OneConfig-17826161c67f6adf5976d7993ac0a229193e2eb6.tar.gz OneConfig-17826161c67f6adf5976d7993ac0a229193e2eb6.tar.bz2 OneConfig-17826161c67f6adf5976d7993ac0a229193e2eb6.zip |
Merge remote-tracking branch 'origin/master'
# Conflicts:
# src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
# src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java
# src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java
# src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
# src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
# src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java
# src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
# src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java
# src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java
# src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java
Diffstat (limited to 'src/main/java')
48 files changed, 400 insertions, 326 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java index 977c53b..e8612b6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java @@ -8,6 +8,7 @@ import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.hud.HudCore; import cc.polyfrost.oneconfig.lwjgl.BlurHandler; +import cc.polyfrost.oneconfig.test.TestCommand; import cc.polyfrost.oneconfig.test.TestConfig; import cc.polyfrost.oneconfig.utils.GuiUtils; import cc.polyfrost.oneconfig.utils.commands.CommandManager; @@ -28,10 +29,10 @@ import java.util.List; @net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") public class OneConfig { public static final File oneConfigDir = new File("./OneConfig"); - public static OneConfigConfig config; - public static TestConfig testConfig; public static final List<Mod> loadedMods = new ArrayList<>(); public static final List<ModMetadata> loadedOtherMods = new ArrayList<>(); + public static OneConfigConfig config; + public static TestConfig testConfig; private static boolean preLaunched = false; private static boolean initialized = false; @@ -60,7 +61,8 @@ public class OneConfig { GuiUtils.getDeltaTime(); // called to make sure static initializer is called BlurHandler.INSTANCE.load(); testConfig = new TestConfig(); - CommandManager.INSTANCE.registerCommand(new OneConfigCommand()); + CommandManager.INSTANCE.registerCommand(OneConfigCommand.class); + CommandManager.INSTANCE.registerCommand(TestCommand.class); EventManager.INSTANCE.register(new HudCore()); EventManager.INSTANCE.register(HypixelUtils.INSTANCE); reloadModsList(); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index faeffff..b867bc0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -14,18 +14,10 @@ import java.util.ArrayList; public class OneConfigConfig extends Config { - public static String currentProfile = "Default Profile"; - public static ArrayList<String> favoriteMods = new ArrayList<>(); - public static ArrayList<OneColor> favoriteColors = new ArrayList<>(); - public static ArrayList<OneColor> recentColors = new ArrayList<>(); - - // the color library public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent - public static final int BLACK = new Color(0, 0, 0, 255).getRGB(); // Black public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 - public static final int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% public static final int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 public static final int GRAY_800_95 = new Color(21, 22, 23, 242).getRGB(); @@ -59,8 +51,10 @@ public class OneConfigConfig extends Config { public static final int ERROR_800_80 = new Color(145, 24, 24, 204).getRGB(); // Red 800 public static final int ERROR_300 = new Color(253, 155, 155).getRGB(); public static final int ERROR_300_80 = new Color(253, 155, 155, 204).getRGB(); - - + public static String currentProfile = "Default Profile"; + public static ArrayList<String> favoriteMods = new ArrayList<>(); + public static ArrayList<OneColor> favoriteColors = new ArrayList<>(); + public static ArrayList<OneColor> recentColors = new ArrayList<>(); public static boolean ROUNDED_CORNERS = true; public static float CORNER_RADIUS_WIN = 20f; public static float CORNER_RADIUS = 12f; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java index 3115f3a..fa4f058 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java @@ -168,8 +168,8 @@ public class VigilanceConfig extends Config { } private static class CompatConfigColorElement extends ConfigColorElement { - private Color prevColor = null; private final Field color; + private Color prevColor = null; private OneColor cachedColor = null; public CompatConfigColorElement(Field color, Vigilant parent, String name, int size) { diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java index dbec72a..9ed1cd9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java @@ -97,6 +97,27 @@ public final class OneColor { // accessors /** + * Get the RGBA color from the HSB color, and apply the alpha. + */ + public static int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) { + int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f); + return ((temp & 0x00ffffff) | (alpha << 24)); + } + + /** + * Get the HSBA color from the RGBA color. + */ + public static short[] RGBAtoHSBA(int rgba) { + short[] hsb = new short[4]; + float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null); + hsb[0] = (short) (hsbArray[0] * 360); + hsb[1] = (short) (hsbArray[1] * 100); + hsb[2] = (short) (hsbArray[2] * 100); + hsb[3] = (short) (rgba >> 24 & 255); + return hsb; + } + + /** * Get the red value of the color (0-255). */ public int getRed() { @@ -145,6 +166,11 @@ public final class OneColor { return hsba[3]; } + public void setAlpha(int alpha) { + this.hsba[3] = (short) alpha; + rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); + } + /** * Get the chroma speed of the color (1s-30s). */ @@ -221,27 +247,6 @@ public final class OneColor { } } - /** - * Get the RGBA color from the HSB color, and apply the alpha. - */ - public static int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) { - int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f); - return ((temp & 0x00ffffff) | (alpha << 24)); - } - - /** - * Get the HSBA color from the RGBA color. - */ - public static short[] RGBAtoHSBA(int rgba) { - short[] hsb = new short[4]; - float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null); - hsb[0] = (short) (hsbArray[0] * 360); - hsb[1] = (short) (hsbArray[1] * 100); - hsb[2] = (short) (hsbArray[2] * 100); - hsb[3] = (short) (rgba >> 24 & 255); - return hsb; - } - public String getHex() { return Integer.toHexString(0xff000000 | getRGB()).toUpperCase().substring(2); } @@ -273,11 +278,6 @@ public final class OneColor { hsba = RGBAtoHSBA(rgba); } - public void setAlpha(int alpha) { - this.hsba[3] = (short) alpha; - rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); - } - private String charsToString(char... chars) { StringBuilder sb = new StringBuilder(); for (char c : chars) { 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 d62247c..d455411 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 cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import gg.essential.universal.UKeyboard; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java index 7849124..241dca7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/Mod.java @@ -9,8 +9,8 @@ public class Mod { public final ModType modType; public final String modIcon; public final Migrator migrator; - public Config config; public final OptionPage defaultPage; + public Config config; public boolean isShortCut = false; /** diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java index 6fa3254..d4b4498 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java @@ -5,11 +5,11 @@ import java.util.function.Supplier; @SuppressWarnings({"unused"}) public abstract class BasicOption { + public final int size; protected final Field field; protected final String name; - public final int size; - private Supplier<Boolean> dependency; protected final Object parent; + private Supplier<Boolean> dependency; /** * Initialize option diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index 531c374..8eb5eb1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -22,10 +22,10 @@ import java.util.*; import java.util.function.Supplier; public class Config { + public final transient HashMap<String, BasicOption> optionNames = new HashMap<>(); transient protected final String configFile; transient protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().create(); transient public Mod mod; - public final transient HashMap<String, BasicOption> optionNames = new HashMap<>(); public transient boolean hasBeenInitialized = false; public boolean enabled = true; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java index 5573a3e..b45aeba 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java @@ -14,8 +14,8 @@ public class VigilanceMigrator implements Migrator { private static final Pattern booleanPattern = Pattern.compile("\"?(?<name>[^\\s\"]+)\"? = (?<value>true|false)"); private static final Pattern numberPattern = Pattern.compile("\"?(?<name>[^\\s\"]+)\"? = (?<value>[\\d.]+)"); private static final Pattern stringPattern = Pattern.compile("\"?(?<name>[^\\s\"]+)\"? = \"(?<value>.+)\""); - protected HashMap<String, HashMap<String, HashMap<String, Object>>> values = null; protected final String filePath; + protected HashMap<String, HashMap<String, HashMap<String, Object>>> values = null; public VigilanceMigrator(String filePath) { this.filePath = filePath; diff --git a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java index c758ec1..cb75a12 100644 --- a/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/events/EventManager.java @@ -1,22 +1,22 @@ package cc.polyfrost.oneconfig.events; -import cc.polyfrost.oneconfig.libs.eventbus.EventBus; -import cc.polyfrost.oneconfig.libs.eventbus.invokers.LMFInvoker; +import me.kbrewster.eventbus.EventBus; +import me.kbrewster.eventbus.invokers.LMFInvoker; /** * Manages all events from OneConfig. */ public final class EventManager { - private EventManager() { - - } - /** * The instance of the {@link EventManager}. */ public static final EventManager INSTANCE = new EventManager(); private final EventBus eventBus = new EventBus(new LMFInvoker(), Throwable::printStackTrace); + private EventManager() { + + } + /** * Returns the {@link EventBus} instance. * diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 72e8e58..52030fc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -3,10 +3,10 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.core.ConfigCore; import cc.polyfrost.oneconfig.hud.BasicHud; import cc.polyfrost.oneconfig.hud.HudCore; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import gg.essential.universal.UKeyboard; +import gg.essential.universal.UMatrixStack; +import gg.essential.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 8db7640..a9da8c2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -9,10 +9,6 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.gui.pages.Page; -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 cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -20,6 +16,10 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Mouse; @@ -28,9 +28,8 @@ import java.util.ArrayList; public class OneConfigGui extends UScreen { public static OneConfigGui INSTANCE; + public static OneConfigGui instanceToRestore = null; private final SideBar sideBar = new SideBar(); - protected Page currentPage; - protected Page prevPage; private final TextInputField textInputField = new TextInputField(248, 40, "Search...", false, false, SVGs.MAGNIFYING_GLASS_BOLD); private final ArrayList<Page> previousPages = new ArrayList<>(); private final ArrayList<Page> nextPages = new ArrayList<>(); @@ -39,9 +38,10 @@ public class OneConfigGui extends UScreen { private final ArrayList<Page> parents = new ArrayList<>(); public ColorSelector currentColorSelector; public boolean mouseDown; - private float scale = 1f; - public static OneConfigGui instanceToRestore = null; public boolean allowClose = true; + protected Page currentPage; + protected Page prevPage; + private float scale = 1f; private Animation animation; public OneConfigGui() { @@ -67,7 +67,6 @@ public class OneConfigGui extends UScreen { public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); long start = System.nanoTime(); - RenderManager.drawScaledString("HELLO", 10, 10, -1, false, 1.5f); int x2 = 0; int y2 = 0; RenderManager.setupAndDraw((vg) -> { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java index 069a807..3f2a552 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -3,11 +3,11 @@ package cc.polyfrost.oneconfig.gui.animations; import cc.polyfrost.oneconfig.utils.GuiUtils; public abstract class Animation { + protected final boolean reverse; private final float duration; private final float start; private final float change; private float timePassed = 0; - protected final boolean reverse; /** * @param duration The duration of the animation diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java index 7b4ba7f..f43c75d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java @@ -18,7 +18,6 @@ public class EaseInOutQuad extends Animation { @Override protected float animate(float timePassed, float duration, float start, float change) { if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed + start; - ; return -change / 2 * ((--timePassed) * (timePassed - 2) - 1) + start; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index e16b83e..683be1e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -26,21 +26,14 @@ import java.awt.datatransfer.StringSelection; import java.util.ArrayList; public class ColorSelector { - private int x; - private int y; private final OneColor color; - private Animation barMoveAnimation = new DummyAnimation(18); - private Animation moveAnimation = new DummyAnimation(1); - private int mouseX, mouseY; private final ArrayList<BasicElement> buttons = new ArrayList<>(); private final BasicElement closeBtn = new BasicElement(32, 32, false); - private final BasicButton copyBtn = new BasicButton(32, 32, SVGs.COPY, BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY); private final BasicButton pasteBtn = new BasicButton(32, 32, SVGs.PASTE, BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY); private final BasicButton guideBtn = new BasicButton(112, 32, "Guide", SVGs.HELP_CIRCLE, SVGs.POP_OUT, BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY); private final BasicButton faveBtn = new BasicButton(32, 32, SVGs.HEART_OUTLINE, BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY); private final BasicButton recentBtn = new BasicButton(32, 32, SVGs.HISTORY, BasicButton.ALIGNMENT_CENTER, ColorPalette.SECONDARY); - private final NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 360, 1); private final NumberInputField saturationInput = new NumberInputField(90, 32, 100, 0, 100, 1); private final NumberInputField brightnessInput = new NumberInputField(90, 32, 100, 0, 100, 1); @@ -49,10 +42,14 @@ public class ColorSelector { private final TextInputField hexInput = new TextInputField(88, 32, true, ""); private final ArrayList<ColorBox> favoriteColors = new ArrayList<>(); private final ArrayList<ColorBox> recentColors = new ArrayList<>(); - private final ColorSlider topSlider = new ColorSlider(384, 0, 360, 127); private final ColorSlider bottomSlider = new ColorSlider(384, 0, 255, 100); private final Slider speedSlider = new Slider(296, 1, 32, 0); + private int x; + private int y; + private Animation barMoveAnimation = new DummyAnimation(18); + private Animation moveAnimation = new DummyAnimation(1); + private int mouseX, mouseY; private int mode = 0, prevMode = 0; private boolean dragging, mouseWasDown; @@ -465,13 +462,13 @@ public class ColorSelector { update(x, y); } - public void setColor(OneColor color) { - this.color = color; - } - public OneColor getColor() { return color; } + + public void setColor(OneColor color) { + this.color = color; + } } } 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 b7fbe9a..863a72d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -6,12 +6,12 @@ import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; -import cc.polyfrost.oneconfig.libs.universal.wrappers.UPlayer; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; +import gg.essential.universal.wrappers.UPlayer; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.fml.common.ModMetadata; import org.jetbrains.annotations.NotNull; @@ -22,9 +22,9 @@ import java.util.ArrayList; public class ModCard extends BasicElement { private final Mod modData; private final BasicButton favoriteButton = new BasicButton(32, 32, SVGs.HEART_OUTLINE, BasicButton.ALIGNMENT_CENTER, ColorPalette.TERTIARY); - private boolean active, disabled, favorite; private final ColorAnimation colorFrame = new ColorAnimation(ColorPalette.SECONDARY); private final ColorAnimation colorToggle = new ColorAnimation(ColorPalette.PRIMARY); + private boolean active, disabled, favorite; private boolean isHoveredMain = false; public ModCard(@NotNull Mod mod, boolean active, boolean disabled, boolean favorite) { @@ -120,14 +120,14 @@ public class ModCard extends BasicElement { return disabled; } - public boolean isActive() { - return active; - } - public void setDisabled(boolean disabled) { this.disabled = disabled; } + public boolean isActive() { + return active; + } + public boolean isFavorite() { return favorite; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index d58852f..19bf058 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -24,6 +24,17 @@ public class ConfigButton extends BasicOption { this.button.setClickAction(getRunnableFromField(field, parent)); } + private static Runnable getRunnableFromField(Field field, Object parent) { + Runnable runnable = () -> { + }; + try { + runnable = (Runnable) field.get(parent); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return runnable; + } + @Override public void draw(long vg, int x, int y) { button.disable(!isEnabled()); @@ -37,15 +48,4 @@ public class ConfigButton extends BasicOption { public int getHeight() { return 32; } - - private static Runnable getRunnableFromField(Field field, Object parent) { - Runnable runnable = () -> { - }; - try { - runnable = (Runnable) field.get(parent); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return runnable; - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index 700d3dd..e7b1083 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -12,8 +12,8 @@ import cc.polyfrost.oneconfig.utils.InputUtils; import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { - private Animation posAnimation; private final String left, right; + private Animation posAnimation; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { super(field, parent, name, size); 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 d873006..a448b14 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 @@ -5,11 +5,11 @@ import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; +import gg.essential.universal.UKeyboard; import java.lang.reflect.Field; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java index 24a512c..8b47045 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java @@ -18,7 +18,7 @@ import java.lang.reflect.Field; public class ConfigPageButton extends BasicOption { public final OptionPage page; public final String description; - private ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY); + private final ColorAnimation backgroundColor = new ColorAnimation(ColorPalette.SECONDARY); public ConfigPageButton(Field field, Object parent, String name, String description, OptionPage page) { super(field, parent, name, 2); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java index 9a38b98..45217c0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java @@ -14,8 +14,8 @@ import java.lang.reflect.Field; public class ConfigSlider extends BasicOption { private final NumberInputField inputField; private final float min, max; - private boolean isFloat = true; private final int step; + private boolean isFloat = true; private boolean dragging = false; private boolean mouseWasDown = false; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index c3edb62..ed05760 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -10,11 +10,11 @@ import cc.polyfrost.oneconfig.utils.color.ColorPalette; public class NumberInputField extends TextInputField { private final BasicElement upArrow = new BasicElement(12, 14, false); private final BasicElement downArrow = new BasicElement(12, 14, false); + private final ColorAnimation colorTop = new ColorAnimation(ColorPalette.SECONDARY); + private final ColorAnimation colorBottom = new ColorAnimation(ColorPalette.SECONDARY); private float min; private float max; private float step; - private final ColorAnimation colorTop = new ColorAnimation(ColorPalette.SECONDARY); - private final ColorAnimation colorBottom = new ColorAnimation(ColorPalette.SECONDARY); private float current; public NumberInputField(int width, int height, float defaultValue, float min, float max, float step) { 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 91a8ff2..b16472d 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 @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.text; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.elements.BasicElement; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -11,6 +10,7 @@ import cc.polyfrost.oneconfig.lwjgl.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 org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; @@ -23,24 +23,24 @@ import java.util.ArrayList; public class TextInputField extends BasicElement { protected final String defaultText; - protected String input, selectedText; protected final boolean multiLine; + protected String input, selectedText; protected boolean password; protected int caretPos; protected int x, y; protected float start, end; protected int startLine, endLine; - private long clickTimeD1; protected long vg; protected int prevCaret = 0; protected boolean isDoubleClick = false; protected boolean onlyNums = false; protected boolean errored = false; protected boolean centered = false; - private int lines = 1; protected SVGs icon; protected ArrayList<String> wrappedText = null; + private long clickTimeD1; + private int lines = 1; public TextInputField(int width, int height, String defaultText, boolean multiLine, boolean password, SVGs icon) { super(width, height, false); @@ -60,28 +60,28 @@ public class TextInputField extends BasicElement { this.centered = centered; } - public void onlyAcceptNumbers(boolean state) { - onlyNums = state; + public static boolean isAllowedCharacter(char character) { + return character != 167 && character >= ' ' && character != 127; } - public void setInput(String input) { - this.input = input; + public void onlyAcceptNumbers(boolean state) { + onlyNums = state; } public String getInput() { return input; } - public void setPassword(boolean password) { - this.password = password; + public void setInput(String input) { + this.input = input; } public boolean getPassword() { return password; } - public void setErrored(boolean errored) { - this.errored = errored; + public void setPassword(boolean password) { + this.password = password; } public void setCentered(boolean centered) { @@ -92,6 +92,10 @@ public class TextInputField extends BasicElement { return errored; } + public void setErrored(boolean errored) { + this.errored = errored; + } + @Override public void draw(long vg, int x, int y) { this.x = x; @@ -529,10 +533,6 @@ public class TextInputField extends BasicElement { return 0; } - public static boolean isAllowedCharacter(char character) { - return character != 167 && character >= ' ' && character != 127; - } - public int getLines() { return lines; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 9c10841..fda6ea2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -10,11 +10,10 @@ import org.lwjgl.input.Mouse; * A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page. */ public abstract class Page { + protected final String title; private Animation scrollAnimation; private float scrollTarget; - protected final String title; - protected Page(String title) { this.title = title; } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java index 200d403..c3e7f9b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.hud; import cc.polyfrost.oneconfig.events.event.HudRenderEvent; -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import cc.polyfrost.oneconfig.libs.universal.UResolution; +import gg.essential.universal.UResolution; +import me.kbrewster.eventbus.Subscribe; import java.util.ArrayList; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 812ba50..9525ba4 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.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import gg.essential.universal.UMinecraft; public abstract class TextHud extends BasicHud { public TextHud(boolean enabled, int x, int y) { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java index d2b4811..1219782 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java @@ -5,10 +5,10 @@ import cc.polyfrost.oneconfig.events.event.RenderEvent; import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent; import cc.polyfrost.oneconfig.events.event.Stage; import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.mixin.ShaderGroupAccessor; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UScreen; +import me.kbrewster.eventbus.Subscribe; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.shader.Shader; @@ -33,14 +33,12 @@ import java.util.List; * https://github.com/boomboompower/ToggleChat/blob/master/LICENSE */ public class BlurHandler { + public static BlurHandler INSTANCE = new BlurHandler(); private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); private final Logger logger = LogManager.getLogger("OneConfig - Blur"); - private long start; private float lastProgress = 0; - public static BlurHandler INSTANCE = new BlurHandler(); - /** * Simply initializes the blur mod so events are properly handled by forge. */ diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index f366648..ef65ecf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -3,9 +3,6 @@ package cc.polyfrost.oneconfig.lwjgl; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.data.InfoType; import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.libs.universal.UGraphics; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.lwjgl.font.Font; import cc.polyfrost.oneconfig.lwjgl.font.FontManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; @@ -14,6 +11,9 @@ import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.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 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/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java index e40c5fc..6618094 100644 --- a/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java +++ b/src/main/java/cc/polyfrost/oneconfig/mixin/MinecraftMixin.java @@ -3,15 +3,16 @@ package cc.polyfrost.oneconfig.mixin; import cc.polyfrost.oneconfig.OneConfig; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.*; -import cc.polyfrost.oneconfig.libs.mixinextras.injector.ModifyExpressionValue; import net.minecraft.client.Minecraft; import net.minecraft.util.Timer; import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.fml.common.eventhandler.Event; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Minecraft.class) @@ -49,14 +50,18 @@ public class MinecraftMixin { EventManager.INSTANCE.post(new TickEvent(Stage.END)); } - @ModifyExpressionValue(method = "displayGuiScreen", at = @At(value = "NEW", target = "Lnet/minecraftforge/client/event/GuiOpenEvent;<init>(Lnet/minecraft/client/gui/GuiScreen;)V", remap = false), remap = true) - private GuiOpenEvent onGuiOpenEvent(GuiOpenEvent screen) { - ScreenOpenEvent event = new ScreenOpenEvent(screen.gui); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - screen.setCanceled(true); + @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) + private Event onGuiOpenEvent(Event a) { + if (a instanceof GuiOpenEvent) { + GuiOpenEvent forgeEvent = (GuiOpenEvent) a; + ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.gui); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + forgeEvent.setCanceled(true); + } + return forgeEvent; } - return screen; + return a; } @Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java index f5cac15..951e942 100644 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java +++ b/src/main/java/cc/polyfrost/oneconfig/plugin/OneConfigMixinPlugin.java @@ -1,6 +1,5 @@ package cc.polyfrost.oneconfig.plugin; -import cc.polyfrost.oneconfig.libs.mixinextras.MixinExtrasBootstrap; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -13,7 +12,6 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin { @Override public void onLoad(String mixinPackage) { - MixinExtrasBootstrap.init(); try { Class.forName("gg.essential.vigilance.Vigilant"); isVigilance = true; diff --git a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java index fecdeed..29cf2fd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java +++ b/src/main/java/cc/polyfrost/oneconfig/plugin/asm/tweakers/VigilantTransformer.java @@ -16,6 +16,20 @@ import org.objectweb.asm.tree.*; import java.io.File; public class VigilantTransformer implements ITransformer { + @SuppressWarnings("unused") + public static VigilanceConfig returnNewConfig(Vigilant vigilant, File file) { + if (vigilant != null && Minecraft.getMinecraft().isCallingFromMinecraftThread()) { + String name = !vigilant.getGuiTitle().equals("Settings") ? vigilant.getGuiTitle() : Loader.instance().activeModContainer() == null ? "Unknown" : Loader.instance().activeModContainer().getName(); + if (name.equals("OneConfig")) name = "Essential"; + String finalName = name; + // duplicate fix + if (ConfigCore.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; + return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); + } else { + return null; + } + } + @Override public String[] getClassName() { return new String[]{"gg.essential.vigilance.Vigilant"}; @@ -88,18 +102,4 @@ public class VigilantTransformer implements ITransformer { } } } - - @SuppressWarnings("unused") - public static VigilanceConfig returnNewConfig(Vigilant vigilant, File file) { - if (vigilant != null && Minecraft.getMinecraft().isCallingFromMinecraftThread()) { - String name = !vigilant.getGuiTitle().equals("Settings") ? vigilant.getGuiTitle() : Loader.instance().activeModContainer() == null ? "Unknown" : Loader.instance().activeModContainer().getName(); - if (name.equals("OneConfig")) name = "Essential"; - String finalName = name; - // duplicate fix - if (ConfigCore.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; - return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); - } else { - return null; - } - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java index d8c37f0..b757c73 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestCommand_Test.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestCommand.java @@ -1,13 +1,13 @@ 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; +import gg.essential.universal.UChat; @Command(value = "test", aliases = {"t"}) -public class TestCommand_Test { +public class TestCommand { @Main private static void main() { // /test 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 f6ad3f5..504c12f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java @@ -1,9 +1,9 @@ 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 gg.essential.universal.UMatrixStack; +import gg.essential.universal.UScreen; import org.jetbrains.annotations.NotNull; import java.awt.*; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java index fa2a6ea..29c26fb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/GuiUtils.java @@ -3,22 +3,22 @@ package cc.polyfrost.oneconfig.utils; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.RenderEvent; import cc.polyfrost.oneconfig.events.event.Stage; -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -import cc.polyfrost.oneconfig.libs.universal.UScreen; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UScreen; +import me.kbrewster.eventbus.Subscribe; import net.minecraft.client.gui.GuiScreen; /** * A class containing utility methods for working with GuiScreens. */ public final class GuiUtils { + private static long time = -1L; + private static long deltaTime = 17L; + static { EventManager.INSTANCE.register(new GuiUtils()); } - private static long time = -1L; - private static long deltaTime = 17L; - /** * Displays a screen after a tick, preventing mouse sync issues. * diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index 0f50a33..7ec5ee5 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 cc.polyfrost.oneconfig.libs.universal.UResolution; +import gg.essential.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 cc.polyfrost.oneconfig.libs.universal.UMouse}. + * For scaled values, see {@link gg.essential.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 cc.polyfrost.oneconfig.libs.universal.UMouse}. + * For scaled values, see {@link gg.essential.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 cc.polyfrost.oneconfig.libs.universal.UMouse}. + * For scaled values, see {@link gg.essential.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 aea7812..5578e1e 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 cc.polyfrost.oneconfig.libs.universal.UDesktop; import com.google.gson.JsonElement; +import gg.essential.universal.UDesktop; import org.apache.commons.io.IOUtils; import java.io.*; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java index 6aaec37..dac995d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/OneUIScreen.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.utils; -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UScreen; import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import gg.essential.universal.UMatrixStack; +import gg.essential.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/TickDelay.java b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java index 35b7b8b..7b6be2c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TickDelay.java @@ -3,14 +3,14 @@ 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 cc.polyfrost.oneconfig.libs.eventbus.Subscribe; +import me.kbrewster.eventbus.Subscribe; /** * Schedules a Runnable to be called after a certain amount of ticks. */ public class TickDelay { - private int delay; private final Runnable function; + private int delay; public TickDelay(Runnable functionName, int ticks) { EventManager.INSTANCE.register(this); diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandHelper.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandHelper.java deleted file mode 100644 index 3e7b7ea..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandHelper.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.polyfrost.oneconfig.utils.commands; - -/** - * A helper class for commands. - * Extend this class and run {@link CommandHelper#preload()} (which does nothing, - * just makes loading look nicer lol) - * - * @see cc.polyfrost.oneconfig.utils.commands.annotations.Command - */ -public abstract class CommandHelper { - - public CommandHelper() { - CommandManager.INSTANCE.registerCommand(this); - } - - public void preload() { - - } -} 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 4a008d3..32bbf5d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java @@ -1,9 +1,12 @@ package cc.polyfrost.oneconfig.utils.commands; -import cc.polyfrost.oneconfig.libs.universal.ChatColor; -import cc.polyfrost.oneconfig.libs.universal.UChat; -import cc.polyfrost.oneconfig.utils.commands.annotations.*; +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.arguments.*; +import gg.essential.universal.ChatColor; +import gg.essential.universal.UChat; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraftforge.client.ClientCommandHandler; @@ -13,7 +16,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; import java.util.*; -import java.util.stream.Collectors; /** * Handles the registration of OneConfig commands. @@ -22,9 +24,9 @@ import java.util.stream.Collectors; */ public class CommandManager { public static final CommandManager INSTANCE = new CommandManager(); - private final HashMap<Class<?>, 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 final HashMap<Class<?>, ArgumentParser<?>> parsers = new HashMap<>(); private CommandManager() { addParser(new StringParser()); @@ -60,22 +62,19 @@ public class CommandManager { /** * Registers the provided command. * - * @param command The command to register. + * @param clazz The command to register as a class. */ - public void registerCommand(Object command) { - Class<?> clazz = command.getClass(); + public void registerCommand(Class<?> clazz) { if (clazz.isAnnotationPresent(Command.class)) { final Command annotation = clazz.getAnnotation(Command.class); - ArrayList<InternalCommand.InternalCommandInvoker> mainCommandFuncs = new ArrayList<>(); + final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() ? "Main command for " + annotation.value() : annotation.description(), null); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class) && method.getParameterCount() == 0) { - mainCommandFuncs.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method)); + root.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, root)); break; } } - - final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() ? "Main command for " + annotation.value() : annotation.description(), mainCommandFuncs); addToInvokers(clazz.getDeclaredClasses(), root); ClientCommandHandler.instance.registerCommand(new CommandBase() { @Override @@ -93,26 +92,57 @@ public class CommandManager { if (args.length == 0) { if (!root.invokers.isEmpty()) { try { - root.invokers.stream().findFirst().get().method.invoke(null); + 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)); + //UChat.chat(sendHelpCommand(root)); } else { + List<InternalCommand.InternalCommandInvoker> commands = new ArrayList<>(); + int depth = 0; for (InternalCommand command : root.children) { - String result = runThroughCommands(command, 0, args); - if (result == null) { - return; - } else if (!result.equals(NOT_FOUND_TEXT)) { - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + result.replace("@ROOT_COMMAND@", getCommandName())); - return; + 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); + } } } - UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + NOT_FOUND_TEXT.replace("@ROOT_COMMAND@", getCommandName())); } } } @@ -121,146 +151,142 @@ public class CommandManager { public int getRequiredPermissionLevel() { return -1; } - }); - } - } - 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"); - for (InternalCommand command : root.children) { - runThroughCommandsHelp(root.name, root, builder); - } - builder.append("\n" + ChatColor.GOLD + "Aliases: " + ChatColor.BOLD); - int index = 0; - for (String alias : root.aliases) { - ++index; - builder.append(alias + (index < root.aliases.length ? ", " : "")); - } - builder.append("\n"); - return builder.toString(); - } + /*/ + @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; + } + } + 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 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()) { - String name = parameter.getName(); - if (parameter.isAnnotationPresent(Name.class)) { - name = parameter.getAnnotation(Name.class).value(); + } + } + } } - builder.append(" <" + name + ">"); - } - if (!command.description.trim().isEmpty()) { - builder.append(": " + ChatColor.BOLD + command.description); - } - } - for (InternalCommand subCommand : command.children) { - runThroughCommandsHelp(append + " " + command.name, subCommand, builder); + + */ + }); } } - private String runThroughCommands(InternalCommand command, int layer, String[] args) { - int newLayer = layer + 1; - if (command.isEqual(args[layer]) && !command.invokers.isEmpty()) { - Set<InternalCommand.InternalCommandInvoker> 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()); - if (!invokers.isEmpty()) { - for (InternalCommand.InternalCommandInvoker invoker : invokers) { - try { - String a = tryInvoker(invoker, newLayer, args); - if (a == null) { - return null; - } else if (a.contains(METHOD_RUN_ERROR)) { - return a; - } - } catch (Exception ignored) { - - } - } - } else { - for (InternalCommand subCommand : command.children) { - String result = runThroughCommands(subCommand, newLayer, args); - if (result == null) { - return null; - } else if (!result.equals(NOT_FOUND_TEXT)) { - return result; + private List<Object> getParametersForInvoker(InternalCommand.InternalCommandInvoker invoker, int depth, String[] args) { + List<Object> parameters = new ArrayList<>(); + int processed = depth; + int currentParam = 0; + while (processed < args.length) { + Parameter param = invoker.method.getParameters()[currentParam]; + if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.method.getParameterCount()) { + return Collections.singletonList(new CustomError("Parsing failed: Greedy parameter must be the last one.")); + } + ArgumentParser<?> parser = parsers.get(param.getType()); + if (parser == null) { + return Collections.singletonList(new CustomError("No parser for " + invoker.method.getParameterTypes()[currentParam].getSimpleName() + "! Please report this to the mod author.")); + } + try { + Arguments arguments = new Arguments(Arrays.copyOfRange(args, processed, args.length), param.isAnnotationPresent(Greedy.class)); + try { + Object a = parser.parse(arguments); + if (a != null) { + parameters.add(a); + processed += arguments.getPosition(); + currentParam++; + } else { + return Collections.singletonList(new CustomError("Failed to parse " + param.getType().getSimpleName() + "! Please report this to the mod author.")); } + } catch (Exception e) { + return Collections.singletonList(new CustomError("A " + e.getClass().getSimpleName() + " has occured while try to parse " + param.getType().getSimpleName() + "! Please report this to the mod author.")); } + } catch (Exception e) { + return Collections.singletonList(new CustomError("A " + e.getClass().getSimpleName() + " has occured while try to parse " + param.getType().getSimpleName() + "! Please report this to the mod author.")); } } - return NOT_FOUND_TEXT; + return parameters; } - private String tryInvoker(InternalCommand.InternalCommandInvoker invoker, int newLayer, String[] args) { - try { - ArrayList<Object> params = new ArrayList<>(); - int processed = newLayer; - int currentParam = 0; - while (processed < args.length) { - Parameter param = invoker.method.getParameters()[currentParam]; - if (param.isAnnotationPresent(Greedy.class) && currentParam + 1 != invoker.method.getParameterCount()) { - return "Parsing failed: Greedy parameter must be the last one."; + private int loopThroughCommands(List<InternalCommand.InternalCommandInvoker> commands, int depth, InternalCommand command, String[] args, boolean checkParams) { + int nextDepth = depth + 1; + if (command.isEqual(args[depth])) { + for (InternalCommand child : command.children) { + if (args.length > nextDepth && child.isEqual(args[nextDepth])) { + int result = loopThroughCommands(commands, nextDepth, child, args, checkParams); + if (result != -1) { + return result; + } } - ArgumentParser<?> parser = parsers.get(param.getType()); - if (parser == null) { - return "No parser for " + invoker.method.getParameterTypes()[currentParam].getSimpleName() + "! Please report this to the mod author."; + } + boolean added = false; + for (InternalCommand.InternalCommandInvoker invoker : command.invokers) { + if (!checkParams || args.length - nextDepth == invoker.method.getParameterCount()) { + commands.add(invoker); + added = true; } - try { - Arguments arguments = new Arguments(Arrays.copyOfRange(args, processed, args.length), param.isAnnotationPresent(Greedy.class)); - try { - Object a = parser.parse(arguments); - if (a != null) { - params.add(a); - processed += arguments.getPosition(); - currentParam++; - } else { - return "Failed to parse " + param.getType().getSimpleName() + "! Please report this to the mod author."; - } - } catch (Exception e) { - return "A " + e.getClass().getSimpleName() + " has occured while try to parse " + param.getType().getSimpleName() + "! Please report this to the mod author."; - } - } catch (Exception e) { - return "A " + e.getClass().getSimpleName() + " has occured while try to parse " + param.getType().getSimpleName() + "! Please report this to the mod author."; + } + if (added) { + return nextDepth; + } + } else { + for (InternalCommand child : command.children) { + int childDepth = loopThroughCommands(commands, nextDepth, child, args, checkParams); + if (childDepth != -1) { + return childDepth; } } - invoker.method.invoke(null, params.toArray()); - return null; - } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | - ExceptionInInitializerError e) { - return ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR; } + return -1; } private void addToInvokers(Class<?>[] classes, InternalCommand parent) { for (Class<?> clazz : classes) { if (clazz.isAnnotationPresent(SubCommand.class)) { SubCommand annotation = clazz.getAnnotation(SubCommand.class); - ArrayList<InternalCommand.InternalCommandInvoker> mainMethods = new ArrayList<>(); + InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), parent); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class)) { - mainMethods.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method)); + command.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, command)); } } - InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), mainMethods); parent.children.add(command); addToInvokers(clazz.getDeclaredClasses(), command); } } } + private static class CustomError { + public String message; + + public CustomError(String message) { + this.message = message; + } + } + private static class InternalCommand { public final String name; public final String[] aliases; public final String description; - public final ArrayList<InternalCommandInvoker> invokers; + public final ArrayList<InternalCommandInvoker> invokers = new ArrayList<>(); + public final InternalCommand parent; public final ArrayList<InternalCommand> children = new ArrayList<>(); - public InternalCommand(String name, String[] aliases, String description, ArrayList<InternalCommandInvoker> invokers) { + public InternalCommand(String name, String[] aliases, String description, InternalCommand parent) { this.name = name; this.aliases = aliases; - this.invokers = invokers; this.description = description; + this.parent = parent; } public boolean isEqual(String name) { @@ -276,13 +302,24 @@ public class CommandManager { return false; } + @Override + public String toString() { + return "InternalCommand{" + + "name='" + name + '\'' + + ", aliases=" + Arrays.toString(aliases) + + ", description='" + description + '\'' + + ", invokers=" + invokers + + '}'; + } + public static class InternalCommandInvoker { public final String name; public final String[] aliases; public final Method method; public final Parameter[] parameterTypes; + public final InternalCommand parent; - public InternalCommandInvoker(String name, String[] aliases, Method method) { + public InternalCommandInvoker(String name, String[] aliases, Method method, InternalCommand parent) { if (!Modifier.isStatic(method.getModifiers())) { throw new IllegalArgumentException("All command methods must be static!"); } @@ -290,10 +327,21 @@ public class CommandManager { this.aliases = aliases; this.method = method; this.parameterTypes = method.getParameters().clone(); + this.parent = parent; if (Modifier.isPrivate(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) { method.setAccessible(true); } } + + @Override + public String toString() { + return "InternalCommandInvoker{" + + "name='" + name + '\'' + + ", aliases=" + Arrays.toString(aliases) + + ", method=" + method + + ", parameterTypes=" + Arrays.toString(parameterTypes) + + '}'; + } } } } 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 89b5227..deec7f1 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 @@ -1,6 +1,5 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; -import cc.polyfrost.oneconfig.utils.commands.CommandHelper; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; @@ -73,8 +72,7 @@ import java.lang.annotation.Target; * }</pre> * </p> * <p> - * To register commands, either extend {@link CommandHelper} and run {@link CommandHelper#preload()} (which does nothing, - * just makes loading look nicer lol), or use {@link CommandManager#registerCommand(Object)}. + * To register commands, use {@link CommandManager#registerCommand(Class)}. * * <p> * Note: if you're viewing this in IntelliJ or just see the @literal tag everywhere, please ignore that. diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java index 61d1e07..8bf811b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser.java @@ -3,12 +3,36 @@ package cc.polyfrost.oneconfig.utils.commands.arguments; import com.google.common.reflect.TypeToken; import org.jetbrains.annotations.Nullable; -@SuppressWarnings("unstable") +import java.lang.reflect.Parameter; +import java.util.Collections; +import java.util.List; + +@SuppressWarnings("UnstableApiUsage") public abstract class ArgumentParser<T> { private final TypeToken<T> type = new TypeToken<T>(getClass()) { }; public final Class<?> typeClass = type.getRawType(); + /** + * Parses the given string into an object of the type specified by this parser. + * Should return null if the string cannot be parsed. + * + * @param arguments The string to parse. + * @return The parsed object, or null if the string cannot be parsed. + */ @Nullable public abstract T parse(Arguments arguments); + + /** + * Returns possible completions for the given arguments. + * Should return an empty list or null if no completions are possible. + * + * @param arguments The arguments to complete. + * @param parameter The parameter to complete. + * @return A list of possible completions, or an empty list or null if no completions are possible. + */ + @Nullable + public List<String> complete(Arguments arguments, Parameter parameter) { + return Collections.emptyList(); + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java index 74a0840..f35cf46 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/Arguments.java @@ -1,9 +1,9 @@ package cc.polyfrost.oneconfig.utils.commands.arguments; public class Arguments { - private int position = 0; public final String[] args; public final boolean greedy; + private int position = 0; public Arguments(String[] args, boolean greedy) { this.args = args; 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 dfdca2d..7411cbe 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 @@ -1,11 +1,31 @@ package cc.polyfrost.oneconfig.utils.commands.arguments; +import com.google.common.collect.Lists; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Parameter; +import java.util.List; +import java.util.Locale; + public class BooleanParser extends ArgumentParser<Boolean> { + private static final List<String> VALUES = Lists.newArrayList("true", "false"); + @Override public @Nullable Boolean parse(Arguments arguments) { return Boolean.parseBoolean(arguments.poll()); } + + @Override + public @Nullable List<String> complete(Arguments arguments, Parameter parameter) { + String value = arguments.poll(); + if (value != null && !value.trim().isEmpty()) { + for (String v : VALUES) { + if (v.startsWith(value.toLowerCase(Locale.ENGLISH))) { + return Lists.newArrayList(v); + } + } + } + return VALUES; + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java index 8c85849..4379e3a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/DoubleParser.java @@ -5,6 +5,10 @@ import org.jetbrains.annotations.Nullable; public class DoubleParser extends ArgumentParser<Double> { @Override public @Nullable Double parse(Arguments arguments) { - return Double.parseDouble(arguments.poll()); + try { + return Double.parseDouble(arguments.poll()); + } catch (NumberFormatException e) { + return null; + } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java index 7053fcb..08e0a45 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/FloatParser.java @@ -6,6 +6,10 @@ public class FloatParser extends ArgumentParser<Float> { @Override public @Nullable Float parse(Arguments arguments) { - return Float.parseFloat(arguments.poll()); + try { + return Float.parseFloat(arguments.poll()); + } catch (NumberFormatException e) { + return null; + } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java index 6910d4b..89f4eca 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/arguments/IntegerParser.java @@ -3,6 +3,10 @@ package cc.polyfrost.oneconfig.utils.commands.arguments; public class IntegerParser extends ArgumentParser<Integer> { @Override public Integer parse(Arguments arguments) { - return Integer.parseInt(arguments.poll()); + try { + return Integer.parseInt(arguments.poll()); + } catch (NumberFormatException e) { + return null; + } } } 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 c890939..a952053 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java @@ -2,17 +2,17 @@ package cc.polyfrost.oneconfig.utils.hypixel; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.*; -import cc.polyfrost.oneconfig.libs.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.utils.JsonUtils; import cc.polyfrost.oneconfig.utils.Multithreading; 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 java.util.Locale; import java.util.concurrent.TimeUnit; |