1.14 support, fixes #105
13 changed files with 392 additions and 313 deletions
|
@ -1,11 +1,19 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
|
import buttondevteam.lib.ThorpeUtils;
|
||||||
|
import lombok.var;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public final class ChatUtils {
|
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.
|
* Dispatch a console command.
|
||||||
|
@ -33,4 +41,20 @@ public final class ChatUtils {
|
||||||
int b = str.indexOf(end, a);
|
int b = str.indexOf(end, a);
|
||||||
return a != -1 && b != -1 ? Optional.of(str.substring(a, b)) : Optional.empty();
|
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;
|
package buttondevteam.chat.components.chatonly;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent;
|
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
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.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
|
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.fun.FunComponent;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
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.chat.listener.PlayerListener;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
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())
|
||||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||||
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
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() {
|
private ChatProcessing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean ProcessChat(TBMCChatEvent e) {
|
public static boolean ProcessChat(TBMCChatEvent e, FormatterComponent component) {
|
||||||
Channel channel = e.getChannel();
|
Channel channel = e.getChannel();
|
||||||
CommandSender sender = e.getSender();
|
CommandSender sender = e.getSender();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
|
@ -141,19 +144,24 @@ public class ChatProcessing {
|
||||||
colormode = Color.Green;
|
colormode = Color.Green;
|
||||||
// If greentext, ignore channel or player colors
|
// If greentext, ignore channel or player colors
|
||||||
|
|
||||||
ArrayList<ChatFormatter> formatters = addFormatters(colormode, e::shouldSendTo);
|
ArrayList<ChatFormatter> formatters;
|
||||||
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
if (component.allowFormatting().get()) {
|
||||||
final AtomicInteger rpc = new AtomicInteger(0);
|
formatters = addFormatters(colormode, e::shouldSendTo);
|
||||||
formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
|
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
final AtomicInteger rpc = new AtomicInteger(0);
|
||||||
return match;
|
formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> {
|
||||||
}).build());
|
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||||
}
|
return match;
|
||||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
}).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());
|
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||||
long combinetime = System.nanoTime();
|
long combinetime = System.nanoTime();
|
||||||
ChatFormatter.Combine(formatters, message, json);
|
ChatFormatter.Combine(formatters, message, json, component.getConfig());
|
||||||
combinetime = System.nanoTime() - combinetime;
|
combinetime = System.nanoTime() - combinetime;
|
||||||
String jsonstr = toJson(json);
|
String jsonstr = toJson(json);
|
||||||
if (jsonstr.length() >= 32767) {
|
if (jsonstr.length() >= 32767) {
|
||||||
|
@ -203,15 +211,15 @@ public class ChatProcessing {
|
||||||
}
|
}
|
||||||
|
|
||||||
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
||||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||||
String origin) {
|
String origin) {
|
||||||
TellrawPart json = new TellrawPart("");
|
TellrawPart json = new TellrawPart("");
|
||||||
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
|
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
|
||||||
json.addExtra(
|
json.addExtra(
|
||||||
new TellrawPart(channelidentifier)
|
new TellrawPart(channelidentifier)
|
||||||
.setHoverEvent(
|
.setHoverEvent(
|
||||||
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
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)))
|
+ "Copy message").setColor(Color.Blue)))
|
||||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||||
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
||||||
|
@ -237,7 +245,7 @@ public class ChatProcessing {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getChannelID(Channel channel, String origin) {
|
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.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.Color;
|
||||||
import buttondevteam.lib.chat.Priority;
|
import buttondevteam.lib.chat.Priority;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -40,6 +42,11 @@ public final class ChatFormatter {
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
Type type = Type.Normal;
|
Type type = Type.Normal;
|
||||||
String hoverText;
|
String hoverText;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
private ConfigData<Boolean> enabled(IHaveConfig config) {
|
||||||
|
return config.getData(name + ".enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
Normal,
|
Normal,
|
||||||
|
@ -58,13 +65,15 @@ public final class ChatFormatter {
|
||||||
R apply(T1 x1, T2 x2, T3 x3);
|
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
|
* This method assumes that there is always a global formatter
|
||||||
*/
|
*/
|
||||||
header("ChatFormatter.Combine begin");
|
header("ChatFormatter.Combine begin");
|
||||||
ArrayList<FormattedSection> sections = new ArrayList<>();
|
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);
|
createSections(formatters, str, sections, true);
|
||||||
|
|
||||||
header("Section creation (excluders done)");
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
|
@ -1,9 +1,9 @@
|
||||||
package buttondevteam.chat.formatting;
|
package buttondevteam.chat.components.formatter.formatting;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
||||||
private static final long serialVersionUID = -1681364161210561505L;
|
private static final long serialVersionUID = -1681364161210561505L;
|
||||||
private transient boolean hoverEvent;
|
private transient boolean hoverEvent;
|
|
@ -1,11 +1,11 @@
|
||||||
package buttondevteam.chat.formatting;
|
package buttondevteam.chat.components.formatter.formatting;
|
||||||
|
|
||||||
|
import buttondevteam.lib.chat.Color;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import buttondevteam.lib.chat.*;
|
|
||||||
|
|
||||||
public final class TellrawPart implements Serializable {
|
public final class TellrawPart implements Serializable {
|
||||||
private static final long serialVersionUID = 4125357644462144024L;
|
private static final long serialVersionUID = 4125357644462144024L;
|
||||||
private Color color;
|
private Color color;
|
|
@ -1,14 +1,14 @@
|
||||||
package buttondevteam.chat.formatting;
|
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.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
import com.google.gson.stream.*;
|
|
||||||
|
|
||||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
|
||||||
|
|
||||||
public abstract class TellrawSerializer {
|
public abstract class TellrawSerializer {
|
||||||
public static class TwEnum extends TypeAdapter<TellrawSerializableEnum> {
|
public static class TwEnum extends TypeAdapter<TellrawSerializableEnum> {
|
||||||
@Override
|
@Override
|
|
@ -1,6 +1,6 @@
|
||||||
package buttondevteam.chat.components.towny;
|
package buttondevteam.chat.components.towny;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatProcessing;
|
import buttondevteam.chat.ChatUtils;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
@ -34,18 +34,18 @@ public class TownyAnnouncer {
|
||||||
if (townChannel == null) return;
|
if (townChannel == null) return;
|
||||||
TBMCChatAPI.SendSystemMessage(townChannel,
|
TBMCChatAPI.SendSystemMessage(townChannel,
|
||||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID),
|
||||||
message, target, ChatProcessing.MCORIGIN);
|
message, target, ChatUtils.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
case "Nation":
|
case "Nation":
|
||||||
if (nationChannel == null) return;
|
if (nationChannel == null) return;
|
||||||
TBMCChatAPI.SendSystemMessage(nationChannel,
|
TBMCChatAPI.SendSystemMessage(nationChannel,
|
||||||
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID),
|
||||||
message, target, ChatProcessing.MCORIGIN);
|
message, target, ChatUtils.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
case "Global":
|
case "Global":
|
||||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat,
|
||||||
Channel.RecipientTestResult.ALL,
|
Channel.RecipientTestResult.ALL,
|
||||||
message, target, ChatProcessing.MCORIGIN);
|
message, target, ChatUtils.MCORIGIN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package buttondevteam.chat.components.towny;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.VanillaUtils;
|
import buttondevteam.chat.VanillaUtils;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package buttondevteam.chat.listener;
|
package buttondevteam.chat.listener;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.ChatProcessing;
|
import buttondevteam.chat.ChatUtils;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
|
import buttondevteam.chat.components.formatter.FormatterComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.core.ComponentManager;
|
import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
|
@ -51,7 +52,8 @@ public class PlayerListener implements Listener {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
//The custom event is called in the core, but doesn't cancel the MC event
|
//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)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
@ -94,7 +96,7 @@ public class PlayerListener implements Listener {
|
||||||
Player player = Bukkit.getPlayer(message.substring(index + 1));
|
Player player = Bukkit.getPlayer(message.substring(index + 1));
|
||||||
if (player != null && sender instanceof Player)
|
if (player != null && sender instanceof Player)
|
||||||
player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " //TODO: Move to the Core
|
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")) {
|
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
|
||||||
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
|
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
|
||||||
String msg = message.substring(index + 1);
|
String msg = message.substring(index + 1);
|
||||||
|
@ -130,7 +132,7 @@ public class PlayerListener implements Listener {
|
||||||
String name = e.getLastToken();
|
String name = e.getLastToken();
|
||||||
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
|
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
|
||||||
if (nicknamekv.getKey().startsWith(name.toLowerCase()))
|
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)
|
if (flair.length() > 0)
|
||||||
e.addInfo("/r/TheButton flair: " + flair);
|
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) {
|
} catch (Exception ex) {
|
||||||
TBMCCoreAPI.SendException("Error while providing chat info for player " + e.getPlayer().getFileName(), 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())
|
if (e.isCancelled())
|
||||||
return;
|
return;
|
||||||
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
||||||
e.setCancelled(ChatProcessing.ProcessChat(e));
|
e.setCancelled(FormatterComponent.handleChat(e));
|
||||||
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
||||||
val str = "§c!§r[" + e.getChannel().DisplayName().get() + "] <"
|
ChatUtils.sendChatMessage(e, s -> "§c!§r" + s);
|
||||||
+ ThorpeUtils.getDisplayName(e.getSender()) + "> " + e.getMessage();
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
|
||||||
if (e.shouldSendTo(p))
|
|
||||||
p.sendMessage(str);
|
|
||||||
Bukkit.getConsoleSender().sendMessage(str);
|
|
||||||
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onNickChange(NickChangeEvent e) {
|
public void onNickChange(NickChangeEvent e) {
|
||||||
String nick = e.getValue();
|
String nick = e.getValue();
|
||||||
if (nick == null)
|
if (nick == null)
|
||||||
nicknames.inverse().remove(e.getAffected().getBase().getUniqueId());
|
nicknames.inverse().remove(e.getAffected().getBase().getUniqueId());
|
||||||
else
|
else
|
||||||
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||||
TownColorComponent.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
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.ObjectTestRunner.Objects;
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter;
|
import buttondevteam.chat.components.formatter.formatting.ChatFormatter;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent;
|
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
|
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickAction;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
|
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
|
||||||
import buttondevteam.core.TestPrepare;
|
import buttondevteam.core.TestPrepare;
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
@ -19,8 +23,6 @@ import org.mockito.Mockito;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
@RunWith(ObjectTestRunner.class)
|
@RunWith(ObjectTestRunner.class)
|
||||||
public class ChatFormatIT {
|
public class ChatFormatIT {
|
||||||
@Objects
|
@Objects
|
||||||
|
@ -92,15 +94,15 @@ public class ChatFormatIT {
|
||||||
@Test
|
@Test
|
||||||
public void testMessage() {
|
public void testMessage() {
|
||||||
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true);
|
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true);
|
||||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatProcessing.MCORIGIN);
|
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
|
||||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
|
||||||
ChatFormatter.Combine(cfs, message, tp);
|
ChatFormatter.Combine(cfs, message, tp, null);
|
||||||
System.out.println("Testing: " + message);
|
System.out.println("Testing: " + message);
|
||||||
// System.out.println(ChatProcessing.toJson(tp));
|
// 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));
|
// System.out.println("Raw: " + ChatProcessing.toJson(expectedtp));
|
||||||
for (TellrawPart extra : extras)
|
for (TellrawPart extra : extras)
|
||||||
expectedtp.addExtra(extra);
|
expectedtp.addExtra(extra);
|
||||||
assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
Assert.assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue