Merge clan chat and player indicators plugin
As the only purpose of clan chat was to add clan chat icons for players in CC, this functionality can be done too from Player Indicators plugin. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
@@ -1,258 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
|
||||
* 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 com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.IOException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.ClanMember;
|
||||
import net.runelite.api.ClanMemberRank;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.IndexedSprite;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.SetMessage;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Clan Chat"
|
||||
)
|
||||
@Slf4j
|
||||
public class ClanChatPlugin extends Plugin
|
||||
{
|
||||
private static final String[] CLANCHAT_IMAGES =
|
||||
{
|
||||
"Friend_clan_rank.png", "Recruit_clan_rank.png",
|
||||
"Corporal_clan_rank.png", "Sergeant_clan_rank.png",
|
||||
"Lieutenant_clan_rank.png", "Captain_clan_rank.png",
|
||||
"General_clan_rank.png", "Owner_clan_rank.png"
|
||||
};
|
||||
|
||||
|
||||
private final LoadingCache<String, ClanMemberRank> clanRanksCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100)
|
||||
.expireAfterAccess(1, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<String, ClanMemberRank>()
|
||||
{
|
||||
@Override
|
||||
public ClanMemberRank load(String key) throws Exception
|
||||
{
|
||||
final ClanMember[] clanMembersArr = client.getClanMembers();
|
||||
|
||||
if (clanMembersArr == null || clanMembersArr.length == 0)
|
||||
{
|
||||
return ClanMemberRank.UNRANKED;
|
||||
}
|
||||
|
||||
return Arrays.stream(clanMembersArr)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(clanMember -> sanitize(clanMember.getUsername()).equals(sanitize(key)))
|
||||
.map(ClanMember::getRank)
|
||||
.findAny()
|
||||
.orElse(ClanMemberRank.UNRANKED);
|
||||
}
|
||||
});
|
||||
|
||||
private int modIconsLength;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
if (modIconsLength == 0 && client.getGameState().compareTo(GameState.LOGIN_SCREEN) >= 0)
|
||||
{
|
||||
loadClanChatIcons();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
clanRanksCache.invalidateAll();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||
{
|
||||
if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN
|
||||
&& modIconsLength == 0)
|
||||
{
|
||||
// this is after "Loading sprites" so we can modify modicons now
|
||||
loadClanChatIcons();
|
||||
}
|
||||
}
|
||||
|
||||
@Schedule(
|
||||
period = 600,
|
||||
unit = ChronoUnit.MILLIS
|
||||
)
|
||||
public void updateClanChatTitle()
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
|
||||
if (clanChatTitleWidget != null)
|
||||
{
|
||||
clanChatTitleWidget.setText("Clan Chat (" + client.getClanChatCount() + "/100)");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onSetMessage(SetMessage setMessage)
|
||||
{
|
||||
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (setMessage.getType() == ChatMessageType.CLANCHAT && client.getClanChatCount() > 0)
|
||||
{
|
||||
insertClanRankIcon(setMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadClanChatIcons()
|
||||
{
|
||||
try
|
||||
{
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
|
||||
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
|
||||
|
||||
for (String resource : CLANCHAT_IMAGES)
|
||||
{
|
||||
IndexedSprite sprite = createIndexedSprite(resource);
|
||||
newModIcons[curPosition++] = sprite;
|
||||
}
|
||||
|
||||
client.setModIcons(newModIcons);
|
||||
modIconsLength = newModIcons.length;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.warn("Failed loading of clan chat icons", e);
|
||||
}
|
||||
}
|
||||
|
||||
private IndexedSprite createIndexedSprite(final String imagePath) throws IOException
|
||||
{
|
||||
final BufferedImage bufferedImage = rgbaToIndexedBufferedImage(ImageIO
|
||||
.read(this.getClass().getResource(imagePath)));
|
||||
|
||||
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel();
|
||||
|
||||
final int width = bufferedImage.getWidth();
|
||||
final int height = bufferedImage.getHeight();
|
||||
final byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
|
||||
final int[] palette = new int[indexedCM.getMapSize()];
|
||||
indexedCM.getRGBs(palette);
|
||||
|
||||
final IndexedSprite newIndexedSprite = client.createIndexedSprite();
|
||||
newIndexedSprite.setPixels(pixels);
|
||||
newIndexedSprite.setPalette(palette);
|
||||
newIndexedSprite.setWidth(width);
|
||||
newIndexedSprite.setHeight(height);
|
||||
newIndexedSprite.setOriginalWidth(width);
|
||||
newIndexedSprite.setOriginalHeight(height);
|
||||
newIndexedSprite.setOffsetX(0);
|
||||
newIndexedSprite.setOffsetY(0);
|
||||
return newIndexedSprite;
|
||||
}
|
||||
|
||||
private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage)
|
||||
{
|
||||
final BufferedImage indexedImage = new BufferedImage(
|
||||
sourceBufferedImage.getWidth(),
|
||||
sourceBufferedImage.getHeight(),
|
||||
BufferedImage.TYPE_BYTE_INDEXED);
|
||||
|
||||
final ColorModel cm = indexedImage.getColorModel();
|
||||
final IndexColorModel icm = (IndexColorModel) cm;
|
||||
|
||||
final int size = icm.getMapSize();
|
||||
final byte[] reds = new byte[size];
|
||||
final byte[] greens = new byte[size];
|
||||
final byte[] blues = new byte[size];
|
||||
icm.getReds(reds);
|
||||
icm.getGreens(greens);
|
||||
icm.getBlues(blues);
|
||||
|
||||
final WritableRaster raster = indexedImage.getRaster();
|
||||
final int pixel = raster.getSample(0, 0, 0);
|
||||
final IndexColorModel resultIcm = new IndexColorModel(8, size, reds, greens, blues, pixel);
|
||||
final BufferedImage resultIndexedImage = new BufferedImage(resultIcm, raster, sourceBufferedImage.isAlphaPremultiplied(), null);
|
||||
resultIndexedImage.getGraphics().drawImage(sourceBufferedImage, 0, 0, null);
|
||||
return resultIndexedImage;
|
||||
}
|
||||
|
||||
private void insertClanRankIcon(final SetMessage message)
|
||||
{
|
||||
final String playerName = sanitize(message.getName());
|
||||
final ClanMemberRank rank = clanRanksCache.getUnchecked(playerName);
|
||||
|
||||
if (rank != null && rank != ClanMemberRank.UNRANKED)
|
||||
{
|
||||
int iconNumber = getIconNumber(rank);
|
||||
message.getMessageNode()
|
||||
.setSender(message.getMessageNode().getSender() + " <img=" + iconNumber + ">");
|
||||
client.refreshChat();
|
||||
}
|
||||
}
|
||||
|
||||
private int getIconNumber(final ClanMemberRank clanMemberRank)
|
||||
{
|
||||
return modIconsLength - CLANCHAT_IMAGES.length + clanMemberRank.getValue();
|
||||
}
|
||||
|
||||
private static String sanitize(String lookup)
|
||||
{
|
||||
final String cleaned = lookup.contains("<img") ? lookup.substring(lookup.lastIndexOf('>') + 1) : lookup;
|
||||
return cleaned.replace('\u00A0', ' ');
|
||||
}
|
||||
}
|
||||
@@ -167,4 +167,15 @@ public interface PlayerIndicatorsConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 12,
|
||||
keyName = "showClanRankIcons",
|
||||
name = "Show clan member rank icons next to names",
|
||||
description = "Configures whether or not icons representing rank are shown next to player names"
|
||||
)
|
||||
default boolean showClanRankIcons()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,22 +56,22 @@ public class PlayerIndicatorsMinimapOverlay extends Overlay
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
|
||||
if (config.drawMinimapNames())
|
||||
{
|
||||
playerIndicatorsService.forEachPlayer((player, color) -> renderPlayerOverlay(graphics, player, color));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color)
|
||||
{
|
||||
final String name = Text.removeTags(actor.getName());
|
||||
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
|
||||
|
||||
if (config.drawMinimapNames())
|
||||
if (minimapLocation != null)
|
||||
{
|
||||
final net.runelite.api.Point minimapLocation = actor.getMinimapLocation();
|
||||
|
||||
if (minimapLocation != null)
|
||||
{
|
||||
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
|
||||
}
|
||||
OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,14 @@ import com.google.inject.Provides;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.SetMessage;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
@@ -42,6 +49,8 @@ import net.runelite.client.ui.overlay.Overlay;
|
||||
)
|
||||
public class PlayerIndicatorsPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private PlayerIndicatorsOverlay playerIndicatorsOverlay;
|
||||
@@ -87,12 +96,43 @@ public class PlayerIndicatorsPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||
{
|
||||
playerIndicatorsService.updateConfig(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onSetMessage(SetMessage setMessage)
|
||||
{
|
||||
if (client.getGameState() != GameState.LOADING && client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (setMessage.getType() == ChatMessageType.CLANCHAT && client.getClanChatCount() > 0)
|
||||
{
|
||||
playerIndicatorsService.insertClanRankIcon(setMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@Schedule(
|
||||
period = 1,
|
||||
unit = ChronoUnit.SECONDS
|
||||
)
|
||||
public void updatePlayerNames()
|
||||
{
|
||||
if (client.getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget clanChatTitleWidget = client.getWidget(WidgetInfo.CLAN_CHAT_TITLE);
|
||||
if (clanChatTitleWidget != null)
|
||||
{
|
||||
clanChatTitleWidget.setText("Clan Chat (" + client.getClanChatCount() + "/100)");
|
||||
}
|
||||
|
||||
playerIndicatorsService.updatePlayers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,74 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.playerindicators;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.ClanMember;
|
||||
import net.runelite.api.ClanMemberRank;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.IndexedSprite;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.PlayerNameMask;
|
||||
import net.runelite.api.events.SetMessage;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@Singleton
|
||||
@Slf4j
|
||||
public class PlayerIndicatorsService
|
||||
{
|
||||
private static final int NUMBER_OF_RANKS = 8;
|
||||
private static final String[] CLANCHAT_IMAGES =
|
||||
{
|
||||
"Friend_clan_rank.png", "Recruit_clan_rank.png",
|
||||
"Corporal_clan_rank.png", "Sergeant_clan_rank.png",
|
||||
"Lieutenant_clan_rank.png", "Captain_clan_rank.png",
|
||||
"General_clan_rank.png", "Owner_clan_rank.png"
|
||||
};
|
||||
|
||||
private final LoadingCache<String, ClanMemberRank> clanRanksCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100)
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<String, ClanMemberRank>()
|
||||
{
|
||||
@Override
|
||||
public ClanMemberRank load(@Nonnull String key)
|
||||
{
|
||||
final ClanMember[] clanMembersArr = client.getClanMembers();
|
||||
|
||||
if (clanMembersArr == null || clanMembersArr.length == 0)
|
||||
{
|
||||
return ClanMemberRank.UNRANKED;
|
||||
}
|
||||
|
||||
return Arrays.stream(clanMembersArr)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(clanMember -> clanMember.getUsername().equals(key))
|
||||
.map(ClanMember::getRank)
|
||||
.findAny()
|
||||
.orElse(ClanMemberRank.UNRANKED);
|
||||
}
|
||||
});
|
||||
|
||||
private final Client client;
|
||||
private final PlayerIndicatorsConfig config;
|
||||
private int modIconsLength;
|
||||
|
||||
@Inject
|
||||
private PlayerIndicatorsService(Client client, PlayerIndicatorsConfig config)
|
||||
@@ -52,6 +102,27 @@ public class PlayerIndicatorsService
|
||||
|
||||
public void updateConfig(boolean reset)
|
||||
{
|
||||
// Update mod icons
|
||||
if (modIconsLength == 0 && client.getGameState().compareTo(GameState.LOGIN_SCREEN) >= 0)
|
||||
{
|
||||
loadClanChatIcons();
|
||||
}
|
||||
|
||||
// Reset player names
|
||||
for (Player player : client.getPlayers())
|
||||
{
|
||||
if (player != null && player.getName() != null)
|
||||
{
|
||||
player.setName(Text.removeTags(player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
// Reset clan rank cache
|
||||
if (reset)
|
||||
{
|
||||
clanRanksCache.invalidateAll();
|
||||
}
|
||||
|
||||
// Update mask
|
||||
int baseMask = 0;
|
||||
|
||||
@@ -79,14 +150,6 @@ public class PlayerIndicatorsService
|
||||
}
|
||||
|
||||
client.setPlayerNameMask(baseMask);
|
||||
|
||||
for (Player player : client.getPlayers())
|
||||
{
|
||||
if (player != null && player.getName() != null)
|
||||
{
|
||||
player.setName(Text.removeTags(player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayers()
|
||||
@@ -97,8 +160,10 @@ public class PlayerIndicatorsService
|
||||
|
||||
public void forEachPlayer(final BiConsumer<Player, Color> consumer)
|
||||
{
|
||||
if (!config.drawOwnName() && !config.drawClanMemberNames()
|
||||
&& !config.drawFriendNames() && !config.drawNonOwnNames()
|
||||
if (!config.drawOwnName()
|
||||
&& !config.drawClanMemberNames()
|
||||
&& !config.drawFriendNames()
|
||||
&& !config.drawNonOwnNames()
|
||||
&& !config.drawTeamMemberNames())
|
||||
{
|
||||
return;
|
||||
@@ -141,35 +206,40 @@ public class PlayerIndicatorsService
|
||||
}
|
||||
}
|
||||
|
||||
public void insertClanRankIcon(final SetMessage message)
|
||||
{
|
||||
if (!config.showClanRankIcons())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final String playerName = Text.removeTags(message.getName());
|
||||
final ClanMemberRank rank = clanRanksCache.getUnchecked(playerName);
|
||||
|
||||
if (rank != null && rank != ClanMemberRank.UNRANKED)
|
||||
{
|
||||
int iconNumber = getIconNumber(rank);
|
||||
message.getMessageNode()
|
||||
.setSender(message.getMessageNode().getSender() + " <img=" + iconNumber + ">");
|
||||
client.refreshChat();
|
||||
}
|
||||
}
|
||||
|
||||
private void injectData(final Player player, final Color color)
|
||||
{
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
final int startIndex = modIcons.length - NUMBER_OF_RANKS;
|
||||
final String strippedName = Text.removeTags(player.getName());
|
||||
|
||||
if (startIndex >= 0 && player.isClanMember())
|
||||
if (config.showClanRankIcons() && player.isClanMember())
|
||||
{
|
||||
final ClanMember[] clanMembersArr = client.getClanMembers();
|
||||
final ClanMemberRank clanMemberRank = clanRanksCache.getUnchecked(strippedName);
|
||||
|
||||
if (clanMembersArr != null && clanMembersArr.length > 0)
|
||||
if (clanMemberRank != ClanMemberRank.UNRANKED)
|
||||
{
|
||||
for (ClanMember clanMember : clanMembersArr)
|
||||
{
|
||||
if (clanMember != null && clanMember.getUsername().equals(strippedName))
|
||||
{
|
||||
if (clanMember.getRank() != ClanMemberRank.UNRANKED)
|
||||
{
|
||||
stringBuilder
|
||||
.append("<img=")
|
||||
.append(startIndex + clanMember.getRank().getValue())
|
||||
.append(">");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
stringBuilder
|
||||
.append("<img=")
|
||||
.append(getIconNumber(clanMemberRank))
|
||||
.append(">");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,4 +251,83 @@ public class PlayerIndicatorsService
|
||||
{
|
||||
return String.format("%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
private void loadClanChatIcons()
|
||||
{
|
||||
try
|
||||
{
|
||||
final IndexedSprite[] modIcons = client.getModIcons();
|
||||
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + CLANCHAT_IMAGES.length);
|
||||
int curPosition = newModIcons.length - CLANCHAT_IMAGES.length;
|
||||
|
||||
for (String resource : CLANCHAT_IMAGES)
|
||||
{
|
||||
IndexedSprite sprite = createIndexedSprite(resource);
|
||||
newModIcons[curPosition++] = sprite;
|
||||
}
|
||||
|
||||
client.setModIcons(newModIcons);
|
||||
modIconsLength = newModIcons.length;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.warn("Failed loading of clan chat icons", e);
|
||||
}
|
||||
}
|
||||
|
||||
private IndexedSprite createIndexedSprite(final String imagePath) throws IOException
|
||||
{
|
||||
final BufferedImage bufferedImage = rgbaToIndexedBufferedImage(ImageIO
|
||||
.read(this.getClass().getResource(imagePath)));
|
||||
|
||||
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel();
|
||||
|
||||
final int width = bufferedImage.getWidth();
|
||||
final int height = bufferedImage.getHeight();
|
||||
final byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
|
||||
final int[] palette = new int[indexedCM.getMapSize()];
|
||||
indexedCM.getRGBs(palette);
|
||||
|
||||
final IndexedSprite newIndexedSprite = client.createIndexedSprite();
|
||||
newIndexedSprite.setPixels(pixels);
|
||||
newIndexedSprite.setPalette(palette);
|
||||
newIndexedSprite.setWidth(width);
|
||||
newIndexedSprite.setHeight(height);
|
||||
newIndexedSprite.setOriginalWidth(width);
|
||||
newIndexedSprite.setOriginalHeight(height);
|
||||
newIndexedSprite.setOffsetX(0);
|
||||
newIndexedSprite.setOffsetY(0);
|
||||
return newIndexedSprite;
|
||||
}
|
||||
|
||||
private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage)
|
||||
{
|
||||
final BufferedImage indexedImage = new BufferedImage(
|
||||
sourceBufferedImage.getWidth(),
|
||||
sourceBufferedImage.getHeight(),
|
||||
BufferedImage.TYPE_BYTE_INDEXED);
|
||||
|
||||
final ColorModel cm = indexedImage.getColorModel();
|
||||
final IndexColorModel icm = (IndexColorModel) cm;
|
||||
|
||||
final int size = icm.getMapSize();
|
||||
final byte[] reds = new byte[size];
|
||||
final byte[] greens = new byte[size];
|
||||
final byte[] blues = new byte[size];
|
||||
icm.getReds(reds);
|
||||
icm.getGreens(greens);
|
||||
icm.getBlues(blues);
|
||||
|
||||
final WritableRaster raster = indexedImage.getRaster();
|
||||
final int pixel = raster.getSample(0, 0, 0);
|
||||
final IndexColorModel resultIcm = new IndexColorModel(8, size, reds, greens, blues, pixel);
|
||||
final BufferedImage resultIndexedImage = new BufferedImage(resultIcm, raster, sourceBufferedImage.isAlphaPremultiplied(), null);
|
||||
resultIndexedImage.getGraphics().drawImage(sourceBufferedImage, 0, 0, null);
|
||||
return resultIndexedImage;
|
||||
}
|
||||
|
||||
private int getIconNumber(final ClanMemberRank clanMemberRank)
|
||||
{
|
||||
return modIconsLength - CLANCHAT_IMAGES.length + clanMemberRank.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |