Skip to content

Commit 539f228

Browse files
authored
Improvements to the profile type in chat feature and bug fix for heads in tablist (#653)
1 parent be27586 commit 539f228

File tree

7 files changed

+64
-28
lines changed

7 files changed

+64
-28
lines changed

src/main/java/codes/biscuit/skyblockaddons/core/Feature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public enum Feature {
213213
SHOW_SKYBLOCK_ITEM_ID(213, "settings.showSkyblockItemId", null, true),
214214
RESET_SALVAGED_ESSENCES_AFTER_LEAVING_MENU(214, "settings.resetSalvagedEssencesAfterLeavingMenu", null, false),
215215
CHANGE_DUNGEON_MAP_ZOOM_WITH_KEYBOARD(215, "settings.changeDungeonMapZoomWithKeyboard", null, false),
216-
PROFILE_TYPE_IN_CHAT(216, "settings.showProfileTypeInChat", null, true),
216+
PLAYER_SYMBOLS_IN_CHAT(216, "settings.showPlayerSymbolsInChat", null, false),
217217
CRIMSON_ARMOR_ABILITY_STACKS(217, "settings.crimsonArmorAbilityStacks", new GuiFeatureData(EnumUtils.DrawType.TEXT, ColorCode.GOLD), false),
218218
HIDE_TRUE_DEFENSE(218, "settings.hideTrueDefense", new GuiFeatureData(ColorCode.RED), false),
219219

src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabListRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void render() {
9090
int savedX = middleX;
9191

9292
if (tabLine.getType() == TabStringType.PLAYER) {
93-
NetworkPlayerInfo networkPlayerInfo = mc.getNetHandler().getPlayerInfo(TextUtils.stripColor(tabLine.getText()));
93+
NetworkPlayerInfo networkPlayerInfo = mc.getNetHandler().getPlayerInfo(TextUtils.stripUsername(tabLine.getText()));
9494
if (networkPlayerInfo != null) {
9595
EntityPlayer entityPlayer = mc.theWorld.getPlayerEntityByUUID(networkPlayerInfo.getGameProfile().getId());
9696

src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabStringType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ public enum TabStringType {
1010
PLAYER;
1111

1212
public static TabStringType fromLine(String line) {
13-
String strippedLine = TextUtils.stripColor(line);
14-
13+
String strippedLine = TextUtils.stripUsername(line);
1514
if (strippedLine.startsWith(" ")) {
1615
return TEXT;
1716
}

src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
import net.minecraft.client.audio.SoundCategory;
4444
import net.minecraft.client.entity.EntityOtherPlayerMP;
4545
import net.minecraft.client.entity.EntityPlayerSP;
46+
import net.minecraft.client.gui.GuiPlayerTabOverlay;
4647
import net.minecraft.client.gui.inventory.GuiChest;
48+
import net.minecraft.client.network.NetHandlerPlayClient;
49+
import net.minecraft.client.network.NetworkPlayerInfo;
4750
import net.minecraft.client.settings.KeyBinding;
4851
import net.minecraft.entity.Entity;
4952
import net.minecraft.entity.item.EntityArmorStand;
@@ -61,7 +64,9 @@
6164
import net.minecraft.item.EnumDyeColor;
6265
import net.minecraft.item.ItemStack;
6366
import net.minecraft.nbt.NBTTagCompound;
67+
import net.minecraft.scoreboard.ScorePlayerTeam;
6468
import net.minecraft.util.*;
69+
import net.minecraft.world.WorldSettings;
6570
import net.minecraftforge.client.event.ClientChatReceivedEvent;
6671
import net.minecraftforge.client.event.GuiScreenEvent;
6772
import net.minecraftforge.client.event.sound.PlaySoundEvent;
@@ -372,20 +377,34 @@ public void onChatReceive(ClientChatReceivedEvent e) {
372377
!fetchur.hasFetchedToday() && unformattedText.contains(fetchur.getFetchurAlreadyDidTaskPhrase())) {
373378
FetchurManager.getInstance().saveLastTimeFetched();
374379
}
375-
// Tries to check if a message is from a player to add the player profile icon
376-
} else if (main.getConfigValues().isEnabled(Feature.PROFILE_TYPE_IN_CHAT) &&
380+
// Tries to check if a message is from a player to add the player profile icon
381+
} else if (main.getConfigValues().isEnabled(Feature.PLAYER_SYMBOLS_IN_CHAT) &&
377382
unformattedText.contains(":")) {
378-
String username = unformattedText.split(":")[0].replaceAll("§.","");
379-
// Remove rank prefix if exists
380-
if (username.contains("]"))
381-
username = username.split("] ")[1];
383+
// For some reason guild chat messages still contain color codes in the unformatted text
384+
String username = TextUtils.stripColor(unformattedText.split(":")[0]);
385+
// Remove rank prefix and guild rank suffix if exists
386+
String[] splitted = username.split("\\[[^\\[\\]]*\\]");
387+
if (splitted.length>1) {
388+
username = TextUtils.trimWhitespaceAndResets(splitted[1]);
389+
logger.info(username);
390+
}
382391
// Check if stripped username is a real username or the player
383392
if (TextUtils.isUsername(username) || username.equals("**MINECRAFTUSERNAME**")) {
384393
EntityPlayer chattingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username);
385394
// Put player in cache if found nearby
386395
if(chattingPlayer != null) {
387396
namesWithType.put(username, chattingPlayer.getDisplayName().getSiblings().get(0).getUnformattedText());
388397
}
398+
// Otherwise search in tablist
399+
else {
400+
Collection<NetworkPlayerInfo> networkPlayerInfos = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap();
401+
String finalUsername = username;
402+
Optional<NetworkPlayerInfo> result = networkPlayerInfos.stream().filter(npi -> npi.getDisplayName() != null).filter(npi -> TextUtils.stripUsername(npi.getDisplayName().getUnformattedText()).equals(finalUsername)).findAny();
403+
// Put in cache if found
404+
if(result.isPresent()){
405+
namesWithType.put(username, result.get().getDisplayName().getFormattedText());
406+
}
407+
}
389408
// Check cache regardless if found nearby
390409
if(namesWithType.containsKey(username)){
391410
IChatComponent oldMessage = e.message;
@@ -827,26 +846,26 @@ public void onEntitySpawn(EntityEvent.EnteringChunk e) {
827846
}
828847
}
829848
if (main.getUtils().isOnSkyblock()) {
830-
Minecraft mc = Minecraft.getMinecraft();
831-
for (Entity cubes : mc.theWorld.loadedEntityList) {
832-
if (main.getConfigValues().isEnabled(Feature.BAL_BOSS_ALERT) && main.getUtils().isOnSkyblock() && LocationUtils.isInCrystalHollows(main.getUtils().getLocation().getScoreboardName())) {
833-
if (cubes instanceof EntityMagmaCube) {
834-
EntitySlime magma = (EntitySlime) cubes;
835-
if (magma.getSlimeSize() > 10) { // Find a big bal boss
836-
if ((lastBal == -1 || System.currentTimeMillis() - lastBal > 240000)) {
837-
lastBal = System.currentTimeMillis();
838-
main.getRenderListener().setTitleFeature(Feature.BAL_BOSS_ALERT); // Enable warning and disable again in four seconds.
839-
balTick = 16; // so the sound plays instantly
840-
main.getScheduler().schedule(Scheduler.CommandType.RESET_TITLE_FEATURE, main.getConfigValues().getWarningSeconds());
841-
}
842-
if (main.getRenderListener().getTitleFeature() == Feature.BAL_BOSS_ALERT && balTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second.
843-
main.getUtils().playLoudSound("random.orb", 0.5);
849+
Minecraft mc = Minecraft.getMinecraft();
850+
for (Entity cubes : mc.theWorld.loadedEntityList) {
851+
if (main.getConfigValues().isEnabled(Feature.BAL_BOSS_ALERT) && main.getUtils().isOnSkyblock() && LocationUtils.isInCrystalHollows(main.getUtils().getLocation().getScoreboardName())) {
852+
if (cubes instanceof EntityMagmaCube) {
853+
EntitySlime magma = (EntitySlime) cubes;
854+
if (magma.getSlimeSize() > 10) { // Find a big bal boss
855+
if ((lastBal == -1 || System.currentTimeMillis() - lastBal > 240000)) {
856+
lastBal = System.currentTimeMillis();
857+
main.getRenderListener().setTitleFeature(Feature.BAL_BOSS_ALERT); // Enable warning and disable again in four seconds.
858+
balTick = 16; // so the sound plays instantly
859+
main.getScheduler().schedule(Scheduler.CommandType.RESET_TITLE_FEATURE, main.getConfigValues().getWarningSeconds());
860+
}
861+
if (main.getRenderListener().getTitleFeature() == Feature.BAL_BOSS_ALERT && balTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second.
862+
main.getUtils().playLoudSound("random.orb", 0.5);
863+
}
844864
}
845865
}
846866
}
847867
}
848868
}
849-
}
850869

851870
if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.ZEALOT_COUNTER_EXPLOSIVE_BOW_SUPPORT) && entity instanceof EntityArrow) {
852871
EntityArrow arrow = (EntityArrow) entity;

src/main/java/codes/biscuit/skyblockaddons/utils/EnumUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,9 @@ public enum FeatureCredit {
296296
SKYCATMINEPOKIE("skycatminepokie", "github.com/skycatminepokie", Feature.OUTBID_ALERT_SOUND),
297297
TIMOLOB("TimoLob", "github.com/TimoLob", Feature.BROOD_MOTHER_ALERT),
298298
NOPOTHEGAMER("NopoTheGamer", "twitch.tv/nopothegamer", Feature.BAL_BOSS_ALERT),
299-
CATFACE("CatFace","github.com/CattoFace",Feature.PROFILE_TYPE_IN_CHAT),
299+
CATFACE("CatFace","github.com/CattoFace",Feature.PLAYER_SYMBOLS_IN_CHAT),
300300
HANNIBAL2("Hannibal2", "github.com/hannibal00212", Feature.CRIMSON_ARMOR_ABILITY_STACKS, Feature.HIDE_TRUE_DEFENSE);
301301

302-
303302
private final Set<Feature> features;
304303
private final String author;
305304
private final String url;

src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TextUtils {
2020
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
2121

2222
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)§[0-9A-FK-ORZ]");
23+
private static final Pattern STRIP_ICONS_PATTERN = Pattern.compile("[♲Ⓑ⚒ቾ]+");
2324
private static final Pattern REPEATED_COLOR_PATTERN = Pattern.compile("(?i)(§[0-9A-FK-ORZ])+");
2425
private static final Pattern NUMBERS_SLASHES = Pattern.compile("[^0-9 /]");
2526
private static final Pattern SCOREBOARD_CHARACTERS = Pattern.compile("[^a-z A-Z:0-9_/'.!§\\[\\]❤]");
@@ -59,6 +60,24 @@ public static String stripColor(final String input) {
5960
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
6061
}
6162

63+
/**
64+
* Strips icons from player names
65+
* @param input Text to strip icons from
66+
* @return Text without icons
67+
*/
68+
public static String stripIcons(String input) {
69+
return STRIP_ICONS_PATTERN.matcher(input).replaceAll("");
70+
}
71+
72+
/**
73+
* Strips icons and colors and trims spaces from a potential username
74+
* @param input Text to strip from
75+
* @return Stripped Text
76+
*/
77+
public static String stripUsername(String input) {
78+
return trimWhitespaceAndResets(stripIcons(stripColor((input))));
79+
}
80+
6281
/**
6382
* Computationally efficient way to test if a given string has a rendered length of 0
6483
* @param input string to test

src/main/resources/lang/en_US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"showFeatureNamesOnHover": "Show Feature Names on Hover",
221221
"resetSalvagedEssencesAfterLeavingMenu": "Reset Salvaged Essence Counter After Closing Menu",
222222
"changeDungeonMapZoomWithKeyboard": "Adjust zoom with +/- keys",
223-
"showProfileTypeInChat": "Show Profile Type In Chat",
223+
"showPlayerSymbolsInChat": "Show Player Symbols In Chat",
224224
"crimsonArmorAbilityStacks": "Show Crimson Armor Stacks",
225225
"hideTrueDefense": "Hide True Defense"
226226
},

0 commit comments

Comments
 (0)