diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 06:12:23 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 06:12:23 +0700 |
commit | d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051 (patch) | |
tree | 9bb9b53e2823f73084780673763504f4098bae69 /src/main/java/cc/polyfrost/oneconfig/utils | |
parent | d2b1d57120bb51e76191302a58d935afe52b89df (diff) | |
download | OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.gz OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.bz2 OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.zip |
Separate Minecraft dependant and non-dependant code
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
6 files changed, 47 insertions, 378 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index b7e620b..a48d369 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -2,9 +2,8 @@ package cc.polyfrost.oneconfig.utils; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; -import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; -import org.lwjgl.input.Mouse; import java.util.ArrayList; @@ -74,7 +73,7 @@ public final class InputUtils { * @return true if the mouse is clicked, false if not */ public static boolean isClicked(boolean ignoreBlock) { - return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX(), mouseY())); + return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX(), mouseY())); } /** @@ -97,8 +96,8 @@ public final class InputUtils { * @return the current mouse X position */ public static int mouseX() { - if (OneConfigGui.INSTANCE == null) return Mouse.getX(); - return (int) (Mouse.getX() / OneConfigGui.INSTANCE.getScaleFactor()); + if (OneConfigGui.INSTANCE == null) return Platform.getMousePlatform().getMouseX(); + return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } /** @@ -111,8 +110,8 @@ public final class InputUtils { * @return the current mouse Y position */ public static int mouseY() { - if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Mouse.getY()); - return (int) ((UResolution.getWindowHeight() - Math.abs(Mouse.getY())) / OneConfigGui.INSTANCE.getScaleFactor()); + if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY()); + return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } /** 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 004f427..16a2f8d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java @@ -1,19 +1,10 @@ package cc.polyfrost.oneconfig.utils.commands; -import cc.polyfrost.oneconfig.utils.commands.annotations.*; +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Main; +import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; import cc.polyfrost.oneconfig.utils.commands.arguments.*; -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; import java.lang.reflect.Modifier; import java.lang.reflect.Parameter; @@ -25,11 +16,12 @@ import java.util.*; * @see Command */ public class CommandManager { + private static final PlatformCommandManager platform = ServiceLoader.load(PlatformCommandManager.class, PlatformCommandManager.class.getClassLoader()).iterator().next(); 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<>(); + static final String NOT_FOUND_TEXT = "Command not found! Type /@ROOT_COMMAND@ help for help."; + static final String TOO_MANY_PARAMETERS = "There were too many / little parameters for this command! Type /@ROOT_COMMAND@ help for help."; + static final String METHOD_RUN_ERROR = "Error while running @ROOT_COMMAND@ method! Please report this to the developer."; + final HashMap<Class<?>, ArgumentParser<?>> parsers = new HashMap<>(); private CommandManager() { addParser(new StringParser()); @@ -79,305 +71,7 @@ public class CommandManager { } } addToInvokers(clazz.getDeclaredClasses(), root); - ClientCommandHandler.instance.registerCommand(new CommandBase() { - @Override - public String getCommandName() { - return annotation.value(); - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + annotation.value(); - } - - @Override - public void processCommand(ICommandSender sender, String[] args) { - handleCommand(root, annotation, args); - } - - @Override - public int getRequiredPermissionLevel() { - return -1; - } - - @Override - public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - 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); - } - } - } - } - } - } - - 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) { - 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.parameterTypes.length) { - 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 parameters; - } - - private int loopThroughCommands(List<InternalCommand.InternalCommandInvoker> commands, int depth, InternalCommand command, String[] args) { - int nextDepth = depth + 1; - boolean thatOneSpecialError = false; - if (command.isValid(args[depth], false)) { - for (InternalCommand child : command.children) { - 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 (args.length - nextDepth == invoker.parameterTypes.length) { - commands.add(invoker); - added = true; - } else { - thatOneSpecialError = true; - } - } - if (added) { - return nextDepth; - } - } - 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); + platform.createCommand(root, annotation); } } @@ -397,7 +91,7 @@ public class CommandManager { } } - private static class CustomError { + static class CustomError { public String message; public CustomError(String message) { @@ -405,7 +99,7 @@ public class CommandManager { } } - private static class InternalCommand { + static class InternalCommand { public final String name; public final String[] aliases; public final String description; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java new file mode 100644 index 0000000..a02f4ff --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java @@ -0,0 +1,7 @@ +package cc.polyfrost.oneconfig.utils.commands; + +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; + +public interface PlatformCommandManager { + void createCommand(CommandManager.InternalCommand root, Command annotation); +} 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 6ff0254..63203e4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -6,13 +6,8 @@ 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.platform.Platform; import cc.polyfrost.oneconfig.utils.TickDelay; -import net.minecraft.client.gui.GuiScreen; - -import java.util.Deque; -import java.util.Optional; -import java.util.concurrent.ConcurrentLinkedDeque; /** * A class containing utility methods for working with GuiScreens. @@ -20,7 +15,6 @@ import java.util.concurrent.ConcurrentLinkedDeque; public final class GuiUtils { private static long time = -1L; private static long deltaTime = 17L; - private static final Deque<Optional<GuiScreen>> screenQueue = new ConcurrentLinkedDeque<>(); static { EventManager.INSTANCE.register(new GuiUtils()); @@ -30,8 +24,10 @@ public final class GuiUtils { * Displays a screen after a tick, preventing mouse sync issues. * * @param screen the screen to display. + * @deprecated Not actually deprecated, but should not be used. */ - public static void displayScreen(GuiScreen screen) { + @Deprecated + public static void displayScreen(Object screen) { displayScreen(screen, screen instanceof OneConfigGui ? 2 : 1); } @@ -41,24 +37,15 @@ public final class GuiUtils { * @param screen the screen to display. * @param ticks the amount of ticks to wait for before displaying the screen. */ - public static void displayScreen(GuiScreen screen, int ticks) { - Optional<GuiScreen> optional = Optional.of(screen); - screenQueue.add(optional); - new TickDelay(() -> { - UScreen.displayScreen(screen); - screenQueue.remove(optional); - }, ticks); - } - - public static Deque<Optional<GuiScreen>> getScreenQueue() { - return screenQueue; + public static void displayScreen(Object screen, int ticks) { + new TickDelay(() -> Platform.getGuiPlatform().setCurrentScreen(screen), ticks); } /** * Close the current open GUI screen. */ public static void closeScreen() { - UScreen.displayScreen(null); + Platform.getGuiPlatform().setCurrentScreen(null); } /** 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 7459224..2dd961e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.utils.gui; -import cc.polyfrost.oneconfig.renderer.RenderManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.gui.GuiPause; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.libs.universal.UScreen; -import net.minecraft.client.gui.GuiScreen; +import cc.polyfrost.oneconfig.platform.Platform; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.utils.InputUtils; import org.jetbrains.annotations.NotNull; -import org.lwjgl.input.Mouse; /** * <h1>OneUIScreen</h1> @@ -14,9 +14,9 @@ import org.lwjgl.input.Mouse; * It contains many handy methods for rendering, including {@link #draw(long, float)} for drawing using OneConfig's {@link RenderManager}. * <p> It also contains methods for mouse input. (see {@link InputUtils} for more utils). * <p></p> - * Use {@link GuiUtils#displayScreen(GuiScreen)} to display a screen; and {@link GuiUtils#closeScreen()} to close it. + * Use GuiUtils to display a screen; and GuiUtils.closeScreen to close it. */ -public abstract class OneUIScreen extends UScreen { +public abstract class OneUIScreen extends UScreen implements GuiPause { private boolean mouseDown; private boolean blockClicks; @@ -40,7 +40,7 @@ public abstract class OneUIScreen extends UScreen { public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); - mouseDown = Mouse.isButtonDown(0); + mouseDown = Platform.getMousePlatform().isButtonDown(0); } /** @@ -77,19 +77,6 @@ public abstract class OneUIScreen extends UScreen { } /** - * Use this method to declare weather or not this Screen pauses the game when it is open. (Single-player only) Its default is false. - */ - public boolean doesScreenPauseGame() { - return false; - } - - @Override - public boolean doesGuiPauseGame() { - return doesScreenPauseGame(); - } - - - /** * Get the current x position of the mouse. */ public int getMouseX() { @@ -114,7 +101,7 @@ public abstract class OneUIScreen extends UScreen { * @param ignoreBlockClicks whether to ignore the current click blocker. */ public boolean isClicked(boolean ignoreBlockClicks) { - return mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlockClicks); + return mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (!blockClicks || ignoreBlockClicks); } /** @@ -128,7 +115,7 @@ public abstract class OneUIScreen extends UScreen { * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. */ public boolean isMouseDown() { - return Mouse.isButtonDown(0); + return Platform.getMousePlatform().isButtonDown(0); } /** 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 5489946..3e719de 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/hypixel/HypixelUtils.java @@ -2,18 +2,15 @@ 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.platform.Platform; 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 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 net.minecraftforge.fml.common.Loader; import java.util.Locale; import java.util.concurrent.TimeUnit; @@ -46,7 +43,7 @@ public class HypixelUtils { return; } EventManager.INSTANCE.register(this); - isSeraph = Loader.isModLoaded("seraph"); + isSeraph = Platform.getLoaderPlatform().isModLoaded("seraph"); initialized = true; } @@ -57,11 +54,9 @@ public class HypixelUtils { * @see <a href="https://canary.discord.com/channels/864592657572560958/945075920664928276/978649312013725747">this discord link from jade / asbyth</a> */ public boolean isHypixel() { - if (UMinecraft.getWorld() == null || UMinecraft.getMinecraft().isSingleplayer()) return false; + if (!Platform.getServerPlatform().inMultiplayer()) return false; - net.minecraft.client.entity.EntityPlayerSP player = UPlayer.getPlayer(); - if (player == null) return false; - String serverBrand = player.getClientBrand(); + String serverBrand = Platform.getServerPlatform().getServerBrand(); if (serverBrand == null) return false; @@ -108,7 +103,7 @@ public class HypixelUtils { @Subscribe private void onMessageReceived(ChatReceiveEvent event) { try { - final String msg = UTextComponent.Companion.stripFormatting(event.message.getUnformattedText()); + final String msg = event.getFullyUnformattedMessage(); // Checking for rate limitation. if (!(msg.startsWith("{") && msg.endsWith("}"))) { if (sentCommand && msg.contains("You are sending too many commands! Please try again in a few seconds.")) // if you're being rate limited, the /locraw command will be resent in 5 seconds. |