diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java
index 15b9030a..1267847e 100644
--- a/src/de/steamwar/bungeecore/Message.java
+++ b/src/de/steamwar/bungeecore/Message.java
@@ -19,13 +19,11 @@
package de.steamwar.bungeecore;
-import de.steamwar.bungeecore.listeners.ConnectionListener;
+import de.steamwar.messages.ChatSender;
import de.steamwar.messages.SteamwarResourceBundle;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -37,26 +35,32 @@ import java.util.ResourceBundle;
public class Message {
+ @Deprecated
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, locale(sender), params)));
}
+ @Deprecated
public static String parsePrefixed(String message, CommandSender sender, Object... params){
return parse(message, true, locale(sender), params);
}
+ @Deprecated
public static String parse(String message, CommandSender sender, Object... params){
return parse(message, false, locale(sender), params);
}
+ @Deprecated
public static String parse(String message, Locale locale, Object... params){
return parse(message, false, locale, params);
}
+ @Deprecated
private static Locale locale(CommandSender sender) {
return sender instanceof ProxiedPlayer ? ((ProxiedPlayer)sender).getLocale() : Locale.getDefault();
}
+ @Deprecated
private static String parse(String message, boolean prefixed, Locale locale, Object... params){
if(locale == null)
locale = Locale.getDefault();
@@ -70,7 +74,7 @@ public class Message {
for (int i = 0; i < params.length; i++) {
if(params[i] instanceof Message) {
Message msg = (Message) params[i];
- params[i] = parse(msg.getMessage(), false, locale, msg.getParams());
+ params[i] = parse(msg.getFormat(), false, locale, msg.getParams());
} else if(params[i] instanceof Date) {
params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
}
@@ -78,91 +82,61 @@ public class Message {
return format.format(params);
}
+ @Deprecated
public static void send(String message, CommandSender sender, Object... params){
send(message, true, sender, ChatMessageType.SYSTEM, null, null, params);
}
+ @Deprecated
public static void sendPrefixless(String message, CommandSender sender, Object... params){
send(message, false, sender, ChatMessageType.SYSTEM, null, null, params);
}
- public static void send(String message, CommandSender sender, ChatMessageType type, Object... params){
- send(message, true, sender, type, null, null, params);
- }
-
- public static void sendPrefixless(String message, CommandSender sender, ChatMessageType type, Object... params){
- send(message, false, sender, type, null, null, params);
- }
-
+ @Deprecated
public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
}
+ @Deprecated
public static void sendPrefixless(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
}
- private static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
- if(type == ChatMessageType.CHAT && sender instanceof ProxiedPlayer && ((ProxiedPlayer)sender).getChatMode() != ProxiedPlayer.ChatMode.SHOWN)
+ @Deprecated
+ private static void send(String message, boolean prefixed, CommandSender s, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
+ ChatSender sender = ChatSender.of(s);
+ if(type == ChatMessageType.CHAT && !sender.chatShown())
return;
- TextComponent msg = parseToComponent(message, prefixed, sender, params);
- if(onHover != null)
- msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
- if(onClick != null)
- msg.setClickEvent(onClick);
- if(sender instanceof ProxiedPlayer)
- ((ProxiedPlayer)sender).sendMessage(type, msg);
- else
- sender.sendMessage(msg);
+
+ sender.send(prefixed, type, new Message("PLAIN_STRING", onHover), onClick, new Message(message, params));
}
- public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params){
- for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers())
- send(message, player, parse(onHover, player, params), onClick, params);
+ public static void broadcast(String message, Object... params) {
+ broadcast(message, null, null, params);
}
- public static void broadcast(String message, Object... params){
- for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers())
- send(message, player, ChatMessageType.SYSTEM, params);
+ public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params) {
+ ChatSender.allReceivers().forEach(player -> player.prefixless(message, new Message(onHover, params), onClick, params));
}
- public static void chat(String message, Object... params){
- for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
- Subserver server = Subserver.getSubserver(player);
- if(server == null || server.getType() != Servertype.ARENA)
- sendPrefixless(message, player, ChatMessageType.CHAT, params);
- }
+ public static void team(String message, Object... params) {
+ team(message, null, null, params);
}
- public static void team(String message, Object... params){
- team(message, ChatMessageType.SYSTEM, params);
+ public static void team(String message, String onHover, ClickEvent onClick, Object... params) {
+ ChatSender.serverteamReceivers().filter(player -> player.user().getUserGroup().isTeamGroup()).forEach(player -> player.prefixless(message, new Message(onHover, params), onClick, params));
}
- public static void team(String message, ChatMessageType type, Object... params){
- for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
- if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) {
- sendPrefixless(message, player, type, params);
- }
- }
- }
-
- public static void team(String message, String onHover, ClickEvent onClick, Object... params){
- for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
- if(player.getGroups().contains(ConnectionListener.TEAM_GROUP))
- sendPrefixless(message, player, Message.parse(onHover, player, params), onClick, params);
- }
- }
-
- private final String message;
+ private final String format;
private final Object[] params;
- public Message(String message, Object... params) {
- this.message = message;
+ public Message(String format, Object... params) {
+ this.format = format;
this.params = params;
}
- public String getMessage() {
- return message;
+ public String getFormat() {
+ return format;
}
public Object[] getParams() {
diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
index e1933923..36e9c3ed 100644
--- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
+++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
@@ -59,10 +59,10 @@ public class SteamwarDiscordBot {
private volatile AnnouncementListener announcementListener;
@Getter
- private volatile IngameChatListener ingameChatListener;
+ private volatile DiscordChatListener ingameChatListener;
@Getter
- private volatile ServerTeamChatListener serverTeamChatListener;
+ private volatile DiscordChatListener serverTeamChatListener;
@Getter
private final JDA jda;
@@ -111,8 +111,8 @@ public class SteamwarDiscordBot {
new DiscordEventListener();
new PrivateMessageListener();
announcementListener = new AnnouncementListener();
- ingameChatListener = new IngameChatListener();
- serverTeamChatListener = new ServerTeamChatListener();
+ ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL");
+ serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM");
new SlashCommandListener();
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
diff --git a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java
similarity index 82%
rename from src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
rename to src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java
index 38dd7b62..63fc644a 100644
--- a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
+++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java
@@ -31,27 +31,32 @@ import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
-public class IngameChatListener extends BasicDiscordListener {
+public class DiscordChatListener extends BasicDiscordListener {
+
+ private final String channel;
+ private final String format;
+
+ public DiscordChatListener(String channel, String format) {
+ this.channel = channel;
+ this.format = format;
+ }
@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
- if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.INGAME_CHANNEL)) {
+ if (!event.getChannel().getId().equals(channel) || event.getAuthor().isBot())
return;
- }
- if (event.getAuthor().isBot()) {
- return;
- }
+
Member member = event.getMember();
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250 || steamwarUser.isPunished(Punishment.PunishmentType.Ban)) {
event.getMessage().delete().queue();
} else {
- ChatListener.sendChat(ChatSender.of(event.getMessage(), steamwarUser), ChatListener.globalReceivers(), "CHAT_DISCORD_GLOBAL", event.getMessage().getContentDisplay().replaceAll("§", "&").replace('\n', ' '));
+ ChatListener.sendChat(ChatSender.of(event.getMessage(), steamwarUser), ChatSender.globalReceivers(), format, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' '));
}
}
public void send(String message) {
- TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.INGAME_CHANNEL);
+ TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(channel);
assert textChannel != null;
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.append(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`"));
diff --git a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
deleted file mode 100644
index 816da82b..00000000
--- a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This file is a part of the SteamWar software.
- *
- * Copyright (C) 2020 SteamWar.de-Serverteam
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package de.steamwar.bungeecore.bot.listeners;
-
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
-import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
-import de.steamwar.bungeecore.commands.ServerTeamchatCommand;
-import de.steamwar.bungeecore.sql.SteamwarUser;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Member;
-import net.dv8tion.jda.api.entities.TextChannel;
-import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
-import org.jetbrains.annotations.NotNull;
-
-public class ServerTeamChatListener extends BasicDiscordListener {
-
- @Override
- public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
- if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL)) {
- return;
- }
- if (event.getAuthor().isBot()) {
- return;
- }
- Member member = event.getMember();
- SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
- if (steamwarUser == null) {
- event.getMessage().delete().complete();
- } else {
- ServerTeamchatCommand.sendToTeam(event.getMessage().getContentRaw(), steamwarUser);
- }
- }
-
- public void send(String message) {
- TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL);
- assert textChannel != null;
- MessageBuilder messageBuilder = new MessageBuilder();
- messageBuilder.append(message.replace("&", ""));
- textChannel.sendMessage(messageBuilder.build()).queue();
- }
-}
diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java
index 67f7013c..09c7cdbb 100644
--- a/src/de/steamwar/bungeecore/commands/MsgCommand.java
+++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java
@@ -19,16 +19,16 @@
package de.steamwar.bungeecore.commands;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
+import de.steamwar.bungeecore.listeners.ChatListener;
import de.steamwar.bungeecore.sql.IgnoreSystem;
-import de.steamwar.bungeecore.sql.Punishment;
-import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.stream.Stream;
import static de.steamwar.bungeecore.Storage.lastChats;
@@ -40,45 +40,32 @@ public class MsgCommand extends BasicCommand {
@Override
public void execute(CommandSender sender, String[] args) {
- if(sender instanceof ProxiedPlayer){
- ProxiedPlayer player = (ProxiedPlayer) sender;
+ if(!(sender instanceof ProxiedPlayer))
+ return;
- if (args.length < 2) {
- Message.send("MSG_USAGE", player);
- return;
- }
-
- SteamwarUser user = SteamwarUser.get(player);
- if (user.isPunishedWithMessage(player, Punishment.PunishmentType.Mute)) {
- return;
- }
-
- ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
- if(target == null){
- Message.send("MSG_OFFLINE", player);
- return;
- }else if (IgnoreSystem.isIgnored(target, player)) {
- Message.send("MSG_IGNORED", player);
- return;
- }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
- Message.send("MSG_NOMESSAGE", player);
- return;
- }else if(target.equals(player)){
- Message.send("MSG_SELF", player);
- return;
- }
-
- StringBuilder msgBuilder = new StringBuilder();
- for (int i = 1; i < args.length; i++){
- msgBuilder.append(args[i]).append(" ");
- }
- Message.sendPrefixless("MSG_FORMAT", player, player.getName(), target.getName(), msgBuilder.toString());
- Message.sendPrefixless("MSG_FORMAT", target, player.getName(), target.getName(), msgBuilder.toString());
- BungeeCore.log(Message.parse("MSG_FORMAT", player, player.getName(), target.getName(), msgBuilder.toString()));
-
- lastChats.put(player, target);
- lastChats.put(target, player);
+ if (args.length < 2) {
+ ChatSender.of(sender).system("MSG_USAGE");
+ return;
}
+
+ msg((ProxiedPlayer) sender, ProxyServer.getInstance().getPlayer(args[0]), Arrays.copyOfRange(args, 1, args.length));
+ }
+
+ public static void msg(ProxiedPlayer player, ProxiedPlayer target, String[] args) {
+ ChatSender sender = ChatSender.of(player);
+ if(target == null || !target.isConnected()) {
+ sender.system("MSG_OFFLINE");
+ return;
+ }
+
+ if (IgnoreSystem.isIgnored(target, player)) {
+ sender.system("MSG_IGNORED");
+ return;
+ }
+
+ ChatListener.sendChat(sender, Stream.of(sender, ChatSender.of(target)), "CHAT_MSG", String.join(" ", args));
+ lastChats.put(player, target);
+ lastChats.put(target, player);
}
@Override
diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java
index c9d70dd2..62e5af8b 100644
--- a/src/de/steamwar/bungeecore/commands/RCommand.java
+++ b/src/de/steamwar/bungeecore/commands/RCommand.java
@@ -19,11 +19,7 @@
package de.steamwar.bungeecore.commands;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.sql.IgnoreSystem;
-import de.steamwar.bungeecore.sql.Punishment;
-import de.steamwar.bungeecore.sql.SteamwarUser;
+import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -37,43 +33,14 @@ public class RCommand extends BasicCommand {
@Override
public void execute(CommandSender sender, String[] args) {
- if(sender instanceof ProxiedPlayer){
- ProxiedPlayer player = (ProxiedPlayer) sender;
- if(args.length == 0){
- Message.send("R_USAGE", player);
- return;
- }
+ if(!(sender instanceof ProxiedPlayer))
+ return;
- SteamwarUser user = SteamwarUser.get(player);
- if (user.isPunishedWithMessage(player, Punishment.PunishmentType.Mute)) {
- return;
- }
-
- ProxiedPlayer target = lastChats.get(player);
- if(target == null){
- Message.send("R_NOTHING", player);
- return;
- }else if(!target.isConnected()){
- Message.send("R_OFFLINE", player);
- lastChats.remove(player);
- return;
- }else if (IgnoreSystem.isIgnored(target, player)) {
- Message.send("R_BLOCKED", player);
- return;
- }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
- Message.send("R_NO_CHAT", player);
- return;
- }
-
- StringBuilder msgBuilder = new StringBuilder();
- for (String arg : args){
- msgBuilder.append(arg).append(" ");
- }
- Message.sendPrefixless("MSG_FORMAT", player, player.getName(), target.getName(), msgBuilder.toString());
- Message.sendPrefixless("MSG_FORMAT", target, player.getName(), target.getName(), msgBuilder.toString());
- BungeeCore.log(Message.parse("MSG_FORMAT", player, player.getName(), target.getName(), msgBuilder.toString()));
-
- lastChats.put(target, player);
+ if(args.length == 0){
+ ChatSender.of(sender).system("R_USAGE");
+ return;
}
+
+ MsgCommand.msg((ProxiedPlayer) sender, lastChats.get(sender), args);
}
}
diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java
index 9e95b204..b3ba30a1 100644
--- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java
+++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java
@@ -19,17 +19,9 @@
package de.steamwar.bungeecore.commands;
-import de.steamwar.bungeecore.BungeeCore;
-import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.listeners.ChatListener;
-import de.steamwar.bungeecore.sql.SteamwarUser;
-import net.md_5.bungee.api.ChatColor;
+import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
-
-import java.util.logging.Level;
public class ServerTeamchatCommand extends BasicCommand {
@@ -38,48 +30,13 @@ public class ServerTeamchatCommand extends BasicCommand {
}
@Override
- public void execute(CommandSender sender, String[] args) {
- if(sender instanceof ProxiedPlayer){
- ProxiedPlayer player = (ProxiedPlayer) sender;
-
- if(args.length == 0){
- Message.sendPrefixless("STC_USAGE", player);
- return;
- }
-
- StringBuilder msgBuilder = new StringBuilder();
- for (String arg : args){
- msgBuilder.append(arg).append(" ");
- }
- String msg = msgBuilder.toString();
- msg = ChatColor.translateAlternateColorCodes('&', msg);
-
- if (SteamwarDiscordBot.instance() != null) {
- try {
- SteamwarDiscordBot.instance().getServerTeamChatListener().send(" " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
- } catch (Exception e) {
- BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send stc message to discord", e);
- }
- }
- sendToTeam(msg, player);
+ public void execute(CommandSender s, String[] args) {
+ ChatSender sender = ChatSender.of(s);
+ if(args.length == 0) {
+ sender.system("STC_USAGE");
+ return;
}
- }
- public static void sendToTeam(String message, SteamwarUser sender){
- for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
- if ((target.hasPermission("bungeecore.teamchat"))
- && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
- Message.sendPrefixless("STC_FORMAT", target, sender.getUserName(), ChatListener.highlightOwnMarks(message, "§r", target));
- }
- }
- }
-
- public static void sendToTeam(String message, ProxiedPlayer sender){
- for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
- if ((target.hasPermission("bungeecore.teamchat"))
- && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
- Message.sendPrefixless("STC_FORMAT", target, sender.getName(), ChatListener.highlightOwnMarks(message, "§r", target));
- }
- }
+ ChatListener.sendChat(sender, ChatSender.serverteamReceivers(), "CHAT_SERVERTEAM", String.join(" ", args));
}
}
diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java
index dceae825..41c3c911 100644
--- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java
+++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java
@@ -19,13 +19,10 @@
package de.steamwar.bungeecore.commands;
-import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.listeners.ChatListener;
import de.steamwar.bungeecore.sql.SteamwarUser;
-import net.md_5.bungee.api.ChatColor;
+import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
public class TeamchatCommand extends BasicCommand {
@@ -34,35 +31,19 @@ public class TeamchatCommand extends BasicCommand {
}
@Override
- public void execute(CommandSender sender, String[] args) {
- if(sender instanceof ProxiedPlayer){
- ProxiedPlayer player = (ProxiedPlayer) sender;
- SteamwarUser user = SteamwarUser.get(player.getUniqueId());
-
- if(user.getTeam() == 0){
- Message.send("TC_NO_TEAM", player);
- return;
- }
-
- if(args.length == 0){
- Message.send("TC_USAGE", player);
- return;
- }
-
- StringBuilder msgBuilder = new StringBuilder();
- for (String arg : args){
- msgBuilder.append(arg).append(" ");
- }
- String msg = msgBuilder.toString();
- msg = ChatColor.translateAlternateColorCodes('&', msg);
-
- for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
- SteamwarUser targetuser = SteamwarUser.get(target.getUniqueId());
- if (targetuser.getTeam() == user.getTeam()
- && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
- Message.sendPrefixless("TC_FORMAT", target, player.getName(), ChatListener.highlightOwnMarks(msg, "§f", target));
- }
- }
+ public void execute(CommandSender s, String[] args) {
+ ChatSender sender = ChatSender.of(s);
+ if(args.length == 0){
+ sender.system("TC_USAGE");
+ return;
}
+
+ SteamwarUser user = sender.user();
+ if(user.getTeam() == 0){
+ sender.system("TC_NO_TEAM");
+ return;
+ }
+
+ ChatListener.sendChat(sender, ChatSender.allReceivers().filter(player -> player.user().getTeam() == user.getTeam()), "CHAT_TEAM", String.join(" ", args));
}
}
diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java
index 7f2377d3..48f5f81b 100644
--- a/src/de/steamwar/bungeecore/listeners/ChatListener.java
+++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java
@@ -30,13 +30,11 @@ import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.TabCompleteEvent;
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
import net.md_5.bungee.api.scheduler.TaskScheduler;
-import net.md_5.bungee.command.ConsoleCommandSender;
import net.md_5.bungee.event.EventHandler;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -58,7 +56,7 @@ public class ChatListener extends BasicListener {
if (message.contains("jndi:ldap")) {
e.setCancelled(true);
- SteamwarUser.get(player.getUniqueId()).punishPerma(Punishment.PunishmentType.Ban, "Versuchte Exploit-Ausnutzung", 0);
+ SteamwarUser.get(player).punishPerma(Punishment.PunishmentType.Ban, "Versuchte Exploit-Ausnutzung", 0);
return;
}
@@ -76,32 +74,73 @@ public class ChatListener extends BasicListener {
} else if (message.startsWith("+")) {
localChat(player, message.substring(1));
} else {
- String finalMessage = message;
- ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> sendChat(ChatSender.of(player), globalReceivers(), "CHAT_GLOBAL", finalMessage));
+ sendChat(ChatSender.of(player), ChatSender.globalReceivers(), "CHAT_GLOBAL", message);
}
}
}
- public static Stream globalReceivers() {
- //TODO: Filter arena players
- return ProxyServer.getInstance().getPlayers().stream();
+ public static void sendChat(ChatSender sender, Stream receivers, String format, String message) {
+ String finalMessage = modifyFilter(sender, message);
+ if(finalMessage == null)
+ return;
+
+ SteamwarUser user = sender.user();
+
+ AtomicBoolean noReceiver = new AtomicBoolean(true);
+ receivers.filter(ChatSender::chatShown).forEach(player -> {
+ noReceiver.set(false);
+ chatToReciever(player, user, format, finalMessage);
+ });
+
+ chatToReciever(ChatSender.console(), user, format, finalMessage);
+
+ if(format.equals("CHAT_GLOBAL")) {
+ if (SteamwarDiscordBot.instance() != null)
+ chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), user, format, finalMessage);
+ } else if (format.equals("CHAT_SERVERTEAM")) {
+ if (SteamwarDiscordBot.instance() != null)
+ chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), user, format, finalMessage);
+ } else if (noReceiver.get()) {
+ sender.system("CHAT_NO_RECEIVER");
+ //TODO always 1 Receiver (own)
+ }
}
- public static void sendChat(ChatSender sender, Stream receivers, String format, String message) {
+ public static void localChat(ProxiedPlayer player, String message) {
+ ChatSender sender = ChatSender.of(player);
+ if(message.length() == 0){
+ sender.system("CHAT_BC_USAGE");
+ return;
+ }
+
+ message = sanitize7(message);
+
+ if(ChatListener.filteredCommand(player, message))
+ return;
+ if(!message.startsWith("/")) {
+ message = modifyFilter(sender, message);
+ if(message == null)
+ return;
+ }
+
+ player.chat(message);
+ }
+
+ private static String modifyFilter(ChatSender sender, String message) {
if(!sender.chatShown()) {
sender.system("CHAT_RECEIVE");
- return;
+ return null;
}
SteamwarUser user = sender.user();
UserGroup group = user.getUserGroup();
if(!group.isTeamGroup() && (message.contains("http:") || message.contains("https:") || message.contains("www."))){
sender.system("CHAT_NO_LINKS");
- return;
+ return null;
}
if (user.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute))
- return;
+ return null;
if(group != UserGroup.Member || coloredTeams.contains(user.getTeam()))
message = ChatColor.translateAlternateColorCodes('&', message);
@@ -110,35 +149,8 @@ public class ChatListener extends BasicListener {
specialAlert(sender, "Lixfel", "CHAT_LIXFEL_", 3, 6, 11, 12, 15);
if (message.contains("YOYONOW"))
specialAlert(sender, "YoyoNow", "CHAT_YOYONOW_", 3, 6, 11, 12);
- //TODO: Extract filters and specials for local chat
- String emblem = UserElo.getEmblem(user);
- String team = user.getTeam() == 0 ? "" : Team.get(user.getTeam()).getTeamColor() + Team.get(user.getTeam()).getTeamKuerzel() + " ";
- String finalMessage = message;
-
- //Location Team Emblem Group Name» Message
- // {0}: sender.getName() {1}: target.getName() {2}: message {3}: team {4}: emblem {5}: usercolor {6}: usergroup {7}: Messagecolor
- // CHAT_SERVERTEAM §eSTC§8»{5}{0} §f{2}
- // CHAT_TEAM {3}{5}{0}§8» §f{2}
- // CHAT_GLOBAL {3}{4}{5}{6}{0}§8» {7}{2}
- // CHAT_DISCORD_GLOBAL §8DC {5}{6}{0}§8» {7}{2}
- // CHAT_MSG §e{0}§8»§e{1} §f{2}
-
- AtomicBoolean noReceiver = new AtomicBoolean(true);
- receivers.map(ChatSender::of).filter(ChatSender::chatShown).forEach(player -> {
- noReceiver.set(false);
- chatToReciever(player, user, format, finalMessage);
- });
-
- chatToReciever(ChatSender.console(), user, format, message); //TODO only global/DCglobal
-
- if(format.equals("CHAT_GLOBAL")) {
- if (SteamwarDiscordBot.instance() != null) {
- chatToReciever(ChatSender.discordConsole(), user, format, message);
- }
- } else if(noReceiver.get()) {
- //TODO nobody hears you message
- }
+ return message;
}
private static void chatToReciever(ChatSender receiver, SteamwarUser sender, String format, String message) {
@@ -146,7 +158,7 @@ public class ChatListener extends BasicListener {
receiver.chat(new Message(format,
sender,
receiver,
- highlightOwnMarks(message, group.getChatColorCode(), receiver),
+ highlightMentions(message, group.getChatColorCode(), receiver),
sender.getTeam() == 0 ? "" : Team.get(sender.getTeam()).getTeamColor() + Team.get(sender.getTeam()).getTeamKuerzel() + " ",
UserElo.getEmblem(sender),
group.getColorCode(),
@@ -154,20 +166,6 @@ public class ChatListener extends BasicListener {
group.getChatColorCode()));
}
- public static void localChat(ProxiedPlayer player, String message) {
- if(message.length() == 0){
- Message.send("CHAT_BC_USAGE", player);
- return;
- }
-
- message = sanitize7(message);
-
- if(ChatListener.filteredCommand(player, message))
- return;
-
- player.chat(message);
- }
-
private static String sanitize7(String message) {
String begin = message.split(" ", 2)[0];
if(begin.startsWith("7") && begin.substring(1).matches("[A-Za-z]+")){
@@ -197,7 +195,7 @@ public class ChatListener extends BasicListener {
}
}
- public static String highlightOwnMarks(String message, String returnColor, ChatSender player) {
+ private static String highlightMentions(String message, String returnColor, ChatSender player) {
if(!message.contains("@"))
return message;
diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties
index b1384967..c2103742 100644
--- a/src/de/steamwar/messages/BungeeCore.properties
+++ b/src/de/steamwar/messages/BungeeCore.properties
@@ -1,6 +1,7 @@
PREFIX=§eSteam§8War»
SPACER=
TIMEFORMAT=HH:mm dd.MM.yyyy
+PLAIN_STRING={0}
UNKNOWN_COMMAND=§cUnbekannter Befehl.
UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht.
@@ -294,11 +295,8 @@ KICK_NORMAL=§cDu wurdest gekickt.
#MsgCommand
MSG_USAGE=§8/§7msg §8[§eBenutzer§8] [§eNachricht§8]
-MSG_OFFLINE=§cDieser Spieler ist derzeit nicht online!
+MSG_OFFLINE=§cKein Gesprächspartner verfügbar!
MSG_IGNORED=§cDieser Spieler hat dich geblockt!
-MSG_NOMESSAGE=§cDieser Spieler empfängt derzeit keine Chatnachrichten!
-MSG_SELF=§cNachrichten an dich selbst hast du wirklich nicht nötig!
-MSG_FORMAT=§e{0}§8»§e{1} §r§7{2}
#PingCommand
PING_RESPONSE=§7Dein Ping beträgt §c{0}§7 ms!
@@ -311,10 +309,6 @@ POLL_ANSWER_NEW=§aDeine Antwort wurde registriert.
#RCommand
R_USAGE=§8/§7r §8[§eAntwort§8]
-R_NOTHING=§cDu hast bisher mit niemandem geschrieben!
-R_OFFLINE=§cDieser Spieler ist derzeit nicht online!
-R_BLOCKED=§cDieser Spieler hat dich geblockt!
-R_NO_CHAT=§cDieser Spieler empfängt derzeit keine Chatnachrichten!
#RegelnCommand
REGELN_RULES=§7§lRegelwerke
@@ -356,12 +350,10 @@ TUTORIAL_OWN_HELP=§8/§7tutorial own §8- §7Liste der eigenen Tutorials
#ServerTeamchatCommand
STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8]
-STC_FORMAT=§8STC §e{0}» §r{1}
#TeamchatCommand
TC_USAGE=§8/§7tc §8[§eNachricht an das Team§8]
TC_NO_TEAM=§cDu bist in keinem Team.
-TC_FORMAT=§8TC §e{0}§8» §r{1}
#TeamCommand
TEAM_IN_TEAM=§cDu bist bereits in einem Team.
@@ -501,6 +493,13 @@ CHAT_YOYONOW_4=Ich wünsche dir noch weiterhin ein reibungsloses Spielerlebnis.
CHAT_RECEIVE=§cUm Chatnachrichten versenden zu können, musst du auch welche empfangen!
CHAT_NO_LINKS=§cDu darfst keine Links versenden.
CHAT_BC_USAGE=§8/§7bc §8[§eNachricht§8]
+CHAT_NO_RECEIVER=§cNiemand empfängt deine Nachricht
+
+CHAT_SERVERTEAM=§8STC §e{0}§8» §f{2}
+CHAT_GLOBAL={3}{4}{5}{6}{0}§8» {7}{2}
+CHAT_DISCORD_GLOBAL=§8Dc {5}{6}{0}§8» {7}{2}
+CHAT_TEAM=§8TC §e{0}§8» §f{2}
+CHAT_MSG=§e{0}§8»§e{1} §7{2}
#CheckListner
CHECK_UNCHECKED=§7Du hast noch §e{0} §7ungeprüfte Schematic§8(§7s§8)!
diff --git a/src/de/steamwar/messages/ChatSender.java b/src/de/steamwar/messages/ChatSender.java
index 032f5cd0..2254eff6 100644
--- a/src/de/steamwar/messages/ChatSender.java
+++ b/src/de/steamwar/messages/ChatSender.java
@@ -19,12 +19,15 @@
package de.steamwar.messages;
+import de.steamwar.bungeecore.Arenaserver;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
-import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
+import de.steamwar.bungeecore.Subserver;
+import de.steamwar.bungeecore.bot.listeners.DiscordChatListener;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -39,9 +42,29 @@ import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
+import java.util.stream.Stream;
public interface ChatSender {
+ static Stream all() {
+ return ProxyServer.getInstance().getPlayers().stream();
+ }
+
+ static Stream allReceivers() {
+ return all().map(ChatSender::of);
+ }
+
+ static Stream globalReceivers() {
+ return all().filter(player -> {
+ Subserver subserver = Subserver.getSubserver(player);
+ return !(subserver instanceof Arenaserver && subserver.getServer() == player.getServer().getInfo());
+ }).map(ChatSender::of);
+ }
+
+ static Stream serverteamReceivers() {
+ return allReceivers().filter(player -> player.user().getUserGroup().isTeamGroup());
+ }
+
SteamwarUser user();
Locale getLocale();
@@ -64,6 +87,10 @@ public interface ChatSender {
send(false, ChatMessageType.SYSTEM, null, null, new Message(message, params));
}
+ default void prefixless(String message, Message onHover, ClickEvent onClick, Object... params) {
+ send(false, ChatMessageType.SYSTEM, onHover, onClick, new Message(message, params));
+ }
+
default void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) {
TextComponent msg = new TextComponent(parse(prefixed, message));
if(onHover != null)
@@ -79,7 +106,7 @@ public interface ChatSender {
String pattern = "";
if(prefixed)
pattern = resourceBundle.getObject("PREFIX") + " ";
- pattern += (String)resourceBundle.getObject(message.getMessage());
+ pattern += (String)resourceBundle.getObject(message.getFormat());
MessageFormat format = new MessageFormat(pattern, locale);
Object[] params = message.getParams();
@@ -158,7 +185,7 @@ public interface ChatSender {
return of(ConsoleCommandSender.getInstance());
}
- static ChatSender discordConsole() {
+ static ChatSender discordChannel(DiscordChatListener channel) {
return new ChatSender() {
@Override
public SteamwarUser user() {
@@ -178,7 +205,7 @@ public interface ChatSender {
@Override
public void sendMessage(ChatMessageType type, BaseComponent... msg) {
try {
- SteamwarDiscordBot.instance().getIngameChatListener().send(" " + new TextComponent(msg).toPlainText());
+ channel.send(" " + new TextComponent(msg).toPlainText());
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e);
}
@@ -206,7 +233,7 @@ public interface ChatSender {
@Override
public void sendMessage(ChatMessageType type, BaseComponent... msg) {
try {
- //TODO SteamwarDiscordBot.instance().getIngameChatListener().send(" " + new TextComponent(msg).toPlainText());
+ message.delete().queue();
} catch (Exception e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat reply to discord user", e);
}