Skip to content

Commit

Permalink
FormattedText - remove optimizations that break obtuse edgecases
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 9, 2022
1 parent 021f194 commit 18ac11e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Expand Up @@ -5,12 +5,14 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.md_5.bungee.api.ChatColor;

public class PlayerCompletesAdvancementScriptEventPaperImpl extends PlayerCompletesAdvancementScriptEvent {

@Override
public ObjectTag getContext(String name) {
Debug.log("Raw json: " + PaperModule.componentToJson(event.message()));
switch (name) {
case "message": return new ElementTag(PaperModule.stringifyComponent(event.message()));
}
Expand Down
Expand Up @@ -92,11 +92,7 @@ public static String stringify(BaseComponent[] components) {
while (output.startsWith(POSSIBLE_RESET_PREFIX) && output.length() > 4 && colorCodeInvalidator.isMatch(output.charAt(3))) {
output = output.substring(2);
}
return output;
}

public static boolean needsAppendCode(ChatColor color, Boolean bool, boolean trueBool) {
return (bool != null && bool) || (color != null && trueBool);
return cleanRedundantCodes(output);
}

public static String stringifyRGBSpigot(String hex) {
Expand All @@ -119,26 +115,26 @@ public static String stringify(BaseComponent component) {
return null;
}
StringBuilder builder = new StringBuilder(128);
ChatColor color = component.getColorRaw();
ChatColor color = component.getColor();
if (color != null) {
builder.append(color);
}
if (needsAppendCode(color, component.isBoldRaw(), component.isBold())) {
if (component.isBold()) {
builder.append(ChatColor.BOLD);
}
if (needsAppendCode(color, component.isItalicRaw(), component.isItalic())) {
if (component.isItalic()) {
builder.append(ChatColor.ITALIC);
}
if (needsAppendCode(color, component.isStrikethroughRaw(), component.isStrikethrough())) {
if (component.isStrikethrough()) {
builder.append(ChatColor.STRIKETHROUGH);
}
if (needsAppendCode(color, component.isUnderlinedRaw(), component.isUnderlined())) {
if (component.isUnderlined()) {
builder.append(ChatColor.UNDERLINE);
}
if (needsAppendCode(color, component.isObfuscatedRaw(), component.isObfuscated())) {
if (component.isObfuscated()) {
builder.append(ChatColor.MAGIC);
}
if (component.getFontRaw() != null || (component.getFont() != null && color != null)) {
if (component.getFontRaw() != null || (component.getFont() != null && component.getColorRaw() != null)) {
builder.append(ChatColor.COLOR_CHAR).append("[font=").append(component.getFont()).append("]");
}
boolean hasInsertion = component.getInsertion() != null;
Expand Down

0 comments on commit 18ac11e

Please sign in to comment.