mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 12:39:05 +00:00
Added the repeatKey field to KeyEvent, distinguishing whether the event was triggered by the key being held down or the first press.
This commit is contained in:
1 parent
4c0ff9bf2e
commit
5c9424bac8
4 files changed
+13
-9
No files matched your search
@@ -395,9 +395,9 @@ public class EventHooks {
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed, boolean buttonDown, int[] heldKeys) {
|
||||
public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed, boolean repeatKey, boolean buttonDown, int[] heldKeys) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
KeyPressedEvent event = new KeyPressedEvent((ScriptPlayer)ScriptController.Instance.getScriptForEntity(player), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, buttonDown, heldKeys);
|
||||
KeyPressedEvent event = new KeyPressedEvent((ScriptPlayer)ScriptController.Instance.getScriptForEntity(player), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, repeatKey, buttonDown, heldKeys);
|
||||
handler.callScript(EnumScriptType.KEY_PRESSED, event);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class PacketHandlerPlayer{
|
||||
boolean isShiftPressed = buffer.readBoolean();
|
||||
boolean isAltPressed = buffer.readBoolean();
|
||||
boolean isMetaPressed = buffer.readBoolean();
|
||||
boolean repeatKey = buffer.readBoolean();
|
||||
boolean buttonDown = buffer.readBoolean();
|
||||
|
||||
String ints = Server.readString(buffer);
|
||||
@@ -88,7 +89,7 @@ public class PacketHandlerPlayer{
|
||||
keysDown = new int[0];
|
||||
}
|
||||
|
||||
EventHooks.onPlayerKeyPressed(player, button, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, buttonDown, keysDown);
|
||||
EventHooks.onPlayerKeyPressed(player, button, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, repeatKey, buttonDown, keysDown);
|
||||
}
|
||||
else if(type == EnumPlayerPacket.MouseClicked) {
|
||||
if(ScriptController.Instance.languages.isEmpty()) {
|
||||
|
||||
@@ -68,19 +68,20 @@ public class ClientTickHandler{
|
||||
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
||||
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
||||
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
|
||||
boolean repeatKey = Keyboard.isRepeatEvent();
|
||||
boolean keyDown = Keyboard.isKeyDown(key);
|
||||
|
||||
StringBuilder keysDownString = new StringBuilder();
|
||||
for(int i = 0; i < Keyboard.getKeyCount(); i++){//Creates a comma separated string of the integer IDs of held keys
|
||||
if(Keyboard.isKeyDown(i)){
|
||||
for (int i = 0; i < Keyboard.getKeyCount(); i++) {//Creates a comma separated string of the integer IDs of held keys
|
||||
if (Keyboard.isKeyDown(i)) {
|
||||
keysDownString.append(Integer.valueOf(i)).append(",");
|
||||
}
|
||||
}
|
||||
if(keysDownString.length() > 0){//Removes last comma for later parsing
|
||||
keysDownString.deleteCharAt(keysDownString.length()-1);
|
||||
if (keysDownString.length() > 0) {//Removes last comma for later parsing
|
||||
keysDownString.deleteCharAt(keysDownString.length() - 1);
|
||||
}
|
||||
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed), Boolean.valueOf(keyDown), keysDownString.toString()});
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed), Boolean.valueOf(repeatKey), Boolean.valueOf(keyDown), keysDownString.toString()});
|
||||
}
|
||||
|
||||
private boolean isIgnoredKey(int key) {
|
||||
|
||||
@@ -41,16 +41,18 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
public final boolean isAltPressed;
|
||||
public final boolean isShiftPressed;
|
||||
public final boolean isMetaPressed;
|
||||
public final boolean repeatKey;
|
||||
public final boolean keyDown;
|
||||
public final int[] keysDown;
|
||||
|
||||
public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed, boolean keyDown, int[] heldKeys) {
|
||||
public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed, boolean repeatKey, boolean keyDown, int[] heldKeys) {
|
||||
super(player);
|
||||
this.key = key;
|
||||
this.isCtrlPressed = isCtrlPressed;
|
||||
this.isAltPressed = isAltPressed;
|
||||
this.isShiftPressed = isShiftPressed;
|
||||
this.isMetaPressed = isMetaPressed;
|
||||
this.repeatKey = repeatKey;
|
||||
this.keyDown = keyDown;
|
||||
this.keysDown = heldKeys;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user