GuiContainerNPCInterface, GuiNPCInterface, GuiNpcMenu all disable repeat key events when closed like all other GUIs now.

The keyEvent scripted event no longer detects repeat held key presses.
This commit is contained in:
Luis C.M committed 2022-05-03 13:34:56 -05:00
1 parent 5c9424bac8
commit 09f76d84c4
7 files changed
+25 -23

No files matched your search

+2 -2
View File
@@ -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);
}
@@ -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()) {
@@ -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) {
@@ -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();
@@ -155,6 +155,7 @@ public abstract class GuiNPCInterface extends GuiScreen
GuiNpcTextField.unfocus();
}
public void close(){
Keyboard.enableRepeatEvents(false);
displayGuiScreen(null);
mc.setIngameFocus();
save();
@@ -99,6 +99,8 @@ public class GuiNpcMenu implements GuiYesNoCallback{
}
private void close() {
Keyboard.enableRepeatEvents(false);
if(parent instanceof GuiContainerNPCInterface2)
((GuiContainerNPCInterface2)parent).close();
@@ -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;
}