Spaces:
Build error
Build error
File size: 5,044 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
package net.minecraft;
import com.google.common.collect.Lists;
import com.mojang.serialization.Codec;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.minecraft.util.StringRepresentable;
import org.jetbrains.annotations.Contract;
public enum ChatFormatting implements StringRepresentable {
BLACK("BLACK", '0', 0, 0),
DARK_BLUE("DARK_BLUE", '1', 1, 170),
DARK_GREEN("DARK_GREEN", '2', 2, 43520),
DARK_AQUA("DARK_AQUA", '3', 3, 43690),
DARK_RED("DARK_RED", '4', 4, 11141120),
DARK_PURPLE("DARK_PURPLE", '5', 5, 11141290),
GOLD("GOLD", '6', 6, 16755200),
GRAY("GRAY", '7', 7, 11184810),
DARK_GRAY("DARK_GRAY", '8', 8, 5592405),
BLUE("BLUE", '9', 9, 5592575),
GREEN("GREEN", 'a', 10, 5635925),
AQUA("AQUA", 'b', 11, 5636095),
RED("RED", 'c', 12, 16733525),
LIGHT_PURPLE("LIGHT_PURPLE", 'd', 13, 16733695),
YELLOW("YELLOW", 'e', 14, 16777045),
WHITE("WHITE", 'f', 15, 16777215),
OBFUSCATED("OBFUSCATED", 'k', true),
BOLD("BOLD", 'l', true),
STRIKETHROUGH("STRIKETHROUGH", 'm', true),
UNDERLINE("UNDERLINE", 'n', true),
ITALIC("ITALIC", 'o', true),
RESET("RESET", 'r', -1, null);
public static final Codec<ChatFormatting> CODEC = StringRepresentable.fromEnum(ChatFormatting::values);
public static final char PREFIX_CODE = '\u00a7';
private static final Map<String, ChatFormatting> FORMATTING_BY_NAME = Arrays.stream(values())
.collect(Collectors.toMap(p_126660_ -> cleanName(p_126660_.name), p_126652_ -> (ChatFormatting)p_126652_));
private static final Pattern STRIP_FORMATTING_PATTERN = Pattern.compile("(?i)\u00a7[0-9A-FK-OR]");
private final String name;
private final char code;
private final boolean isFormat;
private final String toString;
private final int id;
@Nullable
private final Integer color;
private static String cleanName(String p_126663_) {
return p_126663_.toLowerCase(Locale.ROOT).replaceAll("[^a-z]", "");
}
private ChatFormatting(final String p_126627_, final char p_126628_, final int p_126629_, @Nullable final Integer p_126630_) {
this(p_126627_, p_126628_, false, p_126629_, p_126630_);
}
private ChatFormatting(final String p_126634_, final char p_126635_, final boolean p_126636_) {
this(p_126634_, p_126635_, p_126636_, -1, null);
}
private ChatFormatting(final String p_126640_, final char p_126641_, final boolean p_126642_, final int p_126643_, @Nullable final Integer p_126644_) {
this.name = p_126640_;
this.code = p_126641_;
this.isFormat = p_126642_;
this.id = p_126643_;
this.color = p_126644_;
this.toString = "\u00a7" + p_126641_;
}
public char getChar() {
return this.code;
}
public int getId() {
return this.id;
}
public boolean isFormat() {
return this.isFormat;
}
public boolean isColor() {
return !this.isFormat && this != RESET;
}
@Nullable
public Integer getColor() {
return this.color;
}
public String getName() {
return this.name().toLowerCase(Locale.ROOT);
}
@Override
public String toString() {
return this.toString;
}
@Nullable
@Contract("!null->!null;_->_")
public static String stripFormatting(@Nullable String p_126650_) {
return p_126650_ == null ? null : STRIP_FORMATTING_PATTERN.matcher(p_126650_).replaceAll("");
}
@Nullable
public static ChatFormatting getByName(@Nullable String p_126658_) {
return p_126658_ == null ? null : FORMATTING_BY_NAME.get(cleanName(p_126658_));
}
@Nullable
public static ChatFormatting getById(int p_126648_) {
if (p_126648_ < 0) {
return RESET;
} else {
for (ChatFormatting chatformatting : values()) {
if (chatformatting.getId() == p_126648_) {
return chatformatting;
}
}
return null;
}
}
@Nullable
public static ChatFormatting getByCode(char p_126646_) {
char c0 = Character.toLowerCase(p_126646_);
for (ChatFormatting chatformatting : values()) {
if (chatformatting.code == c0) {
return chatformatting;
}
}
return null;
}
public static Collection<String> getNames(boolean p_126654_, boolean p_126655_) {
List<String> list = Lists.newArrayList();
for (ChatFormatting chatformatting : values()) {
if ((!chatformatting.isColor() || p_126654_) && (!chatformatting.isFormat() || p_126655_)) {
list.add(chatformatting.getName());
}
}
return list;
}
@Override
public String getSerializedName() {
return this.getName();
}
} |