87 lines
5.7 KiB
Java
Executable File
87 lines
5.7 KiB
Java
Executable File
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) {
|
|
Minecraft instance = Minecraft.getInstance();
|
|
ServerData server = instance.getCurrentServer();
|
|
if (server == null) { return; }
|
|
if (Minecraft.getInstance().screen != null) { return; }
|
|
if (checkKeyAllowed(instance, event.getKey())) { return; }
|
|
|
|
try {
|
|
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
|
|
} catch (NullPointerException ignored) { }
|
|
}
|
|
|
|
@SubscribeEvent
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void MouseClickEvent(InputEvent.ClickInputEvent event) {
|
|
Minecraft instance = Minecraft.getInstance();
|
|
ServerData server = instance.getCurrentServer();
|
|
if (server == null) { return; }
|
|
if (Minecraft.getInstance().screen != null) { return; }
|
|
if (checkKeyAllowed(instance, event.getKeyBinding().getKey().getValue())) { return; }
|
|
|
|
try {
|
|
LoginProtection.INSTANCE.sendToServer(new C2SKeyPress());
|
|
} catch (NullPointerException ignored) { }
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
private static boolean checkKeyAllowed(Minecraft instance, int key) {
|
|
boolean isAllowed = false;
|
|
|
|
if (key == GLFW.GLFW_KEY_ESCAPE) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PAUSE); }
|
|
if (key == GLFW.GLFW_KEY_F3) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DEBUG); }
|
|
if (key == instance.options.keyFullscreen.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.FULLSCREEN); }
|
|
if (key == instance.options.keyTogglePerspective.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PERSPECTIVE); }
|
|
if (key == instance.options.keySmoothCamera.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SMOOTH_CAMERA); }
|
|
if (key == instance.options.keyScreenshot.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SCREENSHOT); }
|
|
if (key == instance.options.keySpectatorOutlines.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SPECTATOR_OUTLINES); }
|
|
if (key == instance.options.keyAdvancements.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ADVANCEMENTS); }
|
|
if (key == instance.options.keyPlayerList.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PLAYER_LIST); }
|
|
if (key == instance.options.keyChat.getKey().getValue() ||
|
|
key == instance.options.keyCommand.getKey().getValue() ||
|
|
key == GLFW.GLFW_KEY_ENTER) {
|
|
isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.CHAT);
|
|
}
|
|
if (key == instance.options.keySocialInteractions.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SOCIAL_INTERACTIONS); }
|
|
if (key == instance.options.keyLoadHotbarActivator.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.LOAD_HOTBAR_ACTIVATOR); }
|
|
if (key == instance.options.keySaveHotbarActivator.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SAVE_HOTBAR_ACTIVATOR); }
|
|
if (key == instance.options.keySwapOffhand.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SWAP_ITEM); }
|
|
if (key == instance.options.keyInventory.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.INVENTORY); }
|
|
for (int i = 0; i < instance.options.keyHotbarSlots.length; i++) {
|
|
if (key == instance.options.keyHotbarSlots[i].getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.HOTBAR); }
|
|
}
|
|
if (key == instance.options.keyDrop.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.DROP_ITEM); }
|
|
if (key == instance.options.keyUse.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.USE_ITEM); }
|
|
if (key == instance.options.keyPickItem.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.PICK_BLOCK); }
|
|
if (key == instance.options.keyAttack.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.ATTACK); }
|
|
if (key == instance.options.keyUp.getKey().getValue() ||
|
|
key == instance.options.keyRight.getKey().getValue() ||
|
|
key == instance.options.keyDown.getKey().getValue() ||
|
|
key == instance.options.keyLeft.getKey().getValue() ||
|
|
key == instance.options.keySprint.getKey().getValue()) {
|
|
isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.MOVE);
|
|
}
|
|
if (key == instance.options.keyShift.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.SNEAK); }
|
|
if (key == instance.options.keyJump.getKey().getValue()) { isAllowed = Config.MAIN_KEY_ALLOW_LIST.get().contains(Config.KEYS.JUMP); }
|
|
|
|
return isAllowed;
|
|
}
|
|
|
|
}
|