diff --git a/src/main/java/dev/micle/loginprotection/events/OnClientInputEventHandler.java b/src/main/java/dev/micle/loginprotection/events/OnClientInputEventHandler.java index ee1e05a..16da4f1 100755 --- a/src/main/java/dev/micle/loginprotection/events/OnClientInputEventHandler.java +++ b/src/main/java/dev/micle/loginprotection/events/OnClientInputEventHandler.java @@ -81,149 +81,149 @@ public class OnClientInputEventHandler { if (key == GLFW.GLFW_KEY_ESCAPE) { isPausePressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.PAUSE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == GLFW.GLFW_KEY_F3) { isDebugPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.DEBUG.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyFullscreen.getKey().getValue()) { isFullscreenPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.FULLSCREEN.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyTogglePerspective.getKey().getValue()) { isTogglePerspectivePressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.PERSPECTIVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySmoothCamera.getKey().getValue()) { isSmoothCameraPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SMOOTH_CAMERA.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyScreenshot.getKey().getValue()) { isScreenshotPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SCREENSHOT.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySpectatorOutlines.getKey().getValue()) { isSpectatorOutlinesPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SPECTATOR_OUTLINES.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyAdvancements.getKey().getValue()) { isAdvancementsPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.ADVANCEMENTS.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyPlayerList.getKey().getValue()) { isPlayerListPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.PLAYER_LIST.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyChat.getKey().getValue()) { isChatPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.CHAT.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyCommand.getKey().getValue()) { isChatCommandPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.CHAT.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == GLFW.GLFW_KEY_ENTER) { isChatEnterPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.CHAT.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySocialInteractions.getKey().getValue()) { isSocialInteractionsPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SOCIAL_INTERACTIONS.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyLoadHotbarActivator.getKey().getValue()) { isLoadHotbarActivatorPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.LOAD_HOTBAR_ACTIVATOR.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySaveHotbarActivator.getKey().getValue()) { isSaveHotbarActivatorPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SAVE_HOTBAR_ACTIVATOR.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySwapOffhand.getKey().getValue()) { isSwapOffhandPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SWAP_ITEM.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyInventory.getKey().getValue()) { isInventoryPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.INVENTORY.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyDrop.getKey().getValue()) { isDropItemPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.DROP_ITEM.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyUse.getKey().getValue()) { isUseItemPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.USE_ITEM.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyPickItem.getKey().getValue()) { isPickBlockPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.PICK_BLOCK.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyAttack.getKey().getValue()) { isAttackPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.ATTACK.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyUp.getKey().getValue()) { isMoveUpPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.MOVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyRight.getKey().getValue()) { isMoveRightPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.MOVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyDown.getKey().getValue()) { isMoveDownPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.MOVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyLeft.getKey().getValue()) { isMoveLeftPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.MOVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keySprint.getKey().getValue()) { isMoveSprintPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.MOVE.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyShift.getKey().getValue()) { isSneakPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.SNEAK.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else if (key == keyBinds.keyJump.getKey().getValue()) { isJumpPressed = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.JUMP.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } else { for (int i = 0; i < isHotbarPressed.length; i++) { if (key == keyBinds.keyHotbarSlots[i].getKey().getValue()) { isHotbarPressed[i] = isPressed; if (!allowedKeys.contains(Config.Server.KEYS.HOTBAR.toString())) { - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); } } } @@ -265,7 +265,7 @@ public class OnClientInputEventHandler { (isJumpPressed && !allowedKeys.contains(Config.Server.KEYS.JUMP.toString())) || (Arrays.stream(isHotbarPressed).anyMatch(b -> b) && !allowedKeys.contains(Config.Server.KEYS.HOTBAR.toString()))) { // Assign new last input tick - Proxy.Client.setLastInputTick(LoginProtection.getProxy().getClientPlayer().tickCount); + Proxy.Client.updateLastInputTick(); // If player is not active send an input packet if (!Proxy.Client.getPlayerState().equals(ProtectedPlayer.State.ACTIVE)) { diff --git a/src/main/java/dev/micle/loginprotection/proxy/Proxy.java b/src/main/java/dev/micle/loginprotection/proxy/Proxy.java index f3df78c..fd9a743 100644 --- a/src/main/java/dev/micle/loginprotection/proxy/Proxy.java +++ b/src/main/java/dev/micle/loginprotection/proxy/Proxy.java @@ -1,5 +1,6 @@ package dev.micle.loginprotection.proxy; +import dev.micle.loginprotection.LoginProtection; import dev.micle.loginprotection.data.ProtectedPlayer; import dev.micle.loginprotection.data.ProtectedPlayerManager; import dev.micle.loginprotection.events.*; @@ -110,8 +111,8 @@ public class Proxy implements IProxy { return lastInputTick; } - public static void setLastInputTick(int newLastInputTick) { - lastInputTick = newLastInputTick; + public static void updateLastInputTick() { + lastInputTick = LoginProtection.getProxy().getClientPlayer().tickCount; } @Override