1.14 support, fixes #105
13 changed files with 392 additions and 313 deletions
|
@ -1,11 +1,19 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.ThorpeUtils;
|
||||
import lombok.var;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class ChatUtils {
|
||||
private ChatUtils() {}
|
||||
public static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized
|
||||
|
||||
private ChatUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a console command.
|
||||
|
@ -33,4 +41,20 @@ public final class ChatUtils {
|
|||
int b = str.indexOf(end, a);
|
||||
return a != -1 && b != -1 ? Optional.of(str.substring(a, b)) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a regular (non-Markdown) chat message. Used as a fallback if the chat processing fails.
|
||||
*
|
||||
* @param e The chat event
|
||||
* @param modifier A function that alters the message to be displayed to the player
|
||||
*/
|
||||
public static void sendChatMessage(TBMCChatEvent e, Function<String, String> modifier) {
|
||||
var str = "[" + e.getChannel().DisplayName().get() + "] <"
|
||||
+ ThorpeUtils.getDisplayName(e.getSender()) + "> " + e.getMessage();
|
||||
str = modifier.apply(str);
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
if (e.shouldSendTo(p))
|
||||
p.sendMessage(str);
|
||||
Bukkit.getConsoleSender().sendMessage(str);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package buttondevteam.chat.components.chatonly;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package buttondevteam.chat;
|
||||
package buttondevteam.chat.components.formatter;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.VanillaUtils;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
|
||||
import buttondevteam.chat.components.formatter.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawSerializer;
|
||||
import buttondevteam.chat.components.fun.FunComponent;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.chat.formatting.TellrawSerializer;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
|
@ -101,12 +105,11 @@ public class ChatProcessing {
|
|||
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
||||
public static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized
|
||||
|
||||
private ChatProcessing() {
|
||||
}
|
||||
|
||||
public static boolean ProcessChat(TBMCChatEvent e) {
|
||||
public static boolean ProcessChat(TBMCChatEvent e, FormatterComponent component) {
|
||||
Channel channel = e.getChannel();
|
||||
CommandSender sender = e.getSender();
|
||||
String message = e.getMessage();
|
||||
|
@ -141,19 +144,24 @@ public class ChatProcessing {
|
|||
colormode = Color.Green;
|
||||
// If greentext, ignore channel or player colors
|
||||
|
||||
ArrayList<ChatFormatter> formatters = addFormatters(colormode, e::shouldSendTo);
|
||||
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||
final AtomicInteger rpc = new AtomicInteger(0);
|
||||
formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
|
||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||
return match;
|
||||
}).build());
|
||||
}
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
ArrayList<ChatFormatter> formatters;
|
||||
if (component.allowFormatting().get()) {
|
||||
formatters = addFormatters(colormode, e::shouldSendTo);
|
||||
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||
final AtomicInteger rpc = new AtomicInteger(0);
|
||||
formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
|
||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||
return match;
|
||||
}).build());
|
||||
}
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
} else
|
||||
formatters = Lists.newArrayList(ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN)
|
||||
.color(Color.White).priority(Priority.Low).build()); //This formatter is necessary
|
||||
|
||||
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||
long combinetime = System.nanoTime();
|
||||
ChatFormatter.Combine(formatters, message, json);
|
||||
ChatFormatter.Combine(formatters, message, json, component.getConfig());
|
||||
combinetime = System.nanoTime() - combinetime;
|
||||
String jsonstr = toJson(json);
|
||||
if (jsonstr.length() >= 32767) {
|
||||
|
@ -203,15 +211,15 @@ public class ChatProcessing {
|
|||
}
|
||||
|
||||
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||
String origin) {
|
||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||
String origin) {
|
||||
TellrawPart json = new TellrawPart("");
|
||||
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
|
||||
json.addExtra(
|
||||
new TellrawPart(channelidentifier)
|
||||
.setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart((MCORIGIN.equals(origin) ? "" : "From " + origin + "n")
|
||||
new TellrawPart((ChatUtils.MCORIGIN.equals(origin) ? "" : "From " + origin + "n")
|
||||
+ "Copy message").setColor(Color.Blue)))
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
||||
|
@ -237,7 +245,7 @@ public class ChatProcessing {
|
|||
}
|
||||
|
||||
static String getChannelID(Channel channel, String origin) {
|
||||
return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get())
|
||||
return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get())
|
||||
+ "]";
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package buttondevteam.chat.components.formatter;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
|
||||
/**
|
||||
* This component handles the custom processing of chat messages. If this component is disabled channels won't be supported either in Minecraft.
|
||||
* If you only want to disable the formatting features, set allowFormatting to false.
|
||||
*/
|
||||
public class FormatterComponent extends Component<PluginMain> {
|
||||
ConfigData<Boolean> allowFormatting() {
|
||||
return getConfig().getData("allowFormatting", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the chat if the component is enabled.
|
||||
*
|
||||
* @param event The chat event
|
||||
* @return Whether the chat message shouldn't be sent for some reason
|
||||
*/
|
||||
public static boolean handleChat(TBMCChatEvent event) {
|
||||
FormatterComponent component = ComponentManager.getIfEnabled(FormatterComponent.class);
|
||||
if (component == null) return false;
|
||||
return ChatProcessing.ProcessChat(event, component);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package buttondevteam.chat.formatting;
|
||||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.chat.ChatProcessing;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.components.formatter.ChatProcessing;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.Priority;
|
||||
import lombok.Builder;
|
||||
|
@ -40,6 +42,11 @@ public final class ChatFormatter {
|
|||
@Builder.Default
|
||||
Type type = Type.Normal;
|
||||
String hoverText;
|
||||
String name;
|
||||
|
||||
private ConfigData<Boolean> enabled(IHaveConfig config) {
|
||||
return config.getData(name + ".enabled", true);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
Normal,
|
||||
|
@ -58,13 +65,15 @@ public final class ChatFormatter {
|
|||
R apply(T1 x1, T2 x2, T3 x3);
|
||||
}
|
||||
|
||||
public static void Combine(List<ChatFormatter> formatters, String str, TellrawPart tp) {
|
||||
public static void Combine(List<ChatFormatter> formatters, String str, TellrawPart tp, IHaveConfig config) {
|
||||
/*
|
||||
* This method assumes that there is always a global formatter
|
||||
*/
|
||||
header("ChatFormatter.Combine begin");
|
||||
ArrayList<FormattedSection> sections = new ArrayList<>();
|
||||
|
||||
if (config != null) //null if testing
|
||||
formatters.removeIf(cf -> !cf.enabled(config).get()); //Remove disabled formatters
|
||||
createSections(formatters, str, sections, true);
|
||||
|
||||
header("Section creation (excluders done)");
|
|
@ -1,4 +1,4 @@
|
|||
package buttondevteam.chat.formatting;
|
||||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
|
@ -1,76 +1,76 @@
|
|||
package buttondevteam.chat.formatting;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
|
||||
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
||||
private static final long serialVersionUID = -1681364161210561505L;
|
||||
private transient boolean hoverEvent;
|
||||
private T action;
|
||||
private Object value;
|
||||
|
||||
private TellrawEvent(T action, String value) {
|
||||
this.hoverEvent = action instanceof HoverAction;
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private TellrawEvent(T action, TellrawPart value) {
|
||||
this.hoverEvent = action instanceof HoverAction;
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, String value) {
|
||||
return new TellrawEvent<>(action, value);
|
||||
}
|
||||
|
||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, TellrawPart value) {
|
||||
return new TellrawEvent<>(action, value);
|
||||
}
|
||||
|
||||
public boolean isHoverEvent() {
|
||||
return hoverEvent;
|
||||
}
|
||||
|
||||
public T getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public enum ClickAction implements Action {
|
||||
OPEN_URL("open_url"), RUN_COMMAND("run_command"), SUGGEST_COMMAND("suggest_command");
|
||||
private String action;
|
||||
|
||||
ClickAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HoverAction implements Action {
|
||||
SHOW_TEXT("show_text"), SHOW_ITEM("show_item"), SHOW_ACHIEVEMENT("show_achievement"), SHOW_ENTITY(
|
||||
"show_entity");
|
||||
private String action;
|
||||
|
||||
HoverAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Action extends TellrawSerializableEnum {
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
||||
private static final long serialVersionUID = -1681364161210561505L;
|
||||
private transient boolean hoverEvent;
|
||||
private T action;
|
||||
private Object value;
|
||||
|
||||
private TellrawEvent(T action, String value) {
|
||||
this.hoverEvent = action instanceof HoverAction;
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private TellrawEvent(T action, TellrawPart value) {
|
||||
this.hoverEvent = action instanceof HoverAction;
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, String value) {
|
||||
return new TellrawEvent<>(action, value);
|
||||
}
|
||||
|
||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, TellrawPart value) {
|
||||
return new TellrawEvent<>(action, value);
|
||||
}
|
||||
|
||||
public boolean isHoverEvent() {
|
||||
return hoverEvent;
|
||||
}
|
||||
|
||||
public T getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public enum ClickAction implements Action {
|
||||
OPEN_URL("open_url"), RUN_COMMAND("run_command"), SUGGEST_COMMAND("suggest_command");
|
||||
private String action;
|
||||
|
||||
ClickAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
public enum HoverAction implements Action {
|
||||
SHOW_TEXT("show_text"), SHOW_ITEM("show_item"), SHOW_ACHIEVEMENT("show_achievement"), SHOW_ENTITY(
|
||||
"show_entity");
|
||||
private String action;
|
||||
|
||||
HoverAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Action extends TellrawSerializableEnum {
|
||||
}
|
||||
}
|
|
@ -1,115 +1,115 @@
|
|||
package buttondevteam.chat.formatting;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import buttondevteam.lib.chat.*;
|
||||
|
||||
public final class TellrawPart implements Serializable {
|
||||
private static final long serialVersionUID = 4125357644462144024L;
|
||||
private Color color;
|
||||
private boolean italic;
|
||||
private boolean bold;
|
||||
private boolean underlined;
|
||||
private boolean strikethrough;
|
||||
private boolean obfuscated;
|
||||
private List<TellrawPart> extra = new ArrayList<>();
|
||||
private String text;
|
||||
private TellrawEvent<TellrawEvent.HoverAction> hoverEvent;
|
||||
private TellrawEvent<TellrawEvent.ClickAction> clickEvent;
|
||||
|
||||
public TellrawPart(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public TellrawPart setColor(Color color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isItalic() {
|
||||
return italic;
|
||||
}
|
||||
|
||||
public TellrawPart setItalic(boolean italic) {
|
||||
this.italic = italic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
return bold;
|
||||
}
|
||||
|
||||
public TellrawPart setBold(boolean bold) {
|
||||
this.bold = bold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUnderlined() {
|
||||
return underlined;
|
||||
}
|
||||
|
||||
public TellrawPart setUnderlined(boolean underlined) {
|
||||
this.underlined = underlined;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isStrikethrough() {
|
||||
return strikethrough;
|
||||
}
|
||||
|
||||
public TellrawPart setStrikethrough(boolean strikethrough) {
|
||||
this.strikethrough = strikethrough;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isObfuscated() {
|
||||
return obfuscated;
|
||||
}
|
||||
|
||||
public TellrawPart setObfuscated(boolean obfuscated) {
|
||||
this.obfuscated = obfuscated;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Iterable<TellrawPart> getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public TellrawPart addExtra(TellrawPart extra) {
|
||||
this.extra.add(extra);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public TellrawPart setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TellrawEvent<TellrawEvent.HoverAction> getHoverEvent() {
|
||||
return hoverEvent;
|
||||
}
|
||||
|
||||
public TellrawPart setHoverEvent(TellrawEvent<TellrawEvent.HoverAction> hoverEvent) {
|
||||
this.hoverEvent = hoverEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TellrawEvent<TellrawEvent.ClickAction> getClickEvent() {
|
||||
return clickEvent;
|
||||
}
|
||||
|
||||
public TellrawPart setClickEvent(TellrawEvent<TellrawEvent.ClickAction> clickEvent) {
|
||||
this.clickEvent = clickEvent;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.lib.chat.Color;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TellrawPart implements Serializable {
|
||||
private static final long serialVersionUID = 4125357644462144024L;
|
||||
private Color color;
|
||||
private boolean italic;
|
||||
private boolean bold;
|
||||
private boolean underlined;
|
||||
private boolean strikethrough;
|
||||
private boolean obfuscated;
|
||||
private List<TellrawPart> extra = new ArrayList<>();
|
||||
private String text;
|
||||
private TellrawEvent<TellrawEvent.HoverAction> hoverEvent;
|
||||
private TellrawEvent<TellrawEvent.ClickAction> clickEvent;
|
||||
|
||||
public TellrawPart(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public TellrawPart setColor(Color color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isItalic() {
|
||||
return italic;
|
||||
}
|
||||
|
||||
public TellrawPart setItalic(boolean italic) {
|
||||
this.italic = italic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
return bold;
|
||||
}
|
||||
|
||||
public TellrawPart setBold(boolean bold) {
|
||||
this.bold = bold;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isUnderlined() {
|
||||
return underlined;
|
||||
}
|
||||
|
||||
public TellrawPart setUnderlined(boolean underlined) {
|
||||
this.underlined = underlined;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isStrikethrough() {
|
||||
return strikethrough;
|
||||
}
|
||||
|
||||
public TellrawPart setStrikethrough(boolean strikethrough) {
|
||||
this.strikethrough = strikethrough;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isObfuscated() {
|
||||
return obfuscated;
|
||||
}
|
||||
|
||||
public TellrawPart setObfuscated(boolean obfuscated) {
|
||||
this.obfuscated = obfuscated;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Iterable<TellrawPart> getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public TellrawPart addExtra(TellrawPart extra) {
|
||||
this.extra.add(extra);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public TellrawPart setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TellrawEvent<TellrawEvent.HoverAction> getHoverEvent() {
|
||||
return hoverEvent;
|
||||
}
|
||||
|
||||
public TellrawPart setHoverEvent(TellrawEvent<TellrawEvent.HoverAction> hoverEvent) {
|
||||
this.hoverEvent = hoverEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TellrawEvent<TellrawEvent.ClickAction> getClickEvent() {
|
||||
return clickEvent;
|
||||
}
|
||||
|
||||
public TellrawPart setClickEvent(TellrawEvent<TellrawEvent.ClickAction> clickEvent) {
|
||||
this.clickEvent = clickEvent;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,59 +1,59 @@
|
|||
package buttondevteam.chat.formatting;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.*;
|
||||
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
|
||||
public abstract class TellrawSerializer {
|
||||
public static class TwEnum extends TypeAdapter<TellrawSerializableEnum> {
|
||||
@Override
|
||||
public TellrawSerializableEnum read(JsonReader reader) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, TellrawSerializableEnum enumval) throws IOException {
|
||||
if (enumval == null)
|
||||
writer.nullValue();
|
||||
else
|
||||
writer.value(enumval.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwCollection implements JsonSerializer<Collection<?>> {
|
||||
@Override
|
||||
public JsonElement serialize(Collection<?> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src == null || src.isEmpty())
|
||||
return null;
|
||||
|
||||
JsonArray array = new JsonArray();
|
||||
|
||||
for (Object child : src) {
|
||||
JsonElement element = context.serialize(child);
|
||||
array.add(element);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwBool extends TypeAdapter<Boolean> {
|
||||
@Override
|
||||
public Boolean read(JsonReader reader) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, Boolean val) throws IOException {
|
||||
if (val)
|
||||
writer.value(val);
|
||||
else
|
||||
writer.nullValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class TellrawSerializer {
|
||||
public static class TwEnum extends TypeAdapter<TellrawSerializableEnum> {
|
||||
@Override
|
||||
public TellrawSerializableEnum read(JsonReader reader) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, TellrawSerializableEnum enumval) throws IOException {
|
||||
if (enumval == null)
|
||||
writer.nullValue();
|
||||
else
|
||||
writer.value(enumval.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwCollection implements JsonSerializer<Collection<?>> {
|
||||
@Override
|
||||
public JsonElement serialize(Collection<?> src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src == null || src.isEmpty())
|
||||
return null;
|
||||
|
||||
JsonArray array = new JsonArray();
|
||||
|
||||
for (Object child : src) {
|
||||
JsonElement element = context.serialize(child);
|
||||
array.add(element);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwBool extends TypeAdapter<Boolean> {
|
||||
@Override
|
||||
public Boolean read(JsonReader reader) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, Boolean val) throws IOException {
|
||||
if (val)
|
||||
writer.value(val);
|
||||
else
|
||||
writer.nullValue();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package buttondevteam.chat.components.towny;
|
||||
|
||||
import buttondevteam.chat.ChatProcessing;
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
|
@ -34,18 +34,18 @@ public class TownyAnnouncer {
|
|||
if (townChannel == null) return;
|
||||
TBMCChatAPI.SendSystemMessage(townChannel,
|
||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatUtils.MCORIGIN);
|
||||
break;
|
||||
case "Nation":
|
||||
if (nationChannel == null) return;
|
||||
TBMCChatAPI.SendSystemMessage(nationChannel,
|
||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatUtils.MCORIGIN);
|
||||
break;
|
||||
case "Global":
|
||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
||||
Channel.RecipientTestResult.ALL,
|
||||
message, target, ChatProcessing.MCORIGIN);
|
||||
message, target, ChatUtils.MCORIGIN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package buttondevteam.chat.components.towny;
|
|||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.VanillaUtils;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package buttondevteam.chat.listener;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.ChatProcessing;
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.formatter.FormatterComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
|
@ -51,7 +52,8 @@ public class PlayerListener implements Listener {
|
|||
if (event.isCancelled())
|
||||
return;
|
||||
//The custom event is called in the core, but doesn't cancel the MC event
|
||||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||
if (ComponentManager.isEnabled(FormatterComponent.class)) //If not enabled, then let the other plugins deal with the message
|
||||
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
@ -94,7 +96,7 @@ public class PlayerListener implements Listener {
|
|||
Player player = Bukkit.getPlayer(message.substring(index + 1));
|
||||
if (player != null && sender instanceof Player)
|
||||
player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " //TODO: Move to the Core
|
||||
+ ((Player) sender).getWorld().getName());
|
||||
+ ((Player) sender).getWorld().getName());
|
||||
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
|
||||
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
|
||||
String msg = message.substring(index + 1);
|
||||
|
@ -130,7 +132,7 @@ public class PlayerListener implements Listener {
|
|||
String name = e.getLastToken();
|
||||
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
|
||||
if (nicknamekv.getKey().startsWith(name.toLowerCase()))
|
||||
e.getTabCompletions().add(PluginMain.essentials.getUser(Bukkit.getPlayer(nicknamekv.getValue())).getNick(true)); //Tabcomplete with the correct case
|
||||
e.getTabCompletions().add(PluginMain.essentials.getUser(Bukkit.getPlayer(nicknamekv.getValue())).getNick(true)); //Tabcomplete with the correct case
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +155,7 @@ public class PlayerListener implements Listener {
|
|||
if (flair.length() > 0)
|
||||
e.addInfo("/r/TheButton flair: " + flair);
|
||||
}
|
||||
e.addInfo(String.format("Respect: %.2f", cp.getF()));
|
||||
e.addInfo(String.format("Respect: %.2f", cp.getF()));
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), ex);
|
||||
}
|
||||
|
@ -165,25 +167,20 @@ public class PlayerListener implements Listener {
|
|||
if (e.isCancelled())
|
||||
return;
|
||||
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
||||
e.setCancelled(ChatProcessing.ProcessChat(e));
|
||||
e.setCancelled(FormatterComponent.handleChat(e));
|
||||
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
||||
val str = "§c!§r[" + e.getChannel().DisplayName().get() + "] <"
|
||||
+ ThorpeUtils.getDisplayName(e.getSender()) + "> " + e.getMessage();
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
if (e.shouldSendTo(p))
|
||||
p.sendMessage(str);
|
||||
Bukkit.getConsoleSender().sendMessage(str);
|
||||
ChatUtils.sendChatMessage(e, s -> "§c!§r" + s);
|
||||
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNickChange(NickChangeEvent e) {
|
||||
String nick = e.getValue();
|
||||
if (nick == null)
|
||||
nicknames.inverse().remove(e.getAffected().getBase().getUniqueId());
|
||||
else
|
||||
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
||||
String nick = e.getValue();
|
||||
if (nick == null)
|
||||
nicknames.inverse().remove(e.getAffected().getBase().getUniqueId());
|
||||
else
|
||||
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||
TownColorComponent.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package buttondevteam.chat;
|
||||
package buttondevteam.chat.components.formatter;
|
||||
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.ObjectTestRunner;
|
||||
import buttondevteam.chat.ObjectTestRunner.Objects;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
|
||||
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.chat.components.formatter.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickAction;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction;
|
||||
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||
import buttondevteam.core.TestPrepare;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -19,8 +23,6 @@ import org.mockito.Mockito;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(ObjectTestRunner.class)
|
||||
public class ChatFormatIT {
|
||||
@Objects
|
||||
|
@ -92,15 +94,15 @@ public class ChatFormatIT {
|
|||
@Test
|
||||
public void testMessage() {
|
||||
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true);
|
||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatProcessing.MCORIGIN);
|
||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
||||
ChatFormatter.Combine(cfs, message, tp);
|
||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
|
||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
|
||||
ChatFormatter.Combine(cfs, message, tp, null);
|
||||
System.out.println("Testing: " + message);
|
||||
// System.out.println(ChatProcessing.toJson(tp));
|
||||
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
||||
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
|
||||
// System.out.println("Raw: " + ChatProcessing.toJson(expectedtp));
|
||||
for (TellrawPart extra : extras)
|
||||
expectedtp.addExtra(extra);
|
||||
assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
||||
Assert.assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue