Add remember user option

This commit is contained in:
sethtroll
2017-07-09 22:54:13 -05:00
parent 37124ad3fc
commit c1b9185fe7
4 changed files with 155 additions and 0 deletions

View File

@@ -103,6 +103,16 @@ public class Client
return GameState.of(client.getGameState());
}
public String getUsername()
{
return client.getUsername();
}
public void setUsername(String name)
{
client.setUsername(name);
}
public Canvas getCanvas()
{
return client.getCanvas();

View File

@@ -50,6 +50,7 @@ import net.runelite.client.plugins.jewelrycount.JewelryCount;
import net.runelite.client.plugins.mousehighlight.MouseHighlight;
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
import net.runelite.client.plugins.pestcontrol.PestControl;
import net.runelite.client.plugins.rememberusername.RememberUsername;
import net.runelite.client.plugins.runecraft.Runecraft;
import net.runelite.client.plugins.woodcutting.WoodcuttingPlugin;
import net.runelite.client.plugins.xpglobes.XpGlobes;
@@ -97,6 +98,7 @@ public class PluginManager
plugins.add(new ExaminePlugin());
plugins.add(new FishingPlugin());
plugins.add(new WoodcuttingPlugin());
plugins.add(new RememberUsername());
if (RuneLite.getOptions().has("developer-mode"))
{

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.rememberusername;
import com.google.common.eventbus.Subscribe;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.client.RuneLite;
import net.runelite.client.events.GameStateChanged;
import net.runelite.client.plugins.Plugin;
public class RememberUsername extends Plugin
{
private final Client client = RuneLite.getClient();
private final RememberUsernameConfig config = RuneLite.getRunelite().getConfigManager().getConfig(RememberUsernameConfig.class);
@Override
protected void startUp() throws Exception
{
}
@Override
protected void shutDown() throws Exception
{
}
@Subscribe
public void onGameStateChange(GameStateChanged event)
{
if (!config.enabled())
{
return;
}
if (event.getGameState() == GameState.LOGIN_SCREEN)
{
if (config.username() == null || config.username().isEmpty())
{
return;
}
client.setUsername(config.username());
}
if (event.getGameState() == GameState.LOGGED_IN)
{
if (config.username().equals(client.getUsername()))
{
return;
}
config.username(client.getUsername());
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.rememberusername;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup(
keyName = "rememberusername",
name = "Remember Username",
description = "Configuration for the remember username plugin"
)
public interface RememberUsernameConfig
{
@ConfigItem(
keyName = "enabled",
name = "Enable",
description = "Configures whether remember username plugin is enabled"
)
default boolean enabled()
{
return true;
}
@ConfigItem(
keyName = "username",
name = "",
description = "",
hidden = true
)
default String username()
{
return "";
}
@ConfigItem(
keyName = "username",
name = "",
description = ""
)
void username(String key);
}