Fix up notify bar

This commit is contained in:
libraryaddict 2020-07-03 23:45:48 +12:00
parent e74df537bb
commit b5b9b432f7
7 changed files with 41 additions and 16 deletions

@ -231,6 +231,10 @@ public class DisguiseAPI {
if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises())
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
if (hasActionBarPreference(entity) && !isActionBarShown(entity)) {
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
}
disguise.startDisguise(); disguise.startDisguise();
} }
@ -448,15 +452,15 @@ public class DisguiseAPI {
* @param entity * @param entity
* @return * @return
*/ */
public static boolean isViewBarToggled(Player entity) { public static boolean isActionBarShown(Entity entity) {
return hasViewBarPreference(entity) == (DisguiseConfig.getNotifyBar() != DisguiseConfig.NotifyBar.NONE); return !hasActionBarPreference(entity);
} }
public static boolean hasSelfDisguisePreference(Entity entity) { public static boolean hasSelfDisguisePreference(Entity entity) {
return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId()); return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId());
} }
public static boolean hasViewBarPreference(Entity entity) { public static boolean hasActionBarPreference(Entity entity) {
return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId()); 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)) { if (isDisguised(player)) {
Disguise[] disguises = getDisguises(player); Disguise[] disguises = getDisguises(player);
for (Disguise disguise : disguises) { 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)) { if (!hasSelfDisguisePreference(player)) {
DisguiseUtilities.getViewBar().add(player.getUniqueId()); DisguiseUtilities.getViewBar().add(player.getUniqueId());
DisguiseUtilities.addSaveAttempt(); DisguiseUtilities.addSaveAttempt();

@ -74,6 +74,10 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
} }
if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) {
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
}
disguise.startDisguise(); disguise.startDisguise();
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {

@ -116,6 +116,10 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
} }
if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) {
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
}
disguise.startDisguise(); disguise.startDisguise();
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {

@ -194,6 +194,10 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
} }
if (!DisguiseAPI.isActionBarShown(disguise.getEntity())) {
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
}
disguise.startDisguise(); disguise.startDisguise();
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {

@ -21,11 +21,11 @@ public class DisguiseViewBarCommand implements CommandExecutor {
Player player = (Player) sender; Player player = (Player) sender;
if (DisguiseAPI.isViewBarToggled(player)) { if (DisguiseAPI.isActionBarShown(player)) {
DisguiseAPI.setViewBarToggled(player, false); DisguiseAPI.setActionBarShown(player, false);
DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_OFF); DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_OFF);
} else { } else {
DisguiseAPI.setViewBarToggled(player, true); DisguiseAPI.setActionBarShown(player, true);
DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_ON); DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_ON);
} }

@ -373,7 +373,7 @@ public class FlagWatcher {
if (optional.isPresent()) { if (optional.isPresent()) {
BaseComponent[] base = ComponentConverter.fromWrapper(optional.get()); BaseComponent[] base = ComponentConverter.fromWrapper(optional.get());
return DisguiseUtilities.getSimpleChat(base); return DisguiseUtilities.getSimpleString(base);
} }
return null; return null;

@ -2148,6 +2148,14 @@ public class DisguiseUtilities {
return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName(); 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) { public static void sendMessage(CommandSender sender, String message) {
if (!NmsVersion.v1_16.isSupported()) { if (!NmsVersion.v1_16.isSupported()) {
if (!message.isEmpty()) { if (!message.isEmpty()) {
@ -2192,7 +2200,7 @@ public class DisguiseUtilities {
return v; return v;
} }
public static String getSimpleChat(BaseComponent[] components) { public static String getSimpleString(BaseComponent[] components) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (BaseComponent component : components) { for (BaseComponent component : components) {
@ -2231,7 +2239,7 @@ public class DisguiseUtilities {
continue; continue;
} }
builder.append(((TextComponent) component).getText()); builder.append(quoteHex(((TextComponent) component).getText()));
} }
return builder.toString(); return builder.toString();
@ -2318,7 +2326,7 @@ public class DisguiseUtilities {
if (builder.length() > 0) { if (builder.length() > 0) {
old = component; old = component;
component = new TextComponent(component); component = new TextComponent(component);
old.setText(builder.toString()); old.setText(unquoteHex(builder.toString()));
builder = new StringBuilder(); builder = new StringBuilder();
components.add(old); components.add(old);
} }
@ -2326,7 +2334,7 @@ public class DisguiseUtilities {
old = component; old = component;
component = new TextComponent(component); component = new TextComponent(component);
String urlString = message.substring(i, pos); String urlString = message.substring(i, pos);
component.setText(urlString); component.setText(unquoteHex(urlString));
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
urlString.startsWith("http") ? urlString : "http://" + urlString)); urlString.startsWith("http") ? urlString : "http://" + urlString));
components.add(component); components.add(component);
@ -2338,9 +2346,9 @@ public class DisguiseUtilities {
} }
} }
component.setText(builder.toString()); component.setText(unquoteHex(builder.toString()));
components.add(component); components.add(component);
return components.toArray(new BaseComponent[components.size()]); return components.toArray(new BaseComponent[0]);
} }
public static boolean isOlderThan(String requiredVersion, String theirVersion) { public static boolean isOlderThan(String requiredVersion, String theirVersion) {