This repository was archived by the owner on Feb 19, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +54
-10
lines changed
src/main/java/me/zero/client Expand file tree Collapse file tree 3 files changed +54
-10
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2017 ZeroMemes
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package me .zero .client .api .event .defaults .game .core ;
18+
19+ /**
20+ * Event called when a Key is released outside of a GUI while in-game
21+ *
22+ * @see ClickEvent
23+ *
24+ * @author Leaf
25+ * @since 2.1
26+ */
27+ public final class KeyUpEvent {
28+
29+ private final int key ;
30+
31+ /**
32+ * Creates a new instance of KeyUpEvent.
33+ *
34+ * @param key - The key code for the key that was released
35+ */
36+ public KeyUpEvent (int key ) {
37+ this .key = key ;
38+ }
39+
40+ /**
41+ * @return The key code that corresponds to the released key
42+ */
43+ public final int getKey () {
44+ return this .key ;
45+ }
46+ }
Original file line number Diff line number Diff line change 2121import me .zero .alpine .listener .Listener ;
2222import me .zero .client .api .event .defaults .filters .PacketFilter ;
2323import me .zero .alpine .type .EventPriority ;
24+ import me .zero .client .api .event .defaults .game .core .*;
2425import me .zero .client .api .event .defaults .game .misc .ChatEvent ;
2526import me .zero .client .api .event .defaults .game .network .PacketEvent ;
26- import me .zero .client .api .event .defaults .game .core .KeyEvent ;
27- import me .zero .client .api .event .defaults .game .core .ProfilerEvent ;
2827import me .zero .client .api .event .defaults .game .render .Render3DEvent ;
2928import me .zero .client .api .event .defaults .game .render .RenderHudEvent ;
3029import me .zero .client .api .util .interfaces .Helper ;
@@ -68,6 +67,12 @@ public final class ClientHandler implements Helper {
6867 keybinds .forEach (Keybind ::onPress );
6968 });
7069
70+ @ EventHandler
71+ private final Listener <KeyUpEvent > keyUpListener = new Listener <>(event ->
72+ Keybind .getKeybinds ().stream ()
73+ .filter (bind -> bind .getKey () == event .getKey ())
74+ .forEach (Keybind ::onRelease ));
75+
7176 /**
7277 * Handles profiling events
7378 */
Original file line number Diff line number Diff line change 2424import me .zero .client .api .event .defaults .game .render .GuiEvent ;
2525import me .zero .client .api .event .defaults .game .world .WorldEvent ;
2626import me .zero .client .api .event .handle .ClientHandler ;
27- import me .zero .client .api .util .keybind .Keybind ;
2827import me .zero .client .api .util .render .gl .GlUtils ;
2928import me .zero .client .load .ClientInitException ;
3029import me .zero .client .load .mixin .wrapper .IMinecraft ;
@@ -90,13 +89,7 @@ public void onKeyEvent(CallbackInfo ci) {
9089 boolean down = Keyboard .getEventKeyState ();
9190 int key = Keyboard .getEventKey ();
9291
93- if (down )
94- ClientAPI .EVENT_BUS .post (new KeyEvent (key ));
95- else
96- // TODO: split into new KeyUp event
97- Keybind .getKeybinds ().stream ()
98- .filter (bind -> bind .getKey () == key )
99- .forEach (Keybind ::onRelease );
92+ ClientAPI .EVENT_BUS .post (down ? new KeyEvent (key ) : new KeyUpEvent (key ));
10093 }
10194
10295 @ Inject (method = "init" , at = @ At ("RETURN" ))
You can’t perform that action at this time.
0 commit comments