From 667164f90d46e0db86c0d0b5e3655a3c2f1729fb Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Fri, 1 Jul 2022 15:19:50 +0200 Subject: [PATCH] better claim info message close #160 --- Changelog.md | 1 + .../io/github/flemmli97/flan/claim/Claim.java | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index a4169b4..40b2c80 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Flan 1.7.10 Stops unlock cmd message when keep inventory is on - Fix addClaim cmd bypassing world blacklist - Make admin mode ignore world blacklist +- Make claim info message look nicer Flan 1.7.9 ================ diff --git a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java index 4549b76..ab27094 100644 --- a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java +++ b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java @@ -20,7 +20,9 @@ import io.github.flemmli97.flan.player.PlayerClaimData; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; import net.minecraft.resources.ResourceLocation; @@ -803,9 +805,9 @@ public class Claim implements IPermissionContainer { } if (perms) { if (infoType == InfoType.ALL || infoType == InfoType.GLOBAL) - l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimInfoPerms"), this.globalPerm), ChatFormatting.RED)); + l.add(fromPermissionMap("claimInfoPerms", this.globalPerm)); if (infoType == InfoType.ALL || infoType == InfoType.GROUP) { - l.add(PermHelper.simpleColoredText(ConfigHandler.langManager.get("claimGroupInfoHeader"), ChatFormatting.RED)); + l.add(PermHelper.simpleColoredText(ConfigHandler.langManager.get("claimGroupInfoHeader"), ChatFormatting.GOLD)); Map> nameToGroup = new HashMap<>(); for (Map.Entry e : this.playersGroups.entrySet()) { player.getServer().getProfileCache().get(e.getKey()).ifPresent(pgroup -> @@ -817,8 +819,8 @@ public class Claim implements IPermissionContainer { ); } for (Map.Entry> e : this.permissions.entrySet()) { - l.add(PermHelper.simpleColoredText(String.format(" %s:", e.getKey()), ChatFormatting.DARK_RED)); - l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimGroupPerms"), e.getValue()), ChatFormatting.RED)); + l.add(PermHelper.simpleColoredText(String.format(" %s:", e.getKey()), ChatFormatting.YELLOW)); + l.add(fromPermissionMap("claimGroupPerms", e.getValue())); l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimGroupPlayers"), nameToGroup.getOrDefault(e.getKey(), new ArrayList<>())), ChatFormatting.RED)); } } @@ -827,6 +829,20 @@ public class Claim implements IPermissionContainer { return l; } + private static Component fromPermissionMap(String lang, Map map) { + MutableComponent mapComp = new TextComponent("[").withStyle(ChatFormatting.GRAY); + int i = 0; + for (Map.Entry entry : map.entrySet()) { + MutableComponent pComp = new TextComponent((i != 0 ? ", " : "") + entry.getKey().id + "=").withStyle(ChatFormatting.GRAY); + pComp.append(new TextComponent(entry.getValue().toString()).withStyle(entry.getValue() ? ChatFormatting.GREEN : ChatFormatting.RED)); + mapComp.append(pComp); + i++; + } + mapComp.append("]"); + MutableComponent component = new TranslatableComponent(ConfigHandler.langManager.get(lang), mapComp).withStyle(ChatFormatting.DARK_BLUE); + return component; + } + public enum InfoType { ALL, SIMPLE,