This commit is contained in:
gnembon committed 2020-04-28 16:00:51 -03:00
1 parent 9dff0f822a
commit 86e8433d77
1 file changed
+29 -34
+29 -34
View File
@@ -1,14 +1,9 @@
package carpet.utils; package carpet.utils;
import net.minecraft.class_5251;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.BaseText; import net.minecraft.text.*;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@@ -32,32 +27,32 @@ public class Messenger
private static final Pattern colorExtract = Pattern.compile("#([0-9a-fA-F]{6})"); private static final Pattern colorExtract = Pattern.compile("#([0-9a-fA-F]{6})");
public enum CarpetFormatting public enum CarpetFormatting
{ {
ITALIC ('i', (s, f) -> s.setItalic(true)), ITALIC ('i', (s, f) -> s.withItalic(true)),
STRIKE ('s', (s, f) -> s.method_27705(Formatting.STRIKETHROUGH)), STRIKE ('s', (s, f) -> s.withFormatting(Formatting.STRIKETHROUGH)),
UNDERLINE ('u', (s, f) -> s.method_27705(Formatting.UNDERLINE)), UNDERLINE ('u', (s, f) -> s.withFormatting(Formatting.UNDERLINE)),
BOLD ('b', (s, f) -> s.setBold(true)), BOLD ('b', (s, f) -> s.withBold(true)),
OBFUSCATE ('o', (s, f) -> s.method_27705(Formatting.OBFUSCATED)), OBFUSCATE ('o', (s, f) -> s.withFormatting(Formatting.OBFUSCATED)),
WHITE ('w', (s, f) -> s.setColor(Formatting.WHITE)), WHITE ('w', (s, f) -> s.withColor(Formatting.WHITE)),
YELLOW ('y', (s, f) -> s.setColor(Formatting.YELLOW)), YELLOW ('y', (s, f) -> s.withColor(Formatting.YELLOW)),
LIGHT_PURPLE('m', (s, f) -> s.setColor(Formatting.LIGHT_PURPLE)), // magenta LIGHT_PURPLE('m', (s, f) -> s.withColor(Formatting.LIGHT_PURPLE)), // magenta
RED ('r', (s, f) -> s.setColor(Formatting.RED)), RED ('r', (s, f) -> s.withColor(Formatting.RED)),
AQUA ('c', (s, f) -> s.setColor(Formatting.AQUA)), // cyan AQUA ('c', (s, f) -> s.withColor(Formatting.AQUA)), // cyan
GREEN ('l', (s, f) -> s.setColor(Formatting.GREEN)), // lime GREEN ('l', (s, f) -> s.withColor(Formatting.GREEN)), // lime
BLUE ('t', (s, f) -> s.setColor(Formatting.BLUE)), // light blue, teal BLUE ('t', (s, f) -> s.withColor(Formatting.BLUE)), // light blue, teal
DARK_GRAY ('f', (s, f) -> s.setColor(Formatting.DARK_GRAY)), DARK_GRAY ('f', (s, f) -> s.withColor(Formatting.DARK_GRAY)),
GRAY ('g', (s, f) -> s.setColor(Formatting.GRAY)), GRAY ('g', (s, f) -> s.withColor(Formatting.GRAY)),
GOLD ('d', (s, f) -> s.setColor(Formatting.GOLD)), GOLD ('d', (s, f) -> s.withColor(Formatting.GOLD)),
DARK_PURPLE ('p', (s, f) -> s.setColor(Formatting.DARK_PURPLE)), // purple DARK_PURPLE ('p', (s, f) -> s.withColor(Formatting.DARK_PURPLE)), // purple
DARK_RED ('n', (s, f) -> s.setColor(Formatting.DARK_RED)), // brown DARK_RED ('n', (s, f) -> s.withColor(Formatting.DARK_RED)), // brown
DARK_AQUA ('q', (s, f) -> s.setColor(Formatting.DARK_AQUA)), DARK_AQUA ('q', (s, f) -> s.withColor(Formatting.DARK_AQUA)),
DARK_GREEN ('e', (s, f) -> s.setColor(Formatting.DARK_GREEN)), DARK_GREEN ('e', (s, f) -> s.withColor(Formatting.DARK_GREEN)),
DARK_BLUE ('v', (s, f) -> s.setColor(Formatting.DARK_BLUE)), // navy DARK_BLUE ('v', (s, f) -> s.withColor(Formatting.DARK_BLUE)), // navy
BLACK ('k', (s, f) -> s.setColor(Formatting.BLACK)), BLACK ('k', (s, f) -> s.withColor(Formatting.BLACK)),
COLOR ('#', (s, f) -> { COLOR ('#', (s, f) -> {
class_5251 color = class_5251.method_27719("#"+f); TextColor color = TextColor.parse("#"+f);
return color == null ? s : s.method_27703(color); return color == null ? s : s.withColor(color);
}, s -> { }, s -> {
Matcher m = colorExtract.matcher(s); Matcher m = colorExtract.matcher(s);
return m.find() ? m.group(1) : null; return m.find() ? m.group(1) : null;
@@ -87,7 +82,7 @@ public class Messenger
private static BaseText _applyStyleToTextComponent(BaseText comp, String style) private static BaseText _applyStyleToTextComponent(BaseText comp, String style)
{ {
Style myStyle= Style.field_24360.setColor(Formatting.WHITE); Style myStyle= Style.EMPTY.withColor(Formatting.WHITE);
for (CarpetFormatting cf: CarpetFormatting.values()) for (CarpetFormatting cf: CarpetFormatting.values())
{ {
myStyle = cf.apply(style, myStyle); myStyle = cf.apply(style, myStyle);
@@ -137,25 +132,25 @@ public class Messenger
if (desc.charAt(0) == '/') // deprecated if (desc.charAt(0) == '/') // deprecated
{ {
if (previous_message != null) if (previous_message != null)
previous_message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)); previous_message.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message));
return previous_message; return previous_message;
} }
if (desc.charAt(0) == '?') if (desc.charAt(0) == '?')
{ {
if (previous_message != null) if (previous_message != null)
previous_message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message.substring(1))); previous_message.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message.substring(1)));
return previous_message; return previous_message;
} }
if (desc.charAt(0) == '!') if (desc.charAt(0) == '!')
{ {
if (previous_message != null) if (previous_message != null)
previous_message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, message.substring(1))); previous_message.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, message.substring(1)));
return previous_message; return previous_message;
} }
if (desc.charAt(0) == '^') if (desc.charAt(0) == '^')
{ {
if (previous_message != null) if (previous_message != null)
previous_message.getStyle().setHoverEvent(new HoverEvent(HoverEvent.class_5247.field_24342, c(message.substring(1)))); previous_message.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, c(message.substring(1))));
return previous_message; return previous_message;
} }
BaseText txt = new LiteralText(str); BaseText txt = new LiteralText(str);