diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index cfeda7dd..2221c06b 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -231,6 +231,10 @@ public class DisguiseAPI { if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + if (hasActionBarPreference(entity) && !isActionBarShown(entity)) { + disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); + } + disguise.startDisguise(); } @@ -448,15 +452,15 @@ public class DisguiseAPI { * @param entity * @return */ - public static boolean isViewBarToggled(Player entity) { - return hasViewBarPreference(entity) == (DisguiseConfig.getNotifyBar() != DisguiseConfig.NotifyBar.NONE); + public static boolean isActionBarShown(Entity entity) { + return !hasActionBarPreference(entity); } public static boolean hasSelfDisguisePreference(Entity entity) { return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId()); } - public static boolean hasViewBarPreference(Entity entity) { + public static boolean hasActionBarPreference(Entity entity) { return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId()); } @@ -501,16 +505,17 @@ public class DisguiseAPI { } } - public static void setViewBarToggled(Player player, boolean canSeeNotifyBar) { + public static void setActionBarShown(Player player, boolean isShown) { if (isDisguised(player)) { Disguise[] disguises = getDisguises(player); for (Disguise disguise : disguises) { - disguise.setNotifyBar(canSeeNotifyBar ? DisguiseConfig.getNotifyBar() : DisguiseConfig.NotifyBar.NONE); + disguise.setNotifyBar(isShown ? DisguiseConfig.getNotifyBar() : DisguiseConfig.NotifyBar.NONE); } } - if (canSeeNotifyBar == (DisguiseConfig.getNotifyBar() != DisguiseConfig.NotifyBar.NONE)) { + // If default is view and we want the opposite + if (!isShown) { if (!hasSelfDisguisePreference(player)) { DisguiseUtilities.getViewBar().add(player.getUniqueId()); DisguiseUtilities.addSaveAttempt(); diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java index b6b48b52..87a49cea 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseCommand.java @@ -74,6 +74,10 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); } + if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) { + disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); + } + disguise.startDisguise(); if (disguise.isDisguiseInUse()) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java index 1e10dcc8..5aa766bc 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguisePlayerCommand.java @@ -116,6 +116,10 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); } + if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) { + disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); + } + disguise.startDisguise(); if (disguise.isDisguiseInUse()) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java index 29c68818..dc53ac33 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/disguise/DisguiseRadiusCommand.java @@ -194,6 +194,10 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); } + if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) { + disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE); + } + disguise.startDisguise(); if (disguise.isDisguiseInUse()) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewBarCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewBarCommand.java index 9f15088b..f7c2a0b4 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewBarCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseViewBarCommand.java @@ -21,11 +21,11 @@ public class DisguiseViewBarCommand implements CommandExecutor { Player player = (Player) sender; - if (DisguiseAPI.isViewBarToggled(player)) { - DisguiseAPI.setViewBarToggled(player, false); + if (DisguiseAPI.isActionBarShown(player)) { + DisguiseAPI.setActionBarShown(player, false); DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_OFF); } else { - DisguiseAPI.setViewBarToggled(player, true); + DisguiseAPI.setActionBarShown(player, true); DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_ON); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 800bab9b..07aee163 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -373,7 +373,7 @@ public class FlagWatcher { if (optional.isPresent()) { BaseComponent[] base = ComponentConverter.fromWrapper(optional.get()); - return DisguiseUtilities.getSimpleChat(base); + return DisguiseUtilities.getSimpleString(base); } return null; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 8e2802a0..8a05840a 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -2148,6 +2148,14 @@ public class DisguiseUtilities { return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName(); } + public static String quoteHex(String string) { + return string.replaceAll("(<)(#[0-9a-fA-F]{6}>)", "$1\\$2"); + } + + public static String unquoteHex(String string) { + return string.replaceAll("(<)\\\\(#[0-9a-fA-F]{6}>)", "$1$2"); + } + public static void sendMessage(CommandSender sender, String message) { if (!NmsVersion.v1_16.isSupported()) { if (!message.isEmpty()) { @@ -2192,7 +2200,7 @@ public class DisguiseUtilities { return v; } - public static String getSimpleChat(BaseComponent[] components) { + public static String getSimpleString(BaseComponent[] components) { StringBuilder builder = new StringBuilder(); for (BaseComponent component : components) { @@ -2231,7 +2239,7 @@ public class DisguiseUtilities { continue; } - builder.append(((TextComponent) component).getText()); + builder.append(quoteHex(((TextComponent) component).getText())); } return builder.toString(); @@ -2318,7 +2326,7 @@ public class DisguiseUtilities { if (builder.length() > 0) { old = component; component = new TextComponent(component); - old.setText(builder.toString()); + old.setText(unquoteHex(builder.toString())); builder = new StringBuilder(); components.add(old); } @@ -2326,7 +2334,7 @@ public class DisguiseUtilities { old = component; component = new TextComponent(component); String urlString = message.substring(i, pos); - component.setText(urlString); + component.setText(unquoteHex(urlString)); component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, urlString.startsWith("http") ? urlString : "http://" + urlString)); components.add(component); @@ -2338,9 +2346,9 @@ public class DisguiseUtilities { } } - component.setText(builder.toString()); + component.setText(unquoteHex(builder.toString())); components.add(component); - return components.toArray(new BaseComponent[components.size()]); + return components.toArray(new BaseComponent[0]); } public static boolean isOlderThan(String requiredVersion, String theirVersion) {