discord: enforce runeliteplus presence

This commit is contained in:
Zeruth
2019-07-25 22:06:56 -04:00
parent f3a9fbc9fb
commit f48b6b4f4f
3 changed files with 55 additions and 80 deletions

View File

@@ -35,7 +35,6 @@ import net.runelite.http.api.RuneLiteAPI;
@Slf4j @Slf4j
public class RuneLiteProperties public class RuneLiteProperties
{ {
private static final String DISCORD_APP_ID = "409416265891971072";
private static final String DISCORD_APP_ID_PLUS = "560644885250572289"; private static final String DISCORD_APP_ID_PLUS = "560644885250572289";
private final Properties properties = new Properties(); private final Properties properties = new Properties();
@@ -81,19 +80,7 @@ public class RuneLiteProperties
public String getDiscordAppId() public String getDiscordAppId()
{ {
if (this.runeLitePlusConfig == null) return DISCORD_APP_ID_PLUS;
{
return properties.getProperty(DISCORD_APP_ID);
}
if (this.runeLitePlusConfig.customPresence())
{
return properties.getProperty(DISCORD_APP_ID_PLUS);
}
else
{
return properties.getProperty(DISCORD_APP_ID);
}
} }
public String getDiscordInvite() public String getDiscordInvite()

View File

@@ -34,22 +34,11 @@ import net.runelite.client.config.Range;
@ConfigGroup("runeliteplus") @ConfigGroup("runeliteplus")
public interface RuneLitePlusConfig extends Config public interface RuneLitePlusConfig extends Config
{ {
@ConfigItem(
position = 0,
keyName = "customPresence",
name = "RL+ Presence",
description = "Represent RL+ with a custom icon and discord presence."
)
default boolean customPresence()
{
return false;
}
@ConfigItem( @ConfigItem(
keyName = "enableOpacity", keyName = "enableOpacity",
name = "Enable opacity", name = "Enable opacity",
description = "Enables opacity for the whole window.<br>NOTE: This only stays enabled if your pc supports this!", description = "Enables opacity for the whole window.<br>NOTE: This only stays enabled if your pc supports this!",
position = 1 position = 0
) )
default boolean enableOpacity() default boolean enableOpacity()
{ {
@@ -64,7 +53,7 @@ public interface RuneLitePlusConfig extends Config
keyName = "opacityPercentage", keyName = "opacityPercentage",
name = "Opacity percentage", name = "Opacity percentage",
description = "Changes the opacity of the window if opacity is enabled", description = "Changes the opacity of the window if opacity is enabled",
position = 2 position = 1
) )
default int opacityPercentage() default int opacityPercentage()
{ {
@@ -75,7 +64,7 @@ public interface RuneLitePlusConfig extends Config
keyName = "keyboardPin", keyName = "keyboardPin",
name = "Keyboard bank pin", name = "Keyboard bank pin",
description = "Enables you to type your bank pin", description = "Enables you to type your bank pin",
position = 3 position = 2
) )
default boolean keyboardPin() default boolean keyboardPin()
{ {

View File

@@ -55,41 +55,7 @@ import net.runelite.client.ui.ClientUI;
@Slf4j @Slf4j
public class RuneLitePlusPlugin extends Plugin public class RuneLitePlusPlugin extends Plugin
{ {
private class RuneLitePlusKeyListener implements KeyListener private final RuneLitePlusKeyListener keyListener = new RuneLitePlusKeyListener();
{
private int lastKeyCycle;
@Override
public void keyTyped(KeyEvent keyEvent)
{
if (!Character.isDigit(keyEvent.getKeyChar()))
{
return;
}
if (client.getGameCycle() - lastKeyCycle <= 5)
{
keyEvent.consume();
return;
}
lastKeyCycle = client.getGameCycle();
clientThread.invoke(() -> handleKey(keyEvent.getKeyChar()));
keyEvent.consume();
}
@Override
public void keyPressed(KeyEvent keyEvent)
{
}
@Override
public void keyReleased(KeyEvent keyEvent)
{
}
}
@Inject @Inject
private RuneLitePlusConfig config; private RuneLitePlusConfig config;
@@ -107,8 +73,6 @@ public class RuneLitePlusPlugin extends Plugin
@Inject @Inject
private EventBus eventbus; private EventBus eventbus;
private final RuneLitePlusKeyListener keyListener = new RuneLitePlusKeyListener();
private int entered = -1; private int entered = -1;
private int enterIdx; private int enterIdx;
private boolean expectInput; private boolean expectInput;
@@ -132,6 +96,17 @@ public class RuneLitePlusPlugin extends Plugin
expectInput = false; expectInput = false;
} }
@Override
protected void shutDown() throws Exception
{
eventbus.unregister(this);
entered = 0;
enterIdx = 0;
expectInput = false;
keyManager.unregisterKeyListener(keyListener);
}
private void onConfigChanged(ConfigChanged event) private void onConfigChanged(ConfigChanged event)
{ {
if (!event.getGroup().equals("runeliteplus")) if (!event.getGroup().equals("runeliteplus"))
@@ -166,17 +141,6 @@ public class RuneLitePlusPlugin extends Plugin
} }
} }
@Override
protected void shutDown() throws Exception
{
eventbus.unregister(this);
entered = 0;
enterIdx = 0;
expectInput = false;
keyManager.unregisterKeyListener(keyListener);
}
private void addSubscriptions() private void addSubscriptions()
{ {
eventbus.subscribe(ConfigChanged.class, this, this::onConfigChanged); eventbus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
@@ -221,10 +185,10 @@ public class RuneLitePlusPlugin extends Plugin
private void handleKey(char c) private void handleKey(char c)
{ {
if (client.getWidget(WidgetID.BANK_PIN_GROUP_ID, BANK_PIN_INSTRUCTION_TEXT.getChildId()) == null if (client.getWidget(WidgetID.BANK_PIN_GROUP_ID, BANK_PIN_INSTRUCTION_TEXT.getChildId()) == null
|| !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("First click the FIRST digit.") || !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("First click the FIRST digit.")
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Now click the SECOND digit.") && !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Now click the SECOND digit.")
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Time for the THIRD digit.") && !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Time for the THIRD digit.")
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Finally, the FOURTH digit.")) && !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Finally, the FOURTH digit."))
{ {
entered = 0; entered = 0;
@@ -261,4 +225,39 @@ public class RuneLitePlusPlugin extends Plugin
entered += num * 10; entered += num * 10;
} }
} }
private class RuneLitePlusKeyListener implements KeyListener
{
private int lastKeyCycle;
@Override
public void keyTyped(KeyEvent keyEvent)
{
if (!Character.isDigit(keyEvent.getKeyChar()))
{
return;
}
if (client.getGameCycle() - lastKeyCycle <= 5)
{
keyEvent.consume();
return;
}
lastKeyCycle = client.getGameCycle();
clientThread.invoke(() -> handleKey(keyEvent.getKeyChar()));
keyEvent.consume();
}
@Override
public void keyPressed(KeyEvent keyEvent)
{
}
@Override
public void keyReleased(KeyEvent keyEvent)
{
}
}
} }