Merge pull request #1006 from Infinitay/kingdom-of-miscellania
Added Kingdom of Miscellania plugin
This commit is contained in:
@@ -261,7 +261,13 @@ public enum Varbits
|
|||||||
/**
|
/**
|
||||||
* Multicombat area
|
* Multicombat area
|
||||||
*/
|
*/
|
||||||
MULTICOMBAT_AREA(4605);
|
MULTICOMBAT_AREA(4605),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kingdom Management
|
||||||
|
*/
|
||||||
|
KINGDOM_FAVOR(72),
|
||||||
|
KINGDOM_COFFER(74);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* varbit id
|
* varbit id
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
|
* 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.kingdomofmiscellania;
|
||||||
|
|
||||||
|
import net.runelite.client.config.Config;
|
||||||
|
import net.runelite.client.config.ConfigGroup;
|
||||||
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
|
@ConfigGroup(
|
||||||
|
keyName = "kingdom",
|
||||||
|
name = "Kingdom of Miscellania",
|
||||||
|
description = "Configuration for Kingdom of Miscellania plugin"
|
||||||
|
)
|
||||||
|
public interface KingdomConfig extends Config
|
||||||
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "showOnlyInKingdom",
|
||||||
|
name = "Show Only in Kingdom",
|
||||||
|
description = "Configures whether or not to display kingdom information only when in kingdom",
|
||||||
|
position = 1
|
||||||
|
)
|
||||||
|
default boolean showOnlyInKingdom()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "showWhenLow",
|
||||||
|
name = "Show When Low Favor or Coffer",
|
||||||
|
description = "Configures whether or not to display kingdom information when favor or coffer is low",
|
||||||
|
position = 2
|
||||||
|
)
|
||||||
|
default boolean showWhenLow()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "favorLessThanValue",
|
||||||
|
name = "Alert if favor % below",
|
||||||
|
description = "Configures display kingdom information when favor less than value",
|
||||||
|
position = 3
|
||||||
|
)
|
||||||
|
default int favorLessThanValue()
|
||||||
|
{
|
||||||
|
return 95;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "cofferLessThanValue",
|
||||||
|
name = "Alert if coffer below",
|
||||||
|
description = "Configures display kingdom information when coffer less than value",
|
||||||
|
position = 4
|
||||||
|
)
|
||||||
|
default int cofferLessThanValue()
|
||||||
|
{
|
||||||
|
return 1000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
|
* 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.kingdomofmiscellania;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.Counter;
|
||||||
|
import net.runelite.client.util.StackFormatter;
|
||||||
|
|
||||||
|
public class KingdomCounter extends Counter
|
||||||
|
{
|
||||||
|
private final KingdomPlugin plugin;
|
||||||
|
|
||||||
|
public KingdomCounter(BufferedImage image, KingdomPlugin plugin)
|
||||||
|
{
|
||||||
|
super(image, String.valueOf(plugin.getFavor()));
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText()
|
||||||
|
{
|
||||||
|
return KingdomPlugin.getFavorPercent(plugin.getFavor()) + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTooltip()
|
||||||
|
{
|
||||||
|
return String.format("Favor: " + plugin.getFavor() + "/127" + "</br>"
|
||||||
|
+ "Coffer: " + StackFormatter.quantityToRSStackSize(plugin.getCoffer()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Infinitay <https://github.com/Infinitay>
|
||||||
|
* 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.kingdomofmiscellania;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import com.google.common.primitives.Ints;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.Varbits;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
|
import net.runelite.api.events.MapRegionChanged;
|
||||||
|
import net.runelite.api.events.VarbitChanged;
|
||||||
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.plugins.Plugin;
|
||||||
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
|
|
||||||
|
@PluginDescriptor(
|
||||||
|
name = "Kingdom of Miscellania"
|
||||||
|
)
|
||||||
|
@Slf4j
|
||||||
|
public class KingdomPlugin extends Plugin
|
||||||
|
{
|
||||||
|
private static final int[] KINGDOM_REGION = {9787, 9788, 9789, 10043, 10044, 10045, 10299, 10300, 10301};
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private KingdomConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private int favor = -1, coffer = -1;
|
||||||
|
|
||||||
|
private KingdomCounter counter;
|
||||||
|
private BufferedImage counterImage;
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
KingdomConfig provideConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(KingdomConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onConfigChanged(ConfigChanged event)
|
||||||
|
{
|
||||||
|
if (event.getGroup().equals("kingdom") && client.getGameState() == GameState.LOGGED_IN)
|
||||||
|
{
|
||||||
|
processInfobox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startUp() throws Exception
|
||||||
|
{
|
||||||
|
synchronized (ImageIO.class)
|
||||||
|
{
|
||||||
|
counterImage = ImageIO.read(getClass().getResourceAsStream("teak_chest.png"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutDown() throws Exception
|
||||||
|
{
|
||||||
|
removeKingdomInfobox();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onVarbitChanged(VarbitChanged event)
|
||||||
|
{
|
||||||
|
favor = client.getSetting(Varbits.KINGDOM_FAVOR);
|
||||||
|
coffer = client.getSetting(Varbits.KINGDOM_COFFER);
|
||||||
|
processInfobox();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onRegionChanged(MapRegionChanged event)
|
||||||
|
{
|
||||||
|
processInfobox();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processInfobox()
|
||||||
|
{
|
||||||
|
if (client.getGameState() == GameState.LOGGED_IN)
|
||||||
|
{
|
||||||
|
if (!config.showOnlyInKingdom() || isInKingdom())
|
||||||
|
{
|
||||||
|
addKingdomInfobox();
|
||||||
|
}
|
||||||
|
else if (config.showWhenLow() && (isFavorLow(config.favorLessThanValue()) || isCofferLow(config.cofferLessThanValue())))
|
||||||
|
{
|
||||||
|
addKingdomInfobox();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
removeKingdomInfobox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void addKingdomInfobox()
|
||||||
|
{
|
||||||
|
if (counter == null)
|
||||||
|
{
|
||||||
|
counter = new KingdomCounter(counterImage, this);
|
||||||
|
infoBoxManager.addInfoBox(counter);
|
||||||
|
log.debug("Added Kingdom Infobox");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeKingdomInfobox()
|
||||||
|
{
|
||||||
|
if (counter != null)
|
||||||
|
{
|
||||||
|
infoBoxManager.removeInfoBox(counter);
|
||||||
|
counter = null;
|
||||||
|
log.debug("Removed Kingdom Infobox");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInKingdom()
|
||||||
|
{
|
||||||
|
return Ints.indexOf(client.getMapRegions(), KINGDOM_REGION) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFavorLow(int lessThanValue)
|
||||||
|
{
|
||||||
|
int i = getFavorPercent(favor);
|
||||||
|
return i < lessThanValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCofferLow(int lessThanValue)
|
||||||
|
{
|
||||||
|
return coffer < lessThanValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getFavorPercent(int favor)
|
||||||
|
{
|
||||||
|
return (favor * 100) / 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user