Fixes (/u ncolor), not allowing two of the same town colors, not broadcasting announcements if nobody is online #93
16 changed files with 577 additions and 397 deletions
19
.editorconfig
Normal file
19
.editorconfig
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = false
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.java]
|
||||||
|
indent_style = tab
|
||||||
|
tab_width = 4
|
||||||
|
|
||||||
|
[{*.yml, *.yaml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
36
Notes.txt
36
Notes.txt
|
@ -1,36 +0,0 @@
|
||||||
Expected:
|
|
||||||
|
|
||||||
***test***
|
|
||||||
||- ||-
|
|
||||||
|
|
||||||
||: bold
|
|
||||||
-: italic
|
|
||||||
|
|
||||||
|
|
||||||
Actual:
|
|
||||||
|
|
||||||
***test***
|
|
||||||
||- ||-
|
|
||||||
-|| -||
|
|
||||||
- -
|
|
||||||
|
|
||||||
nextSection:
|
|
||||||
*: italic(0)
|
|
||||||
**:
|
|
||||||
Either italic(0), bold(0) - Delete italic
|
|
||||||
bold(0), italic(1) - Delete italic
|
|
||||||
bold(0)
|
|
||||||
Or bold(0), italic(0) - Delete italic?
|
|
||||||
italic, italic - 0-length section as result, delete?
|
|
||||||
|
|
||||||
takenStart, takenEnd
|
|
||||||
because it's ordered, the indexes will be either the same or ascending
|
|
||||||
|
|
||||||
|
|
||||||
^^ Implemented
|
|
||||||
|
|
||||||
**test**
|
|
||||||
^ ^ <-- !
|
|
||||||
start end
|
|
||||||
RemChar: 2
|
|
||||||
tes*
|
|
1
lombok.config
Normal file
1
lombok.config
Normal file
|
@ -0,0 +1 @@
|
||||||
|
lombok.var.flagUsage = ALLOW
|
42
pom.xml
42
pom.xml
|
@ -96,6 +96,46 @@
|
||||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!-- <plugin>
|
||||||
|
<groupId>pl.project13.maven</groupId>
|
||||||
|
<artifactId>git-commit-id-plugin</artifactId>
|
||||||
|
<version>2.2.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>get-the-git-infos</id>
|
||||||
|
<goals>
|
||||||
|
<goal>revision</goal>
|
||||||
|
</goals>
|
||||||
|
*NOTE*: The default phase of revision is initialize, but in case you want to change it, you can do so by adding the phase here
|
||||||
|
<phase>initialize</phase>
|
||||||
|
<configuration>
|
||||||
|
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>validate-the-git-infos</id>
|
||||||
|
<goals>
|
||||||
|
<goal>validateRevision</goal>
|
||||||
|
</goals>
|
||||||
|
*NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here
|
||||||
|
<phase>package</phase>
|
||||||
|
<configuration>
|
||||||
|
<validationProperties>
|
||||||
|
- <validationProperty>
|
||||||
|
<name>validating git dirty</name>
|
||||||
|
<value>${git.branch}</value>
|
||||||
|
<shouldMatchTo>dev</shouldMatchTo>
|
||||||
|
</validationProperty> -
|
||||||
|
</validationProperties>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||||
|
<verbose>true</verbose>
|
||||||
|
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin> -->
|
||||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||||
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
|
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
|
||||||
</goals> </execution> </executions> </plugin> -->
|
</goals> </execution> </executions> </plugin> -->
|
||||||
|
@ -143,7 +183,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
<artifactId>ButtonCore</artifactId>
|
<artifactId>ButtonCore</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>${env.TRAVIS_BRANCH}-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlcleaner/htmlcleaner -->
|
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlcleaner/htmlcleaner -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -13,6 +13,7 @@ public class AnnouncerThread implements Runnable {
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on
|
||||||
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
||||||
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
|
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
|
||||||
AnnounceMessageIndex++;
|
AnnounceMessageIndex++;
|
||||||
|
|
|
@ -1,343 +1,345 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
import buttondevteam.chat.commands.UnlolCommand;
|
import buttondevteam.chat.commands.UnlolCommand;
|
||||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter;
|
import buttondevteam.chat.formatting.ChatFormatter;
|
||||||
import buttondevteam.chat.formatting.TellrawEvent;
|
import buttondevteam.chat.formatting.TellrawEvent;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.chat.formatting.TellrawSerializer;
|
import buttondevteam.chat.formatting.TellrawSerializer;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.player.ChromaGamerBase;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.chat.Priority;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||||
import com.earth2me.essentials.User;
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
import com.google.common.collect.Lists;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import com.google.gson.Gson;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.earth2me.essentials.User;
|
||||||
import lombok.val;
|
import com.google.common.collect.Lists;
|
||||||
import org.bukkit.Bukkit;
|
import com.google.gson.Gson;
|
||||||
import org.bukkit.Sound;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.bukkit.command.CommandSender;
|
import lombok.val;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import javax.annotation.Nullable;
|
import org.bukkit.entity.Player;
|
||||||
import java.util.*;
|
import org.bukkit.scoreboard.Objective;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.function.Consumer;
|
import javax.annotation.Nullable;
|
||||||
import java.util.regex.Pattern;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
public class ChatProcessing {
|
import java.util.function.Consumer;
|
||||||
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
|
import java.util.regex.Pattern;
|
||||||
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
|
|
||||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
|
public class ChatProcessing {
|
||||||
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
|
||||||
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
|
||||||
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)");
|
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
|
||||||
public static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
||||||
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("_");
|
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
||||||
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),&]+(?:#[\\w]+)?)");
|
||||||
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
public static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
||||||
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("_");
|
||||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^()])\\)");
|
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
||||||
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
|
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
||||||
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
|
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
||||||
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^()])\\)");
|
||||||
Color.Blue, Color.DarkPurple};
|
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
|
||||||
private static boolean pingedconsole = false;
|
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
|
||||||
|
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
||||||
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
|
Color.Blue, Color.DarkPurple};
|
||||||
|
private static boolean pingedconsole = false;
|
||||||
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
|
|
||||||
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
|
||||||
.priority(Priority.High).build(),
|
|
||||||
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range).build(),
|
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
|
||||||
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
||||||
.build(),
|
.priority(Priority.High).build(),
|
||||||
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range).build(),
|
||||||
.build(),
|
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
||||||
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").type(ChatFormatter.Type.Excluder).build(),
|
.build(),
|
||||||
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
|
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
||||||
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
|
.build(),
|
||||||
if (!pingedconsole) {
|
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").type(ChatFormatter.Type.Excluder).build(),
|
||||||
System.out.print("\007");
|
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
|
||||||
pingedconsole = true; // Will set it to false in ProcessChat
|
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
|
||||||
}
|
if (!pingedconsole) {
|
||||||
return match;
|
System.out.print("\007");
|
||||||
}).priority(Priority.High).build(),
|
pingedconsole = true; // Will set it to false in ProcessChat
|
||||||
|
}
|
||||||
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
|
return match;
|
||||||
.priority(Priority.High).build(),
|
}).priority(Priority.High).build(),
|
||||||
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
|
|
||||||
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
|
||||||
.build(),
|
.priority(Priority.High).build(),
|
||||||
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
|
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
|
||||||
return match; // TODO!
|
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
||||||
}).build());
|
.build(),
|
||||||
private static Gson gson = new GsonBuilder()
|
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
|
||||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
return match; // TODO!
|
||||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
}).build());
|
||||||
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
private static Gson gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||||
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||||
|
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||||
private ChatProcessing() {
|
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||||
}
|
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
||||||
|
static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized
|
||||||
public static boolean ProcessChat(TBMCChatEvent e) {
|
|
||||||
Channel channel = e.getChannel();
|
private ChatProcessing() {
|
||||||
CommandSender sender = e.getSender();
|
}
|
||||||
String message = e.getMessage();
|
|
||||||
long processstart = System.nanoTime();
|
public static boolean ProcessChat(TBMCChatEvent e) {
|
||||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
Channel channel = e.getChannel();
|
||||||
User user = PluginMain.essentials.getUser(player);
|
CommandSender sender = e.getSender();
|
||||||
|
String message = e.getMessage();
|
||||||
if (player != null) {
|
long processstart = System.nanoTime();
|
||||||
user.updateActivity(true); //Could talk in a private channel, so broadcast
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||||
if (user.isMuted())
|
User user = PluginMain.essentials.getUser(player);
|
||||||
return true;
|
|
||||||
}
|
if (player != null) {
|
||||||
|
user.updateActivity(true); //Could talk in a private channel, so broadcast
|
||||||
doFunStuff(sender, e, message);
|
if (user.isMuted())
|
||||||
|
return true;
|
||||||
ChatPlayer mp;
|
}
|
||||||
if (player != null)
|
|
||||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
doFunStuff(sender, e, message);
|
||||||
else //Due to the online player map, getPlayer() can be more efficient than getAs()
|
|
||||||
mp = e.getUser().getAs(ChatPlayer.class); //May be null
|
ChatPlayer mp;
|
||||||
|
if (player != null)
|
||||||
Color colormode = channel.color;
|
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||||
if (mp != null && mp.OtherColorMode != null)
|
else //Due to the online player map, getPlayer() can be more efficient than getAs()
|
||||||
colormode = mp.OtherColorMode;
|
mp = e.getUser().getAs(ChatPlayer.class); //May be null
|
||||||
if (message.startsWith(">"))
|
|
||||||
colormode = Color.Green;
|
Color colormode = channel.color;
|
||||||
// If greentext, ignore channel or player colors
|
if (mp != null && mp.OtherColorMode != null)
|
||||||
|
colormode = mp.OtherColorMode;
|
||||||
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
|
if (message.startsWith(">"))
|
||||||
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
colormode = Color.Green;
|
||||||
final AtomicInteger rpc = new AtomicInteger(0);
|
// If greentext, ignore channel or player colors
|
||||||
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
|
|
||||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
|
||||||
return match;
|
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||||
}).build());
|
final AtomicInteger rpc = new AtomicInteger(0);
|
||||||
}
|
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
|
||||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||||
final String channelidentifier = getChannelID(channel, sender);
|
return match;
|
||||||
|
}).build());
|
||||||
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier);
|
}
|
||||||
long combinetime = System.nanoTime();
|
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||||
ChatFormatter.Combine(formatters, message, json);
|
final String channelidentifier = getChannelID(channel, sender, e.getOrigin());
|
||||||
combinetime = System.nanoTime() - combinetime;
|
|
||||||
String jsonstr = toJson(json);
|
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||||
if (jsonstr.length() >= 32767) {
|
long combinetime = System.nanoTime();
|
||||||
sender.sendMessage(
|
ChatFormatter.Combine(formatters, message, json);
|
||||||
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
combinetime = System.nanoTime() - combinetime;
|
||||||
return true;
|
String jsonstr = toJson(json);
|
||||||
}
|
if (jsonstr.length() >= 32767) {
|
||||||
DebugCommand.SendDebugMessage(jsonstr);
|
sender.sendMessage(
|
||||||
|
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
||||||
try {
|
return true;
|
||||||
if (channel.filteranderrormsg != null) {
|
}
|
||||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
DebugCommand.SendDebugMessage(jsonstr);
|
||||||
int score = -1;
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
try {
|
||||||
final int mcScore;
|
if (!channel.isGlobal()) {
|
||||||
if (player != null
|
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
||||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
int score = -1;
|
||||||
mcScore = -1; // Don't send the message to them
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
else
|
final int mcScore;
|
||||||
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
if (player != null
|
||||||
obj.getScore(p.getName())
|
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
||||||
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
mcScore = -1; // Don't send the message to them
|
||||||
? score = mcScore : mcScore);
|
else
|
||||||
}
|
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
||||||
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
obj.getScore(p.getName())
|
||||||
score = e.getMCScore(sender);
|
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
||||||
if (score < 0) // Never send messages to score below 0
|
? score = mcScore : mcScore);
|
||||||
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
}
|
||||||
else {
|
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
score = e.getMCScore(sender);
|
||||||
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
if (score < 0) // Never send messages to score below 0
|
||||||
score, jsonstr));
|
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||||
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|
else {
|
||||||
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
||||||
jsonstr = toJson(json);
|
score, jsonstr));
|
||||||
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|
||||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
|
||||||
}
|
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||||
}
|
jsonstr = toJson(json);
|
||||||
} else
|
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
||||||
String.format("tellraw @a %s", jsonstr));
|
}
|
||||||
} catch (Exception ex) {
|
}
|
||||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
} else
|
||||||
sender.sendMessage("§cAn error occured while sending the message.");
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
return true;
|
String.format("tellraw @a %s", jsonstr));
|
||||||
}
|
} catch (Exception ex) {
|
||||||
PluginMain.Instance.getServer().getConsoleSender()
|
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
||||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
sender.sendMessage("§cAn error occured while sending the message.");
|
||||||
DebugCommand.SendDebugMessage(
|
return true;
|
||||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
}
|
||||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
PluginMain.Instance.getServer().getConsoleSender()
|
||||||
return false;
|
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
||||||
}
|
DebugCommand.SendDebugMessage(
|
||||||
|
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||||
static String toJson(TellrawPart json) {
|
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||||
return gson.toJson(json);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
static String toJson(TellrawPart json) {
|
||||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier) {
|
return gson.toJson(json);
|
||||||
TellrawPart json = new TellrawPart("");
|
}
|
||||||
if (mp != null && mp.ChatOnly) {
|
|
||||||
json.addExtra(new TellrawPart("[C]")
|
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||||
}
|
String origin) {
|
||||||
json.addExtra(
|
TellrawPart json = new TellrawPart("");
|
||||||
new TellrawPart(channelidentifier)
|
if (mp != null && mp.ChatOnly) {
|
||||||
.setHoverEvent(
|
json.addExtra(new TellrawPart("[C]")
|
||||||
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
}
|
||||||
+ "Copy message").setColor(Color.Blue)))
|
json.addExtra(
|
||||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
new TellrawPart(channelidentifier)
|
||||||
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
.setHoverEvent(
|
||||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Aqua).setBold(true)
|
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Diamond Patreon supporter")));
|
new TellrawPart((MCORIGIN.equals(origin) ? "" : "From " + origin + "n")
|
||||||
else if (PluginMain.permission.has(sender, "tbmc.badge.gold"))
|
+ "Copy message").setColor(Color.Blue)))
|
||||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Gold).setBold(true)
|
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
|
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
||||||
json.addExtra(new TellrawPart(" <"));
|
json.addExtra(new TellrawPart("[P]").setColor(Color.Aqua).setBold(true)
|
||||||
TellrawPart hovertp = new TellrawPart("");
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Diamond Patreon supporter")));
|
||||||
if (cg != null)
|
else if (PluginMain.permission.has(sender, "tbmc.badge.gold"))
|
||||||
hovertp.addExtra(new TellrawPart(cg.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
json.addExtra(new TellrawPart("[P]").setColor(Color.Gold).setBold(true)
|
||||||
json.addExtra(new TellrawPart(getSenderName(sender, player))
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
json.addExtra(new TellrawPart(" <"));
|
||||||
json.addExtra(new TellrawPart("> "));
|
TellrawPart hovertp = new TellrawPart("");
|
||||||
return json;
|
if (cg != null)
|
||||||
}
|
hovertp.addExtra(new TellrawPart(cg.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
||||||
|
json.addExtra(new TellrawPart(getSenderName(sender, player))
|
||||||
private static String getSenderName(CommandSender sender, Player player) {
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
||||||
if (player == null)
|
json.addExtra(new TellrawPart("> "));
|
||||||
return sender.getName();
|
return json;
|
||||||
return player.getDisplayName();
|
}
|
||||||
}
|
|
||||||
|
private static String getSenderName(CommandSender sender, Player player) {
|
||||||
static String getChannelID(Channel channel, CommandSender sender) {
|
if (player == null)
|
||||||
return ("[" + (sender instanceof IDiscordSender ? "§8D§r|" : "") + channel.DisplayName)
|
return sender.getName();
|
||||||
+ "]";
|
return player.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
static String getChannelID(Channel channel, CommandSender sender, String origin) {
|
||||||
@SuppressWarnings("unchecked")
|
return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName)
|
||||||
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
+ "]";
|
||||||
|
}
|
||||||
formatters.add(
|
|
||||||
ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
|
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
boolean nottest; //Not assigning a default value, so that it can only be used in the if
|
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
||||||
if ((nottest = Bukkit.getOnlinePlayers().size() > 0) || Bukkit.getVersion().equals("test")) {
|
|
||||||
StringBuilder namesb = new StringBuilder("(?i)(");
|
formatters.add(
|
||||||
if (nottest)
|
ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
|
||||||
namesb.append(p.getName()).append("|");
|
boolean nottest; //Not assigning a default value, so that it can only be used in the if
|
||||||
else
|
if ((nottest = Bukkit.getOnlinePlayers().size() > 0) || Bukkit.getVersion().equals("test")) {
|
||||||
for (String testPlayer : testPlayers)
|
StringBuilder namesb = new StringBuilder("(?i)(");
|
||||||
namesb.append(testPlayer).append("|");
|
if (nottest)
|
||||||
namesb.deleteCharAt(namesb.length() - 1);
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
namesb.append(")");
|
namesb.append(p.getName()).append("|");
|
||||||
StringBuilder nicksb = new StringBuilder("(?i)(");
|
else
|
||||||
boolean addNickFormatter = false;
|
for (String testPlayer : testPlayers)
|
||||||
final int size = Bukkit.getOnlinePlayers().size();
|
namesb.append(testPlayer).append("|");
|
||||||
int index = 0;
|
namesb.deleteCharAt(namesb.length() - 1);
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
namesb.append(")");
|
||||||
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
StringBuilder nicksb = new StringBuilder("(?i)(");
|
||||||
if (nick != null) {
|
boolean addNickFormatter = false;
|
||||||
nicksb.append(nick);
|
int index = 0;
|
||||||
if (index < size - 1) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
nicksb.append("|");
|
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
||||||
addNickFormatter = true;
|
if (nick != null) {
|
||||||
}
|
nicksb.append(nick).append("|");
|
||||||
}
|
addNickFormatter = true; //Add it even if there's only 1 player online (it was in the if)
|
||||||
index++;
|
}
|
||||||
}
|
index++;
|
||||||
nicksb.append(")");
|
}
|
||||||
|
nicksb.deleteCharAt(nicksb.length() - 1);
|
||||||
Consumer<String> error = message -> {
|
nicksb.append(")");
|
||||||
if (PluginMain.Instance != null)
|
|
||||||
PluginMain.Instance.getLogger().warning(message);
|
Consumer<String> error = message -> {
|
||||||
else
|
if (PluginMain.Instance != null)
|
||||||
System.out.println(message);
|
PluginMain.Instance.getLogger().warning(message);
|
||||||
};
|
else
|
||||||
|
System.out.println(message);
|
||||||
formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
|
};
|
||||||
.onmatch((match, builder) -> {
|
|
||||||
Player p = Bukkit.getPlayer(match);
|
formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
|
||||||
Optional<String> pn = nottest ? Optional.empty()
|
.onmatch((match, builder) -> {
|
||||||
: Arrays.stream(testPlayers).filter(tp -> tp.equalsIgnoreCase(match)).findAny();
|
Player p = Bukkit.getPlayer(match);
|
||||||
if (nottest ? p == null : !pn.isPresent()) {
|
Optional<String> pn = nottest ? Optional.empty()
|
||||||
error.accept("Error: Can't find player " + match + " but was reported as online.");
|
: Arrays.stream(testPlayers).filter(tp -> tp.equalsIgnoreCase(match)).findAny();
|
||||||
return "§c" + match + "§r";
|
if (nottest ? p == null : !pn.isPresent()) {
|
||||||
}
|
error.accept("Error: Can't find player " + match + " but was reported as online.");
|
||||||
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
|
return "§c" + match + "§r";
|
||||||
if (nottest) {
|
}
|
||||||
if (PlayerListener.NotificationSound == null)
|
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
if (nottest) {
|
||||||
else
|
if (PlayerListener.NotificationSound == null)
|
||||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||||
(float) PlayerListener.NotificationPitch);
|
else
|
||||||
}
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
(float) PlayerListener.NotificationPitch);
|
||||||
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
|
}
|
||||||
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||||
|
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
|
||||||
if (addNickFormatter)
|
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
||||||
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
|
|
||||||
.onmatch((match, builder) -> {
|
if (addNickFormatter)
|
||||||
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
|
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
|
||||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
|
.onmatch((match, builder) -> {
|
||||||
if (p == null) {
|
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
|
||||||
error.accept("Error: Can't find player nicknamed "
|
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
|
||||||
+ match.toLowerCase() + " but was reported as online.");
|
if (p == null) {
|
||||||
return "§c" + match + "§r";
|
error.accept("Error: Can't find player nicknamed "
|
||||||
}
|
+ match.toLowerCase() + " but was reported as online.");
|
||||||
if (PlayerListener.NotificationSound == null)
|
return "§c" + match + "§r";
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
}
|
||||||
else
|
if (PlayerListener.NotificationSound == null)
|
||||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||||
(float) PlayerListener.NotificationPitch);
|
else
|
||||||
return PluginMain.essentials.getUser(p).getNickname();
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||||
}
|
(float) PlayerListener.NotificationPitch);
|
||||||
error.accept("Player nicknamed " + match.toLowerCase()
|
return PluginMain.essentials.getUser(p).getNickname();
|
||||||
+ " not found in nickname map but was reported as online.");
|
}
|
||||||
return "§c" + match + "§r";
|
error.accept("Player nicknamed " + match.toLowerCase()
|
||||||
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
+ " not found in nickname map but was reported as online.");
|
||||||
}
|
return "§c" + match + "§r";
|
||||||
return formatters;
|
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
||||||
}
|
}
|
||||||
|
return formatters;
|
||||||
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
}
|
||||||
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
|
||||||
PlayerListener.Fs.add(sender);
|
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
||||||
|
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||||
String msg = message.toLowerCase();
|
PlayerListener.Fs.add(sender);
|
||||||
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
|
||||||
boolean add;
|
String msg = message.toLowerCase();
|
||||||
if (add = msg.contains("lol"))
|
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
||||||
lld.setLolornot(true);
|
boolean add;
|
||||||
else {
|
if (add = msg.contains("lol"))
|
||||||
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
lld.setLolornot(true);
|
||||||
if (add = msg.contains(PlayerListener.LaughStrings[i])) {
|
else {
|
||||||
lld.setLolornot(false);
|
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||||
break;
|
if (add = msg.contains(PlayerListener.LaughStrings[i])) {
|
||||||
}
|
lld.setLolornot(false);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if (add)
|
}
|
||||||
UnlolCommand.Lastlol.put(event.getChannel(), lld);
|
}
|
||||||
}
|
if (add)
|
||||||
}
|
UnlolCommand.Lastlol.put(event.getChannel(), lld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package buttondevteam.chat;
|
||||||
|
|
||||||
import buttondevteam.chat.commands.YeehawCommand;
|
import buttondevteam.chat.commands.YeehawCommand;
|
||||||
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
||||||
|
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
import buttondevteam.chat.listener.TownyListener;
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
@ -81,6 +82,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||||
|
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||||
|
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this);
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
||||||
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
||||||
Console = this.getServer().getConsoleSender();
|
Console = this.getServer().getConsoleSender();
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.experimental.var;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@CommandClass
|
||||||
|
public class HistoryCommand extends UCommandBase {
|
||||||
|
/**
|
||||||
|
* Key: ChannelID_groupID
|
||||||
|
*/
|
||||||
|
private static HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] GetHelpText(String alias) {
|
||||||
|
return new String[]{ //
|
||||||
|
"§6--- Chat History ----", //
|
||||||
|
"Returns the last 10 messages the player can see." //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
|
return showHistory(sender, alias, args, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean showHistory(CommandSender sender, String alias, String[] args, @Nullable HistoryCommand hc) {
|
||||||
|
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
|
||||||
|
sender.sendMessage("§6---- Chat History ----");
|
||||||
|
Stream<Channel> stream;
|
||||||
|
if (args.length == 0) {
|
||||||
|
stream = Channel.getChannels().stream();
|
||||||
|
} else {
|
||||||
|
Optional<Channel> och = Channel.getChannels().stream().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny();
|
||||||
|
if (!och.isPresent()) {
|
||||||
|
sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " ooc");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
stream = Stream.of(och.get());
|
||||||
|
}
|
||||||
|
AtomicBoolean sent = new AtomicBoolean();
|
||||||
|
val arr = stream.map(getThem).filter(Objects::nonNull).flatMap(Collection::stream)
|
||||||
|
.sorted(Comparator.comparingLong(he -> he.timestamp)).toArray(HistoryEntry[]::new);
|
||||||
|
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
|
||||||
|
HistoryEntry e = arr[i];
|
||||||
|
val cm = e.chatMessage;
|
||||||
|
sender.sendMessage("[" + e.channel.DisplayName + "] " + cm.getSender().getName() + ": " + cm.getMessage());
|
||||||
|
sent.set(true);
|
||||||
|
}
|
||||||
|
if (!sent.get())
|
||||||
|
sender.sendMessage("No messages can be found.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
private static class HistoryEntry {
|
||||||
|
/**
|
||||||
|
* System.nanoTime()
|
||||||
|
*/
|
||||||
|
private final long timestamp;
|
||||||
|
private final ChatMessage chatMessage;
|
||||||
|
private final Channel channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
|
||||||
|
val groupID = channel.getGroupID(chatMessage.getPermCheck());
|
||||||
|
if (groupID == null) return; //Just to be sure
|
||||||
|
var ll = messages.computeIfAbsent(channel.ID + "_" + groupID, k -> new LinkedList<>()); //<-- TIL
|
||||||
|
ll.add(new HistoryEntry(System.nanoTime(), chatMessage, channel)); //Adds as last element
|
||||||
|
while (ll.size() > 10)
|
||||||
|
ll.remove(); //Removes the first element
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,16 +58,16 @@ public class NColorCommand extends UCommandBase {
|
||||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length < towncolors.length) {
|
if (nameparts.length < towncolors.length + 1) { //+1: Nation color
|
||||||
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
|
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length > towncolors.length * 2) {
|
if (nameparts.length > (towncolors.length + 1) * 2) {
|
||||||
player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
|
player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (nameparts.length > towncolors.length) {
|
if (nameparts.length > towncolors.length + 1) {
|
||||||
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1) + ")");
|
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.listener.TownyListener;
|
import buttondevteam.chat.listener.TownyListener;
|
||||||
|
import buttondevteam.lib.chat.Color;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
@ -37,6 +38,14 @@ public class NationColorCommand extends AdminCommandBase {
|
||||||
}
|
}
|
||||||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||||
if (!c.isPresent()) return true;
|
if (!c.isPresent()) return true;
|
||||||
|
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
||||||
|
for (val nc : PluginMain.NationColor.values()) {
|
||||||
|
if (nc.getName().equals(c.get().getName())) {
|
||||||
|
sender.sendMessage("§cAnother nation already uses this color!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
for (Town t : nation.getTowns())
|
for (Town t : nation.getTowns())
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.dynmap.towny.DynmapTownyPlugin;
|
import org.dynmap.towny.DynmapTownyPlugin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -46,6 +47,33 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
return true;
|
return true;
|
||||||
clrs[i - 1] = c.get();
|
clrs[i - 1] = c.get();
|
||||||
}
|
}
|
||||||
|
for (Map.Entry<String, Color[]> other : PluginMain.TownColors.entrySet()) {
|
||||||
|
Color nc, tnc;
|
||||||
|
try {
|
||||||
|
nc = PluginMain.NationColor.get(PluginMain.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
||||||
|
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
|
||||||
|
nc = null;
|
||||||
|
}
|
||||||
|
if (nc == null) nc = Color.White; //Default nation color
|
||||||
|
try {
|
||||||
|
tnc = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
tnc = null;
|
||||||
|
}
|
||||||
|
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
|
||||||
|
if (nc.getName().equals(tnc.getName())) {
|
||||||
|
int C = 0;
|
||||||
|
if (clrs.length == other.getValue().length)
|
||||||
|
for (int i = 0; i < clrs.length; i++)
|
||||||
|
if (clrs[i].getName().equals(other.getValue()[i].getName()))
|
||||||
|
C++;
|
||||||
|
else break;
|
||||||
|
if (C == clrs.length) {
|
||||||
|
sender.sendMessage("§cThis town color combination is already used!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||||
TownyListener.updateTownMembers(targetTown);
|
TownyListener.updateTownMembers(targetTown);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package buttondevteam.chat.commands.ucmds.admin;
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.component.updater.PluginUpdater;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
|
||||||
import buttondevteam.lib.PluginUpdater;
|
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
|
||||||
|
|
||||||
public class UpdatePlugin extends AdminCommandBase {
|
public class UpdatePlugin extends AdminCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package buttondevteam.chat.components;
|
||||||
|
|
||||||
|
import buttondevteam.lib.architecture.Component;
|
||||||
|
import buttondevteam.lib.architecture.ConfigData;
|
||||||
|
|
||||||
|
public class TownColorComponent extends Component {
|
||||||
|
public ConfigData<Byte> colorCount() { //TODO
|
||||||
|
return getData("colorCount", (byte) 1, cc -> (byte) cc, cc -> (int) cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigData<Boolean> useNationColors() { //TODO
|
||||||
|
return getData("useNationColors", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void enable() {
|
||||||
|
//TODO: Don't register all commands automatically (welp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void disable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import buttondevteam.chat.FlairStates;
|
||||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
import buttondevteam.chat.commands.UnlolCommand;
|
import buttondevteam.chat.commands.UnlolCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||||
|
@ -64,14 +65,14 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
nwithoutformatting = p.getName();
|
nwithoutformatting = p.getName();
|
||||||
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
|
||||||
updatePlayerColors(p, cp); //TODO: Doesn't have effect
|
|
||||||
}, 5);
|
|
||||||
|
|
||||||
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
cp.ChatOnly = false;
|
cp.ChatOnly = false;
|
||||||
p.setGameMode(GameMode.SURVIVAL);
|
p.setGameMode(GameMode.SURVIVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -3,6 +3,7 @@ package buttondevteam.chat.listener;
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.ChatProcessing;
|
import buttondevteam.chat.ChatProcessing;
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.*;
|
import buttondevteam.lib.chat.*;
|
||||||
|
@ -258,6 +259,7 @@ public class PlayerListener implements Listener {
|
||||||
try {
|
try {
|
||||||
if (e.isCancelled())
|
if (e.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
HistoryCommand.addChatMessage(e.getCm(), e.getChannel());
|
||||||
e.setCancelled(ChatProcessing.ProcessChat(e));
|
e.setCancelled(ChatProcessing.ProcessChat(e));
|
||||||
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
} catch (NoClassDefFoundError | Exception ex) { // Weird things can happen
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
@ -272,7 +274,7 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChannelRegistered(ChatChannelRegisterEvent e) {
|
public void onChannelRegistered(ChatChannelRegisterEvent e) {
|
||||||
if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
|
if (!e.getChannel().isGlobal() && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet
|
||||||
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
|
PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,11 @@ public class ChatFormatIT {
|
||||||
.setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://norbipeti.github.io/")), new TellrawPart(" heh").setItalic(true)));
|
.setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://norbipeti.github.io/")), new TellrawPart(" heh").setItalic(true)));
|
||||||
list.add(new ChatFormatIT(sender, "*test _test_ test*", new TellrawPart("test ").setItalic(true).setColor(Color.White),
|
list.add(new ChatFormatIT(sender, "*test _test_ test*", new TellrawPart("test ").setItalic(true).setColor(Color.White),
|
||||||
new TellrawPart("test").setItalic(true).setUnderlined(true).setColor(Color.White), new TellrawPart(" test").setItalic(true).setColor(Color.White)));
|
new TellrawPart("test").setItalic(true).setUnderlined(true).setColor(Color.White), new TellrawPart(" test").setItalic(true).setColor(Color.White)));
|
||||||
|
list.add(new ChatFormatIT(sender, "https://norbipeti.github.io/test?test&test#test", new TellrawPart("https://norbipeti.github.io/test?test&test#test")
|
||||||
|
.setColor(Color.White).setUnderlined(true)
|
||||||
|
.setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT,
|
||||||
|
new TellrawPart("Click to open").setColor(Color.Blue)))
|
||||||
|
.setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://norbipeti.github.io/test?test&test#test"))));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -82,12 +87,12 @@ public class ChatFormatIT {
|
||||||
@Test
|
@Test
|
||||||
public void testMessage() {
|
public void testMessage() {
|
||||||
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
|
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White);
|
||||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender);
|
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, ChatProcessing.MCORIGIN);
|
||||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid);
|
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN);
|
||||||
ChatFormatter.Combine(cfs, message, tp);
|
ChatFormatter.Combine(cfs, message, tp);
|
||||||
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);
|
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.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);
|
||||||
|
|
Loading…
Reference in a new issue