Clanchat: Show amount of members near you in infobox
This commit is contained in:
committed by
Tomas Slusny
parent
7f1a50ca77
commit
f57b310e5b
@@ -51,6 +51,16 @@ public interface ClanChatConfig extends Config
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "clanCounter",
|
||||||
|
name = "Clan Members Counter",
|
||||||
|
description = "Show the amount of clan members near you."
|
||||||
|
)
|
||||||
|
default boolean showClanCounter()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "chatsData",
|
keyName = "chatsData",
|
||||||
name = "",
|
name = "",
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Sebastiaan <https://github.com/SebastiaanVanspauwen>
|
||||||
|
* 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.clanchat;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.Counter;
|
||||||
|
|
||||||
|
class ClanChatIndicator extends Counter
|
||||||
|
{
|
||||||
|
private final ClanChatPlugin plugin;
|
||||||
|
|
||||||
|
ClanChatIndicator(BufferedImage image, ClanChatPlugin plugin)
|
||||||
|
{
|
||||||
|
super(image, plugin, plugin.getClanAmount());
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount()
|
||||||
|
{
|
||||||
|
return plugin.getClanAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTooltip()
|
||||||
|
{
|
||||||
|
return plugin.getClanAmount() + " clan member(s) near you";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color getTextColor()
|
||||||
|
{
|
||||||
|
return Color.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.clanchat;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -34,19 +35,27 @@ import net.runelite.api.ChatMessageType;
|
|||||||
import net.runelite.api.ClanMemberRank;
|
import net.runelite.api.ClanMemberRank;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.Player;
|
||||||
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.VarClientStr;
|
import net.runelite.api.VarClientStr;
|
||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.PlayerDespawned;
|
||||||
|
import net.runelite.api.events.PlayerSpawned;
|
||||||
import net.runelite.api.events.VarClientStrChanged;
|
import net.runelite.api.events.VarClientStrChanged;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
import net.runelite.api.widgets.WidgetType;
|
import net.runelite.api.widgets.WidgetType;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.game.ClanManager;
|
import net.runelite.client.game.ClanManager;
|
||||||
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -69,7 +78,18 @@ public class ClanChatPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ClanChatConfig config;
|
private ClanChatConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SpriteManager spriteManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientThread clientThread;
|
||||||
|
|
||||||
private List<String> chats = new ArrayList<>();
|
private List<String> chats = new ArrayList<>();
|
||||||
|
private List<Player> clanMembers = new ArrayList<>();
|
||||||
|
private ClanChatIndicator clanMemberCounter;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ClanChatConfig getConfig(ConfigManager configManager)
|
ClanChatConfig getConfig(ConfigManager configManager)
|
||||||
@@ -86,15 +106,29 @@ public class ClanChatPlugin extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
public void shutDown()
|
public void shutDown()
|
||||||
{
|
{
|
||||||
|
clanMembers.clear();
|
||||||
|
removeClanCounter();
|
||||||
resetClanChats();
|
resetClanChats();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onConfigChanged(ConfigChanged configChanged)
|
public void onConfigChanged(ConfigChanged configChanged)
|
||||||
{
|
{
|
||||||
if (configChanged.getGroup().equals("clanchat") && !config.recentChats())
|
if (configChanged.getGroup().equals("clanchat"))
|
||||||
{
|
{
|
||||||
resetClanChats();
|
if (!config.recentChats())
|
||||||
|
{
|
||||||
|
resetClanChats();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.showClanCounter())
|
||||||
|
{
|
||||||
|
clientThread.invoke(this::addClanCounter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
removeClanCounter();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +181,44 @@ public class ClanChatPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameStateChanged(GameStateChanged state)
|
||||||
|
{
|
||||||
|
if (state.getGameState() == GameState.LOADING)
|
||||||
|
{
|
||||||
|
clanMembers.clear();
|
||||||
|
removeClanCounter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPlayerSpawned(PlayerSpawned event)
|
||||||
|
{
|
||||||
|
if (event.getPlayer().isClanMember())
|
||||||
|
{
|
||||||
|
clanMembers.add(event.getPlayer());
|
||||||
|
|
||||||
|
if (clanMemberCounter == null)
|
||||||
|
{
|
||||||
|
addClanCounter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPlayerDespawned(PlayerDespawned event)
|
||||||
|
{
|
||||||
|
if (clanMembers.remove(event.getPlayer()) && clanMembers.isEmpty())
|
||||||
|
{
|
||||||
|
removeClanCounter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getClanAmount()
|
||||||
|
{
|
||||||
|
return clanMembers.size();
|
||||||
|
}
|
||||||
|
|
||||||
private void insertClanRankIcon(final ChatMessage message)
|
private void insertClanRankIcon(final ChatMessage message)
|
||||||
{
|
{
|
||||||
if (!config.clanChatIcons())
|
if (!config.clanChatIcons())
|
||||||
@@ -228,4 +300,22 @@ public class ClanChatPlugin extends Plugin
|
|||||||
|
|
||||||
config.chatsData(Text.toCSV(chats));
|
config.chatsData(Text.toCSV(chats));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeClanCounter()
|
||||||
|
{
|
||||||
|
infoBoxManager.removeInfoBox(clanMemberCounter);
|
||||||
|
clanMemberCounter = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addClanCounter()
|
||||||
|
{
|
||||||
|
if (!config.showClanCounter() || clanMemberCounter != null )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final BufferedImage image = spriteManager.getSprite(SpriteID.TAB_CLAN_CHAT, 0);
|
||||||
|
clanMemberCounter = new ClanChatIndicator(image, this);
|
||||||
|
infoBoxManager.addInfoBox(clanMemberCounter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class Counter extends InfoBox
|
|||||||
@Override
|
@Override
|
||||||
public String getText()
|
public String getText()
|
||||||
{
|
{
|
||||||
return Integer.toString(count);
|
return Integer.toString(getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user