diff --git a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java index 2eb34683b2..68d7e21a13 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java +++ b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java @@ -213,7 +213,7 @@ public enum Feature { SHOW_SKYBLOCK_ITEM_ID(213, "settings.showSkyblockItemId", null, true), RESET_SALVAGED_ESSENCES_AFTER_LEAVING_MENU(214, "settings.resetSalvagedEssencesAfterLeavingMenu", null, false), CHANGE_DUNGEON_MAP_ZOOM_WITH_KEYBOARD(215, "settings.changeDungeonMapZoomWithKeyboard", null, false), - PROFILE_TYPE_IN_CHAT(216, "settings.showProfileTypeInChat", null, true), + PLAYER_SYMBOLS_IN_CHAT(216, "settings.showPlayerSymbolsInChat", null, false), CRIMSON_ARMOR_ABILITY_STACKS(217, "settings.crimsonArmorAbilityStacks", new GuiFeatureData(EnumUtils.DrawType.TEXT, ColorCode.GOLD), false), HIDE_TRUE_DEFENSE(218, "settings.hideTrueDefense", new GuiFeatureData(ColorCode.RED), false), diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabListRenderer.java b/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabListRenderer.java index 17b49b7ce8..7cf5b6143d 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabListRenderer.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabListRenderer.java @@ -90,7 +90,7 @@ public static void render() { int savedX = middleX; if (tabLine.getType() == TabStringType.PLAYER) { - NetworkPlayerInfo networkPlayerInfo = mc.getNetHandler().getPlayerInfo(TextUtils.stripColor(tabLine.getText())); + NetworkPlayerInfo networkPlayerInfo = mc.getNetHandler().getPlayerInfo(TextUtils.stripUsername(tabLine.getText())); if (networkPlayerInfo != null) { EntityPlayer entityPlayer = mc.theWorld.getPlayerEntityByUUID(networkPlayerInfo.getGameProfile().getId()); diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabStringType.java b/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabStringType.java index 832228720a..289c74a1d6 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabStringType.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/tablist/TabStringType.java @@ -10,8 +10,7 @@ public enum TabStringType { PLAYER; public static TabStringType fromLine(String line) { - String strippedLine = TextUtils.stripColor(line); - + String strippedLine = TextUtils.stripUsername(line); if (strippedLine.startsWith(" ")) { return TEXT; } diff --git a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java index 531101bf7f..ffc1fe7432 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java +++ b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java @@ -43,7 +43,10 @@ import net.minecraft.client.audio.SoundCategory; import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiPlayerTabOverlay; import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; @@ -61,7 +64,9 @@ import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.*; +import net.minecraft.world.WorldSettings; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.client.event.sound.PlaySoundEvent; @@ -372,13 +377,17 @@ public void onChatReceive(ClientChatReceivedEvent e) { !fetchur.hasFetchedToday() && unformattedText.contains(fetchur.getFetchurAlreadyDidTaskPhrase())) { FetchurManager.getInstance().saveLastTimeFetched(); } - // Tries to check if a message is from a player to add the player profile icon - } else if (main.getConfigValues().isEnabled(Feature.PROFILE_TYPE_IN_CHAT) && + // Tries to check if a message is from a player to add the player profile icon + } else if (main.getConfigValues().isEnabled(Feature.PLAYER_SYMBOLS_IN_CHAT) && unformattedText.contains(":")) { - String username = unformattedText.split(":")[0].replaceAll("§.",""); - // Remove rank prefix if exists - if (username.contains("]")) - username = username.split("] ")[1]; + // For some reason guild chat messages still contain color codes in the unformatted text + String username = TextUtils.stripColor(unformattedText.split(":")[0]); + // Remove rank prefix and guild rank suffix if exists + String[] splitted = username.split("\\[[^\\[\\]]*\\]"); + if (splitted.length>1) { + username = TextUtils.trimWhitespaceAndResets(splitted[1]); + logger.info(username); + } // Check if stripped username is a real username or the player if (TextUtils.isUsername(username) || username.equals("**MINECRAFTUSERNAME**")) { EntityPlayer chattingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username); @@ -386,6 +395,16 @@ public void onChatReceive(ClientChatReceivedEvent e) { if(chattingPlayer != null) { namesWithType.put(username, chattingPlayer.getDisplayName().getSiblings().get(0).getUnformattedText()); } + // Otherwise search in tablist + else { + Collection networkPlayerInfos = Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap(); + String finalUsername = username; + Optional result = networkPlayerInfos.stream().filter(npi -> npi.getDisplayName() != null).filter(npi -> TextUtils.stripUsername(npi.getDisplayName().getUnformattedText()).equals(finalUsername)).findAny(); + // Put in cache if found + if(result.isPresent()){ + namesWithType.put(username, result.get().getDisplayName().getFormattedText()); + } + } // Check cache regardless if found nearby if(namesWithType.containsKey(username)){ IChatComponent oldMessage = e.message; @@ -827,26 +846,26 @@ public void onEntitySpawn(EntityEvent.EnteringChunk e) { } } if (main.getUtils().isOnSkyblock()) { - Minecraft mc = Minecraft.getMinecraft(); - for (Entity cubes : mc.theWorld.loadedEntityList) { - if (main.getConfigValues().isEnabled(Feature.BAL_BOSS_ALERT) && main.getUtils().isOnSkyblock() && LocationUtils.isInCrystalHollows(main.getUtils().getLocation().getScoreboardName())) { - if (cubes instanceof EntityMagmaCube) { - EntitySlime magma = (EntitySlime) cubes; - if (magma.getSlimeSize() > 10) { // Find a big bal boss - if ((lastBal == -1 || System.currentTimeMillis() - lastBal > 240000)) { - lastBal = System.currentTimeMillis(); - main.getRenderListener().setTitleFeature(Feature.BAL_BOSS_ALERT); // Enable warning and disable again in four seconds. - balTick = 16; // so the sound plays instantly - main.getScheduler().schedule(Scheduler.CommandType.RESET_TITLE_FEATURE, main.getConfigValues().getWarningSeconds()); - } - if (main.getRenderListener().getTitleFeature() == Feature.BAL_BOSS_ALERT && balTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second. - main.getUtils().playLoudSound("random.orb", 0.5); + Minecraft mc = Minecraft.getMinecraft(); + for (Entity cubes : mc.theWorld.loadedEntityList) { + if (main.getConfigValues().isEnabled(Feature.BAL_BOSS_ALERT) && main.getUtils().isOnSkyblock() && LocationUtils.isInCrystalHollows(main.getUtils().getLocation().getScoreboardName())) { + if (cubes instanceof EntityMagmaCube) { + EntitySlime magma = (EntitySlime) cubes; + if (magma.getSlimeSize() > 10) { // Find a big bal boss + if ((lastBal == -1 || System.currentTimeMillis() - lastBal > 240000)) { + lastBal = System.currentTimeMillis(); + main.getRenderListener().setTitleFeature(Feature.BAL_BOSS_ALERT); // Enable warning and disable again in four seconds. + balTick = 16; // so the sound plays instantly + main.getScheduler().schedule(Scheduler.CommandType.RESET_TITLE_FEATURE, main.getConfigValues().getWarningSeconds()); + } + if (main.getRenderListener().getTitleFeature() == Feature.BAL_BOSS_ALERT && balTick % 4 == 0) { // Play sound every 4 ticks or 1/5 second. + main.getUtils().playLoudSound("random.orb", 0.5); + } } } } } } - } if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.ZEALOT_COUNTER_EXPLOSIVE_BOW_SUPPORT) && entity instanceof EntityArrow) { EntityArrow arrow = (EntityArrow) entity; diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/EnumUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/EnumUtils.java index b30dff1690..d9d2e86ac2 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/EnumUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/EnumUtils.java @@ -296,10 +296,9 @@ public enum FeatureCredit { SKYCATMINEPOKIE("skycatminepokie", "github.com/skycatminepokie", Feature.OUTBID_ALERT_SOUND), TIMOLOB("TimoLob", "github.com/TimoLob", Feature.BROOD_MOTHER_ALERT), NOPOTHEGAMER("NopoTheGamer", "twitch.tv/nopothegamer", Feature.BAL_BOSS_ALERT), - CATFACE("CatFace","github.com/CattoFace",Feature.PROFILE_TYPE_IN_CHAT), + CATFACE("CatFace","github.com/CattoFace",Feature.PLAYER_SYMBOLS_IN_CHAT), HANNIBAL2("Hannibal2", "github.com/hannibal00212", Feature.CRIMSON_ARMOR_ABILITY_STACKS, Feature.HIDE_TRUE_DEFENSE); - private final Set features; private final String author; private final String url; diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java index 3c37de79ea..8599c0dd39 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java @@ -20,6 +20,7 @@ public class TextUtils { public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)§[0-9A-FK-ORZ]"); + private static final Pattern STRIP_ICONS_PATTERN = Pattern.compile("[♲Ⓑ⚒ቾ]+"); private static final Pattern REPEATED_COLOR_PATTERN = Pattern.compile("(?i)(§[0-9A-FK-ORZ])+"); private static final Pattern NUMBERS_SLASHES = Pattern.compile("[^0-9 /]"); 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) { return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); } + /** + * Strips icons from player names + * @param input Text to strip icons from + * @return Text without icons + */ + public static String stripIcons(String input) { + return STRIP_ICONS_PATTERN.matcher(input).replaceAll(""); + } + + /** + * Strips icons and colors and trims spaces from a potential username + * @param input Text to strip from + * @return Stripped Text + */ + public static String stripUsername(String input) { + return trimWhitespaceAndResets(stripIcons(stripColor((input)))); + } + /** * Computationally efficient way to test if a given string has a rendered length of 0 * @param input string to test diff --git a/src/main/resources/lang/en_US.json b/src/main/resources/lang/en_US.json index e1d64d47e7..dd2cf2fcc4 100644 --- a/src/main/resources/lang/en_US.json +++ b/src/main/resources/lang/en_US.json @@ -220,7 +220,7 @@ "showFeatureNamesOnHover": "Show Feature Names on Hover", "resetSalvagedEssencesAfterLeavingMenu": "Reset Salvaged Essence Counter After Closing Menu", "changeDungeonMapZoomWithKeyboard": "Adjust zoom with +/- keys", - "showProfileTypeInChat": "Show Profile Type In Chat", + "showPlayerSymbolsInChat": "Show Player Symbols In Chat", "crimsonArmorAbilityStacks": "Show Crimson Armor Stacks", "hideTrueDefense": "Hide True Defense" },