runelite-client: add ConfigItem.warnOnDisable and warnOnEnable to configure when confirmationWarning is shown

This commit is contained in:
Max Weber
2018-01-06 04:22:50 -07:00
committed by Adam
parent 3f5bf99c70
commit f86b478f74
3 changed files with 10 additions and 3 deletions

View File

@@ -44,4 +44,8 @@ public @interface ConfigItem
boolean hidden() default false;
String confirmationWarining() default "";
boolean warnOnEnable() default false;
boolean warnOnDisable() default false;
}

View File

@@ -47,7 +47,8 @@ public interface RuneLiteConfig extends Config
description = "Enable loading of external plugins",
confirmationWarining = "WARNING: Using untrusted third party plugins is a SECURITY RISK\n"
+ " and can result in loss of YOUR ACCOUNT, and compromise the security\n"
+ "of your computer. Are you sure you want to do this?"
+ "of your computer. Are you sure you want to do this?",
warnOnEnable = true
)
default boolean enablePlugins()
{

View File

@@ -104,14 +104,16 @@ public class ConfigPanel extends PluginPanel
if (component instanceof JCheckBox)
{
JCheckBox checkbox = (JCheckBox) component;
if (checkbox.isSelected() && !configItem.confirmationWarining().isEmpty())
boolean originalState = !checkbox.isSelected();
boolean config = originalState ? configItem.warnOnDisable() : configItem.warnOnEnable();
if (!configItem.confirmationWarining().isEmpty() && config)
{
int value = JOptionPane.showOptionDialog(component, configItem.confirmationWarining(),
"Are you sure?", YES_NO_OPTION, WARNING_MESSAGE,
null, new String[] { "Yes", "No" }, "No");
if (value != YES_OPTION)
{
checkbox.setSelected(false);
checkbox.setSelected(originalState);
return;
}
}