2016-09-08 14:23:44 +00:00
|
|
|
package buttondevteam.chat;
|
2016-06-22 22:08:39 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2016-09-08 16:27:10 +00:00
|
|
|
import java.util.Collection;
|
2016-06-22 22:08:39 +00:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scoreboard.Objective;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
2016-09-05 18:37:08 +00:00
|
|
|
import com.google.gson.Gson;
|
2016-09-08 16:27:10 +00:00
|
|
|
import com.google.gson.GsonBuilder;
|
2016-06-22 22:08:39 +00:00
|
|
|
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;
|
|
|
|
|
2016-09-08 14:23:44 +00:00
|
|
|
import buttondevteam.chat.commands.UnlolCommand;
|
|
|
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
2016-09-08 14:27:45 +00:00
|
|
|
import buttondevteam.chat.formatting.ChatFormatter;
|
|
|
|
import buttondevteam.chat.formatting.ChatFormatterBuilder;
|
|
|
|
import buttondevteam.chat.formatting.TellrawEvent;
|
|
|
|
import buttondevteam.chat.formatting.TellrawPart;
|
2016-09-08 16:27:10 +00:00
|
|
|
import buttondevteam.chat.formatting.TellrawSerializer;
|
2016-10-29 12:11:29 +00:00
|
|
|
import buttondevteam.lib.TBMCPlayer;
|
2016-11-15 21:34:07 +00:00
|
|
|
import buttondevteam.lib.chat.Channel;
|
|
|
|
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
2016-11-04 20:33:28 +00:00
|
|
|
import buttondevteam.chat.listener.PlayerListener;
|
2016-11-15 21:34:07 +00:00
|
|
|
import buttondevteam.lib.chat.*;
|
2016-07-04 22:29:12 +00:00
|
|
|
|
2016-06-22 22:08:39 +00:00
|
|
|
public class ChatProcessing {
|
2016-09-24 11:18:09 +00:00
|
|
|
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\([\\*\\_\\\\])");
|
2016-09-05 14:46:38 +00:00
|
|
|
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 URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)");
|
|
|
|
private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
|
|
|
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_");
|
2016-09-08 17:44:03 +00:00
|
|
|
private static final Pattern ITALIC_PATTERN = Pattern
|
|
|
|
.compile("(?<![\\\\\\*])\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*(?!\\*)");
|
2016-09-05 14:46:38 +00:00
|
|
|
private static final Pattern BOLD_PATTERN = Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*");
|
2016-09-05 18:37:08 +00:00
|
|
|
private static final String[] RainbowPresserColors = new String[] { "red", "gold", "yellow", "green", "blue",
|
|
|
|
"dark_purple" }; // TODO
|
2016-06-28 22:45:04 +00:00
|
|
|
private static boolean pingedconsole = false;
|
|
|
|
|
2016-06-22 22:08:39 +00:00
|
|
|
// Returns e.setCancelled
|
|
|
|
public static boolean ProcessChat(CommandSender sender, String message) {
|
2016-09-24 15:31:55 +00:00
|
|
|
long processstart = System.nanoTime();
|
2016-11-04 20:33:28 +00:00
|
|
|
if (PluginMain.essentials == null)
|
|
|
|
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
2016-06-22 22:08:39 +00:00
|
|
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
|
|
|
|
2016-11-04 20:33:28 +00:00
|
|
|
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
2016-06-22 22:08:39 +00:00
|
|
|
return true;
|
|
|
|
|
2016-07-16 21:55:36 +00:00
|
|
|
ChatPlayer mp = null;
|
2016-06-22 22:08:39 +00:00
|
|
|
if (player != null) {
|
2016-10-29 12:11:29 +00:00
|
|
|
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
|
2016-06-22 22:08:39 +00:00
|
|
|
if (message.equalsIgnoreCase("F")) {
|
|
|
|
if (!mp.PressedF && PlayerListener.ActiveF) {
|
|
|
|
PlayerListener.FCount++;
|
|
|
|
mp.PressedF = true;
|
2016-10-29 12:11:29 +00:00
|
|
|
if (PlayerListener.FPlayer != null && PlayerListener.FPlayer.getFCount() < Integer.MAX_VALUE - 1)
|
|
|
|
PlayerListener.FPlayer.setFCount(PlayerListener.FPlayer.getFCount() + 1);
|
2016-06-22 22:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg = message.toLowerCase();
|
|
|
|
if (msg.contains("lol")) {
|
|
|
|
UnlolCommand.Lastlolornot = true;
|
|
|
|
UnlolCommand.Lastlol = sender;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
|
|
|
if (msg.contains(PlayerListener.LaughStrings[i])) {
|
|
|
|
UnlolCommand.Lastlol = sender;
|
|
|
|
UnlolCommand.Lastlolornot = false;
|
2016-06-23 23:38:17 +00:00
|
|
|
break;
|
2016-06-22 22:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 21:32:41 +00:00
|
|
|
Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel : mp.CurrentChannel);
|
2016-06-22 22:08:39 +00:00
|
|
|
|
2016-06-25 19:05:00 +00:00
|
|
|
ArrayList<ChatFormatter> formatters = new ArrayList<ChatFormatter>();
|
|
|
|
|
2016-11-15 21:34:07 +00:00
|
|
|
Color colormode = currentchannel.color;
|
2016-06-25 19:05:00 +00:00
|
|
|
if (mp != null && mp.OtherColorMode != null)
|
2016-06-22 22:08:39 +00:00
|
|
|
colormode = mp.OtherColorMode;
|
2016-06-25 12:33:25 +00:00
|
|
|
if (mp != null && mp.RainbowPresserColorMode)
|
2016-11-15 21:34:07 +00:00
|
|
|
colormode = Color.RPC;
|
2016-06-22 22:08:39 +00:00
|
|
|
if (message.startsWith(">"))
|
2016-11-15 21:34:07 +00:00
|
|
|
colormode = Color.Green;
|
2016-06-25 19:05:00 +00:00
|
|
|
// If greentext, ignore channel or player colors
|
|
|
|
|
2016-09-05 14:46:38 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(ENTIRE_MESSAGE_PATTERN).setColor(colormode)
|
2016-09-04 19:07:09 +00:00
|
|
|
.setPriority(Priority.Low).build());
|
2016-06-22 22:08:39 +00:00
|
|
|
|
|
|
|
String formattedmessage = message;
|
2016-06-25 19:05:00 +00:00
|
|
|
|
2016-06-22 22:08:39 +00:00
|
|
|
String suggestmsg = formattedmessage;
|
|
|
|
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(BOLD_PATTERN).setFormat(Format.Bold)
|
2016-09-24 11:18:09 +00:00
|
|
|
.setRemoveCharCount((short) 2).build());
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(ITALIC_PATTERN).setFormat(Format.Italic)
|
|
|
|
.setRemoveCharCount((short) 1).build());
|
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setFormat(Format.Underlined)
|
2016-09-24 11:18:09 +00:00
|
|
|
.setRemoveCharCount((short) 1).build());
|
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(ESCAPE_PATTERN).setRemoveCharPos((short) 0).build());
|
2016-06-22 22:08:39 +00:00
|
|
|
|
|
|
|
// URLs + Rainbow text
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1")
|
|
|
|
.build());
|
2016-06-30 22:31:10 +00:00
|
|
|
if (PluginMain.GetPlayers().size() > 0) {
|
2016-09-05 14:46:38 +00:00
|
|
|
StringBuilder namesb = new StringBuilder();
|
|
|
|
namesb.append("(?i)(");
|
|
|
|
for (Player p : PluginMain.GetPlayers())
|
|
|
|
namesb.append(p.getName()).append("|");
|
|
|
|
namesb.deleteCharAt(namesb.length() - 1);
|
|
|
|
namesb.append(")");
|
|
|
|
StringBuilder nicksb = new StringBuilder();
|
|
|
|
nicksb.append("(?i)(");
|
2016-06-30 22:31:10 +00:00
|
|
|
for (Player p : PluginMain.GetPlayers())
|
2016-09-05 14:46:38 +00:00
|
|
|
nicksb.append(PlayerListener.nicknames.inverse().get(p.getUniqueId())).append("|");
|
|
|
|
nicksb.deleteCharAt(nicksb.length() - 1);
|
|
|
|
nicksb.append(")");
|
2016-06-30 22:31:10 +00:00
|
|
|
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(namesb.toString())).setColor(Color.Aqua)
|
|
|
|
.setOnmatch((String match) -> {
|
2016-07-01 21:32:41 +00:00
|
|
|
Player p = Bukkit.getPlayer(match);
|
|
|
|
if (p == null) {
|
2016-08-14 12:41:54 +00:00
|
|
|
PluginMain.Instance.getLogger()
|
2016-09-05 18:37:08 +00:00
|
|
|
.warning("Error: Can't find player " + match + " but was reported as online.");
|
2016-09-05 14:46:38 +00:00
|
|
|
return "§c" + match + "§r";
|
2016-07-01 21:32:41 +00:00
|
|
|
}
|
2016-10-29 12:11:29 +00:00
|
|
|
ChatPlayer mpp = TBMCPlayer.getPlayer(p).asPluginPlayer(ChatPlayer.class);
|
2016-07-01 21:32:41 +00:00
|
|
|
if (PlayerListener.NotificationSound == null)
|
2016-09-08 19:00:50 +00:00
|
|
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
2016-07-01 21:32:41 +00:00
|
|
|
else
|
|
|
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
|
|
|
(float) PlayerListener.NotificationPitch);
|
|
|
|
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
2016-09-05 14:46:38 +00:00
|
|
|
return color + p.getName() + "§r";
|
2016-09-04 19:07:09 +00:00
|
|
|
}).setPriority(Priority.High).build());
|
2016-06-30 22:31:10 +00:00
|
|
|
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString())).setColor(Color.Aqua)
|
|
|
|
.setOnmatch((String match) -> {
|
2016-09-05 14:46:38 +00:00
|
|
|
if (PlayerListener.nicknames.containsKey(match)) {
|
|
|
|
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
2016-07-01 21:32:41 +00:00
|
|
|
if (p == null) {
|
2016-09-05 18:37:08 +00:00
|
|
|
PluginMain.Instance.getLogger().warning(
|
|
|
|
"Error: Can't find player nicknamed " + match + " but was reported as online.");
|
2016-09-05 14:46:38 +00:00
|
|
|
return "§c" + match + "§r";
|
2016-07-01 21:32:41 +00:00
|
|
|
}
|
|
|
|
if (PlayerListener.NotificationSound == null)
|
2016-09-08 19:00:50 +00:00
|
|
|
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
2016-07-01 21:32:41 +00:00
|
|
|
else
|
|
|
|
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
|
|
|
(float) PlayerListener.NotificationPitch);
|
2016-11-04 20:33:28 +00:00
|
|
|
return PluginMain.essentials.getUser(p).getNickname();
|
2016-07-01 21:32:41 +00:00
|
|
|
}
|
2016-09-05 14:46:38 +00:00
|
|
|
Bukkit.getServer().getLogger().warning(
|
|
|
|
"Player nicknamed " + match + " not found in nickname map but was reported as online.");
|
|
|
|
return "§c" + match + "§r";
|
2016-09-04 19:07:09 +00:00
|
|
|
}).setPriority(Priority.High).build());
|
2016-06-30 22:31:10 +00:00
|
|
|
}
|
2016-06-22 22:08:39 +00:00
|
|
|
|
2016-06-28 22:45:04 +00:00
|
|
|
pingedconsole = false;
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
|
2016-09-05 14:46:38 +00:00
|
|
|
.setOnmatch((String match) -> {
|
2016-07-01 21:32:41 +00:00
|
|
|
if (!pingedconsole) {
|
|
|
|
System.out.print("\007");
|
|
|
|
pingedconsole = true;
|
|
|
|
}
|
2016-09-05 14:46:38 +00:00
|
|
|
return match;
|
2016-09-04 19:07:09 +00:00
|
|
|
}).setPriority(Priority.High).build());
|
2016-06-29 22:10:46 +00:00
|
|
|
|
2016-11-15 21:34:07 +00:00
|
|
|
formatters.add(new ChatFormatterBuilder().setRegex(HASHTAG_PATTERN).setColor(Color.Blue)
|
2016-09-05 14:46:38 +00:00
|
|
|
.setOpenlink("https://twitter.com/hashtag/$1").setPriority(Priority.High).build());
|
2016-06-28 22:45:04 +00:00
|
|
|
|
|
|
|
/*
|
2016-09-04 19:07:09 +00:00
|
|
|
* if (!hadurls) { if (formattedmessage.matches("(?i).*" + Pattern.quote("@console") + ".*")) { formattedmessage = formattedmessage.replaceAll( "(?i)" + Pattern.quote("@console"),
|
|
|
|
* "§b@console§r"); formattedmessage = formattedmessage .replaceAll( "(?i)" + Pattern.quote("@console"), String.format(
|
|
|
|
* "\",\"color\":\"%s\"},{\"text\":\"§b@console§r\",\"color\":\"blue\"},{\"text\":\"" , colormode)); System.out.println("\007"); } }
|
2016-06-28 22:45:04 +00:00
|
|
|
*/
|
2016-06-22 22:08:39 +00:00
|
|
|
|
2016-09-08 19:00:50 +00:00
|
|
|
TellrawPart json = new TellrawPart("");
|
2016-09-05 18:37:08 +00:00
|
|
|
if (mp != null && mp.ChatOnly) {
|
|
|
|
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
|
|
|
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
|
|
|
}
|
2016-09-08 16:27:10 +00:00
|
|
|
json.addExtra(
|
|
|
|
new TellrawPart(("[" + currentchannel.DisplayName) + "]" + (mp != null && !mp.RPMode ? "[OOC]" : ""))
|
|
|
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
|
|
|
new TellrawPart("Copy message").setColor(Color.Blue)))
|
|
|
|
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
|
|
|
TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg)));
|
2016-09-05 18:37:08 +00:00
|
|
|
json.addExtra(new TellrawPart(" <"));
|
2016-09-08 16:27:10 +00:00
|
|
|
json.addExtra(
|
|
|
|
new TellrawPart(
|
|
|
|
(player != null ? player.getDisplayName() : sender.getName()))
|
|
|
|
.setHoverEvent(
|
|
|
|
TellrawEvent
|
|
|
|
.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
|
|
|
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()
|
|
|
|
: "-"))))
|
2016-10-29 12:11:29 +00:00
|
|
|
.addExtra(
|
|
|
|
new TellrawPart(String.format("Respect: %s%s%s",
|
|
|
|
(mp != null ? (mp.getFCount()
|
|
|
|
/ (double) mp.getFDeaths())
|
|
|
|
: "Infinite"),
|
|
|
|
(mp != null && mp.getUserName() != null
|
|
|
|
&& !mp.getUserName().isEmpty()
|
|
|
|
? "\nUserName: "
|
|
|
|
+ mp.getUserName()
|
|
|
|
: ""),
|
|
|
|
(mp != null && mp.getPlayerName()
|
|
|
|
.equals("\nAlpha_Bacca44")
|
|
|
|
? "\nDeaths: "
|
|
|
|
+ PlayerListener.AlphaDeaths
|
2016-11-03 18:57:07 +00:00
|
|
|
: ""))))
|
2016-11-19 19:29:42 +00:00
|
|
|
.addExtra(new TellrawPart("\nFor more, do /u info "
|
|
|
|
+ sender.getName())))));
|
2016-09-05 18:37:08 +00:00
|
|
|
json.addExtra(new TellrawPart("> "));
|
2016-09-24 15:31:55 +00:00
|
|
|
long combinetime = System.nanoTime();
|
2016-09-05 18:37:08 +00:00
|
|
|
ChatFormatter.Combine(formatters, formattedmessage, json);
|
2016-09-24 15:31:55 +00:00
|
|
|
combinetime = System.nanoTime() - combinetime;
|
2016-09-08 16:27:10 +00:00
|
|
|
Gson gson = new GsonBuilder()
|
|
|
|
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
|
|
|
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
2016-09-08 17:44:03 +00:00
|
|
|
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
|
|
|
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
2016-09-08 16:27:10 +00:00
|
|
|
String jsonstr = gson.toJson(json);
|
2016-06-22 22:08:39 +00:00
|
|
|
if (jsonstr.length() >= 32767) {
|
2016-07-01 21:32:41 +00:00
|
|
|
sender.sendMessage(
|
2016-09-08 14:51:11 +00:00
|
|
|
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
2016-06-22 22:08:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-05 18:37:08 +00:00
|
|
|
DebugCommand.SendDebugMessage(jsonstr);
|
2016-07-01 21:32:41 +00:00
|
|
|
if (currentchannel.equals(Channel.TownChat) || currentchannel.equals(Channel.NationChat)) {
|
2016-06-22 22:08:39 +00:00
|
|
|
if (player == null) {
|
|
|
|
sender.sendMessage("§cYou are not a player!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (Player p : PluginMain.GetPlayers()) {
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
|
|
|
|
if (!resident.getName().equals(player.getName()) && resident.getModes().contains("spy"))
|
|
|
|
Bukkit.getPlayer(resident.getName()).sendMessage(String.format("[SPY-%s] - %s: %s",
|
|
|
|
currentchannel.DisplayName, player.getDisplayName(), message));
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentchannel.equals(Channel.TownChat)) {
|
|
|
|
try {
|
|
|
|
Town town = null;
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
town = PluginMain.Instance.TU.getResidentMap().get(player.getName().toLowerCase()).getTown();
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (NotRegisteredException e) {
|
|
|
|
}
|
|
|
|
if (town == null) {
|
|
|
|
player.sendMessage("§cYou aren't in a town or an error occured.");
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-28 22:45:04 +00:00
|
|
|
int index = PluginMain.Instance.Towns.indexOf(town);
|
2016-06-22 22:08:39 +00:00
|
|
|
if (index < 0) {
|
|
|
|
PluginMain.Instance.Towns.add(town);
|
|
|
|
index = PluginMain.Instance.Towns.size() - 1;
|
|
|
|
}
|
|
|
|
Objective obj = PluginMain.SB.getObjective("town");
|
|
|
|
for (Player p : PluginMain.GetPlayers()) {
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
if (PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase()).getTown().getName()
|
|
|
|
.equals(town.getName()))
|
2016-06-22 22:08:39 +00:00
|
|
|
obj.getScore(p.getName()).setScore(index);
|
|
|
|
else
|
|
|
|
obj.getScore(p.getName()).setScore(-1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
obj.getScore(p.getName()).setScore(-1);
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 21:32:41 +00:00
|
|
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
2016-09-08 16:27:10 +00:00
|
|
|
String.format("tellraw @a[score_town=%d,score_town_min=%d] %s", index, index, jsonstr));
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
|
|
|
return true;
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (currentchannel.equals(Channel.NationChat)) {
|
|
|
|
try {
|
|
|
|
Town town = null;
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
town = PluginMain.Instance.TU.getResidentMap().get(player.getName().toLowerCase()).getTown();
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (NotRegisteredException e) {
|
|
|
|
}
|
|
|
|
if (town == null) {
|
|
|
|
player.sendMessage("§cYou aren't in a town or an error occured.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Nation nation = null;
|
|
|
|
try {
|
|
|
|
nation = town.getNation();
|
|
|
|
} catch (NotRegisteredException e) {
|
|
|
|
}
|
|
|
|
if (nation == null) {
|
|
|
|
player.sendMessage("§cYour town isn't in a nation or an error occured.");
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-28 22:45:04 +00:00
|
|
|
int index = PluginMain.Instance.Nations.indexOf(nation);
|
2016-06-22 22:08:39 +00:00
|
|
|
if (index < 0) {
|
|
|
|
PluginMain.Instance.Nations.add(nation);
|
|
|
|
index = PluginMain.Instance.Nations.size() - 1;
|
|
|
|
}
|
|
|
|
Objective obj = PluginMain.SB.getObjective("nation");
|
|
|
|
for (Player p : PluginMain.GetPlayers()) {
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
if (PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase()).getTown().getNation()
|
|
|
|
.getName().equals(nation.getName()))
|
2016-06-22 22:08:39 +00:00
|
|
|
obj.getScore(p.getName()).setScore(index);
|
|
|
|
else
|
|
|
|
obj.getScore(p.getName()).setScore(-1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 16:27:10 +00:00
|
|
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
|
|
|
String.format("tellraw @a[score_nation=%d,score_nation_min=%d] %s", index, index, jsonstr));
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
|
|
|
return true;
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (currentchannel.equals(Channel.AdminChat)) {
|
2016-09-08 19:00:50 +00:00
|
|
|
try {
|
2016-06-22 22:08:39 +00:00
|
|
|
if (player != null && !player.isOp()) {
|
|
|
|
player.sendMessage("§cYou need to be an OP to use this channel.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Objective obj = PluginMain.SB.getObjective("admin");
|
|
|
|
for (Player p : PluginMain.GetPlayers()) {
|
|
|
|
if (p.isOp())
|
|
|
|
obj.getScore(p.getName()).setScore(1);
|
|
|
|
else
|
|
|
|
obj.getScore(p.getName()).setScore(0);
|
|
|
|
}
|
2016-07-01 21:32:41 +00:00
|
|
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
2016-09-08 16:27:10 +00:00
|
|
|
String.format("tellraw @a[score_admin=%d,score_admin_min=%d] %s", 1, 1, jsonstr));
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
|
|
|
return true;
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (currentchannel.equals(Channel.ModChat)) {
|
|
|
|
try {
|
2016-07-01 21:32:41 +00:00
|
|
|
if (player != null && !PluginMain.permission.playerInGroup(player, "mod")) {
|
2016-06-22 22:08:39 +00:00
|
|
|
player.sendMessage("§cYou need to be a mod to use this channel.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Objective obj = PluginMain.SB.getObjective("mod");
|
|
|
|
for (Player p : PluginMain.GetPlayers()) {
|
2016-06-23 10:42:22 +00:00
|
|
|
if (PluginMain.permission.playerInGroup(p, "mod"))
|
2016-06-22 22:08:39 +00:00
|
|
|
obj.getScore(p.getName()).setScore(1);
|
|
|
|
else
|
|
|
|
obj.getScore(p.getName()).setScore(0);
|
|
|
|
}
|
2016-07-01 21:32:41 +00:00
|
|
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
2016-09-08 16:27:10 +00:00
|
|
|
String.format("tellraw @a[score_mod=%d,score_mod_min=%d] %s", 1, 1, jsonstr));
|
2016-06-22 22:08:39 +00:00
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalStateException)");
|
|
|
|
return true;
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
player.sendMessage("§cAn error occured while sending the message. (IllegalArgumentException)");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
2016-09-08 16:27:10 +00:00
|
|
|
String.format("tellraw @a %s", jsonstr));
|
2016-07-01 21:32:41 +00:00
|
|
|
PluginMain.Instance.getServer().getConsoleSender()
|
|
|
|
.sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
|
|
|
|
(player != null ? player.getDisplayName() : sender.getName()),
|
|
|
|
(mp != null ? mp.GetFormattedFlair() : ""), message));
|
2016-09-24 16:28:08 +00:00
|
|
|
DebugCommand.SendDebugMessage(
|
|
|
|
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
|
|
|
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
2016-06-22 22:08:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|