antidrag: add option to disable in pvp
This lifts the shift requirement by instead just disabling the feature in pvp Co-authored-by: jcwhisman <jcwhisman@gmail.com>
This commit is contained in:
@@ -563,7 +563,17 @@ public enum Varbits
|
|||||||
TWISTED_LEAGUE_RELIC_2(10050),
|
TWISTED_LEAGUE_RELIC_2(10050),
|
||||||
TWISTED_LEAGUE_RELIC_3(10051),
|
TWISTED_LEAGUE_RELIC_3(10051),
|
||||||
TWISTED_LEAGUE_RELIC_4(10052),
|
TWISTED_LEAGUE_RELIC_4(10052),
|
||||||
TWISTED_LEAGUE_RELIC_5(10053);
|
TWISTED_LEAGUE_RELIC_5(10053),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the Special Attack orb is disabled due to being in a PvP area
|
||||||
|
*
|
||||||
|
* 0 = Enabled (player is not in PvP)
|
||||||
|
* 1 = Disabled (player in in PvP)
|
||||||
|
*
|
||||||
|
* @see <a href="https://oldschool.runescape.wiki/w/Minimap#Special_attack_orb">The OSRS Wiki's Minimap page</a>
|
||||||
|
*/
|
||||||
|
PVP_SPEC_ORB(8121);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw varbit ID.
|
* The raw varbit ID.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import net.runelite.client.config.Config;
|
|||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
@ConfigGroup("antiDrag")
|
@ConfigGroup(AntiDragPlugin.CONFIG_GROUP)
|
||||||
public interface AntiDragConfig extends Config
|
public interface AntiDragConfig extends Config
|
||||||
{
|
{
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
@@ -42,4 +42,15 @@ public interface AntiDragConfig extends Config
|
|||||||
{
|
{
|
||||||
return Constants.GAME_TICK_LENGTH / Constants.CLIENT_TICK_LENGTH; // one game tick
|
return Constants.GAME_TICK_LENGTH / Constants.CLIENT_TICK_LENGTH; // one game tick
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "onShiftOnly",
|
||||||
|
name = "On Shift Only",
|
||||||
|
description = "Configures whether to only adjust the delay while holding shift. Required for anti drag in PvP scenarios.",
|
||||||
|
position = 2
|
||||||
|
)
|
||||||
|
default boolean onShiftOnly()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,34 +28,49 @@ import com.google.inject.Provides;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.api.events.FocusChanged;
|
import net.runelite.api.events.FocusChanged;
|
||||||
|
import net.runelite.api.events.VarbitChanged;
|
||||||
|
import net.runelite.api.events.WidgetLoaded;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
|
import net.runelite.api.widgets.WidgetID;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
|
import net.runelite.client.events.ConfigChanged;
|
||||||
import net.runelite.client.input.KeyListener;
|
import net.runelite.client.input.KeyListener;
|
||||||
import net.runelite.client.input.KeyManager;
|
import net.runelite.client.input.KeyManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Shift Anti Drag",
|
name = "Anti Drag",
|
||||||
description = "Prevent dragging an item for a specified delay",
|
description = "Prevent dragging an item for a specified delay",
|
||||||
tags = {"antidrag", "delay", "inventory", "items"}
|
tags = {"antidrag", "delay", "inventory", "items"},
|
||||||
|
enabledByDefault = false
|
||||||
)
|
)
|
||||||
public class AntiDragPlugin extends Plugin implements KeyListener
|
public class AntiDragPlugin extends Plugin implements KeyListener
|
||||||
{
|
{
|
||||||
|
static final String CONFIG_GROUP = "antiDrag";
|
||||||
|
|
||||||
private static final int DEFAULT_DELAY = 5;
|
private static final int DEFAULT_DELAY = 5;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientThread clientThread;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AntiDragConfig config;
|
private AntiDragConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private KeyManager keyManager;
|
private KeyManager keyManager;
|
||||||
|
|
||||||
|
private boolean inPvp;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
AntiDragConfig getConfig(ConfigManager configManager)
|
AntiDragConfig getConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -65,13 +80,25 @@ public class AntiDragPlugin extends Plugin implements KeyListener
|
|||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
if (client.getGameState() == GameState.LOGGED_IN)
|
||||||
|
{
|
||||||
|
clientThread.invokeLater(() ->
|
||||||
|
{
|
||||||
|
inPvp = client.getVar(Varbits.PVP_SPEC_ORB) == 1;
|
||||||
|
if (!config.onShiftOnly() && !inPvp)
|
||||||
|
{
|
||||||
|
setDragDelay();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
keyManager.registerKeyListener(this);
|
keyManager.registerKeyListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
clientThread.invoke(this::resetDragDelay);
|
||||||
keyManager.unregisterKeyListener(this);
|
keyManager.unregisterKeyListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,31 +111,77 @@ public class AntiDragPlugin extends Plugin implements KeyListener
|
|||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e)
|
public void keyPressed(KeyEvent e)
|
||||||
{
|
{
|
||||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
if (e.getKeyCode() == KeyEvent.VK_SHIFT && config.onShiftOnly())
|
||||||
{
|
{
|
||||||
final int delay = config.dragDelay();
|
setDragDelay();
|
||||||
client.setInventoryDragDelay(delay);
|
|
||||||
setBankDragDelay(delay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e)
|
public void keyReleased(KeyEvent e)
|
||||||
{
|
{
|
||||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
if (e.getKeyCode() == KeyEvent.VK_SHIFT && config.onShiftOnly())
|
||||||
{
|
{
|
||||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
resetDragDelay();
|
||||||
setBankDragDelay(DEFAULT_DELAY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onConfigChanged(ConfigChanged event)
|
||||||
|
{
|
||||||
|
if (event.getGroup().equals(CONFIG_GROUP))
|
||||||
|
{
|
||||||
|
if (config.onShiftOnly() || inPvp)
|
||||||
|
{
|
||||||
|
clientThread.invoke(this::resetDragDelay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clientThread.invoke(this::setDragDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onVarbitChanged(VarbitChanged varbitChanged)
|
||||||
|
{
|
||||||
|
boolean currentStatus = client.getVar(Varbits.PVP_SPEC_ORB) == 1;
|
||||||
|
|
||||||
|
if (currentStatus != inPvp)
|
||||||
|
{
|
||||||
|
inPvp = currentStatus;
|
||||||
|
|
||||||
|
if (!inPvp && !config.onShiftOnly())
|
||||||
|
{
|
||||||
|
setDragDelay();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resetDragDelay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onFocusChanged(FocusChanged focusChanged)
|
public void onFocusChanged(FocusChanged focusChanged)
|
||||||
{
|
{
|
||||||
if (!focusChanged.isFocused())
|
if (!focusChanged.isFocused())
|
||||||
{
|
{
|
||||||
client.setInventoryDragDelay(DEFAULT_DELAY);
|
clientThread.invoke(this::resetDragDelay);
|
||||||
setBankDragDelay(DEFAULT_DELAY);
|
}
|
||||||
|
else if (!inPvp && !config.onShiftOnly())
|
||||||
|
{
|
||||||
|
clientThread.invoke(this::setDragDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onWidgetLoaded(WidgetLoaded widgetLoaded)
|
||||||
|
{
|
||||||
|
if (widgetLoaded.getGroupId() == WidgetID.BANK_GROUP_ID)
|
||||||
|
{
|
||||||
|
setBankDragDelay(config.dragDelay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,4 +198,16 @@ public class AntiDragPlugin extends Plugin implements KeyListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDragDelay()
|
||||||
|
{
|
||||||
|
client.setInventoryDragDelay(config.dragDelay());
|
||||||
|
setBankDragDelay(config.dragDelay());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetDragDelay()
|
||||||
|
{
|
||||||
|
client.setInventoryDragDelay(DEFAULT_DELAY);
|
||||||
|
setBankDragDelay(DEFAULT_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user