Add recent clan chats plugin
Add functionality to display recent clan chats in clan chat interface when you are not in CC.
This commit is contained in:
@@ -35,7 +35,8 @@ import lombok.Getter;
|
|||||||
public enum VarClientStr
|
public enum VarClientStr
|
||||||
{
|
{
|
||||||
CHATBOX_TYPED_TEXT(1),
|
CHATBOX_TYPED_TEXT(1),
|
||||||
INPUT_TEXT(22);
|
INPUT_TEXT(22),
|
||||||
|
RECENT_CLAN_CHAT(129);
|
||||||
|
|
||||||
private final int index;
|
private final int index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ public class WidgetID
|
|||||||
static final int TITLE = 1;
|
static final int TITLE = 1;
|
||||||
static final int NAME = 3;
|
static final int NAME = 3;
|
||||||
static final int OWNER = 5;
|
static final int OWNER = 5;
|
||||||
|
static final int LIST = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Bank
|
static class Bank
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ public enum WidgetInfo
|
|||||||
CLAN_CHAT_TITLE(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.TITLE),
|
CLAN_CHAT_TITLE(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.TITLE),
|
||||||
CLAN_CHAT_NAME(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.NAME),
|
CLAN_CHAT_NAME(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.NAME),
|
||||||
CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER),
|
CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER),
|
||||||
|
CLAN_CHAT_LIST(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.LIST),
|
||||||
|
|
||||||
BANK_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.BANK_CONTAINER),
|
BANK_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.BANK_CONTAINER),
|
||||||
BANK_SEARCH_BUTTON_BACKGROUND(WidgetID.BANK_GROUP_ID, WidgetID.Bank.SEARCH_BUTTON_BACKGROUND),
|
BANK_SEARCH_BUTTON_BACKGROUND(WidgetID.BANK_GROUP_ID, WidgetID.Bank.SEARCH_BUTTON_BACKGROUND),
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Ron <https://github.com/raiyni>
|
||||||
|
* 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 net.runelite.client.config.Config;
|
||||||
|
import net.runelite.client.config.ConfigGroup;
|
||||||
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
|
@ConfigGroup("clanchat")
|
||||||
|
public interface ClanChatConfig extends Config
|
||||||
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "recentChats",
|
||||||
|
name = "Recent Chats",
|
||||||
|
description = "Show recent clan chats.",
|
||||||
|
position = 1
|
||||||
|
)
|
||||||
|
default boolean recentChats()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "chatsData",
|
||||||
|
name = "",
|
||||||
|
description = "",
|
||||||
|
hidden = true
|
||||||
|
)
|
||||||
|
default String chatsData()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "chatsData",
|
||||||
|
name = "",
|
||||||
|
description = ""
|
||||||
|
)
|
||||||
|
void chatsData(String str);
|
||||||
|
}
|
||||||
@@ -24,39 +24,85 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.clanchat;
|
package net.runelite.client.plugins.clanchat;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.time.temporal.ChronoUnit;
|
import com.google.inject.Provides;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.ChatMessageType;
|
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.VarClientStr;
|
||||||
|
import net.runelite.api.WidgetType;
|
||||||
|
import net.runelite.api.events.ConfigChanged;
|
||||||
|
import net.runelite.api.events.GameTick;
|
||||||
import net.runelite.api.events.SetMessage;
|
import net.runelite.api.events.SetMessage;
|
||||||
|
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.client.config.ConfigManager;
|
||||||
import net.runelite.client.game.ClanManager;
|
import net.runelite.client.game.ClanManager;
|
||||||
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.task.Schedule;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Clan Chat",
|
name = "Clan Chat",
|
||||||
description = "Add rank icons to users talking in clan chat",
|
description = "Add rank icons to users talking in clan chat",
|
||||||
tags = {"icons", "rank"}
|
tags = {"icons", "rank", "recent"}
|
||||||
)
|
)
|
||||||
public class ClanChatPlugin extends Plugin
|
public class ClanChatPlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
private static final int MAX_CHATS = 10;
|
||||||
|
private static final String CLAN_CHAT_TITLE = "Clan Chat";
|
||||||
|
private static final String RECENT_TITLE = "Recent Clan Chats";
|
||||||
|
private static final Joiner JOINER = Joiner.on(',').skipNulls();
|
||||||
|
private static final Splitter SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClanManager clanManager;
|
private ClanManager clanManager;
|
||||||
|
|
||||||
@Schedule(
|
@Inject
|
||||||
period = 600,
|
private ClanChatConfig config;
|
||||||
unit = ChronoUnit.MILLIS
|
|
||||||
)
|
private List<String> chats = new ArrayList<>();
|
||||||
public void updateClanChatTitle()
|
|
||||||
|
@Provides
|
||||||
|
ClanChatConfig getConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(ClanChatConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startUp()
|
||||||
|
{
|
||||||
|
chats = new ArrayList<>(SPLITTER.splitToList(config.chatsData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutDown()
|
||||||
|
{
|
||||||
|
resetClanChats();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onConfigChanged(ConfigChanged configChanged)
|
||||||
|
{
|
||||||
|
if (configChanged.getGroup().equals("clanchat") && !config.recentChats())
|
||||||
|
{
|
||||||
|
resetClanChats();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameTick(GameTick gameTick)
|
||||||
{
|
{
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
if (client.getGameState() != GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
@@ -66,7 +112,27 @@ public class ClanChatPlugin extends Plugin
|
|||||||
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
|
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
|
||||||
if (clanChatTitleWidget != null)
|
if (clanChatTitleWidget != null)
|
||||||
{
|
{
|
||||||
clanChatTitleWidget.setText("Clan Chat (" + client.getClanChatCount() + "/100)");
|
Widget clanChatList = client.getWidget(WidgetInfo.CLAN_CHAT_LIST);
|
||||||
|
|
||||||
|
if (client.getClanChatCount() > 0)
|
||||||
|
{
|
||||||
|
clanChatTitleWidget.setText(CLAN_CHAT_TITLE + " (" + client.getClanChatCount() + "/100)");
|
||||||
|
}
|
||||||
|
else if (config.recentChats() && clanChatList.getChildren() == null)
|
||||||
|
{
|
||||||
|
clanChatTitleWidget.setText(RECENT_TITLE);
|
||||||
|
|
||||||
|
loadClanChats();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onVarClientStrChanged(VarClientStrChanged strChanged)
|
||||||
|
{
|
||||||
|
if (strChanged.getIndex() == VarClientStr.RECENT_CLAN_CHAT.getIndex() && config.recentChats())
|
||||||
|
{
|
||||||
|
updateRecentChat(client.getVar(VarClientStr.RECENT_CLAN_CHAT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +150,6 @@ public class ClanChatPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void insertClanRankIcon(final SetMessage message)
|
private void insertClanRankIcon(final SetMessage message)
|
||||||
{
|
{
|
||||||
final ClanMemberRank rank = clanManager.getRank(message.getName());
|
final ClanMemberRank rank = clanManager.getRank(message.getName());
|
||||||
@@ -98,5 +163,65 @@ public class ClanChatPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetClanChats()
|
||||||
|
{
|
||||||
|
Widget clanChatList = client.getWidget(WidgetInfo.CLAN_CHAT_LIST);
|
||||||
|
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
|
||||||
|
|
||||||
|
if (clanChatList == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.getClanChatCount() == 0)
|
||||||
|
{
|
||||||
|
clanChatList.setChildren(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
clanChatTitleWidget.setText(CLAN_CHAT_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadClanChats()
|
||||||
|
{
|
||||||
|
Widget clanChatList = client.getWidget(WidgetInfo.CLAN_CHAT_LIST);
|
||||||
|
if (clanChatList == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int y = 2;
|
||||||
|
clanChatList.setChildren(null);
|
||||||
|
for (String chat : Lists.reverse(chats))
|
||||||
|
{
|
||||||
|
Widget widget = clanChatList.createChild(-1, WidgetType.TEXT);
|
||||||
|
widget.setFontId(494);
|
||||||
|
widget.setTextColor(0xffffff);
|
||||||
|
widget.setText(chat);
|
||||||
|
widget.setOriginalHeight(14);
|
||||||
|
widget.setOriginalWidth(142);
|
||||||
|
widget.setOriginalY(y);
|
||||||
|
widget.setOriginalX(20);
|
||||||
|
widget.revalidate();
|
||||||
|
|
||||||
|
y += 14;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateRecentChat(String s)
|
||||||
|
{
|
||||||
|
if (Strings.isNullOrEmpty(s))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chats.removeIf(s::equalsIgnoreCase);
|
||||||
|
chats.add(s);
|
||||||
|
|
||||||
|
while (chats.size() > MAX_CHATS)
|
||||||
|
{
|
||||||
|
chats.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.chatsData(JOINER.join(chats));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user