Merge pull request #1136 from runelite-extended/discord-presence
discord: enforce runeliteplus presence
This commit is contained in:
@@ -35,7 +35,6 @@ import net.runelite.http.api.RuneLiteAPI;
|
||||
@Slf4j
|
||||
public class RuneLiteProperties
|
||||
{
|
||||
private static final String DISCORD_APP_ID = "409416265891971072";
|
||||
private static final String DISCORD_APP_ID_PLUS = "560644885250572289";
|
||||
|
||||
private final Properties properties = new Properties();
|
||||
@@ -81,19 +80,7 @@ public class RuneLiteProperties
|
||||
|
||||
public String getDiscordAppId()
|
||||
{
|
||||
if (this.runeLitePlusConfig == null)
|
||||
{
|
||||
return properties.getProperty(DISCORD_APP_ID);
|
||||
}
|
||||
|
||||
if (this.runeLitePlusConfig.customPresence())
|
||||
{
|
||||
return properties.getProperty(DISCORD_APP_ID_PLUS);
|
||||
}
|
||||
else
|
||||
{
|
||||
return properties.getProperty(DISCORD_APP_ID);
|
||||
}
|
||||
return DISCORD_APP_ID_PLUS;
|
||||
}
|
||||
|
||||
public String getDiscordInvite()
|
||||
|
||||
@@ -34,22 +34,11 @@ import net.runelite.client.config.Range;
|
||||
@ConfigGroup("runeliteplus")
|
||||
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(
|
||||
keyName = "enableOpacity",
|
||||
name = "Enable opacity",
|
||||
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()
|
||||
{
|
||||
@@ -64,7 +53,7 @@ public interface RuneLitePlusConfig extends Config
|
||||
keyName = "opacityPercentage",
|
||||
name = "Opacity percentage",
|
||||
description = "Changes the opacity of the window if opacity is enabled",
|
||||
position = 2
|
||||
position = 1
|
||||
)
|
||||
default int opacityPercentage()
|
||||
{
|
||||
@@ -75,7 +64,7 @@ public interface RuneLitePlusConfig extends Config
|
||||
keyName = "keyboardPin",
|
||||
name = "Keyboard bank pin",
|
||||
description = "Enables you to type your bank pin",
|
||||
position = 3
|
||||
position = 2
|
||||
)
|
||||
default boolean keyboardPin()
|
||||
{
|
||||
|
||||
@@ -55,41 +55,7 @@ import net.runelite.client.ui.ClientUI;
|
||||
@Slf4j
|
||||
public class RuneLitePlusPlugin extends Plugin
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private final RuneLitePlusKeyListener keyListener = new RuneLitePlusKeyListener();
|
||||
@Inject
|
||||
private RuneLitePlusConfig config;
|
||||
|
||||
@@ -107,8 +73,6 @@ public class RuneLitePlusPlugin extends Plugin
|
||||
|
||||
@Inject
|
||||
private EventBus eventbus;
|
||||
|
||||
private final RuneLitePlusKeyListener keyListener = new RuneLitePlusKeyListener();
|
||||
private int entered = -1;
|
||||
private int enterIdx;
|
||||
private boolean expectInput;
|
||||
@@ -117,55 +81,14 @@ public class RuneLitePlusPlugin extends Plugin
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
addSubscriptions();
|
||||
|
||||
if (config.customPresence())
|
||||
{
|
||||
ClientUI.currentPresenceName = ("RuneLitePlus");
|
||||
ClientUI.frame.setTitle(ClientUI.currentPresenceName);
|
||||
}
|
||||
|
||||
discordService.close();
|
||||
discordService.init();
|
||||
ClientUI.currentPresenceName = ("RuneLitePlus");
|
||||
ClientUI.frame.setTitle(ClientUI.currentPresenceName);
|
||||
|
||||
entered = -1;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
}
|
||||
|
||||
private void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (!event.getGroup().equals("runeliteplus"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getKey().equals("customPresence"))
|
||||
{
|
||||
if (config.customPresence())
|
||||
{
|
||||
ClientUI.currentPresenceName = ("RuneLitePlus");
|
||||
ClientUI.frame.setTitle(ClientUI.currentPresenceName);
|
||||
discordService.close();
|
||||
discordService.init();
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientUI.currentPresenceName = ("RuneLite");
|
||||
ClientUI.frame.setTitle(ClientUI.currentPresenceName);
|
||||
discordService.close();
|
||||
discordService.init();
|
||||
}
|
||||
}
|
||||
|
||||
else if (!config.keyboardPin())
|
||||
{
|
||||
entered = 0;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
@@ -177,6 +100,22 @@ public class RuneLitePlusPlugin extends Plugin
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
}
|
||||
|
||||
private void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (!event.getGroup().equals("runeliteplus"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
else if (!config.keyboardPin())
|
||||
{
|
||||
entered = 0;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSubscriptions()
|
||||
{
|
||||
eventbus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
|
||||
@@ -221,10 +160,10 @@ public class RuneLitePlusPlugin extends Plugin
|
||||
private void handleKey(char c)
|
||||
{
|
||||
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("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("Finally, the FOURTH 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("Time for the THIRD digit.")
|
||||
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Finally, the FOURTH digit."))
|
||||
|
||||
{
|
||||
entered = 0;
|
||||
@@ -261,4 +200,39 @@ public class RuneLitePlusPlugin extends Plugin
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user