use of net.minecraft.server.v1_13_R1.ChatModifier in project PaperDev by Kamillaova.
the class CraftChatMessage method fromComponent.
public static String fromComponent(IChatBaseComponent component, EnumChatFormat defaultColor) {
if (component == null)
return "";
StringBuilder out = new StringBuilder();
for (IChatBaseComponent c : (Iterable<IChatBaseComponent>) component) {
ChatModifier modi = c.getChatModifier();
out.append(modi.getColor() == null ? defaultColor : modi.getColor());
if (modi.isBold()) {
out.append(EnumChatFormat.BOLD);
}
if (modi.isItalic()) {
out.append(EnumChatFormat.ITALIC);
}
if (modi.isUnderlined()) {
out.append(EnumChatFormat.UNDERLINE);
}
if (modi.isStrikethrough()) {
out.append(EnumChatFormat.STRIKETHROUGH);
}
if (modi.isRandom()) {
out.append(EnumChatFormat.OBFUSCATED);
}
out.append(c.getText());
}
return out.toString().replaceFirst("^(" + defaultColor + ")*", "");
}
use of net.minecraft.server.v1_13_R1.ChatModifier in project PaperDev by Kamillaova.
the class CraftChatMessage method fixComponent.
private static IChatBaseComponent fixComponent(IChatBaseComponent component, Matcher matcher) {
if (component instanceof ChatComponentText) {
ChatComponentText text = ((ChatComponentText) component);
String msg = text.g();
if (matcher.reset(msg).find()) {
matcher.reset();
ChatModifier modifier = text.getChatModifier() != null ? text.getChatModifier() : new ChatModifier();
List<IChatBaseComponent> extras = new ArrayList<IChatBaseComponent>();
List<IChatBaseComponent> extrasOld = new ArrayList<IChatBaseComponent>(text.a());
component = text = new ChatComponentText("");
int pos = 0;
while (matcher.find()) {
String match = matcher.group();
if (!(match.startsWith("http://") || match.startsWith("https://"))) {
match = "http://" + match;
}
ChatComponentText prev = new ChatComponentText(msg.substring(pos, matcher.start()));
prev.setChatModifier(modifier);
extras.add(prev);
ChatComponentText link = new ChatComponentText(matcher.group());
ChatModifier linkModi = modifier.clone();
linkModi.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
link.setChatModifier(linkModi);
extras.add(link);
pos = matcher.end();
}
ChatComponentText prev = new ChatComponentText(msg.substring(pos));
prev.setChatModifier(modifier);
extras.add(prev);
extras.addAll(extrasOld);
for (IChatBaseComponent c : extras) {
text.addSibling(c);
}
}
}
List extras = component.a();
for (int i = 0; i < extras.size(); i++) {
IChatBaseComponent comp = (IChatBaseComponent) extras.get(i);
if (comp.getChatModifier() != null && comp.getChatModifier().h() == null) {
extras.set(i, fixComponent(comp, matcher));
}
}
if (component instanceof ChatMessage) {
Object[] subs = ((ChatMessage) component).j();
for (int i = 0; i < subs.length; i++) {
Object comp = subs[i];
if (comp instanceof IChatBaseComponent) {
IChatBaseComponent c = (IChatBaseComponent) comp;
if (c.getChatModifier() != null && c.getChatModifier().h() == null) {
subs[i] = fixComponent(c, matcher);
}
} else if (comp instanceof String && matcher.reset((String) comp).find()) {
subs[i] = fixComponent(new ChatComponentText((String) comp), matcher);
}
}
}
return component;
}
Aggregations