Advertisement
Guest User

AntiDragPlugin.java

a guest
Feb 17th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2018, DennisDeV <https://github.com/DevDennis>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package net.runelite.client.plugins.antidrag;
  26.  
  27. import com.google.common.eventbus.Subscribe;
  28. import com.google.inject.Provides;
  29. import net.runelite.api.Client;
  30. import net.runelite.api.events.ConfigChanged;
  31. import net.runelite.client.config.ConfigManager;
  32. import net.runelite.client.input.KeyListener;
  33. import net.runelite.client.input.KeyManager;
  34. import net.runelite.client.plugins.Plugin;
  35. import net.runelite.client.plugins.PluginDescriptor;
  36. import javax.inject.Inject;
  37. import java.awt.event.KeyEvent;
  38.  
  39. @PluginDescriptor(
  40. name = "Anti Drag",
  41. enabledByDefault = false
  42. )
  43. public class AntiDragPlugin extends Plugin implements KeyListener
  44. {
  45. static final String CONFIG_GROUP = "antiDrag";
  46.  
  47. static final int DEFAULT_DELAY = 5;
  48.  
  49. @Inject
  50. private Client client;
  51.  
  52. @Inject
  53. private AntiDragConfig config;
  54.  
  55. @Inject
  56. private KeyManager keyManager;
  57.  
  58. @Provides
  59. AntiDragConfig getConfig(ConfigManager configManager)
  60. {
  61. return configManager.getConfig(AntiDragConfig.class);
  62. }
  63.  
  64. @Override
  65. protected void startUp() throws Exception
  66. {
  67. if (!config.onShiftOnly())
  68. {
  69. client.setInventoryDragDelay(config.dragDelay());
  70. }
  71. keyManager.registerKeyListener(this);
  72. }
  73.  
  74. @Override
  75. protected void shutDown() throws Exception
  76. {
  77. client.setInventoryDragDelay(DEFAULT_DELAY);
  78. keyManager.unregisterKeyListener(this);
  79. }
  80.  
  81. @Override
  82. public void keyTyped(KeyEvent e)
  83. {
  84.  
  85. }
  86.  
  87. @Override
  88. public void keyPressed(KeyEvent e)
  89. {
  90. if (config.onShiftOnly() && e.getKeyCode() == KeyEvent.VK_SHIFT)
  91. {
  92. client.setInventoryDragDelay(config.dragDelay());
  93. }
  94. }
  95.  
  96. @Override
  97. public void keyReleased(KeyEvent e)
  98. {
  99. if (config.onShiftOnly() && e.getKeyCode() == KeyEvent.VK_SHIFT)
  100. {
  101. client.setInventoryDragDelay(DEFAULT_DELAY);
  102. }
  103. }
  104.  
  105. @Subscribe
  106. public void onConfigChanged(ConfigChanged event)
  107. {
  108. if (event.getGroup().equals(CONFIG_GROUP))
  109. {
  110. if (config.onShiftOnly())
  111. {
  112. client.setInventoryDragDelay(DEFAULT_DELAY);
  113. }
  114. else
  115. {
  116. client.setInventoryDragDelay(config.dragDelay());
  117. }
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement