diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index c0fe11173..abf0a84a8 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -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 repeatKey, boolean buttonDown, int[] heldKeys) { + public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed, boolean buttonDown, int[] heldKeys) { PlayerDataScript handler = ScriptController.Instance.playerScripts; - KeyPressedEvent event = new KeyPressedEvent((ScriptPlayer)ScriptController.Instance.getScriptForEntity(player), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, repeatKey, buttonDown, heldKeys); + KeyPressedEvent event = new KeyPressedEvent((ScriptPlayer)ScriptController.Instance.getScriptForEntity(player), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, buttonDown, heldKeys); handler.callScript(EnumScriptType.KEY_PRESSED, event); WrapperNpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 5c4787165..963a9f94c 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -69,7 +69,6 @@ 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); @@ -89,7 +88,7 @@ public class PacketHandlerPlayer{ keysDown = new int[0]; } - EventHooks.onPlayerKeyPressed(player, button, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, repeatKey, buttonDown, keysDown); + EventHooks.onPlayerKeyPressed(player, button, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, buttonDown, keysDown); } else if(type == EnumPlayerPacket.MouseClicked) { if(ScriptController.Instance.languages.isEmpty()) { diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index c559579d1..16c08ad20 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -63,25 +63,26 @@ public class ClientTickHandler{ mc.setIngameFocus(); } - int key = Keyboard.getEventKey(); - boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); - 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); + if(!Keyboard.isRepeatEvent()) { + int key = Keyboard.getEventKey(); + boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); + 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 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)) { - keysDownString.append(Integer.valueOf(i)).append(","); + 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)) { + 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(repeatKey), 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(keyDown), keysDownString.toString()}); + } } private boolean isIgnoredKey(int key) { diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java index 236556aa3..c1430fd42 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java @@ -125,6 +125,7 @@ public abstract class GuiContainerNPCInterface extends GuiContainer public void buttonEvent(GuiButton guibutton){}; public void close(){ + Keyboard.enableRepeatEvents(false); GuiNpcTextField.unfocus(); save(); player.closeScreen(); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 1e896158f..e8e9b87e3 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -155,6 +155,7 @@ public abstract class GuiNPCInterface extends GuiScreen GuiNpcTextField.unfocus(); } public void close(){ + Keyboard.enableRepeatEvents(false); displayGuiScreen(null); mc.setIngameFocus(); save(); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java index 3080b54af..fef629e78 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java @@ -99,6 +99,8 @@ public class GuiNpcMenu implements GuiYesNoCallback{ } private void close() { + Keyboard.enableRepeatEvents(false); + if(parent instanceof GuiContainerNPCInterface2) ((GuiContainerNPCInterface2)parent).close(); diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 36a145b2f..306bd81f1 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -41,18 +41,16 @@ 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 repeatKey, boolean keyDown, int[] heldKeys) { + public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed, 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; }