Some things
Some fixes and @ someone are days old. The FTopComomand is weeks old.
This commit is contained in:
parent
91e44c20c2
commit
4340a50789
5 changed files with 411 additions and 420 deletions
5
pom.xml
5
pom.xml
|
@ -51,11 +51,6 @@
|
||||||
<include>org.javassist:javassist</include>
|
<include>org.javassist:javassist</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<pluginExecution>
|
|
||||||
<action>
|
|
||||||
<execute />
|
|
||||||
</action>
|
|
||||||
</pluginExecution>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
|
@ -1,5 +1,32 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
|
import buttondevteam.chat.commands.UnlolCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
|
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.lib.TBMCChatEvent;
|
||||||
|
import buttondevteam.lib.TBMCChatEventBase;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.*;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scoreboard.Objective;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -8,378 +35,312 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scoreboard.Objective;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
|
|
||||||
import buttondevteam.chat.commands.UnlolCommand;
|
|
||||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
|
||||||
import buttondevteam.chat.formatting.*;
|
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
|
||||||
import buttondevteam.lib.TBMCChatEventBase;
|
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
|
||||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
|
||||||
import lombok.val;
|
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
|
||||||
import buttondevteam.lib.chat.*;
|
|
||||||
|
|
||||||
public class ChatProcessing {
|
public class ChatProcessing {
|
||||||
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
|
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
|
||||||
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
|
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
|
||||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
|
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
|
||||||
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
||||||
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
||||||
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)");
|
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)");
|
||||||
private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
||||||
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("\\_");
|
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("_");
|
||||||
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
||||||
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
||||||
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
||||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^\\(\\)])\\)");
|
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^()])\\)");
|
||||||
private static final Color[] RainbowPresserColors = new Color[] { Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
|
||||||
Color.Blue, Color.DarkPurple };
|
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
||||||
private static boolean pingedconsole = false;
|
Color.Blue, Color.DarkPurple};
|
||||||
|
private static boolean pingedconsole = false;
|
||||||
|
|
||||||
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
|
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
|
||||||
|
|
||||||
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
|
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
|
||||||
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).range(true)
|
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).range(true)
|
||||||
.priority(Priority.High).build(),
|
.priority(Priority.High).build(),
|
||||||
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).range(true).build(),
|
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).range(true).build(),
|
||||||
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).range(true)
|
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).range(true)
|
||||||
.build(),
|
.build(),
|
||||||
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").build(),
|
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").build(),
|
||||||
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
|
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
|
||||||
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
|
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
|
||||||
if (!pingedconsole) {
|
if (!pingedconsole) {
|
||||||
System.out.print("\007");
|
System.out.print("\007");
|
||||||
pingedconsole = true; // Will set it to false in ProcessChat
|
pingedconsole = true; // Will set it to false in ProcessChat
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}).priority(Priority.High).build(),
|
}).priority(Priority.High).build(),
|
||||||
|
|
||||||
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
|
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
|
||||||
.priority(Priority.High).build(),
|
.priority(Priority.High).build(),
|
||||||
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
|
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
|
||||||
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).range(true)
|
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).range(true)
|
||||||
.build(),
|
.build(),
|
||||||
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
|
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
|
||||||
return match; // TODO!
|
return match; // TODO!
|
||||||
}).build());
|
}).build());
|
||||||
private static Gson gson = new GsonBuilder()
|
private static Gson gson = new GsonBuilder()
|
||||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||||
.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 ChatProcessing() {
|
private ChatProcessing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean ProcessChat(TBMCChatEvent e) {
|
public static boolean ProcessChat(TBMCChatEvent e) {
|
||||||
Channel channel = e.getChannel();
|
Channel channel = e.getChannel();
|
||||||
CommandSender sender = e.getSender();
|
CommandSender sender = e.getSender();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
long processstart = System.nanoTime();
|
long processstart = System.nanoTime();
|
||||||
if (PluginMain.essentials == null)
|
if (PluginMain.essentials == null)
|
||||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||||
|
|
||||||
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
doFunStuff(sender, e, message);
|
doFunStuff(sender, e, message);
|
||||||
|
|
||||||
ChatPlayer mp = null;
|
ChatPlayer mp = null;
|
||||||
if (player != null)
|
if (player != null)
|
||||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||||
|
|
||||||
Color colormode = channel.color;
|
Color colormode = channel.color;
|
||||||
if (mp != null && mp.OtherColorMode != null)
|
if (mp != null && mp.OtherColorMode != null)
|
||||||
colormode = mp.OtherColorMode;
|
colormode = mp.OtherColorMode;
|
||||||
if (message.startsWith(">"))
|
if (message.startsWith(">"))
|
||||||
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);
|
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
|
||||||
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||||
final AtomicInteger rpc = new AtomicInteger(0);
|
final AtomicInteger rpc = new AtomicInteger(0);
|
||||||
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
|
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
|
||||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||||
return match;
|
return match;
|
||||||
}).build());
|
}).build());
|
||||||
}
|
}
|
||||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||||
final String channelidentifier = getChannelID(channel, sender);
|
final String channelidentifier = getChannelID(channel, sender);
|
||||||
|
|
||||||
TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier);
|
TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier);
|
||||||
long combinetime = System.nanoTime();
|
long combinetime = System.nanoTime();
|
||||||
ChatFormatter.Combine(formatters, message, json);
|
ChatFormatter.Combine(formatters, message, json);
|
||||||
combinetime = System.nanoTime() - combinetime;
|
combinetime = System.nanoTime() - combinetime;
|
||||||
String jsonstr = toJson(json);
|
String jsonstr = toJson(json);
|
||||||
if (jsonstr.length() >= 32767) {
|
if (jsonstr.length() >= 32767) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DebugCommand.SendDebugMessage(jsonstr);
|
DebugCommand.SendDebugMessage(jsonstr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (channel.filteranderrormsg != null) {
|
if (channel.filteranderrormsg != null) {
|
||||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
||||||
int score = -1;
|
int score = -1;
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
final int mcScore;
|
final int mcScore;
|
||||||
if (player != null
|
if (player != null
|
||||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
||||||
mcScore = -1; // Don't send the message to them
|
mcScore = -1; // Don't send the message to them
|
||||||
else
|
else
|
||||||
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
||||||
obj.getScore(p.getName())
|
obj.getScore(p.getName())
|
||||||
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
||||||
? score = mcScore : mcScore);
|
? score = mcScore : mcScore);
|
||||||
}
|
}
|
||||||
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
||||||
score = e.getMCScore(sender);
|
score = e.getMCScore(sender);
|
||||||
if (score < 0) // Never send messages to score below 0
|
if (score < 0) // Never send messages to score below 0
|
||||||
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||||
else {
|
else {
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
||||||
score, jsonstr));
|
score, jsonstr));
|
||||||
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|
||||||
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
|
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
|
||||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||||
jsonstr = toJson(json);
|
jsonstr = toJson(json);
|
||||||
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
||||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||||
String.format("tellraw @a %s", jsonstr));
|
String.format("tellraw @a %s", jsonstr));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
||||||
sender.sendMessage("§cAn error occured while sending the message.");
|
sender.sendMessage("§cAn error occured while sending the message.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PluginMain.Instance.getServer().getConsoleSender()
|
PluginMain.Instance.getServer().getConsoleSender()
|
||||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
||||||
DebugCommand.SendDebugMessage(
|
DebugCommand.SendDebugMessage(
|
||||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String toJson(TellrawPart json) {
|
static String toJson(TellrawPart json) {
|
||||||
String jsonstr = gson.toJson(json);
|
return gson.toJson(json);
|
||||||
return jsonstr;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static TellrawPart createTellraw(CommandSender sender, String message, Player player, ChatPlayer mp,
|
static TellrawPart createTellraw(CommandSender sender, String message, Player player, ChatPlayer mp,
|
||||||
final String channelidentifier) {
|
final String channelidentifier) {
|
||||||
TellrawPart json = new TellrawPart("");
|
TellrawPart json = new TellrawPart("");
|
||||||
if (mp != null && mp.ChatOnly) {
|
if (mp != null && mp.ChatOnly) {
|
||||||
json.addExtra(new TellrawPart("[C]")
|
json.addExtra(new TellrawPart("[C]")
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||||
}
|
}
|
||||||
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((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\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)));
|
||||||
json.addExtra(new TellrawPart(" <"));
|
json.addExtra(new TellrawPart(" <"));
|
||||||
json.addExtra(
|
TellrawPart hovertp = new TellrawPart("");
|
||||||
new TellrawPart(
|
if (mp != null)
|
||||||
getSenderName(
|
hovertp.addExtra(new TellrawPart(mp.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
||||||
sender, player))
|
json.addExtra(new TellrawPart(getSenderName(sender, player))
|
||||||
.setHoverEvent(
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
||||||
TellrawEvent
|
json.addExtra(new TellrawPart("> "));
|
||||||
.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
return json;
|
||||||
new TellrawPart("")
|
}
|
||||||
.addExtra(new TellrawPart(String.format(
|
|
||||||
"Flair: %s",
|
|
||||||
(mp != null ? mp.GetFormattedFlair()
|
|
||||||
: "-"))))
|
|
||||||
.addExtra(new TellrawPart(String.format(
|
|
||||||
"\nPlayername: %s\n",
|
|
||||||
(player != null ? player.getName()
|
|
||||||
: sender.getName())))
|
|
||||||
.setColor(Color.Aqua))
|
|
||||||
.addExtra(new TellrawPart(String.format(
|
|
||||||
"World: %s\n",
|
|
||||||
(player != null
|
|
||||||
? player.getWorld().getName()
|
|
||||||
: "-"))))
|
|
||||||
.addExtra(new TellrawPart(String.format(
|
|
||||||
"Respect: %s%s%s",
|
|
||||||
(mp != null ? (mp.FCount().get()
|
|
||||||
/ (double) mp.FDeaths().get())
|
|
||||||
: "Infinite"),
|
|
||||||
(mp != null
|
|
||||||
&& mp.UserName().get() != null
|
|
||||||
&& !mp.UserName().get()
|
|
||||||
.isEmpty()
|
|
||||||
? "\nUserName: "
|
|
||||||
+ mp.UserName()
|
|
||||||
.get()
|
|
||||||
: ""),
|
|
||||||
(mp != null && mp.PlayerName().get()
|
|
||||||
.equals("\nAlpha_Bacca44")
|
|
||||||
? "\nDeaths: "
|
|
||||||
+ PlayerListener.AlphaDeaths
|
|
||||||
: ""))))
|
|
||||||
.addExtra(new TellrawPart(
|
|
||||||
"\nFor more, do /u info "
|
|
||||||
+ sender.getName())))));
|
|
||||||
json.addExtra(new TellrawPart("> "));
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSenderName(CommandSender sender, Player player) {
|
private static String getSenderName(CommandSender sender, Player player) {
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return sender.getName();
|
return sender.getName();
|
||||||
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
val res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase());
|
||||||
if (res == null || !res.hasTown())
|
if (res == null || !res.hasTown())
|
||||||
return player.getDisplayName();
|
return player.getDisplayName();
|
||||||
try {
|
try {
|
||||||
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
val clrs = PluginMain.TownColors.get(res.getTown().getName().toLowerCase());
|
||||||
if (clrs == null)
|
if (clrs == null)
|
||||||
return player.getDisplayName();
|
return player.getDisplayName();
|
||||||
StringBuilder ret = new StringBuilder();
|
StringBuilder ret = new StringBuilder();
|
||||||
String name = ChatColor.stripColor(player.getDisplayName());
|
String name = ChatColor.stripColor(player.getDisplayName());
|
||||||
AtomicInteger prevlen = new AtomicInteger();
|
AtomicInteger prevlen = new AtomicInteger();
|
||||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i) -> "§"
|
BiFunction<Integer, Integer, String> coloredNamePart = (len, i) -> "§"
|
||||||
+ Integer.toHexString(clrs[i].ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
+ Integer.toHexString(clrs[i].ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
||||||
+ (i + 1 == clrs.length ? name.substring(prevlen.get())
|
+ (i + 1 == clrs.length ? name.substring(prevlen.get())
|
||||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||||
int len = name.length() / clrs.length;
|
int len = name.length() / clrs.length;
|
||||||
val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get();
|
val nclar = ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations().get();
|
||||||
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
||||||
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length))
|
||||||
ncl = null; // Reset if name length changed
|
ncl = null; // Reset if name length changed
|
||||||
if (name.charAt(0) == '~') { // Ignore ~ in nicknames
|
if (name.charAt(0) == '~') { // Ignore ~ in nicknames
|
||||||
prevlen.incrementAndGet();
|
prevlen.incrementAndGet();
|
||||||
ret.append("~");
|
ret.append("~");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < clrs.length; i++)
|
for (int i = 0; i < clrs.length; i++)
|
||||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i], i));
|
||||||
return ret.toString();
|
return ret.toString();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
return player.getDisplayName();
|
return player.getDisplayName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getChannelID(Channel channel, CommandSender sender) {
|
static String getChannelID(Channel channel, CommandSender sender) {
|
||||||
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName)
|
return ("[" + (sender instanceof IDiscordSender ? "§bD§r|" : "") + channel.DisplayName)
|
||||||
+ "]";
|
+ "]";
|
||||||
return channelidentifier;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
||||||
|
|
||||||
formatters.add(
|
formatters.add(
|
||||||
ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
|
ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
|
||||||
|
|
||||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||||
StringBuilder namesb = new StringBuilder("(?i)(");
|
StringBuilder namesb = new StringBuilder("(?i)(");
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
namesb.append(p.getName()).append("|");
|
namesb.append(p.getName()).append("|");
|
||||||
namesb.deleteCharAt(namesb.length() - 1);
|
namesb.deleteCharAt(namesb.length() - 1);
|
||||||
namesb.append(")");
|
namesb.append(")");
|
||||||
StringBuilder nicksb = new StringBuilder("(?i)(");
|
StringBuilder nicksb = new StringBuilder("(?i)(");
|
||||||
boolean addNickFormatter = false;
|
boolean addNickFormatter = false;
|
||||||
final int size = Bukkit.getOnlinePlayers().size();
|
final int size = Bukkit.getOnlinePlayers().size();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
||||||
if (nick != null) {
|
if (nick != null) {
|
||||||
nicksb.append(nick);
|
nicksb.append(nick);
|
||||||
if (index < size - 1) {
|
if (index < size - 1) {
|
||||||
nicksb.append("|");
|
nicksb.append("|");
|
||||||
addNickFormatter = true;
|
addNickFormatter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
nicksb.append(")");
|
nicksb.append(")");
|
||||||
|
|
||||||
formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
|
formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
|
||||||
.onmatch((match, builder) -> {
|
.onmatch((match, builder) -> {
|
||||||
Player p = Bukkit.getPlayer(match);
|
Player p = Bukkit.getPlayer(match);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
PluginMain.Instance.getLogger()
|
PluginMain.Instance.getLogger()
|
||||||
.warning("Error: Can't find player " + match + " but was reported as online.");
|
.warning("Error: Can't find player " + match + " but was reported as online.");
|
||||||
return "§c" + match + "§r";
|
return "§c" + match + "§r";
|
||||||
}
|
}
|
||||||
ChatPlayer mpp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
ChatPlayer mpp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||||
if (PlayerListener.NotificationSound == null)
|
if (PlayerListener.NotificationSound == null)
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||||
else
|
else
|
||||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||||
(float) PlayerListener.NotificationPitch);
|
(float) PlayerListener.NotificationPitch);
|
||||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||||
return color + p.getName() + "§r";
|
return color + p.getName() + "§r";
|
||||||
}).priority(Priority.High).build());
|
}).priority(Priority.High).build());
|
||||||
|
|
||||||
if (addNickFormatter)
|
if (addNickFormatter)
|
||||||
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
|
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
|
||||||
.onmatch((match, builder) -> {
|
.onmatch((match, builder) -> {
|
||||||
if (PlayerListener.nicknames.containsKey(match)) {
|
if (PlayerListener.nicknames.containsKey(match)) {
|
||||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
||||||
+ match + " but was reported as online.");
|
+ match + " but was reported as online.");
|
||||||
return "§c" + match + "§r";
|
return "§c" + match + "§r";
|
||||||
}
|
}
|
||||||
if (PlayerListener.NotificationSound == null)
|
if (PlayerListener.NotificationSound == null)
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||||
else
|
else
|
||||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||||
(float) PlayerListener.NotificationPitch);
|
(float) PlayerListener.NotificationPitch);
|
||||||
return PluginMain.essentials.getUser(p).getNickname();
|
return PluginMain.essentials.getUser(p).getNickname();
|
||||||
}
|
}
|
||||||
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
|
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
|
||||||
+ " not found in nickname map but was reported as online.");
|
+ " not found in nickname map but was reported as online.");
|
||||||
return "§c" + match + "§r";
|
return "§c" + match + "§r";
|
||||||
}).priority(Priority.High).build());
|
}).priority(Priority.High).build());
|
||||||
}
|
}
|
||||||
return formatters;
|
return formatters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
||||||
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||||
PlayerListener.Fs.add(sender);
|
PlayerListener.Fs.add(sender);
|
||||||
|
|
||||||
String msg = message.toLowerCase();
|
String msg = message.toLowerCase();
|
||||||
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
||||||
boolean add = false;
|
boolean add;
|
||||||
if (add = msg.contains("lol"))
|
if (add = msg.contains("lol"))
|
||||||
lld.setLolornot(true);
|
lld.setLolornot(true);
|
||||||
else {
|
else {
|
||||||
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||||
if (add = msg.contains(PlayerListener.LaughStrings[i])) {
|
if (add = msg.contains(PlayerListener.LaughStrings[i])) {
|
||||||
lld.setLolornot(false);
|
lld.setLolornot(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (add)
|
if (add)
|
||||||
UnlolCommand.Lastlol.put(event.getChannel(), lld);
|
UnlolCommand.Lastlol.put(event.getChannel(), lld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,28 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
|
import buttondevteam.chat.commands.YeehawCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
||||||
|
import buttondevteam.chat.listener.PlayerListener;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
||||||
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.palmergames.bukkit.towny.Towny;
|
||||||
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import lombok.val;
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
@ -17,45 +36,15 @@ import org.dynmap.towny.DynmapTownyPlugin;
|
||||||
import org.htmlcleaner.HtmlCleaner;
|
import org.htmlcleaner.HtmlCleaner;
|
||||||
import org.htmlcleaner.TagNode;
|
import org.htmlcleaner.TagNode;
|
||||||
|
|
||||||
import buttondevteam.chat.commands.YeehawCommand;
|
import java.io.File;
|
||||||
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
import java.io.IOException;
|
||||||
import buttondevteam.chat.listener.PlayerListener;
|
import java.io.InputStream;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
|
||||||
import buttondevteam.lib.chat.Color;
|
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
|
||||||
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.palmergames.bukkit.towny.Towny;
|
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.String;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -120,9 +109,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
setTownColor(dtp, entry.getKey(), entry.getValue());
|
setTownColor(dtp, entry.getKey(), entry.getValue());
|
||||||
});
|
});
|
||||||
|
|
||||||
setupChat();
|
if (!setupChat() || !setupEconomy() || !setupPermissions())
|
||||||
setupEconomy();
|
getLogger().warning("Failed to set up chat or economy or permissions!");
|
||||||
setupPermissions();
|
|
||||||
|
|
||||||
new Thread(this::FlairGetterThreadMethod).start();
|
new Thread(this::FlairGetterThreadMethod).start();
|
||||||
new Thread(new AnnouncerThread()).start();
|
new Thread(new AnnouncerThread()).start();
|
||||||
|
@ -296,17 +284,18 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
yc.load(file);
|
yc.load(file);
|
||||||
PlayerListener.NotificationSound = yc.getString("notificationsound");
|
PlayerListener.NotificationSound = yc.getString("notificationsound");
|
||||||
PlayerListener.NotificationPitch = yc.getDouble("notificationpitch");
|
PlayerListener.NotificationPitch = yc.getDouble("notificationpitch");
|
||||||
AnnounceTime = yc.getInt("announcetime");
|
AnnounceTime = yc.getInt("announcetime", 15 * 60 * 1000);
|
||||||
AnnounceMessages.addAll(yc.getStringList("announcements"));
|
AnnounceMessages.addAll(yc.getStringList("announcements"));
|
||||||
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
|
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
|
||||||
val cs = yc.getConfigurationSection("towncolors");
|
val cs = yc.getConfigurationSection("towncolors");
|
||||||
if (cs != null)
|
if (cs != null)
|
||||||
TownColors.putAll(cs.getValues(true).entrySet().stream()
|
TownColors.putAll(cs.getValues(true).entrySet().stream()
|
||||||
.collect(Collectors.toMap(k -> k.getKey(), v -> ((List<String>) v.getValue()).stream()
|
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
||||||
.map(c -> Color.valueOf(c)).toArray(Color[]::new))));
|
.map(Color::valueOf).toArray(Color[]::new))));
|
||||||
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
||||||
}
|
PluginMain.Instance.getLogger().info("Loaded files!");
|
||||||
PluginMain.Instance.getLogger().info("Loaded files!");
|
} else
|
||||||
|
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||||
}
|
}
|
||||||
|
@ -323,7 +312,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
yc.set("announcements", AnnounceMessages);
|
yc.set("announcements", AnnounceMessages);
|
||||||
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
||||||
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(k -> k.getKey(),
|
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(k -> k.getKey(),
|
||||||
v -> Arrays.stream(v.getValue()).map(c -> c.toString()).toArray(String[]::new))));
|
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
||||||
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
||||||
yc.save(file);
|
yc.save(file);
|
||||||
PluginMain.Instance.getLogger().info("Saved files!");
|
PluginMain.Instance.getLogger().info("Saved files!");
|
||||||
|
|
43
src/main/java/buttondevteam/chat/commands/FTopCommand.java
Normal file
43
src/main/java/buttondevteam/chat/commands/FTopCommand.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
|
import buttondevteam.chat.ChatPlayer;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@CommandClass
|
||||||
|
public class FTopCommand extends TBMCCommandBase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] GetHelpText(String arg0) {
|
||||||
|
return new String[]{ //
|
||||||
|
"§6---- F Top ----", //
|
||||||
|
"Shows the respect leaderboard" //
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
|
||||||
|
private ChatPlayer[] cached;
|
||||||
|
private long lastcache = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) {
|
||||||
|
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
|
||||||
|
cached = Arrays.stream(playerdir.listFiles())
|
||||||
|
.map(f -> TBMCPlayerBase.getPlayer(
|
||||||
|
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class))
|
||||||
|
.sorted((cp1, cp2) -> Float.compare((float) cp2.FCount().get() / (float) cp2.FDeaths().get(),
|
||||||
|
(float) cp1.FCount().get() / (float) cp1.FDeaths().get()))
|
||||||
|
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
|
||||||
|
lastcache = System.nanoTime();
|
||||||
|
}
|
||||||
|
Arrays.stream(cached).limit(10);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,37 +1,40 @@
|
||||||
package buttondevteam.chat.listener;
|
package buttondevteam.chat.listener;
|
||||||
|
|
||||||
import java.util.*;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import java.util.Map.Entry;
|
import buttondevteam.chat.ChatProcessing;
|
||||||
import java.util.function.Consumer;
|
import buttondevteam.chat.PluginMain;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.*;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.bukkit.event.player.*;
|
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
|
||||||
import org.bukkit.help.HelpTopic;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
import buttondevteam.chat.*;
|
|
||||||
import buttondevteam.lib.TBMCChatEvent;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.ChatChannelRegisterEvent;
|
import buttondevteam.lib.chat.ChatChannelRegisterEvent;
|
||||||
import buttondevteam.lib.chat.ChatRoom;
|
import buttondevteam.lib.chat.ChatRoom;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||||
import net.ess3.api.events.NickChangeEvent;
|
|
||||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.vexsoftware.votifier.model.Vote;
|
import com.vexsoftware.votifier.model.Vote;
|
||||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||||
|
import net.ess3.api.events.NickChangeEvent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.*;
|
||||||
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +202,7 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void onVotifierEvent(VotifierEvent event) {
|
public void onVotifierEvent(VotifierEvent event) { //TODO: Move to teh Core eh
|
||||||
Vote vote = event.getVote();
|
Vote vote = event.getVote();
|
||||||
PluginMain.Instance.getLogger().info("Vote: " + vote);
|
PluginMain.Instance.getLogger().info("Vote: " + vote);
|
||||||
org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername());
|
org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername());
|
||||||
|
|
Loading…
Reference in a new issue