Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bind command #4611

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import meteordevelopment.meteorclient.systems.modules.Modules;
import net.minecraft.command.CommandSource;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

public class BindCommand extends Command {
public BindCommand() {
super("bind", "Binds a specified module to the next pressed key.");
Expand All @@ -24,6 +22,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(argument("module", ModuleArgumentType.create()).executes(context -> {
Module module = context.getArgument("module", Module.class);
Modules.get().setModuleToBind(module);
Modules.get().awaitKeyRelease();
module.info("Press a key to bind the module to.");
return SINGLE_SUCCESS;
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class Modules extends System<Modules> {

private final List<Module> active = new ArrayList<>();
private Module moduleToBind;
private boolean awaitingKeyRelease = false;

public Modules() {
super("modules");
Expand Down Expand Up @@ -220,6 +221,14 @@ public void setModuleToBind(Module moduleToBind) {
this.moduleToBind = moduleToBind;
}

/***
* @see meteordevelopment.meteorclient.commands.commands.BindCommand
* For ensuring we don't instantly bind the module to the enter key.
*/
public void awaitKeyRelease() {
this.awaitingKeyRelease = true;
}

public boolean isBinding() {
return moduleToBind != null;
}
Expand All @@ -237,6 +246,13 @@ private void onButtonBinding(MouseButtonEvent event) {
private boolean onBinding(boolean isKey, int value, int modifiers) {
if (!isBinding()) return false;

if (awaitingKeyRelease) {
if (!isKey || value != GLFW.GLFW_KEY_ENTER) return false;

awaitingKeyRelease = false;
return false;
}

if (moduleToBind.keybind.canBindTo(isKey, value, modifiers)) {
moduleToBind.keybind.set(isKey, value, modifiers);
moduleToBind.info("Bound to (highlight)%s(default).", moduleToBind.keybind);
Expand Down
Loading