Implemented configurable keybinding options that will allow players perform certain actions while protected without becoming active.
This commit is contained in:
@ -2,19 +2,66 @@ package com.micle.loginprotection.events;
|
||||
|
||||
import com.micle.loginprotection.LoginProtection;
|
||||
import com.micle.loginprotection.network.C2SKeyPress;
|
||||
import com.micle.loginprotection.setup.Config;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class OnKeyPressEventHandler {
|
||||
@SubscribeEvent
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void KeyPressEvent(InputEvent.KeyInputEvent event) {
|
||||
ServerData server = Minecraft.getInstance().getCurrentServer();
|
||||
Minecraft instance = Minecraft.getInstance();
|
||||
ServerData server = instance.getCurrentServer();
|
||||
if (server == null) { return; }
|
||||
if (Minecraft.getInstance().screen != null) { return; }
|
||||
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE) && event.getKey() == GLFW.GLFW_KEY_ESCAPE) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG) && event.getKey() == GLFW.GLFW_KEY_F3) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN) && event.getKey() == instance.options.keyFullscreen.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE) && event.getKey() == instance.options.keyTogglePerspective.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA) && event.getKey() == instance.options.keySmoothCamera.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT) && event.getKey() == instance.options.keyScreenshot.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES) && event.getKey() == instance.options.keySpectatorOutlines.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS) && event.getKey() == instance.options.keyAdvancements.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST) && event.getKey() == instance.options.keyPlayerList.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT)) {
|
||||
if (event.getKey() == instance.options.keyChat.getKey().getValue() ||
|
||||
event.getKey() == instance.options.keyCommand.getKey().getValue() ||
|
||||
event.getKey() == GLFW.GLFW_KEY_ENTER) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS) && event.getKey() == instance.options.keySocialInteractions.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR) && event.getKey() == instance.options.keyLoadHotbarActivator.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR) && event.getKey() == instance.options.keySaveHotbarActivator.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM) && event.getKey() == instance.options.keySwapOffhand.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY) && event.getKey() == instance.options.keyInventory.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR)) {
|
||||
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
|
||||
if (event.getKey() == instance.options.keyHotbarSlots[i].getKey().getValue()) { return; }
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM) && event.getKey() == instance.options.keyDrop.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM) && event.getKey() == instance.options.keyUse.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK) && event.getKey() == instance.options.keyPickItem.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK) && event.getKey() == instance.options.keyAttack.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE)) {
|
||||
if (event.getKey() == instance.options.keyUp.getKey().getValue() ||
|
||||
event.getKey() == instance.options.keyRight.getKey().getValue() ||
|
||||
event.getKey() == instance.options.keyDown.getKey().getValue() ||
|
||||
event.getKey() == instance.options.keyLeft.getKey().getValue() ||
|
||||
event.getKey() == instance.options.keySprint.getKey().getValue()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK) && event.getKey() == instance.options.keyShift.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP) && event.getKey() == instance.options.keyJump.getKey().getValue()) { return; }
|
||||
|
||||
try {
|
||||
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
|
||||
} catch (NullPointerException ignored) { }
|
||||
@ -23,8 +70,53 @@ public class OnKeyPressEventHandler {
|
||||
@SubscribeEvent
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void MouseClickEvent(InputEvent.ClickInputEvent event) {
|
||||
ServerData server = Minecraft.getInstance().getCurrentServer();
|
||||
Minecraft instance = Minecraft.getInstance();
|
||||
ServerData server = instance.getCurrentServer();
|
||||
if (server == null) { return; }
|
||||
if (Minecraft.getInstance().screen != null) { return; }
|
||||
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE) && event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_ESCAPE) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG) && event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_F3) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN) && event.getKeyBinding().getKey().getValue() == instance.options.keyFullscreen.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE) && event.getKeyBinding().getKey().getValue() == instance.options.keyTogglePerspective.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA) && event.getKeyBinding().getKey().getValue() == instance.options.keySmoothCamera.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT) && event.getKeyBinding().getKey().getValue() == instance.options.keyScreenshot.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES) && event.getKeyBinding().getKey().getValue() == instance.options.keySpectatorOutlines.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS) && event.getKeyBinding().getKey().getValue() == instance.options.keyAdvancements.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST) && event.getKeyBinding().getKey().getValue() == instance.options.keyPlayerList.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT)) {
|
||||
if (event.getKeyBinding().getKey().getValue() == instance.options.keyChat.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == instance.options.keyCommand.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == GLFW.GLFW_KEY_ENTER) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS) && event.getKeyBinding().getKey().getValue() == instance.options.keySocialInteractions.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR) && event.getKeyBinding().getKey().getValue() == instance.options.keyLoadHotbarActivator.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR) && event.getKeyBinding().getKey().getValue() == instance.options.keySaveHotbarActivator.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keySwapOffhand.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY) && event.getKeyBinding().getKey().getValue() == instance.options.keyInventory.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR)) {
|
||||
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
|
||||
if (event.getKeyBinding().getKey().getValue() == instance.options.keyHotbarSlots[i].getKey().getValue()) { return; }
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keyDrop.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM) && event.getKeyBinding().getKey().getValue() == instance.options.keyUse.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK) && event.getKeyBinding().getKey().getValue() == instance.options.keyPickItem.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK) && event.getKeyBinding().getKey().getValue() == instance.options.keyAttack.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE)) {
|
||||
if (event.getKeyBinding().getKey().getValue() == instance.options.keyUp.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == instance.options.keyRight.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == instance.options.keyDown.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == instance.options.keyLeft.getKey().getValue() ||
|
||||
event.getKeyBinding().getKey().getValue() == instance.options.keySprint.getKey().getValue()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK) && event.getKeyBinding().getKey().getValue() == instance.options.keyShift.getKey().getValue()) { return; }
|
||||
if (Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP) && event.getKeyBinding().getKey().getValue() == instance.options.keyJump.getKey().getValue()) { return; }
|
||||
|
||||
try {
|
||||
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
|
||||
} catch (NullPointerException ignored) { }
|
||||
|
||||
Reference in New Issue
Block a user