Skip to content

Commit 33af759

Browse files
committed
Update KeyEvent and MouseClickEvent with some helper methods
1 parent 23a6839 commit 33af759

File tree

11 files changed

+32
-20
lines changed

11 files changed

+32
-20
lines changed

src/main/java/meteordevelopment/meteorclient/events/meteor/KeyEvent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ public static KeyEvent get(KeyInput input, KeyAction action) {
2121
INSTANCE.action = action;
2222
return INSTANCE;
2323
}
24+
25+
public int key() {
26+
return INSTANCE.input.key();
27+
}
28+
29+
public int modifiers() {
30+
return INSTANCE.input.modifiers();
31+
}
2432
}

src/main/java/meteordevelopment/meteorclient/events/meteor/MouseClickEvent.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
public class MouseClickEvent extends Cancellable {
1414
private static final MouseClickEvent INSTANCE = new MouseClickEvent();
1515

16-
public MouseInput input;
1716
public Click click;
17+
public MouseInput input;
1818
public KeyAction action;
1919

20-
public static MouseClickEvent get(MouseInput mouseInput, Click click, KeyAction action) {
20+
public static MouseClickEvent get(Click click, KeyAction action) {
2121
INSTANCE.setCancelled(false);
22-
INSTANCE.input = mouseInput;
2322
INSTANCE.click = click;
23+
INSTANCE.input = click.buttonInfo();
2424
INSTANCE.action = action;
2525
return INSTANCE;
2626
}
27+
28+
public int button() {
29+
return INSTANCE.input.button();
30+
}
2731
}

src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private void onMouseButton(long window, MouseInput mouseInput, int action, Callb
4141
Input.setButtonState(mouseInput.button(), action != GLFW_RELEASE);
4242

4343
Click click = new Click(getScaledX(client.getWindow()), getScaledY(client.getWindow()), mouseInput);
44-
if (MeteorClient.EVENT_BUS.post(MouseClickEvent.get(mouseInput, click, KeyAction.get(action))).isCancelled()) ci.cancel();
44+
if (MeteorClient.EVENT_BUS.post(MouseClickEvent.get(click, KeyAction.get(action))).isCancelled()) ci.cancel();
4545
}
4646

4747
@Inject(method = "onMouseScroll", at = @At("HEAD"), cancellable = true)

src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public KeybindSetting(String name, String description, Keybind defaultValue, Con
3232
@EventHandler(priority = EventPriority.HIGHEST)
3333
private void onKeyBinding(KeyEvent event) {
3434
if (widget == null) return;
35-
if (event.action == KeyAction.Press && event.input.key() == GLFW.GLFW_KEY_ESCAPE && widget.onClear()) event.cancel();
36-
else if (event.action == KeyAction.Release && widget.onAction(true, event.input.key(), event.input.modifiers())) event.cancel();
35+
if (event.action == KeyAction.Press && event.key() == GLFW.GLFW_KEY_ESCAPE && widget.onClear()) event.cancel();
36+
else if (event.action == KeyAction.Release && widget.onAction(true, event.key(), event.modifiers())) event.cancel();
3737
}
3838

3939
@EventHandler(priority = EventPriority.HIGHEST)
4040
private void onMouseClickBinding(MouseClickEvent event) {
41-
if (event.action == KeyAction.Press && widget != null && widget.onAction(false, event.input.button(), 0)) event.cancel();
41+
if (event.action == KeyAction.Press && widget != null && widget.onAction(false, event.button(), 0)) event.cancel();
4242
}
4343

4444
@EventHandler(priority = EventPriority.HIGH)

src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private void onKey(KeyEvent event) {
6262
if (event.action == KeyAction.Release) return;
6363

6464
for (Macro macro : macros) {
65-
if (macro.onAction(true, event.input.key(), event.input.modifiers())) return;
65+
if (macro.onAction(true, event.key(), event.modifiers())) return;
6666
}
6767
}
6868

@@ -71,7 +71,7 @@ private void onMouse(MouseClickEvent event) {
7171
if (event.action == KeyAction.Release) return;
7272

7373
for (Macro macro : macros) {
74-
if (macro.onAction(false, event.input.button(), 0)) return;
74+
if (macro.onAction(false, event.button(), 0)) return;
7575
}
7676
}
7777

src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ public boolean isBinding() {
213213

214214
@EventHandler(priority = EventPriority.HIGHEST)
215215
private void onKeyBinding(KeyEvent event) {
216-
if (event.action == KeyAction.Release && onBinding(true, event.input.key(), event.input.modifiers())) event.cancel();
216+
if (event.action == KeyAction.Release && onBinding(true, event.key(), event.modifiers())) event.cancel();
217217
}
218218

219219
@EventHandler(priority = EventPriority.HIGHEST)
220220
private void onButtonBinding(MouseClickEvent event) {
221-
if (event.action == KeyAction.Release && onBinding(false, event.input.button(), 0)) event.cancel();
221+
if (event.action == KeyAction.Release && onBinding(false, event.button(), 0)) event.cancel();
222222
}
223223

224224
private boolean onBinding(boolean isKey, int value, int modifiers) {
@@ -250,13 +250,13 @@ else if (value == GLFW.GLFW_KEY_ESCAPE) {
250250
@EventHandler(priority = EventPriority.HIGH)
251251
private void onKey(KeyEvent event) {
252252
if (event.action == KeyAction.Repeat) return;
253-
onAction(true, event.input.key(), event.input.modifiers(), event.action == KeyAction.Press);
253+
onAction(true, event.key(), event.modifiers(), event.action == KeyAction.Press);
254254
}
255255

256256
@EventHandler(priority = EventPriority.HIGH)
257257
private void onMouseClick(MouseClickEvent event) {
258258
if (event.action == KeyAction.Repeat) return;
259-
onAction(false, event.input.button(), 0, event.action == KeyAction.Press);
259+
onAction(false, event.button(), 0, event.action == KeyAction.Press);
260260
}
261261

262262
private void onAction(boolean isKey, int value, int modifiers, boolean isPress) {

src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Offhand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ else if ((isClicking || !autoTotem.isLocked() && !item.isOffhand())) {
240240
@EventHandler
241241
private void onMouseClick(MouseClickEvent event) {
242242
// Detects if the User is right-clicking
243-
isClicking = mc.currentScreen == null && !Modules.get().get(AutoTotem.class).isLocked() && !usableItem() && !mc.player.isUsingItem() && event.action == KeyAction.Press && event.input.button() == GLFW_MOUSE_BUTTON_RIGHT;
243+
isClicking = mc.currentScreen == null && !Modules.get().get(AutoTotem.class).isLocked() && !usableItem() && !mc.player.isUsingItem() && event.action == KeyAction.Press && event.button() == GLFW_MOUSE_BUTTON_RIGHT;
244244
}
245245

246246
private boolean usableItem() {

src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ public boolean disableArrows() {
112112

113113
@EventHandler
114114
private void onKey(KeyEvent event) {
115-
onInput(event.input.key(), event.action);
115+
onInput(event.key(), event.action);
116116
}
117117

118118
@EventHandler
119119
private void onButton(MouseClickEvent event) {
120-
onInput(event.input.button(), event.action);
120+
onInput(event.button(), event.action);
121121
}
122122

123123
private void onInput(int key, KeyAction action) {

src/main/java/meteordevelopment/meteorclient/systems/modules/player/MiddleClickExtra.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void onDeactivate() {
9090

9191
@EventHandler
9292
private void onMouseClick(MouseClickEvent event) {
93-
if (event.action != KeyAction.Press || event.input.button() != GLFW_MOUSE_BUTTON_MIDDLE || mc.currentScreen != null) return;
93+
if (event.action != KeyAction.Press || event.button() != GLFW_MOUSE_BUTTON_MIDDLE || mc.currentScreen != null) return;
9494

9595
if (mode.get() == Mode.AddFriend) {
9696
if (mc.targetedEntity == null) return;

src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,14 @@ public void onKey(KeyEvent event) {
284284
if (Input.isKeyPressed(GLFW.GLFW_KEY_F3)) return;
285285
if (checkGuiMove()) return;
286286

287-
if (onInput(event.input.key(), event.action)) event.cancel();
287+
if (onInput(event.key(), event.action)) event.cancel();
288288
}
289289

290290
@EventHandler(priority = EventPriority.HIGH)
291291
private void onMouseClick(MouseClickEvent event) {
292292
if (checkGuiMove()) return;
293293

294-
if (onInput(event.input.button(), event.action)) event.cancel();
294+
if (onInput(event.button(), event.action)) event.cancel();
295295
}
296296

297297
private boolean onInput(int key, KeyAction action) {

0 commit comments

Comments
 (0)