Advertisement
4epB9Ik

Untitled

Sep 15th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2017 - 2019 | Wurst-Imperium | All rights reserved.
  3. *
  4. * This source code is subject to the terms of the GNU General Public
  5. * License, version 3. If a copy of the GPL was not distributed with this
  6. * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
  7. */
  8. package net.wurstclient.forge;
  9.  
  10. import org.lwjgl.input.Keyboard;
  11.  
  12. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  13. import net.minecraftforge.fml.common.gameevent.InputEvent;
  14.  
  15. public final class KeybindProcessor
  16. {
  17. private final HackList hax;
  18. private final KeybindList keybinds;
  19. private final CommandProcessor cmdProcessor;
  20.  
  21. public KeybindProcessor(HackList hax, KeybindList keybinds,
  22. CommandProcessor cmdProcessor)
  23. {
  24. this.hax = hax;
  25. this.keybinds = keybinds;
  26. this.cmdProcessor = cmdProcessor;
  27. }
  28. private static boolean prevState = false;
  29. @SubscribeEvent
  30. public void onKeyInput(InputEvent.KeyInputEvent event)
  31. {
  32. int keyCode = Keyboard.getEventKey();
  33. boolean newState = Keyboard.isKeyDown(Keyboard.getEventKey());
  34. if (newState && !prevState) {
  35. prevState = newState;
  36. if(keyCode == 0 || !Keyboard.getEventKeyState())
  37. return;
  38.  
  39. String commands = keybinds.getCommands(Keyboard.getKeyName(keyCode));
  40. if(commands == null)
  41. return;
  42.  
  43. commands = commands.replace(";", "\u00a7").replace("\u00a7\u00a7", ";");
  44. for(String command : commands.split("\u00a7"))
  45. {
  46. command = command.trim();
  47.  
  48. if(command.startsWith("."))
  49. cmdProcessor.runCommand(command.substring(1));
  50. else if(command.contains(" "))
  51. cmdProcessor.runCommand(command);
  52. else
  53. {
  54. Hack hack = hax.get(command);
  55.  
  56. if(hack != null)
  57. hack.setEnabled(!hack.isEnabled());
  58. else
  59. cmdProcessor.runCommand(command);
  60. }
  61. }
  62.  
  63. }
  64. prevState = newState;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement