From e1e1d661777397fb34613b265965f1f1e9101599 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 12 May 2024 17:20:37 +0200 Subject: [PATCH 01/22] WIP message deprecation Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/EventStarter.java | 9 +- src/de/steamwar/bungeecore/Message.java | 33 +----- src/de/steamwar/bungeecore/ServerStarter.java | 8 +- .../steamwar/bungeecore/SubserverSystem.java | 14 +-- .../bungeecore/bot/SteamwarDiscordBot.java | 6 +- .../bungeecore/bot/commands/BanCommand.java | 3 +- .../bungeecore/bot/commands/MuteCommand.java | 3 +- .../bot/listeners/AnnouncementListener.java | 4 +- .../bot/listeners/DiscordChatListener.java | 10 +- .../bot/listeners/DiscordTicketListener.java | 5 +- .../bungeecore/commands/AlertCommand.java | 7 +- .../bungeecore/commands/BauCommand.java | 3 +- .../bungeecore/commands/BugCommand.java | 4 +- .../commands/BuilderCloudCommand.java | 14 +-- .../bungeecore/commands/ChallengeCommand.java | 9 +- .../bungeecore/commands/CheckCommand.java | 69 +++++------ .../bungeecore/commands/DevCommand.java | 6 +- .../bungeecore/commands/EventCommand.java | 4 +- .../bungeecore/commands/FightCommand.java | 12 +- .../bungeecore/commands/HelpCommand.java | 20 ++-- .../bungeecore/commands/HistoricCommand.java | 4 +- .../bungeecore/commands/JoinmeCommand.java | 3 +- .../bungeecore/commands/KickCommand.java | 9 +- .../bungeecore/commands/MsgCommand.java | 13 +- .../commands/PunishmentCommand.java | 12 +- .../bungeecore/commands/ReplayCommand.java | 8 +- .../commands/ServerTeamchatCommand.java | 4 +- .../bungeecore/commands/SetLocaleCommand.java | 4 +- .../bungeecore/commands/TeamCommand.java | 4 +- .../bungeecore/commands/TeamchatCommand.java | 10 +- .../bungeecore/commands/TpCommand.java | 6 +- .../bungeecore/commands/TypeMappers.java | 4 +- .../commands/WebpasswordCommand.java | 8 +- .../bungeecore/commands/WhoisCommand.java | 6 +- .../bungeecore/listeners/BanListener.java | 8 +- .../bungeecore/listeners/ChatListener.java | 50 ++++---- .../listeners/ConnectionListener.java | 6 +- .../bungeecore/listeners/PluginMessage.java | 10 +- src/de/steamwar/bungeecore/mods/ModUtils.java | 4 +- .../steamwar/bungeecore/tablist/Tablist.java | 8 +- .../bungeecore/tablist/TablistBuild.java | 4 +- .../bungeecore/tablist/TablistGroup.java | 4 +- .../bungeecore/tablist/TablistPart.java | 4 +- .../bungeecore/tablist/TablistServer.java | 4 +- src/de/steamwar/bungeecore/util/BauLock.java | 6 +- src/de/steamwar/command/SWCommand.java | 22 ++-- .../steamwar/messages/BungeeCore.properties | 3 +- .../messages/BungeeCore_de.properties | 1 - .../{ChatSender.java => Chatter.java} | 112 +++++++++--------- src/de/steamwar/messages/ChatterGroup.java | 71 +++++++++++ 50 files changed, 356 insertions(+), 299 deletions(-) rename src/de/steamwar/messages/{ChatSender.java => Chatter.java} (76%) create mode 100644 src/de/steamwar/messages/ChatterGroup.java diff --git a/src/de/steamwar/bungeecore/EventStarter.java b/src/de/steamwar/bungeecore/EventStarter.java index 60ad4547..f70a7b1b 100644 --- a/src/de/steamwar/bungeecore/EventStarter.java +++ b/src/de/steamwar/bungeecore/EventStarter.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore; +import de.steamwar.messages.Chatter; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import net.md_5.bungee.api.ProxyServer; @@ -59,6 +60,7 @@ public class EventStarter { Team red = Team.get(next.getTeamRed()); //Don't start EventServer if not the event bungee + String command; if(BungeeCore.EVENT_MODE || next.getSpectatePort() == 0) { ServerStarter starter = new ServerStarter().event(next); @@ -67,12 +69,11 @@ public class EventStarter { eventServer.put(red.getTeamId(), subserver); }).start(); - Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); + command = "/event " + blue.getTeamKuerzel(); } else { - Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + spectatePorts.get(next.getSpectatePort())), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); + command = "/" + spectatePorts.get(next.getSpectatePort()); } + Chatter.broadcast().system("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, command), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); } } diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java index 683b9ed8..e1073667 100644 --- a/src/de/steamwar/bungeecore/Message.java +++ b/src/de/steamwar/bungeecore/Message.java @@ -19,12 +19,11 @@ package de.steamwar.bungeecore; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; 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.chat.ClickEvent; -import net.md_5.bungee.api.chat.TextComponent; import java.text.DateFormat; import java.text.MessageFormat; @@ -34,16 +33,6 @@ 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); @@ -56,7 +45,7 @@ public class Message { @Deprecated private static Locale locale(CommandSender sender) { - return ChatSender.of(sender).getLocale(); + return Chatter.of(sender).getLocale(); } @Deprecated @@ -103,29 +92,13 @@ public class Message { @Deprecated private static void send(String message, boolean prefixed, CommandSender s, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){ - ChatSender sender = ChatSender.of(s); + Chatter sender = Chatter.of(s); if(type == ChatMessageType.CHAT && !sender.chatShown()) return; sender.send(prefixed, type, onHover != null ? new Message("PLAIN_STRING", onHover) : null, onClick, new Message(message, params)); } - public static void broadcast(String message, Object... params) { - broadcast(message, null, null, params); - } - - public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params) { - ChatSender.allReceivers().forEach(player -> player.system(message, onHover != null ? new Message(onHover, params) : null, onClick, params)); - } - - public static void team(String message, Object... params) { - team(message, null, null, params); - } - - public static void team(String message, String onHover, ClickEvent onClick, Object... params) { - ChatSender.serverteamReceivers().forEach(player -> player.prefixless(message, onHover != null ? new Message(onHover, params) : null, onClick, params)); - } - private final String format; private final Object[] params; diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index fdea7c1c..e4bfab41 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -1,6 +1,6 @@ package de.steamwar.bungeecore; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.*; import lombok.Getter; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -144,7 +144,7 @@ public class ServerStarter { }); if (!atLeastOneSupervisor) { for (ProxiedPlayer p : playersToSend) { - ChatSender.of(p).system("BAU_START_NOT_ALLOWED"); + Chatter.of(p).system("BAU_START_NOT_ALLOWED"); } } return atLeastOneSupervisor; @@ -243,7 +243,7 @@ public class ServerStarter { node = Node.getNode(); if(node == null) { for (ProxiedPlayer p : playersToSend) - ChatSender.of(p).system("SERVER_START_OVERLOAD"); + Chatter.of(p).system("SERVER_START_OVERLOAD"); return false; } @@ -291,7 +291,7 @@ public class ServerStarter { private static boolean startingBau(ProxiedPlayer p) { Bauserver subserver = Bauserver.get(p.getUniqueId()); if(subserver != null && !subserver.isStarted()) { - ChatSender.of(p).system("BAU_START_ALREADY"); + Chatter.of(p).system("BAU_START_ALREADY"); return true; } return false; diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 71b58096..b134e6d3 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -21,9 +21,10 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.FightInfoHandler; +import de.steamwar.messages.Chatter; +import de.steamwar.network.packets.server.StartingServerPacket; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; -import de.steamwar.network.packets.server.StartingServerPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -37,18 +38,17 @@ public class SubserverSystem { node.execute("rm", "-r", worldName); } - public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){ + public static void sendDeniedMessage(Chatter p, UUID owner){ ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); if(o == null) return; - if(IgnoreSystem.isIgnored(owner, p.getUniqueId())){ - Message.send("SERVER_IGNORED", p); + if(IgnoreSystem.isIgnored(owner, p.user().getUUID())){ + p.system("SERVER_IGNORED"); return; } - Message.send("SERVER_ADD_MEMBER", o, p.getName()); - Message.sendPrefixless("SERVER_ADD_MESSAGE", o, Message.parse("SERVER_ADD_MESSAGE_HOVER", o, p.getName()), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName())); + Message.send("SERVER_ADD_MEMBER", o, p); + Message.sendPrefixless("SERVER_ADD_MESSAGE", o, "SERVER_ADD_MESSAGE_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.user().getUserName())); } public static void sendPlayer(Subserver subserver, ProxiedPlayer player) { diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 759edcca..c9628e76 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -28,7 +28,7 @@ import de.steamwar.bungeecore.bot.listeners.*; import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; import de.steamwar.bungeecore.bot.util.DiscordTicketMessage; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import lombok.Getter; import net.dv8tion.jda.api.JDA; @@ -112,8 +112,8 @@ public class SteamwarDiscordBot { new DiscordEventListener(); new PrivateMessageListener(); announcementListener = new AnnouncementListener(); - ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL", ChatSender::globalReceivers); - serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM", ChatSender::serverteamReceivers); + ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL", Chatter::broadcast); + serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM", Chatter::serverteam); new SlashCommandListener(); jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue()); diff --git a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java index ed6569ef..987866cf 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -60,7 +61,7 @@ public class BanCommand extends BasicDiscordCommand { boolean isPerma = event.getOption("time").getAsString().equals("perma"); PunishmentCommand.ban(target, time, msg, sender, isPerma); - Message.team("BAN_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); + Chatter.serverteam().system("BAN_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java index 3c296f4d..154152fa 100644 --- a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.bot.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -61,7 +62,7 @@ public class MuteCommand extends BasicDiscordCommand { boolean isPerma = event.getOption("time").getAsString().equals("perma"); target.punish(Punishment.PunishmentType.Mute, time, msg, sender.getId(), isPerma); - Message.team("MUTE_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); + Chatter.serverteam().system("MUTE_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).queue(); } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java b/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java index ab4be193..5a72baeb 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java @@ -19,9 +19,9 @@ package de.steamwar.bungeecore.bot.listeners; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; +import de.steamwar.messages.Chatter; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; @@ -37,7 +37,7 @@ public class AnnouncementListener extends BasicDiscordListener { if (event.getAuthor().isBot()) { return; } - Message.broadcast("ALERT", event.getMessage().getContentDisplay()); + Chatter.broadcast().system("ALERT", event.getMessage().getContentDisplay()); } public void announce(String message) { diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java index 13b5fca9..1803d94b 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java @@ -22,9 +22,10 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.listeners.ChatListener; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.ChatterGroup; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; -import de.steamwar.messages.ChatSender; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.TextChannel; @@ -32,16 +33,15 @@ import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import org.jetbrains.annotations.NotNull; import java.util.function.Supplier; -import java.util.stream.Stream; public class DiscordChatListener extends BasicDiscordListener { private final String channel; private final String format; - private final Supplier> targets; + private final Supplier targets; - public DiscordChatListener(String channel, String format, Supplier> targets) { + public DiscordChatListener(String channel, String format, Supplier targets) { this.channel = channel; this.format = format; this.targets = targets; @@ -57,7 +57,7 @@ public class DiscordChatListener extends BasicDiscordListener { 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), targets.get(), format, null, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' ')); + ChatListener.sendChat(Chatter.of(event.getMessage(), steamwarUser), targets.get(), format, null, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' ')); } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java index e41342e4..c6bb73ca 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import net.dv8tion.jda.api.EmbedBuilder; @@ -72,7 +73,7 @@ public class DiscordTicketListener extends BasicDiscordListener { ticketChannel.sendMessage(messageBuilder.build()).complete(); event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete(); - Message.team("DISCORD_TICKET_NEW", ticketChannel.getName()); + Chatter.serverteam().prefixless("DISCORD_TICKET_NEW", ticketChannel.getName()); } else if(event.getComponentId().startsWith("close-")) { TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG); @@ -127,7 +128,7 @@ public class DiscordTicketListener extends BasicDiscordListener { logChannel.sendMessage(builder.build()).queue(); }); - Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); + Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); event.getTextChannel().delete().reason("Closed").queue(); } } diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index 7b56870a..210f5b04 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -19,11 +19,10 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -36,12 +35,12 @@ public class AlertCommand extends SWCommand { @Register(description = "USAGE_ALERT") public void broadcast(CommandSender sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { if (message.length == 0) { - ChatSender.of(sender).system(new Message("USAGE_ALERT")); + Chatter.of(sender).system("USAGE_ALERT"); return; } String s = String.join(" ", message); - Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s)); + Chatter.broadcast().system("ALERT", ChatColor.translateAlternateColorCodes('&', s)); if ("-discord".equals(sendToDiscord) && SteamwarDiscordBot.instance() != null) { SteamwarDiscordBot.instance().getAnnouncementListener().announce(s); } diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 9981b71d..60872e69 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -30,6 +30,7 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; @@ -157,7 +158,7 @@ public class BauCommand extends SWCommand { } ProxiedPlayer p = (ProxiedPlayer) sender; if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) { - SubserverSystem.sendDeniedMessage(p, value.getUUID()); + SubserverSystem.sendDeniedMessage(Chatter.of(p), value.getUUID()); messageSender.send("BAU_TP_NOALLOWED"); return false; } diff --git a/src/de/steamwar/bungeecore/commands/BugCommand.java b/src/de/steamwar/bungeecore/commands/BugCommand.java index f93e23d0..d537628c 100644 --- a/src/de/steamwar/bungeecore/commands/BugCommand.java +++ b/src/de/steamwar/bungeecore/commands/BugCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.sql.SWException; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; public class BugCommand extends SWCommand { @@ -35,6 +35,6 @@ public class BugCommand extends SWCommand { String server = player.getServer().getInfo().getName(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SWException.log(String.join(" ", message), server + " " + player.getName() + " " + user.getId()); - ChatSender.of(player).system("BUG_MESSAGE"); + Chatter.of(player).system("BUG_MESSAGE"); } } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 90eb22f8..64a6507c 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -6,7 +6,7 @@ import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -44,7 +44,7 @@ public class BuilderCloudCommand extends SWCommand { @Register(description = "BUILDERCLOUD_USAGE") public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); return; } @@ -55,13 +55,13 @@ public class BuilderCloudCommand extends SWCommand { public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String oldName, String newName) { File oldMap = mapFile(version, oldName); if(!oldMap.exists()) { - ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); return; } File newMap = mapFile(version, newName); if(newMap.exists()) { - ChatSender.of(player).system("BUILDERCLOUD_EXISTING_MAP"); + Chatter.of(player).system("BUILDERCLOUD_EXISTING_MAP"); return; } @@ -71,20 +71,20 @@ public class BuilderCloudCommand extends SWCommand { throw new SecurityException(e); } - ChatSender.of(player).system("BUILDERCLOUD_RENAMED"); + Chatter.of(player).system("BUILDERCLOUD_RENAMED"); } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); return; } ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { BungeeCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); - ChatSender.of(player).system("BUILDERCLOUD_DEPLOY_FINISHED"); + Chatter.of(player).system("BUILDERCLOUD_DEPLOY_FINISHED"); }); } diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 72a42e19..32d0748f 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; +import de.steamwar.messages.Chatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; @@ -44,7 +45,7 @@ public class ChallengeCommand extends SWCommand { challenges.remove(p); new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).callback( - arena -> Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()) + arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()) ).start(); }else{ if(!challenges.containsKey(p)){ @@ -53,10 +54,10 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); - Message.send("CHALLENGE_CHALLENGED", p, target.getName(), mode.getDisplayName()); - Message.send("CHALLENGE_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? Message.parse("CHALLENGE_CHALLENGED_MAP", target, m) : ""); + Chatter.of(p).system("CHALLENGE_CHALLENGED", target.getName(), mode.getDisplayName()); + Chatter.of(target).system("CHALLENGE_CHALLENGED_TARGET", p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? new Message("CHALLENGE_CHALLENGED_MAP", m) : ""); - Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + m)); + Chatter.of(target).system("CHALLENGE_ACCEPT", new Message("CHALLENGE_ACCEPT_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + m)); } }); } diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 82ebaa68..9b983733 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -22,9 +22,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.messages.Chatter; import de.steamwar.sql.*; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -66,40 +68,40 @@ public class CheckCommand extends SWCommand { public CheckCommand() { super("check", ConnectionListener.CHECK_PERMISSION); - ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - List schematics = getSchemsToCheck(); - if(schematics.size() != currentCheckers.size()) - Message.team("CHECK_REMINDER", "CHECK_REMINDER_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size()); - }, 10, 10, TimeUnit.MINUTES); + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> sendReminder(Chatter.serverteam()), 10, 10, TimeUnit.MINUTES); } - public static void sendReminder(ProxiedPlayer player) { + + public static void sendReminder(Chatter chatter) { List schematics = getSchemsToCheck(); - if(schematics.size() != currentCheckers.size()) - Message.send("CHECK_REMINDER", player, Message.parse("CHECK_REMINDER_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size()); + if(schematics.size() == currentCheckers.size()) + return; + + chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size()); } @Register(value = "list", description = "CHECK_HELP_LIST") public void list(ProxiedPlayer player) { + Chatter chatter = Chatter.of(player); List schematicList = getSchemsToCheck(); - Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size()); + chatter.prefixless("CHECK_LIST_HEADER", schematicList.size()); for (SchematicNode schematic : schematicList) { CheckSession current = currentSchems.get(schematic.getId()); long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime(); - String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "§c" : "§e") : "§a"; + String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "c" : "e") : "a"; long hours = waitedMillis / 3600000; long minutes = (waitedMillis - hours * 3600000) / 60000; - String waitTime = color + Message.parse("CHECK_LIST_WAIT", player, hours, (minutes < 10) ? "0" + minutes : minutes); + Message waitTime = new Message("CHECK_LIST_WAIT", player, color, hours, (minutes < 10) ? "0" + minutes : minutes); if (current == null) { - Message.sendPrefixless("CHECK_LIST_TO_CHECK", player, - Message.parse("CHECK_LIST_TO_CHECK_HOVER", player), + chatter.prefixless("CHECK_LIST_TO_CHECK", + new Message("CHECK_LIST_TO_CHECK_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()), waitTime, schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName()); } else { - Message.sendPrefixless("CHECK_LIST_CHECKING", player, - Message.parse("CHECK_LIST_CHECKING_HOVER", player), + chatter.prefixless("CHECK_LIST_CHECKING", + new Message("CHECK_LIST_CHECKING_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()), waitTime, schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName()); @@ -109,8 +111,9 @@ public class CheckCommand extends SWCommand { @Register(value = "schematic", noTabComplete = true) public void schematic(ProxiedPlayer player, String schemID) { + Chatter chatter = Chatter.of(player); if(isChecking(player)){ - Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player); + chatter.system("CHECK_SCHEMATIC_ALREADY_CHECKING"); return; } @@ -120,16 +123,16 @@ public class CheckCommand extends SWCommand { ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!"); return; }else if(schem.getOwner() == checkingUser.getId()) { - Message.send("CHECK_SCHEMATIC_OWN", player); + chatter.system("CHECK_SCHEMATIC_OWN"); return; } int playerTeam = checkingUser.hasPerm(UserPerm.MODERATION) ? 0 : checkingUser.getTeam(); if (playerTeam != 0 && SteamwarUser.get(schem.getOwner()).getTeam() == playerTeam) { - Message.send("CHECK_SCHEMATIC_OWN_TEAM", player); + chatter.system("CHECK_SCHEMATIC_OWN_TEAM"); return; } - new CheckSession(player, schem); + new CheckSession(chatter, schem); } @Register(value = "cancel", description = "CHECK_HELP_CANCEL") @@ -142,7 +145,7 @@ public class CheckCommand extends SWCommand { if(notChecking(player)) return; - Message.send("CHECK_ABORT", player); + Chatter.of(player).system("CHECK_ABORT"); currentCheckers.get(player.getUniqueId()).abort(); } @@ -185,7 +188,7 @@ public class CheckCommand extends SWCommand { private static boolean notChecking(ProxiedPlayer player){ if(!isChecking(player)){ - Message.send("CHECK_NOT_CHECKING", player); + Chatter.of(player).system("CHECK_NOT_CHECKING"); return true; } return false; @@ -200,7 +203,7 @@ public class CheckCommand extends SWCommand { try{ rank = Integer.parseInt(args[0]); }catch(NumberFormatException e){ - Message.send("CHECK_INVALID_RANK", player); + Chatter.of(player).system("CHECK_INVALID_RANK"); return; } } @@ -209,30 +212,30 @@ public class CheckCommand extends SWCommand { } private static class CheckSession{ - private final ProxiedPlayer checker; + private final Chatter checker; private final SchematicNode schematic; private final Timestamp startTime; private final ListIterator checkList; - private CheckSession(ProxiedPlayer checker, SchematicNode schematic){ + private CheckSession(Chatter checker, SchematicNode schematic){ this.checker = checker; this.schematic = schematic; this.startTime = Timestamp.from(Instant.now()); this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> checker.withPlayer(player -> { ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); - if(!new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start()) { + if(!new ServerStarter().test(mode, mode.getRandomMap(), player).check(schematic.getId()).start()) { remove(); return; } - currentCheckers.put(checker.getUniqueId(), this); + currentCheckers.put(checker.user().getUUID(), this); currentSchems.put(schematic.getId(), this); for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) - Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); + checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); next(0); - }); + })); } private void next(int rank) { @@ -241,7 +244,7 @@ public class CheckCommand extends SWCommand { return; } - checker.sendMessage(TextComponent.fromLegacyText(checkList.next())); + checker.sendMessage(ChatMessageType.SYSTEM, TextComponent.fromLegacy(checkList.next())); TextComponent next = new TextComponent(); next.setColor(ChatColor.GREEN); @@ -274,7 +277,7 @@ public class CheckCommand extends SWCommand { if(createLog("freigegeben")) { if(ranks.containsKey(schematic.getSchemtype())){ if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ - Message.send("CHECK_INVALID_RANK", checker); + checker.system("CHECK_INVALID_RANK"); return; } schematic.setRank(rank); @@ -288,7 +291,7 @@ public class CheckCommand extends SWCommand { } else { DiscordSchemAlert.sendAccept(schematic, user); } - Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); + Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); } stop(); } @@ -302,7 +305,7 @@ public class CheckCommand extends SWCommand { } else { DiscordSchemAlert.sendDecline(schematic, user, reason); } - Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); + Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); schematic.setType(SchematicType.Normal.toDB()); } diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index 834f96df..d0048c4b 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; import de.steamwar.command.*; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -45,7 +45,7 @@ public class DevCommand extends SWCommand { @Register public void simpleCommand(@Validator ProxiedPlayer player) { updateDevServers(); - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if (devServers.isEmpty()) { sender.system("DEV_NO_SERVER"); return; @@ -66,7 +66,7 @@ public class DevCommand extends SWCommand { @Register public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) { updateDevServers(); - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); ServerInfo info = devServers.get(name.toLowerCase()); if (info == null) { sender.system("DEV_NO_SERVER"); diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index fe197e72..f5ceb7e0 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.*; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -118,7 +118,7 @@ public class EventCommand extends SWCommand { Message.send("EVENT_NO_FIGHT_TEAM", player); return; } - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { SubserverSystem.sendPlayer(eventArena, player); } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index a397d97d..6e613325 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -47,7 +47,7 @@ public class FightCommand extends SWCommand { super("fight", "", "f"); } - private static ArenaMode getMode(ChatSender sender, String arg){ + private static ArenaMode getMode(Chatter sender, String arg){ ArenaMode mode = ArenaMode.getByChat(arg); if(mode != null) return mode; @@ -56,7 +56,7 @@ public class FightCommand extends SWCommand { return null; } - private static String getMap(ChatSender sender, ArenaMode mode, String arg){ + private static String getMap(Chatter sender, ArenaMode mode, String arg){ String realMap = mode.hasMap(arg.toLowerCase()); if(realMap != null) return realMap; @@ -67,7 +67,7 @@ public class FightCommand extends SWCommand { return null; } - private static void getModes(ChatSender sender, String precommand, boolean historic){ + private static void getModes(Chatter sender, String precommand, boolean historic){ TextComponent start = new TextComponent(); TextComponent current = start; for(ArenaMode mode : ArenaMode.getAllModes()){ @@ -98,7 +98,7 @@ public class FightCommand extends SWCommand { } static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if(alreadyInArena(player)) return; @@ -161,7 +161,7 @@ public class FightCommand extends SWCommand { public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) ).start() ); } diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index e7138941..36b9d7e8 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -33,7 +33,7 @@ public class HelpCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer player) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_LOBBY", "/l", @@ -49,12 +49,12 @@ public class HelpCommand extends SWCommand { @Register({"build","world"}) public void buildWorld(ProxiedPlayer player) { - printPage(ChatSender.of(player), "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); + printPage(Chatter.of(player), "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); } @Register({"build","player"}) public void buildPlayer(ProxiedPlayer player) { - printPage(ChatSender.of(player), "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); + printPage(Chatter.of(player), "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); } @Register({"build","worldedit"}) @@ -62,19 +62,19 @@ public class HelpCommand extends SWCommand { @Register({"build","world-edit"}) @Register({"build","edit"}) public void buildWorldedit(ProxiedPlayer player) { - printPage(ChatSender.of(player), "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); + printPage(Chatter.of(player), "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); } @Register({"build","other"}) public void buildOther(ProxiedPlayer player) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); printPage(sender, "HELP_BAU_GROUP_OTHER_TITLE", "HELP_TESTBLOCK", "HELP_SKULL", "HELP_BAUINFO"); sender.prefixless("HELP_SCHEMSUBMIT", new Message("HELP_SCHEMSUBMIT_HOVER"), new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.youtube.com/watch?v=9QrQ3UBWveE")); } @Register("build") public void sendBauHelpGroup(ProxiedPlayer player) { - printPage(ChatSender.of(player), ClickEvent.Action.RUN_COMMAND, + printPage(Chatter.of(player), ClickEvent.Action.RUN_COMMAND, "HELP_BAU_GROUP_ADMIN", "/help build admin", "HELP_BAU_GROUP_WORLD", "/help build world", "HELP_BAU_GROUP_PLAYER", "/help build player", @@ -87,7 +87,7 @@ public class HelpCommand extends SWCommand { @Register({"build","owner"}) @Register({"build","bauwelt"}) public void sendBauHelp(ProxiedPlayer player) { - printPage(ChatSender.of(player), ClickEvent.Action.SUGGEST_COMMAND, + printPage(Chatter.of(player), ClickEvent.Action.SUGGEST_COMMAND, "HELP_BAU_TP", "/build tp ", "HELP_BAU_ADDMEMBER", "/build addmember ", "HELP_BAU_DELMEMBER", "/build delmember ", @@ -100,7 +100,7 @@ public class HelpCommand extends SWCommand { "HELP_BAU_UNLOCK", "/build unlock"); } - private static void printPage(ChatSender sender, ClickEvent.Action action, String... args) { + private static void printPage(Chatter sender, ClickEvent.Action action, String... args) { for(int i = 0; i < args.length; i += 2) { String message = args[i]; String hoverMessage = message + "_HOVER"; @@ -110,7 +110,7 @@ public class HelpCommand extends SWCommand { } } - private static void printPage(ChatSender sender, String title, String... messages) { + private static void printPage(Chatter sender, String title, String... messages) { sender.system(title); for (String message : messages) { sender.prefixless(message); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index f5778b5e..f61ca160 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -20,9 +20,9 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,7 +35,7 @@ public class HistoricCommand extends SWCommand { public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) ).start(); }); } diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 54d4bec3..a7b9efb7 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Subserver; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import net.md_5.bungee.api.chat.ClickEvent; @@ -40,7 +41,7 @@ public class JoinmeCommand extends SWCommand { Message.send("JOINME_USAGE", player); return; } - Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", + Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName()); } diff --git a/src/de/steamwar/bungeecore/commands/KickCommand.java b/src/de/steamwar/bungeecore/commands/KickCommand.java index ccaac303..7a0b8730 100644 --- a/src/de/steamwar/bungeecore/commands/KickCommand.java +++ b/src/de/steamwar/bungeecore/commands/KickCommand.java @@ -19,10 +19,9 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,10 +34,10 @@ public class KickCommand extends SWCommand { @Register(description = "KICK_USAGE") public void genericCommand(CommandSender sender, @ErrorMessage("KICK_OFFLINE") ProxiedPlayer target, String... message) { if (message.length == 0) { - target.disconnect(Message.parseToComponent("KICK_NORMAL", true, target)); + Chatter.disconnect(target).system("KICK_NORMAL"); } else { - target.disconnect(BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§c" + String.join(" ", message))); + Chatter.disconnect(target).system("KICK_CUSTOM", String.join(" ", message)); } - Message.send("KICK_CONFIRM", sender, target.getName()); + Chatter.of(sender).system("KICK_CONFIRM", target); } } diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index ce9b8d79..b25ea63e 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -20,13 +20,12 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; -import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.ChatterGroup; +import de.steamwar.sql.IgnoreSystem; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.stream.Stream; - import static de.steamwar.bungeecore.Storage.lastChats; public class MsgCommand extends SWCommand { @@ -41,7 +40,7 @@ public class MsgCommand extends SWCommand { } public static void msg(ProxiedPlayer player, ProxiedPlayer target, String[] args) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if(target == null || !target.isConnected()) { sender.system("MSG_OFFLINE"); return; @@ -52,8 +51,8 @@ public class MsgCommand extends SWCommand { return; } - ChatSender receiver = ChatSender.of(target); - ChatListener.sendChat(sender, Stream.of(sender, receiver), "CHAT_MSG", receiver, String.join(" ", args)); + Chatter receiver = Chatter.of(target); + ChatListener.sendChat(sender, new ChatterGroup(sender, receiver), "CHAT_MSG", receiver, String.join(" ", args)); lastChats.put(player, target); lastChats.put(target, player); } diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index 03a36b37..d279492d 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -27,7 +27,7 @@ import de.steamwar.bungeecore.listeners.IPSanitizer; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.BannedUserIPs; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; @@ -83,7 +83,7 @@ public class PunishmentCommand { return null; } - public static boolean isPunishedWithMessage(ChatSender player, Punishment.PunishmentType punishment) { + public static boolean isPunishedWithMessage(Chatter player, Punishment.PunishmentType punishment) { SteamwarUser user = player.user(); if (!user.isPunished(punishment)) { return false; @@ -98,7 +98,7 @@ public class PunishmentCommand { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); if (player != null) { String ip = IPSanitizer.getTrueAddress(player.getPendingConnection()).getHostAddress(); - ChatSender.disconnect(player).system(punishmentMessage(user, Punishment.PunishmentType.Ban)); + Chatter.disconnect(player).system(punishmentMessage(user, Punishment.PunishmentType.Ban)); for (BannedUserIPs banned : BannedUserIPs.get(ip)) { SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); if (bannedUser.isPunished(Punishment.PunishmentType.Ban) && bannedUser.getPunishment(Punishment.PunishmentType.Ban).getEndTime().before(time)) { @@ -142,12 +142,12 @@ public class PunishmentCommand { ban(target, banTime, msg, punisher, isPerma); else target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); - Message.team(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); + Chatter.serverteam().system(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); } @Register public void genericError(ProxiedPlayer player, String... args) { - ChatSender.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); + Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); } @Mapper(value = "toPunish", local = true) @@ -192,7 +192,7 @@ public class PunishmentCommand { @Register public void genericError(ProxiedPlayer player, String... args) { - ChatSender.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", antiCommand)); + Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", antiCommand)); } }; } diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index 5f8256ce..3019a93d 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.sql.*; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; @@ -40,7 +40,7 @@ public class ReplayCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer player, @OptionalValue("") String optionalMap) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) return; @@ -65,7 +65,7 @@ public class ReplayCommand extends SWCommand { }, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(sender, fight), fight)).collect(Collectors.toList())).open(); } - private SWItem getFightItem(ChatSender sender, Fight fight) { + private SWItem getFightItem(Chatter sender, Fight fight) { SchematicType type = fight.getSchemType(); SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(sender, fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1)); @@ -84,7 +84,7 @@ public class ReplayCommand extends SWCommand { return item; } - private String parseLeader(ChatSender sender, SteamwarUser leader, int players, boolean winner) { + private String parseLeader(Chatter sender, SteamwarUser leader, int players, boolean winner) { return sender.parseToLegacy(winner ? (players > 1 ? "REPLAY_WINNER" : "REPLAY_SOLO_WINNER") : (players > 1 ? "REPLAY_LOSER" : "REPLAY_SOLO_LOSER"), leader.getUserName(), players - 1); } } diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java index b768b1a6..b8f99683 100644 --- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.CommandSender; public class ServerTeamchatCommand extends SWCommand { @@ -33,6 +33,6 @@ public class ServerTeamchatCommand extends SWCommand { @Register(description = "STC_USAGE") public void genericCommand(CommandSender commandSender, @ErrorMessage(value = "STC_USAGE", allowEAs = false) String... message) { - ChatListener.sendChat(ChatSender.of(commandSender), ChatSender.serverteamReceivers(), "CHAT_SERVERTEAM", null, String.join(" ", message)); + ChatListener.sendChat(Chatter.of(commandSender), Chatter.serverteam(), "CHAT_SERVERTEAM", null, String.join(" ", message)); } } diff --git a/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java b/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java index d02c53cd..cf893d0d 100644 --- a/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java +++ b/src/de/steamwar/bungeecore/commands/SetLocaleCommand.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.network.packets.server.LocaleInvalidationPacket; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,7 +35,7 @@ public class SetLocaleCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer player) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); sender.user().setLocale(Objects.requireNonNull(player.getLocale()), true); NetworkSender.send(player, new LocaleInvalidationPacket(sender.user().getId())); sender.system("LOCK_LOCALE_CHANGED"); diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index fe738a99..0f8e77eb 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -27,7 +27,7 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.*; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ChatColor; @@ -533,7 +533,7 @@ public class TeamCommand extends SWCommand { public void server(@Validator("isLeader") ProxiedPlayer player, String server, @Min(intValue = 1) @Max(intValue = 65535) @ErrorMessage("TEAM_SERVER_PORT_INVALID") int port){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Team team = Team.get(user.getTeam()); - if (PunishmentCommand.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) { + if (PunishmentCommand.isPunishedWithMessage(Chatter.of(player), Punishment.PunishmentType.NoTeamServer)) { return; } diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index 9d691a50..fb1dd741 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -20,10 +20,10 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.ChatterGroup; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; public class TeamchatCommand extends SWCommand { @@ -34,7 +34,7 @@ public class TeamchatCommand extends SWCommand { @Register(description = "TC_USAGE") public void genericCommand(ProxiedPlayer player, @ErrorMessage(value = "TC_USAGE", allowEAs = false) String... args) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); SteamwarUser user = sender.user(); if(user.getTeam() == 0){ @@ -42,6 +42,6 @@ public class TeamchatCommand extends SWCommand { return; } - ChatListener.sendChat(sender, ChatSender.allReceivers().filter(p -> p.user().getTeam() == user.getTeam()), "CHAT_TEAM", null, String.join(" ", args)); + ChatListener.sendChat(sender, new ChatterGroup(Chatter.allStream().filter(p -> p.user().getTeam() == user.getTeam())), "CHAT_TEAM", null, String.join(" ", args)); } } diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index b98414d8..833d0906 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -42,7 +42,7 @@ public class TpCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer p) { - ChatSender.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT"); + Chatter.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT"); } @Register @@ -95,7 +95,7 @@ public class TpCommand extends SWCommand { } public static void teleport(ProxiedPlayer player, ServerInfo server) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if(CheckCommand.isChecking(player)){ sender.system("CHECK_CHECKING"); return; diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 1af07b5f..549f1975 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Punishment; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.CommandSender; @@ -43,7 +43,7 @@ public class TypeMappers { private static TypeValidator arenaPlayer() { return (sender, value, messageSender) -> { - ChatSender player = ChatSender.of(value); + Chatter player = Chatter.of(value); if (PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { return false; } diff --git a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java index 2e45c274..7994fbcc 100644 --- a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.BufferedReader; @@ -37,7 +37,7 @@ public class WebpasswordCommand extends SWCommand { @Register(description = "WEB_USAGE") public void genericCommand(ProxiedPlayer player, String password) { if(password.length() < 8) { - ChatSender.of(player).system("WEB_PASSWORD_LENGTH"); + Chatter.of(player).system("WEB_PASSWORD_LENGTH"); return; } @@ -49,14 +49,14 @@ public class WebpasswordCommand extends SWCommand { String errorLine; if((errorLine = reader.readLine()) != null) { if ("updated".equals(errorLine)) { - ChatSender.of(player).system("WEB_UPDATED"); + Chatter.of(player).system("WEB_UPDATED"); return; } else { throw new SecurityException("Could not create webaccount " + errorLine); } } - ChatSender.of(player).system("WEB_CREATED"); + Chatter.of(player).system("WEB_CREATED"); } catch (IOException e) { throw new SecurityException("Could not create webaccount", e); } diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 023d2110..9f98ce2b 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.mods.ModUtils; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.*; import lombok.Getter; import net.md_5.bungee.BungeeCord; @@ -48,7 +48,7 @@ public class WhoisCommand extends SWCommand { @Register(description = "WHOIS_USAGE") public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, WhoisParameterTypes... parameters) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); SteamwarUser user = SteamwarUser.get(target); if (sender.user().hasPerm(UserPerm.ADMINISTRATION)) { if (user == null) { @@ -83,7 +83,7 @@ public class WhoisCommand extends SWCommand { return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); } - private static void sendUserinfo(ChatSender sender, SteamwarUser user, EnumSet parameterTypes) { + private static void sendUserinfo(Chatter sender, SteamwarUser user, EnumSet parameterTypes) { Team team = Team.get(user.getTeam()); sender.system("WHOIS_USERNAME", user.getUserName()); diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index 3cb9f0f9..1610356a 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; import de.steamwar.bungeecore.commands.WebpasswordCommand; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.BannedUserIPs; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; @@ -50,7 +50,7 @@ public class BanListener extends BasicListener { if (user.isPunished(Punishment.PunishmentType.Ban)) { event.setCancelled(true); BannedUserIPs.banIP(user.getId(), ip); - ChatSender.of(event).system(PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.Ban)); + Chatter.of(event).system(PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.Ban)); event.completeIntent(BungeeCore.get()); return; } @@ -75,7 +75,7 @@ public class BanListener extends BasicListener { + (perma?"perma":highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm"))) + " Ban Evasion - Bannumgehung"); - ChatSender.serverteamReceivers().forEach(sender -> sender.system( + Chatter.serverteam().system( "BAN_AVOIDING_ALERT", new Message("BAN_AVOIDING_BAN_HOVER"), clickEvent, @@ -85,7 +85,7 @@ public class BanListener extends BasicListener { return sender.parseToLegacy("BAN_AVOIDING_LIST", bannedUser.getUserName(), banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(sender.parseToPlain("TIMEFORMAT")))); }).collect(Collectors.joining(" ")) - )); + ); } event.completeIntent(BungeeCore.get()); diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 2158fffc..72701650 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -24,23 +24,24 @@ import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.commands.PunishmentCommand; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.util.Chat19; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.ChatterGroup; import de.steamwar.network.packets.server.PingPacket; import de.steamwar.sql.*; -import net.md_5.bungee.api.*; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; 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.event.EventHandler; -import java.util.*; +import java.util.Arrays; +import java.util.List; 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; public class ChatListener extends BasicListener { @@ -71,7 +72,7 @@ public class ChatListener extends BasicListener { } else if (message.startsWith("+")) { localChat(player, message.substring(1)); } else { - sendChat(ChatSender.of(player), ChatSender.globalReceivers(), "CHAT_GLOBAL", null, message); + sendChat(Chatter.of(player), Chatter.globalChat(), "CHAT_GLOBAL", null, message); } } @@ -92,34 +93,37 @@ public class ChatListener extends BasicListener { return isCommand; } - public static void sendChat(ChatSender sender, Stream receivers, String format, ChatSender msgReceiver, String message) { + public static void sendChat(Chatter sender, ChatterGroup receivers, String format, Chatter msgReceiver, String message) { SteamwarUser user = sender.user(); final String coloredMessage = user.hasPerm(UserPerm.COLOR_CHAT) ? ChatColor.translateAlternateColorCodes('&', message) : message; if(chatFilter(sender, coloredMessage)) return; - AtomicBoolean noReceiver = new AtomicBoolean(true); - receivers.filter(ChatSender::chatShown).forEach(player -> { - if(sender.user().getId() != player.user().getId()) - noReceiver.set(false); - chatToReciever(player, msgReceiver, user, format, coloredMessage); - }); + boolean noReceiver = true; + for(Chatter player : receivers.getChatters()) { + if(player.chatShown()) { + chatToReciever(player, msgReceiver, user, format, coloredMessage); + if(sender.user().getId() != player.user().getId()) + noReceiver = false; + } - chatToReciever(ChatSender.console(), msgReceiver, user, format, coloredMessage); + } + + chatToReciever(Chatter.console(), msgReceiver, user, format, coloredMessage); if(format.equals("CHAT_GLOBAL")) { if (SteamwarDiscordBot.instance() != null) - chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), msgReceiver, user, format, coloredMessage); + chatToReciever(Chatter.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), msgReceiver, user, format, coloredMessage); } else if (format.equals("CHAT_SERVERTEAM")) { if (SteamwarDiscordBot.instance() != null) - chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), msgReceiver, user, format, coloredMessage); - } else if (noReceiver.get()) { + chatToReciever(Chatter.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), msgReceiver, user, format, coloredMessage); + } else if (noReceiver) { sender.system("CHAT_NO_RECEIVER"); } } public static void localChat(ProxiedPlayer player, String message) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); if(message.length() == 0){ sender.system("CHAT_BC_USAGE"); return; @@ -134,7 +138,7 @@ public class ChatListener extends BasicListener { Chat19.chat(player, message); } - private static boolean chatFilter(ChatSender sender, String message) { + private static boolean chatFilter(Chatter sender, String message) { if(!sender.chatShown()) { sender.system("CHAT_RECEIVE"); return true; @@ -164,7 +168,7 @@ public class ChatListener extends BasicListener { return false; } - private static void chatToReciever(ChatSender receiver, ChatSender msgReceiver, SteamwarUser sender, String format, String message) { + private static void chatToReciever(Chatter receiver, Chatter msgReceiver, SteamwarUser sender, String format, String message) { UserPerm.Prefix prefix = sender.prefix(); String chatColorCode = sender.hasPerm(UserPerm.TEAM) ? "§f" : "§7"; receiver.chat(new Message(format, @@ -187,7 +191,7 @@ public class ChatListener extends BasicListener { return false; } - private static void specialAlert(ChatSender sender, String name, String baseMessage, int... delay) { + private static void specialAlert(Chatter sender, String name, String baseMessage, int... delay) { sender.system("CHAT_LIXFEL_ACTION_BAR"); TaskScheduler scheduler = ProxyServer.getInstance().getScheduler(); for(int i = 0; i < delay.length; i++) { @@ -196,7 +200,7 @@ public class ChatListener extends BasicListener { } } - private static String highlightMentions(String message, String returnColor, ChatSender player) { + private static String highlightMentions(String message, String returnColor, Chatter player) { if(!message.contains("@")) return message; diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 6cafdb01..bbd44f5b 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -30,6 +30,7 @@ import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.commands.ModCommand; import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.mods.ModUtils; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import net.md_5.bungee.api.AbstractReconnectHandler; @@ -70,6 +71,7 @@ public class ConnectionListener extends BasicListener { public void onPostLogin(PostLoginEvent event) { ProxiedPlayer player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Chatter chatter = Chatter.of(player); if(user.hasPerm(UserPerm.ADMINISTRATION)) { player.setPermission("bungeecord.command.end", true); @@ -95,7 +97,7 @@ public class ConnectionListener extends BasicListener { } if(user.hasPerm(UserPerm.CHECK)) { - CheckCommand.sendReminder(player); + CheckCommand.sendReminder(chatter); player.setPermission(CHECK_PERMISSION, true); } @@ -114,7 +116,7 @@ public class ConnectionListener extends BasicListener { } if(newPlayers.contains(player.getUniqueId())){ - Message.broadcast("JOIN_FIRST", player.getName()); + Chatter.broadcast().system("JOIN_FIRST", player.getName()); newPlayers.remove(player.getUniqueId()); } diff --git a/src/de/steamwar/bungeecore/listeners/PluginMessage.java b/src/de/steamwar/bungeecore/listeners/PluginMessage.java index e04723d4..3985fbbd 100644 --- a/src/de/steamwar/bungeecore/listeners/PluginMessage.java +++ b/src/de/steamwar/bungeecore/listeners/PluginMessage.java @@ -25,7 +25,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.TeamCommand; import de.steamwar.bungeecore.mods.*; import de.steamwar.bungeecore.network.ServerMetaInfo; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.network.packets.NetworkPacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; @@ -151,9 +151,9 @@ public class PluginMessage extends BasicListener { channelRegisterHandlers.put(ApolloManager.PLUGIN_MESSAGE_CHANNEL, lunar::sendRestrictions); channelRegisterHandlers.put(Feather.CHANNEL, new Feather()::sendRestrictions); channelRegisterHandlers.put("xaerominimap:main", player -> player.sendMessage(ChatMessageType.SYSTEM, new TextComponent("§n§o§m§i§n§i§m§a§p"))); //https://www.curseforge.com/minecraft/mc-mods/xaeros-minimap - channelRegisterHandlers.put("litemoretica:init_easy_place", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "litematica")))); //https://github.com/Earthcomputer/litemoretica/tree/master - channelRegisterHandlers.put("voxelmap:settings", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "voxelmap")))); //https://modrinth.com/mod/voxelmap-updated undocumented - channelRegisterHandlers.put("worldinfo:world_id", player -> player.disconnect(ChatSender.of(player).parseToComponent(false, new Message("MOD_YELLOW_SING", "minimap")))); // JourneyMap and VoxelMap + channelRegisterHandlers.put("litemoretica:init_easy_place", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "litematica")))); //https://github.com/Earthcomputer/litemoretica/tree/master + channelRegisterHandlers.put("voxelmap:settings", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "voxelmap")))); //https://modrinth.com/mod/voxelmap-updated undocumented + channelRegisterHandlers.put("worldinfo:world_id", player -> player.disconnect(Chatter.of(player).parse(false, new Message("MOD_YELLOW_SING", "minimap")))); // JourneyMap and VoxelMap channelRegisterHandlers.put(Controlify.CHANNEL, new Controlify()::onRegister); registerBiDirPassthrough("worldedit:cui"); @@ -283,7 +283,7 @@ public class PluginMessage extends BasicListener { private void steamWarBrand(PluginMessageEvent event) { ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); - String brandString = ChatSender.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1)); + String brandString = Chatter.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1)); ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); DefinedPacket.writeString(brandString, brand); diff --git a/src/de/steamwar/bungeecore/mods/ModUtils.java b/src/de/steamwar/bungeecore/mods/ModUtils.java index 40a17903..5c4083ba 100644 --- a/src/de/steamwar/bungeecore/mods/ModUtils.java +++ b/src/de/steamwar/bungeecore/mods/ModUtils.java @@ -23,7 +23,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.commands.PunishmentCommand; import de.steamwar.sql.SteamwarUser; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Mod; import de.steamwar.sql.Mod.ModType; import de.steamwar.sql.UserPerm; @@ -48,7 +48,7 @@ public class ModUtils { private static final Map> playerModMap = new HashMap<>(); public static boolean handleMods(ProxiedPlayer player, List mods) { - return handleMods(player.getUniqueId(), ChatSender.of(player).getLocale(), player::disconnect, mods); + return handleMods(player.getUniqueId(), Chatter.of(player).getLocale(), player::disconnect, mods); } public static boolean handleMods(UUID uuid, Locale locale, Consumer disconnect, List mods){ diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 804ff18f..cc8c40a9 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Storage; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; @@ -55,12 +55,12 @@ public class Tablist extends MessageToMessageDecoder { private final List current = new ArrayList<>(); private final ProxiedPlayer player; - private final ChatSender viewer; + private final Chatter viewer; private ServerConnection connection; public Tablist(ProxiedPlayer player) { this.player = player; - this.viewer = ChatSender.of(player); + this.viewer = Chatter.of(player); this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>()); injection(); } @@ -344,7 +344,7 @@ public class Tablist extends MessageToMessageDecoder { } } - private BaseComponent[] header(ChatSender p, int seconds) { + private BaseComponent[] header(Chatter p, int seconds) { int phase = (seconds % 10) / 5; if (phase == 0) return p.parse(false, "TABLIST_PHASE_DISCORD"); diff --git a/src/de/steamwar/bungeecore/tablist/TablistBuild.java b/src/de/steamwar/bungeecore/tablist/TablistBuild.java index 4f7f2b64..15f6058f 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistBuild.java +++ b/src/de/steamwar/bungeecore/tablist/TablistBuild.java @@ -21,7 +21,7 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -55,7 +55,7 @@ public class TablistBuild implements TablistPart { } @Override - public void print(ChatSender viewer, ProxiedPlayer player, List tablist, List direct) { + public void print(Chatter viewer, ProxiedPlayer player, List tablist, List direct) { ServerInfo server = player.getServer().getInfo(); if(players.keySet().stream().anyMatch(info -> server != info)) { tablist.add(new Item(null, "", TablistServer.GRAY)); diff --git a/src/de/steamwar/bungeecore/tablist/TablistGroup.java b/src/de/steamwar/bungeecore/tablist/TablistGroup.java index fdb227a9..0ff29764 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistGroup.java +++ b/src/de/steamwar/bungeecore/tablist/TablistGroup.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.tablist; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.List; @@ -37,7 +37,7 @@ public class TablistGroup implements TablistPart { } @Override - public void print(ChatSender viewer, ProxiedPlayer player, List tablist, List direct) { + public void print(Chatter viewer, ProxiedPlayer player, List tablist, List direct) { for (TablistPart sublist : sublists) { sublist.print(viewer, player, tablist, direct); } diff --git a/src/de/steamwar/bungeecore/tablist/TablistPart.java b/src/de/steamwar/bungeecore/tablist/TablistPart.java index f15a239b..1ea256c7 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistPart.java +++ b/src/de/steamwar/bungeecore/tablist/TablistPart.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.tablist; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; import net.md_5.bungee.api.chat.BaseComponent; @@ -34,7 +34,7 @@ import java.util.UUID; interface TablistPart { String sortKey(); - void print(ChatSender viewer, ProxiedPlayer player, List tablist, List direct); + void print(Chatter viewer, ProxiedPlayer player, List tablist, List direct); class Item { diff --git a/src/de/steamwar/bungeecore/tablist/TablistServer.java b/src/de/steamwar/bungeecore/tablist/TablistServer.java index 812588df..12992e49 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistServer.java +++ b/src/de/steamwar/bungeecore/tablist/TablistServer.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.sql.SteamwarUser; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.network.packets.common.FightInfoPacket; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.config.ServerInfo; @@ -68,7 +68,7 @@ public class TablistServer implements TablistPart { } @Override - public void print(ChatSender viewer, ProxiedPlayer player, List tablist, List direct) { + public void print(Chatter viewer, ProxiedPlayer player, List tablist, List direct) { boolean onServer = player.getServer().getInfo() == server; List items = onServer ? direct : tablist; diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java index e47dabe4..fe0a5a4c 100644 --- a/src/de/steamwar/bungeecore/util/BauLock.java +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -20,7 +20,7 @@ package de.steamwar.bungeecore.util; import de.steamwar.bungeecore.Message; -import de.steamwar.messages.ChatSender; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; @@ -39,7 +39,7 @@ public class BauLock { } public static boolean checkNotifyLocked(SteamwarUser owner, ProxiedPlayer player) { - ChatSender sender = ChatSender.of(player); + Chatter sender = Chatter.of(player); SteamwarUser target = sender.user(); if (owner.getId() == target.getId()) return false; @@ -72,7 +72,7 @@ public class BauLock { ProxiedPlayer ownerPlayer = ProxyServer.getInstance().getPlayer(owner.getUUID()); if(ownerPlayer != null) - ChatSender.of(ownerPlayer).system("BAU_LOCK_BLOCKED", player.getName()); + Chatter.of(ownerPlayer).system("BAU_LOCK_BLOCKED", player.getName()); } return locked; diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 83b4d8d0..536a891a 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -21,8 +21,7 @@ package de.steamwar.command; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.messages.ChatSender; -import net.md_5.bungee.BungeeCord; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -31,7 +30,6 @@ import net.md_5.bungee.api.plugin.TabExecutor; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.logging.Level; @@ -103,7 +101,7 @@ public class SWCommand extends AbstractSWCommand { @Override protected void commandSystemError(CommandSender sender, CommandFrameworkException e) { BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e); - ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR"); + Chatter.of(sender).prefixless("COMMAND_SYSTEM_ERROR"); } @Override @@ -117,15 +115,15 @@ public class SWCommand extends AbstractSWCommand { @Override protected void sendMessage(CommandSender sender, String message, Object[] args) { - ChatSender.of(sender).system(message, args); + Chatter.of(sender).system(message, args); } @Register(noTabComplete = true) public void internalHelp(ProxiedPlayer p, String... args) { - ChatSender chatSender = ChatSender.of(p); + Chatter chatter = Chatter.of(p); try { - chatSender.prefixless("COMMAND_HELP_HEAD", command.getName()); - defaultHelpMessages.forEach(chatSender::prefixless); + chatter.prefixless("COMMAND_HELP_HEAD", command.getName()); + defaultHelpMessages.forEach(chatter::prefixless); } catch (Exception e) { BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e); return; @@ -141,7 +139,7 @@ public class SWCommand extends AbstractSWCommand { boolean hasTabCompletes = tabCompletes.stream() .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { - send(chatSender, subCommand); + send(chatter, subCommand); } else { atomicInteger.incrementAndGet(); } @@ -150,18 +148,18 @@ public class SWCommand extends AbstractSWCommand { if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) { - send(chatSender, subCommand); + send(chatter, subCommand); } }); } } - private void send(ChatSender chatSender, SubCommand subCommand) { + private void send(Chatter chatter, SubCommand subCommand) { try { for (String s : subCommand.description) { String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand); - chatSender.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); + chatter.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); } } catch (Exception e) { BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index b8470988..8d2ea6fe 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -283,7 +283,7 @@ CHECK_HELP_DECLINE=§8/§7check decline §8[§ereason§8] - §7Decline schematic CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Cancels reviewing process CHECK_LIST_HEADER=§e§l{0} schematics are left to review CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3} -CHECK_LIST_WAIT={0}:{1} +CHECK_LIST_WAIT=§{0}{1}:{2} CHECK_LIST_TO_CHECK_HOVER=§eCheck schematic CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7is being reviewed by §e{4} CHECK_LIST_CHECKING_HOVER=§eTo the reviewer @@ -322,6 +322,7 @@ KICK_USAGE=§8/§7kick §8[§ePlayer§8] [§eMessage§8] KICK_OFFLINE=§cThis player is currently not online! KICK_CONFIRM=The player {0} was kicked. KICK_NORMAL=§cYou were kicked. +KICK_CUSTOM=§c{0} #MsgCommand MSG_USAGE=§8/§7msg §8[§euser§8] [§emessage§8] diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 979a5a33..178abd53 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -266,7 +266,6 @@ CHECK_HELP_DECLINE=§8/§7check decline §8[§eGrund§8] - §7Schematic ablehnen CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Bricht den Prüfvorgang ab CHECK_LIST_HEADER=§e§lZu prüfen sind {0} Schematics CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3} -CHECK_LIST_WAIT={0}:{1} CHECK_LIST_TO_CHECK_HOVER=§eSchematic prüfen CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7wird geprüft von §e{4} CHECK_LIST_CHECKING_HOVER=§eZum Prüfer diff --git a/src/de/steamwar/messages/ChatSender.java b/src/de/steamwar/messages/Chatter.java similarity index 76% rename from src/de/steamwar/messages/ChatSender.java rename to src/de/steamwar/messages/Chatter.java index 99916a0a..b1166443 100644 --- a/src/de/steamwar/messages/ChatSender.java +++ b/src/de/steamwar/messages/Chatter.java @@ -19,7 +19,10 @@ package de.steamwar.messages; -import de.steamwar.bungeecore.*; +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.Servertype; +import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.bot.listeners.DiscordChatListener; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserPerm; @@ -41,28 +44,33 @@ import java.util.Date; import java.util.Locale; import java.util.ResourceBundle; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.logging.Level; import java.util.stream.Stream; -public interface ChatSender { +public interface Chatter { - static Stream all() { + static Stream allPlayers() { return ProxyServer.getInstance().getPlayers().stream(); } - static Stream allReceivers() { - return all().map(ChatSender::of); + static Stream allStream() { + return Stream.concat(Stream.of(Chatter.console()), allPlayers().map(Chatter::of)); } - static Stream globalReceivers() { - return all().filter(player -> { + static ChatterGroup broadcast() { + return new ChatterGroup(allStream()); + } + + static ChatterGroup globalChat() { + return new ChatterGroup(Stream.concat(Stream.of(Chatter.console()), allPlayers().filter(player -> { Subserver subserver = Subserver.getSubserver(player); return subserver == null || !(subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getServer().getInfo()); - }).map(ChatSender::of); + }).map(Chatter::of))); } - static Stream serverteamReceivers() { - return allReceivers().filter(player -> player.user().hasPerm(UserPerm.TEAM)); + static ChatterGroup serverteam() { + return new ChatterGroup(allStream().filter(player -> player.user().hasPerm(UserPerm.TEAM))); } SteamwarUser user(); @@ -70,6 +78,7 @@ public interface ChatSender { Locale getLocale(); boolean chatShown(); void sendMessage(ChatMessageType type, BaseComponent... msg); + void withPlayer(Consumer function); default void chat(Message message) { send(false, ChatMessageType.CHAT, null, null, message); @@ -96,7 +105,7 @@ public interface ChatSender { } default void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) { - TextComponent msg = parseToComponent(prefixed, message); + BaseComponent msg = parse(prefixed, message); if(onHover != null) msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(parse(false, onHover)))); if(onClick != null) @@ -104,16 +113,12 @@ public interface ChatSender { sendMessage(type, msg); } - default TextComponent parseToComponent(boolean prefixed, Message message) { - return new TextComponent(parse(prefixed, message)); - } - default String parseToPlain(String format, Object... params) { return parseToPlain(new Message(format, params)); } default String parseToPlain(Message message) { - return parseToComponent(false, message).toPlainText(); + return parse(false, message).toPlainText(); } default String parseToLegacy(String format, Object... params) { @@ -121,14 +126,14 @@ public interface ChatSender { } default String parseToLegacy(Message message) { - return parseToComponent(false, message).toLegacyText(); + return parse(false, message).toLegacyText(); } - default BaseComponent[] parse(boolean prefixed, String format, Object... params) { + default BaseComponent parse(boolean prefixed, String format, Object... params) { return parse(prefixed, new Message(format, params)); } - default BaseComponent[] parse(boolean prefixed, Message message) { + default BaseComponent parse(boolean prefixed, Message message) { Locale locale = getLocale(); ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale); String pattern = ""; @@ -147,15 +152,15 @@ public interface ChatSender { params[i] = ((SteamwarUser) params[i]).getUserName(); } else if(params[i] instanceof ProxiedPlayer) { params[i] = ((ProxiedPlayer) params[i]).getName(); - } else if(params[i] instanceof ChatSender) { - params[i] = ((ChatSender) params[i]).user().getUserName(); + } else if(params[i] instanceof Chatter) { + params[i] = ((Chatter) params[i]).user().getUserName(); } } - return TextComponent.fromLegacyText(format.format(params)); + return TextComponent.fromLegacy(format.format(params)); } - static ChatSender ofProxiedPlayer(ProxiedPlayer player, BiConsumer sendMessage) { - return new ChatSender() { + static Chatter ofProxiedPlayer(ProxiedPlayer player, BiConsumer sendMessage) { + return new Chatter() { @Override public SteamwarUser user() { return SteamwarUser.get(player.getUniqueId()); @@ -175,33 +180,33 @@ public interface ChatSender { public void sendMessage(ChatMessageType type, BaseComponent... msg) { sendMessage.accept(type, msg); } + + @Override + public void withPlayer(Consumer function) { + function.accept(player); + } }; } - static ChatSender of(ProxiedPlayer player) { + static Chatter of(ProxiedPlayer player) { return ofProxiedPlayer(player, player::sendMessage); } - static ChatSender disconnect(ProxiedPlayer player) { + static Chatter disconnect(ProxiedPlayer player) { return ofProxiedPlayer(player, (type, msg) -> player.disconnect(msg)); } - static ChatSender of(CommandSender sender) { + static Chatter of(CommandSender sender) { if(sender instanceof ProxiedPlayer) return of((ProxiedPlayer) sender); //Console - return new ChatSender() { + return new PlayerlessChatter() { @Override public SteamwarUser user() { return SteamwarUser.get(-1); } - @Override - public Locale getLocale() { - return Locale.getDefault(); - } - @Override public boolean chatShown() { return true; @@ -214,22 +219,17 @@ public interface ChatSender { }; } - static ChatSender console() { + static Chatter console() { return of(ConsoleCommandSender.getInstance()); } - static ChatSender of(LoginEvent event) { - return new ChatSender() { + static Chatter of(LoginEvent event) { + return new PlayerlessChatter() { @Override public SteamwarUser user() { return SteamwarUser.get(event.getConnection().getUniqueId()); } - @Override - public Locale getLocale() { - return Locale.getDefault(); - } - @Override public boolean chatShown() { return false; @@ -242,18 +242,13 @@ public interface ChatSender { }; } - static ChatSender discordChannel(DiscordChatListener channel) { - return new ChatSender() { + static Chatter discordChannel(DiscordChatListener channel) { + return new PlayerlessChatter() { @Override public SteamwarUser user() { return SteamwarUser.get(-1); } - @Override - public Locale getLocale() { - return Locale.getDefault(); - } - @Override public boolean chatShown() { return true; @@ -270,18 +265,13 @@ public interface ChatSender { }; } - static ChatSender of(net.dv8tion.jda.api.entities.Message message, SteamwarUser user) { - return new ChatSender() { + static Chatter of(net.dv8tion.jda.api.entities.Message message, SteamwarUser user) { + return new PlayerlessChatter() { @Override public SteamwarUser user() { return user; } - @Override - public Locale getLocale() { - return Locale.getDefault(); - } - @Override public boolean chatShown() { return true; @@ -297,4 +287,16 @@ public interface ChatSender { } }; } + + abstract class PlayerlessChatter implements Chatter { + @Override + public Locale getLocale() { + return Locale.getDefault(); + } + + @Override + public void withPlayer(Consumer function) { + //Not a player + } + } } diff --git a/src/de/steamwar/messages/ChatterGroup.java b/src/de/steamwar/messages/ChatterGroup.java new file mode 100644 index 00000000..ebdd92a3 --- /dev/null +++ b/src/de/steamwar/messages/ChatterGroup.java @@ -0,0 +1,71 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.messages; + +import de.steamwar.bungeecore.Message; +import de.steamwar.sql.SteamwarUser; +import lombok.Getter; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; + +import java.util.Arrays; +import java.util.Locale; +import java.util.stream.Stream; + +@Getter +public class ChatterGroup implements Chatter { + + final Chatter[] chatters; + + public ChatterGroup(Stream stream) { + chatters = stream.toArray(Chatter[]::new); + } + + public ChatterGroup(Chatter... chatters) { + this.chatters = chatters; + } + + @Override + public boolean chatShown() { + return Arrays.stream(chatters).allMatch(Chatter::chatShown); + } + + @Override + public void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) { + for(Chatter sender : chatters) + sender.send(prefixed, type, onHover, onClick, message); + } + + @Override + public SteamwarUser user() { + throw new UnsupportedOperationException(); + } + + @Override + public Locale getLocale() { + throw new UnsupportedOperationException(); + } + + @Override + public void sendMessage(ChatMessageType type, BaseComponent... msg) { + throw new UnsupportedOperationException(); + } +} From 3b5be809dd13f19b8429c930d7eed61ad49c9046 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 12 May 2024 21:24:15 +0200 Subject: [PATCH 02/22] WIP message deprecation Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 14 ++ src/de/steamwar/bungeecore/Node.java | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 32 +-- src/de/steamwar/bungeecore/ServerVersion.java | 87 +++++++ .../bungeecore/bot/util/DiscordAlert.java | 63 +++++ .../bot/util/DiscordSchemAlert.java | 79 ------ .../bungeecore/commands/ArenaCommand.java | 3 +- .../bungeecore/commands/BauCommand.java | 238 ++++++------------ .../commands/BuilderCloudCommand.java | 51 +--- .../bungeecore/commands/CheckCommand.java | 159 +++++------- .../bungeecore/commands/EventCommand.java | 103 ++++---- .../commands/EventRescheduleCommand.java | 39 +-- .../bungeecore/commands/FightCommand.java | 49 +--- .../bungeecore/commands/HistoricCommand.java | 8 +- .../bungeecore/commands/IgnoreCommand.java | 11 +- .../bungeecore/commands/JoinmeCommand.java | 39 +-- .../bungeecore/commands/ListCommand.java | 10 +- .../bungeecore/commands/ModCommand.java | 98 +++----- .../bungeecore/commands/PingCommand.java | 4 +- .../bungeecore/commands/PlaytimeCommand.java | 6 +- .../bungeecore/commands/TeamCommand.java | 21 +- .../bungeecore/commands/TutorialCommand.java | 7 +- .../bungeecore/inventory/SWInventory.java | 89 ++----- .../steamwar/bungeecore/inventory/SWItem.java | 108 +++----- .../bungeecore/inventory/SWListInv.java | 2 +- .../bungeecore/inventory/SWStreamInv.java | 10 + src/de/steamwar/command/TypeUtils.java | 36 ++- .../steamwar/messages/BungeeCore.properties | 8 +- .../messages/BungeeCore_de.properties | 9 +- src/de/steamwar/messages/Chatter.java | 38 ++- 30 files changed, 598 insertions(+), 825 deletions(-) create mode 100644 src/de/steamwar/bungeecore/ServerVersion.java create mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordAlert.java delete mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index f6de66bc..56dbe301 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -61,6 +61,7 @@ public class BungeeCore extends Plugin { public static boolean MAIN_SERVER; + @Deprecated public static String CHAT_PREFIX; public static String LOBBY_SERVER; public static boolean EVENT_MODE; @@ -214,21 +215,27 @@ public class BungeeCore extends Plugin { return instance; } + @Deprecated public static TextComponent stringToText(String msg){ return new TextComponent(TextComponent.fromLegacyText(msg)); } + @Deprecated public static void send(ProxiedPlayer player, String msg){ send(player, msg, null, null); } + @Deprecated public static void send(CommandSender sender, String msg){ sender.sendMessage(stringToText(msg)); } + @Deprecated public static void send(ProxiedPlayer player, ChatMessageType type, String msg){ send(player, type, msg, null, null); } + @Deprecated public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){ send(player, ChatMessageType.SYSTEM, msg, onHover, onClick); } + @Deprecated public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){ if(type == ChatMessageType.CHAT && player.getChatMode() != ProxiedPlayer.ChatMode.SHOWN) return; @@ -239,9 +246,11 @@ public class BungeeCore extends Plugin { message.setClickEvent(onClick); player.sendMessage(type, message); } + @Deprecated public static void broadcast(String msg){ ProxyServer.getInstance().broadcast(stringToText(msg)); } + @Deprecated public static void broadcast(String msg, String onHover, ClickEvent onClick){ TextComponent message = stringToText(msg); if(onHover != null) @@ -251,18 +260,23 @@ public class BungeeCore extends Plugin { ProxyServer.getInstance().broadcast(message); } + @Deprecated public static void log(final ServerInfo server, final String msg){ log(server.getName() + ": " + msg); } + @Deprecated public static void log(final ProxiedPlayer player, final String msg){ log(player.getName() + ": " + msg); } + @Deprecated public static void log(final String msg){ log(Level.INFO, msg); } + @Deprecated public static void log(final Level logLevel, final String msg){ get().getLogger().log(logLevel, msg); } + @Deprecated public static void log(final String msg, final Throwable e){ get().getLogger().log(Level.SEVERE, msg, e); } diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index eb132e20..30b548ec 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -36,7 +36,7 @@ public abstract class Node { "-XX:+EnableCRIUSupport", "-XX:-CRIURestoreNonPortableMode", "-Xgc:excessiveGCratio=80", "-Xdisableexplicitgc", "-Xnoclassgc", "-Xmos128M", "-Xmns48M", "-XX:+ExitOnOutOfMemoryError", // initial heap half values of memory observed by 1.19 spectate server "-Xsyslog:none", "-Xtrace:none", "-Xverify:none", "-Xdump:system:none", "-Xdump:jit:none", "-Xdump:snap:none", - "-Dlog4j.configurationFile=log4j2.xml" + "-XX:+EnableDynamicAgentLoading", "-Dlog4j.configurationFile=log4j2.xml" ); private static final Set JAVA_8 = new HashSet<>(); static { diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index e4bfab41..4fd86ee0 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -2,7 +2,6 @@ package de.steamwar.bungeecore; import de.steamwar.messages.Chatter; import de.steamwar.sql.*; -import lombok.Getter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.DataOutputStream; @@ -22,7 +21,7 @@ public class ServerStarter { private static final Portrange BAU_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200); private static final Portrange ARENA_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS); - private static final String SERVER_PATH = "/servers/"; + public static final String SERVER_PATH = "/servers/"; private static final String USER_HOME = System.getProperty("user.home") + "/"; private static final String EVENT_PATH = USER_HOME + "event/"; public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; @@ -114,11 +113,11 @@ public class ServerStarter { return this; } - public ServerStarter build(Version version, UUID owner) { + public ServerStarter build(ServerVersion version, UUID owner) { directory = version.getServerDirectory("Bau"); serverJar = version.getServerJar(); worldDir = version.getWorldFolder(WORLDS_BASE_PATH); - worldName = version != Version.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); + worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); checkpoint = true; build(owner); @@ -188,7 +187,7 @@ public class ServerStarter { serverNameProvider = port -> bauServerName(SteamwarUser.get(owner)); } - public ServerStarter builder(Version version, String map, File generator) { + public ServerStarter builder(ServerVersion version, String map, File generator) { serverJar = version.getServerJar(); directory = version.getServerDirectory("Builder"); worldDir = version.getWorldFolder(BUILDER_BASE_PATH); @@ -349,27 +348,4 @@ public class ServerStarter { } } - @Getter - public enum Version { - SPIGOT_12("spigot-1.12.2.jar", 12), - SPIGOT_15("spigot-1.15.2.jar", 15), - PAPER_19("paper-1.19.3.jar", 19), - PAPER_20("paper-1.20.1.jar", 20); - - private final String serverJar; - private final int versionSuffix; - - Version(String serverJar, int versionSuffix) { - this.serverJar = serverJar; - this.versionSuffix = versionSuffix; - } - - public String getWorldFolder(String base) { - return base + versionSuffix + "/"; - } - - public File getServerDirectory(String base) { - return new File(SERVER_PATH, base + versionSuffix); - } - } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/ServerVersion.java b/src/de/steamwar/bungeecore/ServerVersion.java new file mode 100644 index 00000000..16250716 --- /dev/null +++ b/src/de/steamwar/bungeecore/ServerVersion.java @@ -0,0 +1,87 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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; + +import lombok.Getter; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@Getter +public enum ServerVersion { + SPIGOT_12("spigot-1.12.2.jar", 12), + SPIGOT_15("spigot-1.15.2.jar", 15), + PAPER_19("paper-1.19.3.jar", 19), + PAPER_20("paper-1.20.1.jar", 20); + + private static final Map chatMap = new HashMap<>(); + + static { + chatMap.put("20", ServerVersion.PAPER_20); + chatMap.put("1.20", ServerVersion.PAPER_20); + chatMap.put("1.20.1", ServerVersion.PAPER_20); + chatMap.put("as", ServerVersion.PAPER_20); + chatMap.put("airship", ServerVersion.PAPER_20); + chatMap.put("wg", ServerVersion.PAPER_20); + chatMap.put("wargear", ServerVersion.PAPER_20); + chatMap.put("ws", ServerVersion.PAPER_20); + chatMap.put("warship", ServerVersion.PAPER_20); + chatMap.put("mwg", ServerVersion.PAPER_20); + chatMap.put("miniwargear", ServerVersion.PAPER_20); + + chatMap.put("19", ServerVersion.PAPER_19); + chatMap.put("1.19", ServerVersion.PAPER_19); + chatMap.put("1.19.2", ServerVersion.PAPER_19); + + chatMap.put("15", ServerVersion.SPIGOT_15); + chatMap.put("1.15", ServerVersion.SPIGOT_15); + chatMap.put("1.15.2", ServerVersion.SPIGOT_15); + + chatMap.put("12", ServerVersion.SPIGOT_12); + chatMap.put("1.12", ServerVersion.SPIGOT_12); + chatMap.put("1.12.2", ServerVersion.SPIGOT_12); + } + + public static ServerVersion get(String chat) { + return chatMap.get(chat.toLowerCase()); + } + + public static Set chatVersions() { + return chatMap.keySet(); + } + + private final String serverJar; + private final int versionSuffix; + + ServerVersion(String serverJar, int versionSuffix) { + this.serverJar = serverJar; + this.versionSuffix = versionSuffix; + } + + public String getWorldFolder(String base) { + return base + versionSuffix + "/"; + } + + public File getServerDirectory(String base) { + return new File(ServerStarter.SERVER_PATH, base + versionSuffix); + } +} diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordAlert.java new file mode 100644 index 00000000..62c03680 --- /dev/null +++ b/src/de/steamwar/bungeecore/bot/util/DiscordAlert.java @@ -0,0 +1,63 @@ +/* + 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.util; + +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.messages.Chatter; +import lombok.experimental.UtilityClass; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Emoji; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.interactions.components.Button; + +import java.awt.*; +import java.time.Instant; + +@UtilityClass +public class DiscordAlert { + + public static void send(Chatter player, Color color, Message title, Message description, boolean success) { + Long discordId = player.user().getDiscordId(); + if(SteamwarDiscordBot.instance() == null || discordId == null) + return; + + User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(discordId).complete(); + EmbedBuilder builder = new EmbedBuilder(); + builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); + builder.setColor(color); + builder.setTitle(player.parseToPlain(title)); + builder.setDescription(player.parseToPlain(description)); + builder.setTimestamp(Instant.now()); + + MessageBuilder messageBuilder = new MessageBuilder(); + messageBuilder.setEmbeds(builder.build()); + if(success) + messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); + + try { + dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue(); + } catch (Exception e) { + // Ignored + } + } +} diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java b/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java deleted file mode 100644 index b0f48eb5..00000000 --- a/src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java +++ /dev/null @@ -1,79 +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.util; - -import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.sql.SchematicNode; -import de.steamwar.sql.SteamwarUser; -import lombok.experimental.UtilityClass; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; - -import java.awt.*; -import java.time.Instant; - -@UtilityClass -public class DiscordSchemAlert { - - public void sendDecline(SchematicNode schematic, SteamwarUser user, String reason) { - if(user.getDiscordId() != null) { - User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); - EmbedBuilder builder = new EmbedBuilder(); - builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); - builder.setColor(Color.RED); - builder.setTitle("SteamWar-Schematic Info"); - builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde abgelehnt. **Grund:** \n" + reason); - builder.setTimestamp(Instant.now()); - - MessageBuilder messageBuilder = new MessageBuilder(); - messageBuilder.setEmbeds(builder.build()); - try { - dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue(); - } catch (Exception e) { - // Ignored - } - } - } - - public void sendAccept(SchematicNode schematic, SteamwarUser user) { - if(user.getDiscordId() != null) { - User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete(); - EmbedBuilder builder = new EmbedBuilder(); - builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png"); - builder.setColor(Color.GREEN); - builder.setTitle("SteamWar-Schematic Info"); - builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde angenommen."); - builder.setTimestamp(Instant.now()); - - MessageBuilder messageBuilder = new MessageBuilder(); - messageBuilder.setEmbeds(builder.build()); - messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); - try { - dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue(); - } catch (Exception e) { - // Ignored - } - } - } -} diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 7f6503f2..10bac329 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import net.md_5.bungee.api.CommandSender; @@ -60,7 +61,7 @@ public class ArenaCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { List subserverList = Subserver.getServerList(); synchronized (subserverList) { return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 60872e69..39388ff5 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -36,13 +36,10 @@ import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.function.Consumer; import java.util.stream.Collectors; public class BauCommand extends SWCommand { @@ -60,68 +57,15 @@ public class BauCommand extends SWCommand { } @Register - public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { + public void toBau(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { new ServerStarter().build(version, p.getUniqueId()).send(p).start(); } - @Mapper(value = "version", local = true) - public TypeMapper versionMapper() { - Map versionMap = new HashMap<>(); - versionMap.put("20", ServerStarter.Version.PAPER_20); - versionMap.put("1.20", ServerStarter.Version.PAPER_20); - versionMap.put("as", ServerStarter.Version.PAPER_20); - versionMap.put("airship", ServerStarter.Version.PAPER_20); - versionMap.put("wg", ServerStarter.Version.PAPER_20); - versionMap.put("wargear", ServerStarter.Version.PAPER_20); - versionMap.put("ws", ServerStarter.Version.PAPER_20); - versionMap.put("warship", ServerStarter.Version.PAPER_20); - - versionMap.put("19", ServerStarter.Version.PAPER_19); - versionMap.put("1.19", ServerStarter.Version.PAPER_19); - versionMap.put("mwg", ServerStarter.Version.PAPER_19); - versionMap.put("miniwargear", ServerStarter.Version.PAPER_19); - - versionMap.put("15", ServerStarter.Version.SPIGOT_15); - versionMap.put("1.15", ServerStarter.Version.SPIGOT_15); - - versionMap.put("12", ServerStarter.Version.SPIGOT_12); - versionMap.put("1.12", ServerStarter.Version.SPIGOT_12); - - return new TypeMapper() { - @Override - public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) { - if (commandSender == null) return null; - ProxiedPlayer player = (ProxiedPlayer) commandSender; - if (s.isEmpty()) { - int version = player.getPendingConnection().getVersion(); - if (version > 762) { // Version > 1.19.4 - return ServerStarter.Version.PAPER_20; - } else if (version > 578) { // Version > 1.15.2 - return ServerStarter.Version.PAPER_19; - } else if (version > 340) { // Version > 1.12.2 - return ServerStarter.Version.SPIGOT_15; - } else { - return ServerStarter.Version.SPIGOT_12; - } - } - return versionMap.get(s.toLowerCase()); - } - - @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - return versionMap.keySet(); - } - }; - } - @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { BauweltMember.addMember(p.getUniqueId(), target.getUUID()); - Message.send("BAU_ADDMEMBER_ADDED", p); - - ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUUID()); - if(z != null) - Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName()); + Chatter.of(p).system("BAU_ADDMEMBER_ADDED"); + Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", p); } @Validator(value = "addMemberTarget", local = true) @@ -145,7 +89,7 @@ public class BauCommand extends SWCommand { @Register(value = "tp", description = "BAU_TP_USAGE") @Register("teleport") - public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { + public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { new ServerStarter().build(version, worldOwner.getUUID()).send(p).start(); } @@ -173,83 +117,64 @@ public class BauCommand extends SWCommand { @Register("setspectator") public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - if (user == null) { - Message.send("BAU_MEMBER_SET_USAGE", p, "setspectator"); - return; - } - BauweltMember target = member(p, user); - if (target == null) - return; - - target.setBuild(false); - target.setSupervisor(false); - clearMembercache(p); - sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SPECTATOR"); + setPerms(p, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> { + member.setBuild(false); + member.setSupervisor(false); + }); } @Register("setbuild") public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - if (user == null) { - Message.send("BAU_MEMBER_SET_USAGE", p, "setbuild"); - return; - } - BauweltMember target = member(p, user); - if (target == null) - return; - - target.setBuild(true); - target.setSupervisor(false); - clearMembercache(p); - sendPermissionUpdate(p, target, "BAU_MEMBER_SET_BUILDER"); + setPerms(p, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> { + member.setBuild(true); + member.setSupervisor(false); + }); } @Register("setsupervisor") public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - if (user == null) { - Message.send("BAU_MEMBER_SET_USAGE", p, "setsupervisor"); - return; - } - BauweltMember target = member(p, user); - if (target == null) - return; - - target.setBuild(true); - target.setSupervisor(true); - clearMembercache(p); - sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SUPERVISOR"); + setPerms(p, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> { + member.setBuild(true); + member.setSupervisor(true); + }); } - private static void clearMembercache(ProxiedPlayer p){ - for(ServerInfo info : ProxyServer.getInstance().getServers().values()){ - Subserver server = Subserver.getSubserver(info); - if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){ - info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); - break; - } + private void setPerms(ProxiedPlayer p, SteamwarUser user, String name, String permName, Consumer setter) { + Chatter owner = Chatter.of(p); + if (user == null) { + owner.system("BAU_MEMBER_SET_USAGE", name); + return; } + + withMember(owner, user, target -> { + setter.accept(target); + + Bauserver bauserver = Bauserver.get(p.getUniqueId()); + if(bauserver != null) + bauserver.getServer().getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); + + Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", p.getName(), new Message(permName)); + owner.system("BAU_MEMBER_SET", new Message(permName)); + }); } @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE") public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) { - BauweltMember target = member(p, user); - if (target == null) - return; + Chatter owner = Chatter.of(p); + withMember(owner, user, target -> { + target.remove(); - if(SteamwarUser.get(target.getMemberID()).getUUID().equals(p.getUniqueId())) { - Message.send("BAU_DELMEMBER_SELFDEL", p); - return; - } + Chatter member = Chatter.of(user.getUUID()); + member.system("BAU_DELMEMBER_DELETED_TARGET", p); + member.withPlayer(toRemove -> { + Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); + if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) { + toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); + } + }); - target.remove(); - ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID()); - if(toRemove != null){ - Message.send("BAU_DELMEMBER_DELETED_TARGET", toRemove, p.getName()); - Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); - if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) { - toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); - } - } - Message.send("BAU_DELMEMBER_DELETED", p); + owner.system("BAU_DELMEMBER_DELETED"); + }); } @Mapper(value = "addedUsers", local = true) @@ -262,10 +187,8 @@ public class BauCommand extends SWCommand { @Override public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - if (!(sender instanceof ProxiedPlayer)) return Collections.emptyList(); - return BauweltMember.getMembers(((ProxiedPlayer) sender).getUniqueId()).stream() - .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID())) - .map(steamwarUser -> steamwarUser.getUserName()) + return BauweltMember.getMembers(Chatter.of(sender).user().getId()).stream() + .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()).getUserName()) .collect(Collectors.toList()); } }; @@ -273,39 +196,34 @@ public class BauCommand extends SWCommand { @Register("resetall") @Register("delete") - public void delete(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { - deleteConfirmation(p, () -> deleteWorld(p, version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerStarter.Version.SPIGOT_12 ? SteamwarUser.get(p.getUniqueId()).getId() : p.getUniqueId().toString()))); - } + public void delete(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + Chatter player = Chatter.of(p); - private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) { - SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p)); - inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click -> - inventory.close() - ); - inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> { - worldDeletion.run(); - inventory.close(); + SWInventory inventory = new SWInventory(player, 9, new Message("BAU_DELETE_GUI_NAME")); + inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> { + String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? player.user().getId() : p.getUniqueId().toString()); + + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + Bauserver subserver = Bauserver.get(p.getUniqueId()); + if(subserver != null) + subserver.stop(); + + SubserverSystem.deleteFolder(BungeeCore.local, world); + player.system("BAU_DELETE_DELETED"); + }); + + inventory.close(); }); + inventory.addItem(8, new SWItem(new Message("BAU_DELETE_GUI_CANCEL"), 1), click -> inventory.close()); inventory.open(); } - private static void deleteWorld(ProxiedPlayer player, String world) { - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - Bauserver subserver = Bauserver.get(player.getUniqueId()); - if(subserver != null) - subserver.stop(); - - SubserverSystem.deleteFolder(BungeeCore.local, world); - Message.send("BAU_DELETE_DELETED", player); - }); - } - @Register("test") @Register("testarena") public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> { - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start()); - }); + FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start()) + ); } @Register(value = "lock", description = "BAU_LOCKED_OPTIONS") @@ -318,24 +236,18 @@ public class BauCommand extends SWCommand { BauLock.setLocked(p, BauLockState.OPEN); } - private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){ + private static void withMember(Chatter owner, SteamwarUser member, Consumer function) { if (member == null) { - Message.send("UNKNOWN_PLAYER", p); - return null; + owner.system("UNKNOWN_PLAYER"); + return; } - BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUUID()); + BauweltMember target = BauweltMember.getBauMember(owner.user().getId(), member.getId()); if (target == null) { - Message.send("BAU_MEMBER_NOMEMBER", p); - return null; + owner.system("BAU_MEMBER_NOMEMBER"); + return; } - return target; - } - private static void sendPermissionUpdate(ProxiedPlayer p, BauweltMember target, String what){ - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID()); - if(player != null) - Message.send("BAU_MEMBER_SET_TARGET", player, p.getName(), Message.parse(what, player)); - Message.send("BAU_MEMBER_SET", p, Message.parse(what, p)); + function.accept(target); } } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 64a6507c..8cf195c1 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -3,7 +3,9 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.ServerStarter; +import de.steamwar.bungeecore.ServerVersion; import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.messages.Chatter; @@ -19,30 +21,18 @@ import java.util.stream.Collectors; public class BuilderCloudCommand extends SWCommand { - private final Map versionMap = new HashMap<>(); - public BuilderCloudCommand() { super("buildercloud", ConnectionListener.BUILDERCLOUD_PERMISSION, "builder"); - - versionMap.put("15", ServerStarter.Version.SPIGOT_15); - versionMap.put("1.15", ServerStarter.Version.SPIGOT_15); - versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15); - versionMap.put("19", ServerStarter.Version.PAPER_19); - versionMap.put("1.19", ServerStarter.Version.PAPER_19); - versionMap.put("1.19.2", ServerStarter.Version.PAPER_19); - versionMap.put("20", ServerStarter.Version.PAPER_20); - versionMap.put("1.20", ServerStarter.Version.PAPER_20); - versionMap.put("1.20.1", ServerStarter.Version.PAPER_20); } @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE") - public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { mapFile(version, map).mkdir(); new ServerStarter().builder(version, map, generator).send(player).start(); } @Register(description = "BUILDERCLOUD_USAGE") - public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { + public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); return; @@ -52,7 +42,7 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE") - public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String oldName, String newName) { + public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) { File oldMap = mapFile(version, oldName); if(!oldMap.exists()) { Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); @@ -75,7 +65,7 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") - public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { + public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); return; @@ -88,21 +78,6 @@ public class BuilderCloudCommand extends SWCommand { }); } - @ClassMapper(value = ServerStarter.Version.class, local = true) - private TypeMapper versionTypeMapper() { - return new TypeMapper() { - @Override - public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) { - return versionMap.get(s); - } - - @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - return versionMap.keySet(); - } - }; - } - @Cached(global = true) @Mapper(value = "map", local = true) private TypeMapper mapTypeMapper() { @@ -114,8 +89,8 @@ public class BuilderCloudCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - File folder = getWorldFolder(previousArguments, 1); + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments.userArgs, 1); String[] files; if(folder == null || (files = folder.list()) == null) @@ -133,7 +108,7 @@ public class BuilderCloudCommand extends SWCommand { return new TypeMapper() { @Override public File map(CommandSender commandSender, String[] previousArguments, String s) { - if(s.equals("")) + if(s.isEmpty()) return null; File folder = getWorldFolder(previousArguments, 2); @@ -149,8 +124,8 @@ public class BuilderCloudCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - File folder = getWorldFolder(previousArguments, 2); + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments.userArgs, 2); String[] files; if(folder == null || (files = folder.list()) == null) @@ -161,12 +136,12 @@ public class BuilderCloudCommand extends SWCommand { }; } - private File mapFile(ServerStarter.Version version, String map) { + private File mapFile(ServerVersion version, String map) { return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map); } private File getWorldFolder(String[] previousArguments, int offset) { - ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]); + ServerVersion v = ServerVersion.get(previousArguments[previousArguments.length - offset]); if(v == null) return null; return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH)); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 9b983733..3ab407c7 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -20,11 +20,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; +import de.steamwar.bungeecore.bot.util.DiscordAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.*; -import de.steamwar.command.SWCommand; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ProxyServer; @@ -33,24 +33,23 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.config.Configuration; +import java.awt.*; import java.sql.Timestamp; import java.time.Instant; +import java.util.List; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class CheckCommand extends SWCommand { private static final Map fightTypes = new HashMap<>(); - private static Map> checkQuestions = new HashMap<>(); - private static Map> ranks = new HashMap<>(); + private static final Map> checkQuestions = new HashMap<>(); - private static Map currentCheckers = new HashMap<>(); - private static Map currentSchems = new HashMap<>(); + private static final Map currentCheckers = new HashMap<>(); + private static final Map currentSchems = new HashMap<>(); public static void setCheckQuestions(SchematicType checkType, Configuration config) { checkQuestions.put(checkType, config.getStringList("CheckQuestions")); - if(!config.getStringList("Ranks").isEmpty()) - ranks.put(checkType, config.getStringList("Ranks")); } public static void addFightType(SchematicType checkType, SchematicType fightType) { @@ -102,9 +101,9 @@ public class CheckCommand extends SWCommand { } else { chatter.prefixless("CHECK_LIST_CHECKING", new Message("CHECK_LIST_CHECKING_HOVER"), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()), + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.user().getUserName()), waitTime, - schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName()); + schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName()); } } } @@ -120,7 +119,7 @@ public class CheckCommand extends SWCommand { SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId()); SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID)); if(!schem.getSchemtype().check()){ - ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!"); + ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> player.getName() + " tried to check an uncheckable schematic!"); return; }else if(schem.getOwner() == checkingUser.getId()) { chatter.system("CHECK_SCHEMATIC_OWN"); @@ -151,16 +150,15 @@ public class CheckCommand extends SWCommand { @Register(value = "next", description = "CHECK_HELP_NEXT") public void next(ProxiedPlayer player) { - next(player, new String[0]); + if(notChecking(player)) + return; + + currentCheckers.get(player.getUniqueId()).next(); } @Register(value = "accept") public void accept(ProxiedPlayer player, @OptionalValue("") String rank) { - if (rank.equals("")) { - next(player, new String[0]); - } else { - next(player, new String[]{rank}); - } + next(player); } @Register(value = "decline", description = "CHECK_HELP_DECLINE") @@ -176,14 +174,14 @@ public class CheckCommand extends SWCommand { for (SchematicType type : SchematicType.values()) { if (type.check()) - schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB())); + schematicList.addAll(SchematicNode.getAllSchematicsOfType(type)); } return schematicList; } public static String getChecker(SchematicNode schematic) { if (currentSchems.get(schematic.getId()) == null) return null; - return currentSchems.get(schematic.getId()).checker.getName(); + return currentSchems.get(schematic.getId()).checker.user().getUserName(); } private static boolean notChecking(ProxiedPlayer player){ @@ -194,23 +192,6 @@ public class CheckCommand extends SWCommand { return false; } - private void next(ProxiedPlayer player, String[] args){ - if(notChecking(player)) - return; - - int rank = 0; - if(args.length > 0){ - try{ - rank = Integer.parseInt(args[0]); - }catch(NumberFormatException e){ - Chatter.of(player).system("CHECK_INVALID_RANK"); - return; - } - } - - currentCheckers.get(player.getUniqueId()).next(rank); - } - private static class CheckSession{ private final Chatter checker; private final SchematicNode schematic; @@ -234,13 +215,13 @@ public class CheckCommand extends SWCommand { currentSchems.put(schematic.getId(), this); for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); - next(0); + next(); })); } - private void next(int rank) { + private void next() { if(!checkList.hasNext()){ - accept(rank); + accept(); return; } @@ -249,95 +230,67 @@ public class CheckCommand extends SWCommand { TextComponent next = new TextComponent(); next.setColor(ChatColor.GREEN); if(checkList.hasNext()){ - next.setText(Message.parse("CHECK_NEXT", checker)); + next.setText(checker.parseToPlain("CHECK_NEXT")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); - }else if(ranks.containsKey(schematic.getSchemtype())){ - List r = ranks.get(schematic.getSchemtype()); - for(int i = 0; i < r.size(); i++){ - Message.sendPrefixless("CHECK_RANK", checker, - Message.parse("CHECK_RANK_HOVER", checker), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept " + (i+1)), - i+1, r.get(i)); - Message.sendPrefixless("SPACER", checker); - } }else{ - next.setText(Message.parse("CHECK_ACCEPT", checker)); + next.setText(checker.parseToPlain("CHECK_ACCEPT")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept")); } - TextComponent decline = new TextComponent(" " + Message.parse("CHECK_DECLINE", checker)); + TextComponent decline = new TextComponent(" " + checker.parseToPlain("CHECK_DECLINE")); decline.setColor(ChatColor.RED); decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline ")); next.addExtra(decline); - checker.sendMessage(next); + checker.sendMessage(ChatMessageType.SYSTEM, next); } - private void accept(int rank){ - if(createLog("freigegeben")) { - if(ranks.containsKey(schematic.getSchemtype())){ - if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ - checker.system("CHECK_INVALID_RANK"); - return; - } - schematic.setRank(rank); - } - - schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB()); - SteamwarUser user = SteamwarUser.get(schematic.getOwner()); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); - if(player != null) { - Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName()); - } else { - DiscordSchemAlert.sendAccept(schematic, user); - } - Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName()); + private void accept(){ + if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) { + Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); + owner.withPlayerOrDiscord( + player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()), + user -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) + ); + Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName()); } - stop(); } private void decline(String reason){ - if(createLog(reason)) { - SteamwarUser user = SteamwarUser.get(schematic.getOwner()); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); - if(player != null) { - Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); - } else { - DiscordSchemAlert.sendDecline(schematic, user, reason); - } - Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason); - schematic.setType(SchematicType.Normal.toDB()); + if(concludeCheckSession(reason, SchematicType.Normal)) { + Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); + owner.withPlayerOrDiscord( + player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason), + user -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) + ); + Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason); } - - stop(); } private void abort(){ - createLog("Prüfvorgang abgebrochen"); - stop(); + concludeCheckSession("Prüfvorgang abgebrochen", null); } - private void stop(){ - currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getId()); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - Bauserver subserver = Bauserver.get(checker.getUniqueId()); - if(subserver != null) - subserver.stop(); - }); - } - - private void remove() { - currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getId()); - } - - private boolean createLog(String reason) { + private boolean concludeCheckSession(String reason, SchematicType type) { if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted return false; - CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); + CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason); + if(type != null) + schematic.setSchemtype(type); + + remove(); + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + Bauserver subserver = Bauserver.get(checker.user().getUUID()); + if(subserver != null) + subserver.stop(); + }); return true; } + + private void remove() { + currentCheckers.remove(checker.user().getUUID()); + currentSchems.remove(schematic.getId()); + } } } diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index f5ceb7e0..03860066 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -19,19 +19,18 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.*; +import de.steamwar.bungeecore.EventStarter; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.SubserverSystem; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; import de.steamwar.sql.*; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; -import de.steamwar.command.TypeValidator; +import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -48,91 +47,75 @@ public class EventCommand extends SWCommand { } @Register - public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){ - Message.send("EVENT_NO_CURRENT", player); + public void noCurrentEvent(@Validator("noEvent") CommandSender sender) { + Chatter player = Chatter.of(sender); + player.system("EVENT_NO_CURRENT"); + List coming = Event.getComing(); + if(coming.isEmpty()) + return; + + player.system("EVENT_COMING"); + Instant now = Instant.now(); - if(!coming.isEmpty()){ - DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player)); - Message.send("EVENT_COMING", player); - for(Event e : coming){ - Message.send("EVENT_COMING_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEnd().toLocalDateTime().format(dateFormat), e.getEventName()); - Set teams = TeamTeilnahme.getTeams(e.getEventID()); - if(now.isBefore(e.getDeadline().toInstant())) { - Message.send("EVENT_COMING_DEADLINE", player, e.getDeadline()); - } - SchematicType schemType = e.getSchematicType(); - if (schemType != null) { - if (schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) { - Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline()); - } - } - if(!teams.isEmpty()){ - StringBuilder tline = new StringBuilder(); - for(Team t : teams){ - tline.append(' ').append(Message.parse("EVENT_COMING_TEAM", player, t.getTeamColor(), t.getTeamKuerzel())); - } - Message.send("EVENT_COMING_TEAMS", player, tline.toString()); - } - } + DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_DATE_FORMAT")); + for(Event e : coming){ + player.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName()); + + if(now.isBefore(e.getDeadline().toInstant())) + player.prefixless("EVENT_COMING_DEADLINE", e.getDeadline()); + + SchematicType schemType = e.getSchematicType(); + if (schemType != null && schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) + player.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline()); + + Set teams = TeamTeilnahme.getTeams(e.getEventID()); + if(!teams.isEmpty()) + player.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> player.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" "))); } } @Register - public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) { + public void eventOverview(@Validator(value = "noEvent", invert = true) CommandSender sender) { + Chatter player = Chatter.of(sender); + player.system("EVENT_USAGE"); + Event currentEvent = Event.get(); - Message.send("EVENT_USAGE", player); + player.system("EVENT_CURRENT_EVENT", currentEvent.getEventName()); - List fights = EventFight.getEvent(currentEvent.getEventID()); - - Message.send("EVENT_CURRENT_EVENT", player, currentEvent.getEventName()); - - DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_TIME_FORMAT", player)); - for(EventFight fight : fights){ + DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_TIME_FORMAT")); + for(EventFight fight : EventFight.getEvent(currentEvent.getEventID())){ Team blue = Team.get(fight.getTeamBlue()); Team red = Team.get(fight.getTeamRed()); - StringBuilder fline = new StringBuilder(Message.parse("EVENT_CURRENT_FIGHT", player, fight.getStartTime().toLocalDateTime().format(timeFormat), blue.getTeamColor(), blue.getTeamKuerzel(), - red.getTeamColor(), red.getTeamKuerzel())); + StringBuilder fline = new StringBuilder(player.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel())); if(fight.hasFinished()){ switch(fight.getErgebnis()){ case 1: - fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, blue.getTeamColor(), blue.getTeamKuerzel())); + fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel())); break; case 2: - fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, red.getTeamColor(), red.getTeamKuerzel())); + fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel())); break; default: - fline.append(Message.parse("EVENT_CURRENT_FIGHT_DRAW", player)); + fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW")); } } - BungeeCore.send(player, fline.toString()); + player.prefixless("PLAIN_STRING", fline.toString()); } } @Register public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) { + Chatter sender = Chatter.of(player); Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ - Message.send("EVENT_NO_FIGHT_TEAM", player); + sender.system("EVENT_NO_FIGHT_TEAM"); return; } - Chatter sender = Chatter.of(player); if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { SubserverSystem.sendPlayer(eventArena, player); } } - - @ClassMapper(Team.class) - @Cached(cacheDuration = 10, global = true) - public TypeMapper teamMapper() { - return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer() - .keySet() - .stream() - .map(Team::get) - .map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor())) - .flatMap(Collection::stream) - .collect(Collectors.toList())); - } } diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index 3bf2a07e..d2d65383 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -19,23 +19,18 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.ConnectionListener; +import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeMapper; -import de.steamwar.sql.Event; import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.sql.Timestamp; -import java.util.Collection; import java.util.Date; import java.util.List; import java.util.ListIterator; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class EventRescheduleCommand extends SWCommand { @@ -44,10 +39,12 @@ public class EventRescheduleCommand extends SWCommand { } @Register - public void reschedule(ProxiedPlayer player, Team teamBlue, Team teamRed) { + public void reschedule(CommandSender sender, Team teamBlue, Team teamRed) { + Chatter player = Chatter.of(sender); + Event event = Event.get(); if(event == null){ - Message.send("EVENTRESCHEDULE_UNKNOWN_TEAM", player); + player.system("EVENTRESCHEDULE_UNKNOWN_TEAM"); return; } @@ -60,31 +57,13 @@ public class EventRescheduleCommand extends SWCommand { continue; if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){ - Message.send("EVENTRESCHEDULE_STARTING", player); + player.system("EVENTRESCHEDULE_STARTING"); fight.reschedule(); EventFight.loadAllComingFights(); return; } } - Message.send("EVENTRESCHEDULE_NO_FIGHT", player); - } - - @ClassMapper(value = Team.class, local = true) - public TypeMapper teamTypeMapper() { - return new TypeMapper() { - @Override - public Team map(CommandSender commandSender, String[] previousArguments, String s) { - return Team.get(s); - } - - @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - Event event = Event.get(); - if (event == null) return null; - List fights = EventFight.getEvent(event.getEventID()); - return fights.stream().flatMap(fight -> Stream.of(fight.getTeamBlue(), fight.getTeamRed())).map(Team::get).map(Team::getTeamKuerzel).distinct().collect(Collectors.toList()); - } - }; + player.system("EVENTRESCHEDULE_NO_FIGHT"); } } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 6e613325..61e7bb58 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -32,41 +32,12 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.connection.ProxiedPlayer; -/** - * Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette: - * - * [ArenaMode] [Map] - * - * Sollte der ArenaMode fehlen, kann er mit getMode() bestimmt werden. - * Sollte die Map fehlen, kann sie mit getMap() bestimmt werden. - */ - public class FightCommand extends SWCommand { public FightCommand() { super("fight", "", "f"); } - private static ArenaMode getMode(Chatter sender, String arg){ - ArenaMode mode = ArenaMode.getByChat(arg); - if(mode != null) - return mode; - - sender.system("FIGHT_UNKNOWN_GAMEMODE", arg); - return null; - } - - private static String getMap(Chatter sender, ArenaMode mode, String arg){ - String realMap = mode.hasMap(arg.toLowerCase()); - if(realMap != null) - return realMap; - if(arg.equalsIgnoreCase("Random")) - return mode.getRandomMap(); - - sender.system("FIGHT_UNKNOWN_ARENA"); - return null; - } - private static void getModes(Chatter sender, String precommand, boolean historic){ TextComponent start = new TextComponent(); TextComponent current = start; @@ -90,7 +61,7 @@ public class FightCommand extends SWCommand { private static boolean alreadyInArena(ProxiedPlayer player){ Subserver subserver = Subserver.getSubserver(player); if(subserver != null && subserver.getType() == Servertype.ARENA){ - Message.send("FIGHT_IN_ARENA", player); + Chatter.of(player).system("FIGHT_IN_ARENA"); return true; } @@ -137,20 +108,21 @@ public class FightCommand extends SWCommand { return; } - SWInventory inventory = new SWInventory(player, 9, Message.parse("FIGHT_MERGE_TITLE", player)); - inventory.addItem(0, new SWItem(Message.parse("FIGHT_MERGE_DECLINE", player), 1), click -> { + Chatter chatter = Chatter.of(player); + SWInventory inventory = new SWInventory(chatter, 9, new Message("FIGHT_MERGE_TITLE")); + inventory.addItem(0, new SWItem(new Message("FIGHT_MERGE_DECLINE"), 1), click -> { inventory.close(); declineMerge.run(player, mode, map); }); Arenaserver finalMergable = mergable; - SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11); - item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName())); + SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.getDisplayName(), finalMergable.getMap()), 11); + item.addLore(new Message("FIGHT_MERGE_INFO_LORE_1", finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName())); inventory.addItem(4, item, click -> {}); - inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> { + inventory.addItem(8, new SWItem(new Message("FIGHT_MERGE_ACCEPT"), 10), click -> { if(Subserver.getServerList().contains(finalMergable)) { finalMergable.sendPlayer(player); } else { - Message.send("FIGHT_MERGE_OFFLINE", player); + chatter.system("FIGHT_MERGE_OFFLINE"); declineMerge.run(player, mode, map); } }); @@ -166,10 +138,7 @@ public class FightCommand extends SWCommand { ); } - /** - * Is called when arena parameters are clear. - */ - interface FightCallback { + public interface FightCallback { void run(ProxiedPlayer player, ArenaMode mode, String map); } } diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index f61ca160..e7f74511 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -33,10 +33,8 @@ public class HistoricCommand extends SWCommand { @Register public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { - new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) - ).start(); - }); + FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + ).start()); } } diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index 3a4ee623..47ba16af 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -19,8 +19,8 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -33,18 +33,19 @@ public class IgnoreCommand extends SWCommand { @Register(description = "USAGE_IGNORE") public void genericCommand(ProxiedPlayer p, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + Chatter player = Chatter.of(p); + SteamwarUser user = player.user(); if(target.equals(user)){ - Message.send("IGNORE_YOURSELF", p); + player.system("IGNORE_YOURSELF"); return; } if(IgnoreSystem.isIgnored(user, target)){ - Message.send("IGNORE_ALREADY", p); + player.system("IGNORE_ALREADY"); return; } IgnoreSystem.ignore(user, target); - Message.send("IGNORE_MESSAGE", p, target.getUserName()); + player.system("IGNORE_MESSAGE", target); } } diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index a7b9efb7..aa894e57 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -19,51 +19,20 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; public class JoinmeCommand extends SWCommand { public JoinmeCommand() { - super("joinme"); - } - - @Register(description = "JOINME_USAGE") - public void genericCommand(ProxiedPlayer player) { - if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.TEAM)) { - Message.send("JOINME_USAGE", player); - return; - } - Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName()); + super("joinme", ConnectionListener.TEAMCHAT_PERMISSION); } @Register - public void genericCommand(ProxiedPlayer player, @Validator ProxiedPlayer target) { - if (target.equals(player)){ - Message.send("JOINME_PLAYER_SELF", player); - return; - } - - Subserver subserver = Subserver.getSubserver(target); - TpCommand.teleport(player, subserver != null ? subserver.getServer() : target.getServer().getInfo()); - } - - @ClassValidator(ProxiedPlayer.class) - public TypeValidator playerMapper() { - return (sender, value, messageSender) -> { - if (value == null || !value.isConnected()) { - messageSender.send("JOINME_PLAYER_OFFLINE", sender); - return false; - } - return true; - }; + public void genericCommand(ProxiedPlayer player) { + Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player, player.getServer().getInfo().getName()); } } diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index 6caa4a14..f1e31af1 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -19,10 +19,10 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -62,14 +62,16 @@ public class ListCommand extends SWCommand { } @Register - public void genericCommand(CommandSender commandSender) { + public void list(CommandSender sender) { + Chatter chatter = Chatter.of(sender); + TreeMap> playerMap = getCustomTablist(); for (String server : playerMap.navigableKeySet()) { String serverName = server; if (server.equals("Bau")) { - serverName = Message.parse("TABLIST_BAU", commandSender); + serverName = chatter.parseToLegacy("TABLIST_BAU"); } - Message.send("LIST_COMMAND", commandSender, serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); + chatter.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); } } } diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index e82b1b45..59fd46cd 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -26,12 +26,14 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Mod; -import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.HashMap; import java.util.Map; +import java.util.UUID; +import java.util.function.Consumer; import java.util.stream.Collectors; public class ModCommand extends SWCommand { @@ -40,109 +42,83 @@ public class ModCommand extends SWCommand { super("mod", ConnectionListener.MOD_PERMISSION, "mods"); } - public static final Map playerFilterType = new HashMap<>(); + public static final Map playerFilterType = new HashMap<>(); @Register - public void genericCommand(ProxiedPlayer p) { - playerFilterType.putIfAbsent(p,Mod.ModType.UNKLASSIFIED); - openGui(p); + public void mods(ProxiedPlayer p) { + playerFilterType.putIfAbsent(p.getUniqueId(), Mod.ModType.UNKLASSIFIED); + openGui(Chatter.of(p)); } - private void openGui(ProxiedPlayer p) { - SWStreamInv swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { - openClassificationGui(p,element); - },page -> { - Mod.ModType filtertype = playerFilterType.get(p); - return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); + private void openGui(Chatter player) { + SWStreamInv swStreamInv = new SWStreamInv<>(player, new Message("MOD_COMMAND_GUI_TITLE"), (click, mod) -> openTypeGUI(player, "MOD_COMMAND_CLASSICIATION_GUI", type -> { + mod.setModType(type); + SWInventory.close(player); + openGui(player); + }), page -> { + Mod.ModType filtertype = playerFilterType.get(player.user().getUUID()); + return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(new SWItem("NAME_TAG", new Message("PLAIN_STRING", mod.getModName())).addLore(new Message("PLAIN_STRING", mod.getPlatform().name())), mod)).collect(Collectors.toList()); }); - swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> { + swStreamInv.addItem(52, new SWItem("NAME_TAG", new Message("MOD_TITLE_FILTER")), click -> { swStreamInv.close(); - openFilterGui(p); + openTypeGUI(player, "MOD_TITLE_FILTER", type -> playerFilterType.replace(player.user().getUUID(), type)); }); swStreamInv.open(); } - public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) { - mod.setModType(modType); - toClose.close(); - openGui(p); - } + private void openTypeGUI(Chatter player, String title, Consumer function) { + SWInventory inv = new SWInventory(player, 9, new Message(title)); - private void openFilterGui(ProxiedPlayer p) { - SWInventory inv = new SWInventory(p, 9, "Filter"); + inv.addItem(1, new SWItem(new Message("MOD_UNCLASSIFIED"), 8), click -> function.accept(Mod.ModType.UNKLASSIFIED)); + inv.addItem(2, new SWItem(new Message("MOD_ALLOWED"), 2), click -> function.accept(Mod.ModType.GREEN)); + inv.addItem(3, new SWItem(new Message("MOD_FORBIDDEN"), 11), click -> function.accept(Mod.ModType.YELLOW)); + inv.addItem(4, new SWItem(new Message("MOD_AUTOBAN"), 1), click -> function.accept(Mod.ModType.RED)); + inv.addItem(5, new SWItem(new Message("MOD_YT"), 13), click -> function.accept(Mod.ModType.YOUTUBER_ONLY)); - inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED)); - inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN)); - inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW)); - inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED)); - inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY)); - - inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> { + inv.addItem(8, new SWItem("ARROW", new Message("MOD_ITEM_BACK")), click -> { inv.close(); - openGui(p); + openGui(player); }); inv.open(); } - private void openClassificationGui(ProxiedPlayer p,Mod element) { - SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p)); - - swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p))); - swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p))); - swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p))); - swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p))); - swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p))); - - swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> { - swInventory.close(); - openGui(p); - }); - - swInventory.open(); - } - - private SWItem getModItem(Mod modEntry) { - SWItem item = new SWItem("NAME_TAG", modEntry.getModName()); - - item.addLore(modEntry.getPlatform().name()); - - return item; - } - @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") - public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) { + public void set(ProxiedPlayer p, String modName, Mod.Platform platform, Mod.ModType newModType) { + Chatter player = Chatter.of(p); Mod mod = Mod.get(modName, platform); if(mod == null) { - Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name()); + player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } mod.setModType(newModType); - Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); + player.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name()); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") - public void get(ProxiedPlayer p,String modName,Mod.Platform platform) { + public void get(ProxiedPlayer p, String modName, Mod.Platform platform) { + Chatter player = Chatter.of(p); Mod mod = Mod.get(modName, platform); if(mod == null) { - Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name()); + player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } - Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name()); + player.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name()); } @Register(value = {"next"}) public void next(ProxiedPlayer p) { + Chatter player = Chatter.of(p); Mod mod = Mod.findFirstMod(); if(mod == null) { - Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); + player.system("MOD_NO_MORE_UNCLASSIFIED_MODS"); return; } - Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),mod.getModName(),mod.getPlatform().name()); + player.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name()); } } diff --git a/src/de/steamwar/bungeecore/commands/PingCommand.java b/src/de/steamwar/bungeecore/commands/PingCommand.java index 04c22fa1..707eef50 100644 --- a/src/de/steamwar/bungeecore/commands/PingCommand.java +++ b/src/de/steamwar/bungeecore/commands/PingCommand.java @@ -19,8 +19,8 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; public class PingCommand extends SWCommand { @@ -31,6 +31,6 @@ public class PingCommand extends SWCommand { @Register public void genericCommand(ProxiedPlayer player) { - Message.send("PING_RESPONSE", player, player.getPing()); + Chatter.of(player).system("PING_RESPONSE", player.getPing()); } } diff --git a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java index bbe0ddab..6323fb1d 100644 --- a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java +++ b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java @@ -19,9 +19,9 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.NumberFormat; @@ -39,6 +39,6 @@ public class PlaytimeCommand extends SWCommand { format.setMaximumFractionDigits(2); String formattedText = format.format((user.getOnlinetime() / (double) 3600)); - Message.send("HOURS_PLAYED", player, formattedText); + Chatter.of(player).system("HOURS_PLAYED", formattedText); } } diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index 0f8e77eb..1ede5f03 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -489,7 +489,7 @@ public class TeamCommand extends SWCommand { } @Register("tp") - public void tp(ProxiedPlayer player, @ErrorMessage("TEAM_TP_NO_TEAM") @Mapper("teamWithTeamServer") Team targetTeam) { + public void tp(ProxiedPlayer player, @ErrorMessage("TEAM_TP_NO_TEAM") Team targetTeam) { if (targetTeam.getAddress() == null || targetTeam.getAddress().isEmpty()) { Message.send("TEAM_NO_ADDRESS", player); return; @@ -678,25 +678,6 @@ public class TeamCommand extends SWCommand { }; } - @Mapper(value = "teamWithTeamServer", local = true) - @Cached(global = true, cacheDuration = 60) - public TypeMapper teamWithTeamServer() { - return new TypeMapper() { - @Override - public Team map(CommandSender commandSender, String[] previousArguments, String s) { - return Team.get(s); - } - - @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - return Team.getAll().stream() - .filter(team -> team.getAddress() != null && !team.getAddress().isEmpty()) - .flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel())) - .collect(Collectors.toList()); - } - }; - } - private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ Team t = Team.get(arg); if(t != null && t.getTeamId() != team.getTeamId()){ diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index d7bce433..229fae81 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Tutorial; import de.steamwar.sql.UserPerm; @@ -131,12 +132,12 @@ public class TutorialCommand extends SWCommand { } private void rate(ProxiedPlayer player, Tutorial tutorial) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Chatter chatter = Chatter.of(player); int[] rates = new int[]{1, 2, 3, 4, 5}; new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> { - tutorial.rate(user.getId(), rate); - SWInventory.close(player); + tutorial.rate(chatter.user().getId(), rate); + SWInventory.close(chatter); }).open(); } diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index 637668c4..a100f2dc 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -19,11 +19,14 @@ package de.steamwar.bungeecore.inventory; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler; -import de.steamwar.sql.SteamwarUser; +import de.steamwar.messages.Chatter; import de.steamwar.network.packets.server.CloseInventoryPacket; import de.steamwar.network.packets.server.InventoryPacket; +import lombok.Getter; +import lombok.Setter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; @@ -35,22 +38,28 @@ import java.util.function.BiFunction; public class SWInventory { - private final Map itemMap; + private final Map itemMap = new HashMap<>(); + private final Chatter player; + private final int size; + private final Message title; + @Setter private InvCallback close; - private ProxiedPlayer player; - private int size; - private String title; - private boolean next; + @Getter + @Setter + private boolean next = false; private final AtomicBoolean processingClick = new AtomicBoolean(); + @Deprecated public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) { - itemMap = new HashMap<>(); - InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer.getUniqueId()).getId(), this); - this.player = proxiedPlayer; + this(Chatter.of(proxiedPlayer), size, new Message("PLAIN_STRING", title)); + } + + public SWInventory(Chatter player, int size, Message title) { + InventoryCallbackHandler.inventoryHashMap.put(player.user().getId(), this); + this.player = player; this.size = size; this.title = title; - next = false; } public void addItem(int pos, SWItem item, InvCallback callback) { @@ -67,44 +76,10 @@ public class SWInventory { itemMap.put(pos, item); } - public void addItem(int pos, SWItem item, String name, InvCallback callback) { - item.setName(name); - item.setCallback(callback); - itemMap.put(pos, item); - } - - public void removeItem(int position) { - itemMap.remove(position); - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } - - public void setTitle(String title) { - this.title = title; - } - public void setCallback(int pos, InvCallback callback) { itemMap.get(pos).setCallback(callback); } - public void setNext(boolean next) { - this.next = next; - } - - public boolean isNext() { - return next; - } - - public Map getItems() { - return itemMap; - } - public void handleCallback(InvCallback.ClickType type, int pos) { if(processingClick.compareAndSet(false, true)) { itemMap.get(pos).getCallback().clicked(type); @@ -114,7 +89,7 @@ public class SWInventory { public void handleClose() { if(processingClick.compareAndSet(false, true)) { - InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player.getUniqueId()).getId(), this); + InventoryCallbackHandler.inventoryHashMap.remove(player.user().getId(), this); if(close != null) close.clicked(null); processingClick.set(false); @@ -122,8 +97,8 @@ public class SWInventory { } public void open() { - InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player.getUniqueId()).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString())); - NetworkSender.send(player, inv); + InventoryPacket inv = new InventoryPacket(player.parseToLegacy(title), player.user().getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(player, integer).toString())); + player.withPlayer(p -> NetworkSender.send(p, inv)); } private static Map map(Map map, BiFunction function) { @@ -136,23 +111,7 @@ public class SWInventory { close(player); } - public static void close(ProxiedPlayer player) { - NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player.getUniqueId()).getId())); - } - - public void setClose(InvCallback close) { - this.close = close; - } - - public ProxiedPlayer getPlayer() { - return player; - } - - public void setPlayer(ProxiedPlayer player) { - this.player = player; - } - - public String getTitle() { - return title; + public static void close(Chatter player) { + player.withPlayer(p -> NetworkSender.send(p, new CloseInventoryPacket(player.user().getId()))); } } diff --git a/src/de/steamwar/bungeecore/inventory/SWItem.java b/src/de/steamwar/bungeecore/inventory/SWItem.java index f5a4476a..41aa10b0 100644 --- a/src/de/steamwar/bungeecore/inventory/SWItem.java +++ b/src/de/steamwar/bungeecore/inventory/SWItem.java @@ -21,28 +21,44 @@ package de.steamwar.bungeecore.inventory; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import de.steamwar.bungeecore.Message; +import de.steamwar.messages.Chatter; +import lombok.Getter; +import lombok.Setter; import java.util.ArrayList; import java.util.List; +@Setter public class SWItem { - private String material, title, skullOwner; - private boolean enchanted, hideAttributes; - private List lore; + @Getter + private String material = "DYE"; + private Message title; + private String skullOwner; + private boolean enchanted; + private boolean hideAttributes; + private List lore = new ArrayList<>(); + @Getter private InvCallback callback; - private int color; + private int color = 0; + @Deprecated public SWItem(String material, String title) { - this.material = material.toUpperCase(); - lore = new ArrayList<>(); - this.title = title; - color = 0; + this(material, new Message("PLAIN_STRING", title)); } + public SWItem(String material, Message title) { + this.material = material.toUpperCase(); + this.title = title; + } + + @Deprecated public SWItem(String title, int color) { - this.material = "DYE"; - lore = new ArrayList<>(); + this(new Message("PLAIN_STRING", title), color); + } + + public SWItem(Message title, int color) { this.title = title; this.color = color; } @@ -53,68 +69,27 @@ public class SWItem { return item; } - public void setCallback(InvCallback callback) { - this.callback = callback; - } - - public void setColor(int color) { - this.color = color; - } - - public InvCallback getCallback() { - return callback; - } - - public String getMaterial() { - return material; - } - - public void setMaterial(String material) { - this.material = material.toUpperCase(); - } - - public String getSkullOwner() { - return skullOwner; - } - - public void setSkullOwner(String skullOwner) { - this.skullOwner = skullOwner; - } - - public boolean isEnchanted() { - return enchanted; - } - - public void setEnchanted(boolean enchanted) { - this.enchanted = enchanted; - } - - public boolean isHideAttributes() { - return hideAttributes; - } - - public void setHideAttributes(boolean hideAttributes) { - this.hideAttributes = hideAttributes; - } - + @Deprecated public SWItem setName(String name) { - title = name; + title = new Message("PLAIN_STRING", name); return this; } - public String getTitle() { - return title; - } - + @Deprecated public void addLore(String lore) { - this.lore.add(lore); + addLore(new Message("PLAIN_STRING", lore)); } - public JsonObject writeToString(int position) { + public SWItem addLore(Message lore) { + this.lore.add(lore); + return this; + } + + public JsonObject writeToString(Chatter player, int position) { JsonObject object = new JsonObject(); object.addProperty("material", material); object.addProperty("position", position); - object.addProperty("title", title); + object.addProperty("title", player.parseToLegacy(title)); if(skullOwner != null) object.addProperty("skullOwner", skullOwner); if(enchanted) @@ -125,9 +100,8 @@ public class SWItem { object.addProperty("color", color); if(lore != null) { JsonArray array = new JsonArray(); - for (String lores: - lore) { - array.add(lores); + for (Message lores : lore) { + array.add(player.parseToLegacy(lores)); } object.add("lore", array); } @@ -153,10 +127,6 @@ public class SWItem { return true; } - public void setLore(List lore) { - this.lore = lore; - } - public SWItem clone() { SWItem item; if(color != 0) { diff --git a/src/de/steamwar/bungeecore/inventory/SWListInv.java b/src/de/steamwar/bungeecore/inventory/SWListInv.java index 8636054d..8547e5b3 100644 --- a/src/de/steamwar/bungeecore/inventory/SWListInv.java +++ b/src/de/steamwar/bungeecore/inventory/SWListInv.java @@ -47,7 +47,7 @@ public class SWListInv extends SWInventory { else addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {}); if(page < elements.size()/45) - addItem(53, new SWItem("§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> { + addItem(53, new SWItem("§eSeite vor", 10), (InvCallback.ClickType click) -> { page++; open(); }); diff --git a/src/de/steamwar/bungeecore/inventory/SWStreamInv.java b/src/de/steamwar/bungeecore/inventory/SWStreamInv.java index 1235de0c..a7440442 100644 --- a/src/de/steamwar/bungeecore/inventory/SWStreamInv.java +++ b/src/de/steamwar/bungeecore/inventory/SWStreamInv.java @@ -1,5 +1,7 @@ package de.steamwar.bungeecore.inventory; +import de.steamwar.bungeecore.Message; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.List; @@ -10,6 +12,14 @@ public class SWStreamInv extends SWInventory { private final Function>> constructor; private int page; + public SWStreamInv(Chatter chatter, Message title, SWListInv.ListCallback callback, Function>> constructor) { + super(chatter, 54, title); + this.callback = callback; + this.constructor = constructor; + page = 0; + } + + @Deprecated public SWStreamInv(ProxiedPlayer proxiedPlayer, String title, SWListInv.ListCallback callback, Function>> constructor) { super(proxiedPlayer, 54, title); this.callback = callback; diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index b83cb966..2a6d7a73 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -19,20 +19,54 @@ package de.steamwar.command; +import de.steamwar.bungeecore.ServerVersion; import de.steamwar.bungeecore.commands.TypeMappers; import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.Team; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.Collection; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import java.util.stream.Stream; @UtilityClass public class TypeUtils { static void init() { - SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper() { + @Override + public ServerVersion map(CommandSender sender, String[] previousArguments, String s) { + if (sender instanceof ProxiedPlayer && s.isEmpty()) { + int version = ((ProxiedPlayer) sender).getPendingConnection().getVersion(); + if (version > 762) { // Version > 1.19.4 + return ServerVersion.PAPER_20; + } else if (version > 578) { // Version > 1.15.2 + return ServerVersion.PAPER_19; + } else if (version > 340) { // Version > 1.12.2 + return ServerVersion.SPIGOT_15; + } else { + return ServerVersion.SPIGOT_12; + } + } + + return ServerVersion.get(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return ServerVersion.chatVersions(); + } + }); + + AbstractTypeMapper teamMapper = SWCommandUtils.createMapper(Team::get, s -> Team.getAll().stream().flatMap(team -> Stream.of(team.getTeamKuerzel(), team.getTeamName())).collect(Collectors.toList())); + TabCompletionCache.add(teamMapper, true, 10, TimeUnit.SECONDS); + SWCommandUtils.addMapper(Team.class, teamMapper); TypeMappers.init(); } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8d2ea6fe..64c80e45 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -253,7 +253,7 @@ EVENT_COMING=§eUpcoming events§8: EVENT_COMING_EVENT=§7{0}§8-§7{1}§8: §e{2} EVENT_COMING_DEADLINE=§7 Registration deadline§8: §7{0} EVENT_COMING_SCHEM_DEADLINE=§7 Submission deadline§8: §7{0} -EVENT_COMING_TEAMS=§7 With§8:{0} +EVENT_COMING_TEAMS=§7 With§8: {0} EVENT_COMING_TEAM= §{0}{1} EVENT_CURRENT_EVENT=§e§l{0} EVENT_CURRENT_FIGHT=§7{0} §{1}{2}§8 vs §{3}{4} @@ -691,9 +691,15 @@ MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}. MOD_COMMAND_GUI_TITLE=Unclassified Mods MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer MOD_OPEN_GUI=§7Open Gui +MOD_TITLE_FILTER=Filter MOD_UNCLASSIFIED=§7Unclassified MOD_ALLOWED=§aAllowed MOD_FORBIDDEN=§eForbidden MOD_AUTOBAN=§cAutoban MOD_YT=§5YT Only MOD_ITEM_BACK=§7Back + +#Discord +DC_TITLE_SCHEMINFO=Schematic Info +DC_SCHEM_ACCEPT=Your schematic **{0}** has been accepted. +DC_SCHEM_DECLINE=Your schematic **{0}** has been declined.\n**Reason:**{1} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 178abd53..40a350b0 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -236,7 +236,7 @@ EVENT_COMING=§eKommende Events§8: EVENT_COMING_EVENT=§7{0}§8-§7{1}§8: §e{2} EVENT_COMING_DEADLINE=§7 Anmeldeschluss§8: §7{0} EVENT_COMING_SCHEM_DEADLINE=§7 Einsendeschluss§8: §7{0} -EVENT_COMING_TEAMS=§7 Mit§8:{0} +EVENT_COMING_TEAMS=§7 Mit§8: {0} EVENT_COMING_TEAM= §{0}{1} EVENT_CURRENT_EVENT=§e§l{0} EVENT_CURRENT_FIGHT=§7{0} §{1}{2}§8 vs §{3}{4} @@ -650,4 +650,9 @@ ADVENT_CALENDAR_TITLE=§eAdventskalender ADVENT_CALENDAR_DAY=§7Tag§8: §e{0} ADVENT_CALENDAR_MESSAGE=§eHast du heute schon dein Geschenk geholt? ADVENT_CALENDAR_MESSAGE_HOVER=§eKlicken zum öffnen! -ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! \ No newline at end of file +ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! + +#Discord +DC_TITLE_SCHEMINFO=Schematicinfo +DC_SCHEM_ACCEPT=Deine Schematic **{0}** wurde angenommen. +DC_SCHEM_DECLINE=Deine Schematic **{0}** wurde abgelehnt. **Grund:** \n{1} diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java index b1166443..fc122406 100644 --- a/src/de/steamwar/messages/Chatter.java +++ b/src/de/steamwar/messages/Chatter.java @@ -43,6 +43,7 @@ import java.text.MessageFormat; import java.util.Date; import java.util.Locale; import java.util.ResourceBundle; +import java.util.UUID; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.logging.Level; @@ -78,7 +79,11 @@ public interface Chatter { Locale getLocale(); boolean chatShown(); void sendMessage(ChatMessageType type, BaseComponent... msg); - void withPlayer(Consumer function); + void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord); + + default void withPlayer(Consumer function) { + withPlayerOrDiscord(function, user -> {}); + } default void chat(Message message) { send(false, ChatMessageType.CHAT, null, null, message); @@ -182,8 +187,8 @@ public interface Chatter { } @Override - public void withPlayer(Consumer function) { - function.accept(player); + public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { + withPlayer.accept(player); } }; } @@ -219,6 +224,29 @@ public interface Chatter { }; } + static Chatter of(UUID uuid) { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); + if(player != null) + return Chatter.of(player); + + return new PlayerlessChatter() { + @Override + public SteamwarUser user() { + return SteamwarUser.get(uuid); + } + + @Override + public boolean chatShown() { + return false; + } + + @Override + public void sendMessage(ChatMessageType type, BaseComponent... msg) { + // Nowhere to send + } + }; + } + static Chatter console() { return of(ConsoleCommandSender.getInstance()); } @@ -295,8 +323,8 @@ public interface Chatter { } @Override - public void withPlayer(Consumer function) { - //Not a player + public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { + withDiscord.accept(user()); } } } From a188ce2c6f8f8f5f07d3fd90de7a1ac04a9c3f3c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 13 May 2024 17:23:42 +0200 Subject: [PATCH 03/22] WIP message deprecation Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 12 +- .../bungeecore/commands/AlertCommand.java | 5 +- .../bungeecore/commands/ArenaCommand.java | 16 +- .../bungeecore/commands/BauCommand.java | 106 +++++----- .../bungeecore/commands/BugCommand.java | 13 +- .../commands/BuilderCloudCommand.java | 47 +++-- .../bungeecore/commands/ChallengeCommand.java | 20 +- .../bungeecore/commands/CheckCommand.java | 72 ++++--- .../bungeecore/commands/DevCommand.java | 33 ++- .../bungeecore/commands/EventCommand.java | 46 ++-- .../commands/EventRescheduleCommand.java | 11 +- .../commands/EventreloadCommand.java | 6 +- .../bungeecore/commands/FightCommand.java | 42 ++-- .../bungeecore/commands/GDPRQuery.java | 44 ++-- .../bungeecore/commands/HelpCommand.java | 28 ++- .../bungeecore/commands/HistoricCommand.java | 8 +- .../bungeecore/commands/IgnoreCommand.java | 4 +- .../bungeecore/commands/JoinmeCommand.java | 6 +- .../bungeecore/commands/KickCommand.java | 5 +- .../bungeecore/commands/ListCommand.java | 8 +- .../bungeecore/commands/LocalCommand.java | 5 +- .../bungeecore/commands/ModCommand.java | 33 ++- .../bungeecore/commands/MsgCommand.java | 12 +- .../bungeecore/commands/PingCommand.java | 7 +- .../bungeecore/commands/PlaytimeCommand.java | 7 +- .../bungeecore/commands/PollCommand.java | 32 ++- .../commands/PollresultCommand.java | 23 +- .../commands/PunishmentCommand.java | 197 ++++++++++-------- .../bungeecore/commands/TypeMappers.java | 12 +- .../bungeecore/inventory/SWInventory.java | 1 + .../bungeecore/listeners/ChatListener.java | 8 +- .../bungeecore/listeners/PollSystem.java | 34 +-- src/de/steamwar/bungeecore/util/BauLock.java | 18 +- .../steamwar/command/CommandRegistering.java | 37 ---- src/de/steamwar/command/SWCommand.java | 46 ++-- src/de/steamwar/command/TypeMapper.java | 6 +- src/de/steamwar/command/TypeUtils.java | 11 +- src/de/steamwar/command/TypeValidator.java | 5 +- .../steamwar/messages/BungeeCore.properties | 4 +- .../messages/BungeeCore_de.properties | 4 +- src/de/steamwar/messages/Chatter.java | 85 ++++---- src/de/steamwar/messages/ChatterGroup.java | 10 +- src/de/steamwar/messages/PlayerChatter.java | 61 ++++++ 43 files changed, 574 insertions(+), 616 deletions(-) delete mode 100644 src/de/steamwar/command/CommandRegistering.java create mode 100644 src/de/steamwar/messages/PlayerChatter.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 56dbe301..f005033b 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -27,10 +27,8 @@ import de.steamwar.bungeecore.mods.ServerListPing; import de.steamwar.bungeecore.mods.*; import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.tablist.TablistManager; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.SWTypeMapperCreator; -import de.steamwar.command.TabCompletionCache; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; +import de.steamwar.messages.Chatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; @@ -80,14 +78,14 @@ public class BungeeCore extends Plugin { errorLogger = new ErrorLogger(); - SWCommandUtils.init((SWTypeMapperCreator, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper() { + SWCommandUtils.init((SWTypeMapperCreator, Chatter, Object>) (mapper, tabCompleter) -> new TypeMapper() { @Override - public Object map(CommandSender commandSender, String[] previousArguments, String s) { + public Object map(Chatter sender, PreviousArguments previousArguments, String s) { return mapper.apply(s); } @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return tabCompleter.apply(sender, s); } }); diff --git a/src/de/steamwar/bungeecore/commands/AlertCommand.java b/src/de/steamwar/bungeecore/commands/AlertCommand.java index 210f5b04..2e856bbb 100644 --- a/src/de/steamwar/bungeecore/commands/AlertCommand.java +++ b/src/de/steamwar/bungeecore/commands/AlertCommand.java @@ -24,7 +24,6 @@ import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; public class AlertCommand extends SWCommand { @@ -33,9 +32,9 @@ public class AlertCommand extends SWCommand { } @Register(description = "USAGE_ALERT") - public void broadcast(CommandSender sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { + public void broadcast(Chatter sender, @OptionalValue("") @StaticValue("-discord") String sendToDiscord, String... message) { if (message.length == 0) { - Chatter.of(sender).system("USAGE_ALERT"); + sender.system("USAGE_ALERT"); return; } diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index 10bac329..274d45fe 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -24,9 +24,9 @@ import de.steamwar.bungeecore.Subserver; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; import java.util.List; @@ -39,29 +39,29 @@ public class ArenaCommand extends SWCommand { } @Register - public void arenaJoin(ProxiedPlayer player, Subserver server) { - TpCommand.teleport(player, server.getServer()); + public void arenaJoin(PlayerChatter sender, Subserver server) { + TpCommand.teleport(sender.getPlayer(), server.getServer()); } @ClassMapper(value = Subserver.class, local = true) public TypeMapper serverInfoTypeMapper() { return new TypeMapper() { @Override - public Subserver map(CommandSender commandSender, String[] previousArguments, String s) { + public Subserver map(Chatter sender, PreviousArguments previousArguments, String s) { return Subserver.getSubserver(ProxyServer.getInstance().getServerInfo(s)); } @Override - public boolean validate(CommandSender sender, Subserver value, MessageSender messageSender) { + public boolean validate(Chatter sender, Subserver value, MessageSender messageSender) { if (value == null || value.getType() != Servertype.ARENA) { - messageSender.send("ARENA_NOT_FOUND"); + sender.system("ARENA_NOT_FOUND"); return false; } return true; } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { List subserverList = Subserver.getServerList(); synchronized (subserverList) { return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 39388ff5..d106703e 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -31,12 +31,11 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; -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.Collection; import java.util.function.Consumer; @@ -46,26 +45,26 @@ public class BauCommand extends SWCommand { private final HelpCommand command; - public BauCommand(HelpCommand command){ + public BauCommand(HelpCommand command) { super("bau", null, "b", "build", "gs"); this.command = command; } @Register(noTabComplete = true) - public void genericHelp(ProxiedPlayer p, String... args) { - this.command.sendBauHelp(p); + public void genericHelp(Chatter sender, String... args) { + this.command.sendBauHelp(sender); } @Register - public void toBau(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - new ServerStarter().build(version, p.getUniqueId()).send(p).start(); + public void toBau(PlayerChatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + new ServerStarter().build(version, sender.user().getUUID()).send(sender.getPlayer()).start(); } @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE") - public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { - BauweltMember.addMember(p.getUniqueId(), target.getUUID()); - Chatter.of(p).system("BAU_ADDMEMBER_ADDED"); - Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", p); + public void addmember(Chatter sender, @Validator("addMemberTarget") SteamwarUser target) { + BauweltMember.addMember(sender.user().getUUID(), target.getUUID()); + sender.system("BAU_ADDMEMBER_ADDED"); + Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", sender); } @Validator(value = "addMemberTarget", local = true) @@ -75,11 +74,11 @@ public class BauCommand extends SWCommand { messageSender.send("UNKNOWN_PLAYER"); return false; } - if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUUID())) { + if (sender.user().getUUID().equals(value.getUUID())) { messageSender.send("BAU_ADDMEMBER_SELFADD"); return false; } - if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUUID()) != null) { + if (BauweltMember.getBauMember(sender.user().getId(), value.getId()) != null) { messageSender.send("BAU_ADDMEMBER_ISADDED"); return false; } @@ -89,8 +88,8 @@ public class BauCommand extends SWCommand { @Register(value = "tp", description = "BAU_TP_USAGE") @Register("teleport") - public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - new ServerStarter().build(version, worldOwner.getUUID()).send(p).start(); + public void teleport(PlayerChatter sender, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + new ServerStarter().build(version, worldOwner.getUUID()).send(sender.getPlayer()).start(); } @Validator(value = "teleportTarget", local = true) @@ -100,47 +99,45 @@ public class BauCommand extends SWCommand { messageSender.send("UNKNOWN_PLAYER"); return false; } - ProxiedPlayer p = (ProxiedPlayer) sender; - if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) { - SubserverSystem.sendDeniedMessage(Chatter.of(p), value.getUUID()); + if (sender.user().getId() != value.getId() && BauweltMember.getBauMember(value.getId(), sender.user().getId()) == null) { + SubserverSystem.sendDeniedMessage(sender, value.getUUID()); messageSender.send("BAU_TP_NOALLOWED"); return false; } - return !BauLock.checkNotifyLocked(value, p); + return !BauLock.checkNotifyLocked(value, sender); }; } @Register("info") - public void info(ProxiedPlayer p) { - Chat19.chat(p, "/bauinfo"); + public void info(PlayerChatter sender) { + Chat19.chat(sender.getPlayer(), "/bauinfo"); } @Register("setspectator") - public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> { + public void setSpectator(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> { member.setBuild(false); member.setSupervisor(false); }); } @Register("setbuild") - public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> { + public void setBuild(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> { member.setBuild(true); member.setSupervisor(false); }); } @Register("setsupervisor") - public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { - setPerms(p, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> { + public void setSupervisor(Chatter sender, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { + setPerms(sender, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> { member.setBuild(true); member.setSupervisor(true); }); } - private void setPerms(ProxiedPlayer p, SteamwarUser user, String name, String permName, Consumer setter) { - Chatter owner = Chatter.of(p); + private void setPerms(Chatter owner, SteamwarUser user, String name, String permName, Consumer setter) { if (user == null) { owner.system("BAU_MEMBER_SET_USAGE", name); return; @@ -149,28 +146,25 @@ public class BauCommand extends SWCommand { withMember(owner, user, target -> { setter.accept(target); - Bauserver bauserver = Bauserver.get(p.getUniqueId()); + Bauserver bauserver = Bauserver.get(owner.user().getUUID()); if(bauserver != null) bauserver.getServer().getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); - Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", p.getName(), new Message(permName)); + Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", owner, new Message(permName)); owner.system("BAU_MEMBER_SET", new Message(permName)); }); } @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE") - public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) { - Chatter owner = Chatter.of(p); + public void delmember(Chatter owner, @Mapper("addedUsers") SteamwarUser user) { withMember(owner, user, target -> { target.remove(); Chatter member = Chatter.of(user.getUUID()); - member.system("BAU_DELMEMBER_DELETED_TARGET", p); - member.withPlayer(toRemove -> { - Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); - if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) { - toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); - } + member.system("BAU_DELMEMBER_DELETED_TARGET", owner); + member.withPlayer(player -> { + if (Bauserver.get(owner.user().getUUID()).getServer().getPlayers().contains(player)) + player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); }); owner.system("BAU_DELMEMBER_DELETED"); @@ -181,13 +175,13 @@ public class BauCommand extends SWCommand { public TypeMapper addedUsers() { return new TypeMapper() { @Override - public SteamwarUser map(CommandSender commandSender, String[] previousArguments, String s) { - return SteamwarUser.get(s); + public SteamwarUser map(Chatter sender, PreviousArguments previousArguments, String s) { + return sender.user(); } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - return BauweltMember.getMembers(Chatter.of(sender).user().getId()).stream() + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + return BauweltMember.getMembers(sender.user().getId()).stream() .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()).getUserName()) .collect(Collectors.toList()); } @@ -196,20 +190,18 @@ public class BauCommand extends SWCommand { @Register("resetall") @Register("delete") - public void delete(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { - Chatter player = Chatter.of(p); - - SWInventory inventory = new SWInventory(player, 9, new Message("BAU_DELETE_GUI_NAME")); + public void delete(Chatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { + SWInventory inventory = new SWInventory(sender, 9, new Message("BAU_DELETE_GUI_NAME")); inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> { - String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? player.user().getId() : p.getUniqueId().toString()); + String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? sender.user().getId() : sender.user().getUUID().toString()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - Bauserver subserver = Bauserver.get(p.getUniqueId()); + Bauserver subserver = Bauserver.get(sender.user().getUUID()); if(subserver != null) subserver.stop(); SubserverSystem.deleteFolder(BungeeCore.local, world); - player.system("BAU_DELETE_DELETED"); + sender.system("BAU_DELETE_DELETED"); }); inventory.close(); @@ -220,20 +212,20 @@ public class BauCommand extends SWCommand { @Register("test") @Register("testarena") - public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start()) + public void testarena(PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(sender.getPlayer(), "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, sender.getPlayer()).start()) ); } @Register(value = "lock", description = "BAU_LOCKED_OPTIONS") - public void lock(ProxiedPlayer p, BauLockState bauLockState) { - BauLock.setLocked(p, bauLockState); + public void lock(Chatter sender, BauLockState bauLockState) { + BauLock.setLocked(sender, bauLockState); } @Register("unlock") - public void unlock(ProxiedPlayer p) { - BauLock.setLocked(p, BauLockState.OPEN); + public void unlock(Chatter sender) { + BauLock.setLocked(sender, BauLockState.OPEN); } private static void withMember(Chatter owner, SteamwarUser member, Consumer function) { diff --git a/src/de/steamwar/bungeecore/commands/BugCommand.java b/src/de/steamwar/bungeecore/commands/BugCommand.java index d537628c..84ee6dff 100644 --- a/src/de/steamwar/bungeecore/commands/BugCommand.java +++ b/src/de/steamwar/bungeecore/commands/BugCommand.java @@ -20,10 +20,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.sql.SWException; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class BugCommand extends SWCommand { public BugCommand() { @@ -31,10 +29,11 @@ public class BugCommand extends SWCommand { } @Register - public void bugMessage(ProxiedPlayer player, String... message) { - String server = player.getServer().getInfo().getName(); - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - SWException.log(String.join(" ", message), server + " " + player.getName() + " " + user.getId()); - Chatter.of(player).system("BUG_MESSAGE"); + public void bugMessage(Chatter sender, String... message) { + SWException.log( + String.join(" ", message), + sender.withPlayerOrOffline(player -> player.getServer().getInfo().getName(), () -> "offline") + " " + sender.user().getUserName() + " " + sender.user().getId() + ); + sender.system("BUG_MESSAGE"); } } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 8cf195c1..012b94de 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -9,14 +9,15 @@ import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.stream.Collectors; public class BuilderCloudCommand extends SWCommand { @@ -26,32 +27,32 @@ public class BuilderCloudCommand extends SWCommand { } @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE") - public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + public void create(Chatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { mapFile(version, map).mkdir(); - new ServerStarter().builder(version, map, generator).send(player).start(); + sender.withPlayer(p -> new ServerStarter().builder(version, map, generator).send(p).start()); } @Register(description = "BUILDERCLOUD_USAGE") - public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void start(PlayerChatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } - new ServerStarter().builder(version, map, null).send(player).start(); + new ServerStarter().builder(version, map, null).send(sender.getPlayer()).start(); } @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE") - public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) { + public void rename(Chatter sender, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) { File oldMap = mapFile(version, oldName); if(!oldMap.exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } File newMap = mapFile(version, newName); if(newMap.exists()) { - Chatter.of(player).system("BUILDERCLOUD_EXISTING_MAP"); + sender.system("BUILDERCLOUD_EXISTING_MAP"); return; } @@ -61,20 +62,20 @@ public class BuilderCloudCommand extends SWCommand { throw new SecurityException(e); } - Chatter.of(player).system("BUILDERCLOUD_RENAMED"); + sender.system("BUILDERCLOUD_RENAMED"); } @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") - public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { + public void deploy(Chatter sender, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) { if(!mapFile(version, map).exists()) { - Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + sender.system("BUILDERCLOUD_UNKNOWN_MAP"); return; } ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { BungeeCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); - Chatter.of(player).system("BUILDERCLOUD_DEPLOY_FINISHED"); + sender.system("BUILDERCLOUD_DEPLOY_FINISHED"); }); } @@ -84,13 +85,13 @@ public class BuilderCloudCommand extends SWCommand { return new TypeMapper() { @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(Chatter sender, PreviousArguments previousArguments, String s) { return s; } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - File folder = getWorldFolder(previousArguments.userArgs, 1); + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 1); String[] files; if(folder == null || (files = folder.list()) == null) @@ -107,7 +108,7 @@ public class BuilderCloudCommand extends SWCommand { return new TypeMapper() { @Override - public File map(CommandSender commandSender, String[] previousArguments, String s) { + public File map(Chatter sender, PreviousArguments previousArguments, String s) { if(s.isEmpty()) return null; @@ -124,8 +125,8 @@ public class BuilderCloudCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - File folder = getWorldFolder(previousArguments.userArgs, 2); + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 2); String[] files; if(folder == null || (files = folder.list()) == null) @@ -140,8 +141,8 @@ public class BuilderCloudCommand extends SWCommand { return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map); } - private File getWorldFolder(String[] previousArguments, int offset) { - ServerVersion v = ServerVersion.get(previousArguments[previousArguments.length - offset]); + private File getWorldFolder(PreviousArguments previousArguments, int offset) { + ServerVersion v = ServerVersion.get(previousArguments.userArgs[previousArguments.userArgs.length - offset]); if(v == null) return null; return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH)); diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 32d0748f..fe5ab519 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; @@ -38,13 +39,14 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { + public void challenge(@Validator("arenaPlayer") PlayerChatter sender, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(sender, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (chatter, mode, m) -> { + ProxiedPlayer p = sender.getPlayer(); if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); challenges.remove(p); - new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).callback( + new ServerStarter().arena(mode, map).blueLeader(sender.getPlayer()).redLeader(target).callback( arena -> Chatter.broadcast().system("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()) ).start(); }else{ @@ -54,7 +56,7 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); - Chatter.of(p).system("CHALLENGE_CHALLENGED", target.getName(), mode.getDisplayName()); + sender.system("CHALLENGE_CHALLENGED", target.getName(), mode.getDisplayName()); Chatter.of(target).system("CHALLENGE_CHALLENGED_TARGET", p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? new Message("CHALLENGE_CHALLENGED_MAP", m) : ""); Chatter.of(target).system("CHALLENGE_ACCEPT", new Message("CHALLENGE_ACCEPT_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + m)); @@ -66,21 +68,21 @@ public class ChallengeCommand extends SWCommand { public TypeValidator targetValidator() { return (sender, value, messageSender) -> { if (value == null) { - messageSender.send("CHALLENGE_OFFLINE"); + sender.system("CHALLENGE_OFFLINE"); return false; } if (sender == value) { - messageSender.send("CHALLENGE_SELF"); + sender.system("CHALLENGE_SELF"); return false; } - if (IgnoreSystem.isIgnored(value.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) { - messageSender.send("CHALLENGE_IGNORED"); + if (IgnoreSystem.isIgnored(value.getUniqueId(), sender.user().getUUID())) { + sender.system("CHALLENGE_IGNORED"); return false; } Subserver subserver = Subserver.getSubserver(value); if (subserver != null && subserver.getType() == Servertype.ARENA) { - messageSender.send("CHALLENGE_INARENA"); + sender.system("CHALLENGE_INARENA"); return false; } return true; diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 3ab407c7..5e97c839 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.util.DiscordAlert; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; @@ -79,11 +80,10 @@ public class CheckCommand extends SWCommand { } @Register(value = "list", description = "CHECK_HELP_LIST") - public void list(ProxiedPlayer player) { - Chatter chatter = Chatter.of(player); + public void list(Chatter sender) { List schematicList = getSchemsToCheck(); - chatter.prefixless("CHECK_LIST_HEADER", schematicList.size()); + sender.system("CHECK_LIST_HEADER", schematicList.size()); for (SchematicNode schematic : schematicList) { CheckSession current = currentSchems.get(schematic.getId()); @@ -91,15 +91,15 @@ public class CheckCommand extends SWCommand { String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "c" : "e") : "a"; long hours = waitedMillis / 3600000; long minutes = (waitedMillis - hours * 3600000) / 60000; - Message waitTime = new Message("CHECK_LIST_WAIT", player, color, hours, (minutes < 10) ? "0" + minutes : minutes); + Message waitTime = new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes); if (current == null) { - chatter.prefixless("CHECK_LIST_TO_CHECK", + sender.prefixless("CHECK_LIST_TO_CHECK", new Message("CHECK_LIST_TO_CHECK_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()), waitTime, schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName()); } else { - chatter.prefixless("CHECK_LIST_CHECKING", + sender.prefixless("CHECK_LIST_CHECKING", new Message("CHECK_LIST_CHECKING_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.user().getUserName()), waitTime, @@ -109,35 +109,33 @@ public class CheckCommand extends SWCommand { } @Register(value = "schematic", noTabComplete = true) - public void schematic(ProxiedPlayer player, String schemID) { - Chatter chatter = Chatter.of(player); - if(isChecking(player)){ - chatter.system("CHECK_SCHEMATIC_ALREADY_CHECKING"); + public void schematic(PlayerChatter sender, String schemID) { + if(isChecking(sender.getPlayer())){ + sender.system("CHECK_SCHEMATIC_ALREADY_CHECKING"); return; } - SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId()); SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID)); if(!schem.getSchemtype().check()){ - ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> player.getName() + " tried to check an uncheckable schematic!"); + ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> sender.user().getUserName() + " tried to check an uncheckable schematic!"); return; - }else if(schem.getOwner() == checkingUser.getId()) { - chatter.system("CHECK_SCHEMATIC_OWN"); + }else if(schem.getOwner() == sender.user().getId()) { + sender.system("CHECK_SCHEMATIC_OWN"); return; } - int playerTeam = checkingUser.hasPerm(UserPerm.MODERATION) ? 0 : checkingUser.getTeam(); + int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam(); if (playerTeam != 0 && SteamwarUser.get(schem.getOwner()).getTeam() == playerTeam) { - chatter.system("CHECK_SCHEMATIC_OWN_TEAM"); - return; + sender.system("CHECK_SCHEMATIC_OWN_TEAM"); + return; } - new CheckSession(chatter, schem); + new CheckSession(sender, schem); } @Register(value = "cancel", description = "CHECK_HELP_CANCEL") @Register("abort") - public void abortCommand(ProxiedPlayer player) { - abort(player); + public void abortCommand(PlayerChatter sender) { + abort(sender.getPlayer()); } public static void abort(ProxiedPlayer player) { @@ -149,24 +147,24 @@ public class CheckCommand extends SWCommand { } @Register(value = "next", description = "CHECK_HELP_NEXT") - public void next(ProxiedPlayer player) { - if(notChecking(player)) + public void next(PlayerChatter sender) { + if(notChecking(sender.getPlayer())) return; - currentCheckers.get(player.getUniqueId()).next(); + currentCheckers.get(sender.getPlayer().getUniqueId()).next(); } @Register(value = "accept") - public void accept(ProxiedPlayer player, @OptionalValue("") String rank) { - next(player); + public void accept(PlayerChatter sender) { + next(sender); } @Register(value = "decline", description = "CHECK_HELP_DECLINE") - public void decline(ProxiedPlayer player, String... message) { - if(notChecking(player)) + public void decline(PlayerChatter sender, String... message) { + if(notChecking(sender.getPlayer())) return; - currentCheckers.get(player.getUniqueId()).decline(String.join(" ", message)); + currentCheckers.get(sender.getPlayer().getUniqueId()).decline(String.join(" ", message)); } public static List getSchemsToCheck(){ @@ -193,20 +191,20 @@ public class CheckCommand extends SWCommand { } private static class CheckSession{ - private final Chatter checker; + private final PlayerChatter checker; private final SchematicNode schematic; private final Timestamp startTime; private final ListIterator checkList; - private CheckSession(Chatter checker, SchematicNode schematic){ + private CheckSession(PlayerChatter checker, SchematicNode schematic){ this.checker = checker; this.schematic = schematic; this.startTime = Timestamp.from(Instant.now()); this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator(); - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> checker.withPlayer(player -> { + ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); - if(!new ServerStarter().test(mode, mode.getRandomMap(), player).check(schematic.getId()).start()) { + if(!new ServerStarter().test(mode, mode.getRandomMap(), checker.getPlayer()).check(schematic.getId()).start()) { remove(); return; } @@ -216,7 +214,7 @@ public class CheckCommand extends SWCommand { for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); next(); - })); + }); } private void next() { @@ -248,9 +246,9 @@ public class CheckCommand extends SWCommand { private void accept(){ if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrDiscord( + owner.withPlayerOrOffline( player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()), - user -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) + () -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true) ); Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName()); } @@ -259,9 +257,9 @@ public class CheckCommand extends SWCommand { private void decline(String reason){ if(concludeCheckSession(reason, SchematicType.Normal)) { Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID()); - owner.withPlayerOrDiscord( + owner.withPlayerOrOffline( player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason), - user -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) + () -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false) ); Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason); } diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index d0048c4b..fc3ffcae 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -19,14 +19,15 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; -import de.steamwar.command.*; -import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.net.InetSocketAddress; @@ -43,46 +44,42 @@ public class DevCommand extends SWCommand { } @Register - public void simpleCommand(@Validator ProxiedPlayer player) { + public void simpleCommand(@Validator PlayerChatter sender) { updateDevServers(); - Chatter sender = Chatter.of(player); if (devServers.isEmpty()) { sender.system("DEV_NO_SERVER"); return; } else if (devServers.size() == 1) { - player.connect(devServers.values().stream().findAny().get()); + sender.getPlayer().connect(devServers.values().stream().findAny().get()); return; } - ServerInfo info = devServers.get(player.getName().toLowerCase()); + ServerInfo info = devServers.get(sender.getPlayer().getName().toLowerCase()); if (info == null) { sender.system("DEV_UNKNOWN_SERVER"); return; } - player.connect(info); + sender.getPlayer().connect(info); } @Register - public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) { + public void selectedCommand(@Validator PlayerChatter sender, @Mapper("dev") String name) { updateDevServers(); - Chatter sender = Chatter.of(player); ServerInfo info = devServers.get(name.toLowerCase()); if (info == null) { sender.system("DEV_NO_SERVER"); return; } - player.connect(info); + sender.getPlayer().connect(info); } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator punishmentGuardChecker() { + @ClassValidator(value = PlayerChatter.class, local = true) + public TypeValidator punishmentGuardChecker() { return (sender, value, messageSender) -> { - SteamwarUser user = SteamwarUser.get(value.getUniqueId()); - if (user.isPunished(Punishment.PunishmentType.NoDevServer)) { - Message message = PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.NoDevServer); - messageSender.send(message.getFormat(), message.getParams()); + if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) { + sender.system(PunishmentCommand.punishmentMessage(sender.user(), Punishment.PunishmentType.NoDevServer)); return false; } return true; diff --git a/src/de/steamwar/bungeecore/commands/EventCommand.java b/src/de/steamwar/bungeecore/commands/EventCommand.java index 03860066..926dd32b 100644 --- a/src/de/steamwar/bungeecore/commands/EventCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventCommand.java @@ -25,9 +25,8 @@ import de.steamwar.bungeecore.SubserverSystem; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.*; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.time.Instant; import java.time.format.DateTimeFormatter; @@ -42,80 +41,77 @@ public class EventCommand extends SWCommand { } @Validator("noEvent") - public TypeValidator noEventValidator() { + public TypeValidator noEventValidator() { return (sender, value, messageSender) -> Event.get() == null; } @Register - public void noCurrentEvent(@Validator("noEvent") CommandSender sender) { - Chatter player = Chatter.of(sender); - player.system("EVENT_NO_CURRENT"); + public void noCurrentEvent(@Validator("noEvent") Chatter sender) { + sender.system("EVENT_NO_CURRENT"); List coming = Event.getComing(); if(coming.isEmpty()) return; - player.system("EVENT_COMING"); + sender.system("EVENT_COMING"); Instant now = Instant.now(); - DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_DATE_FORMAT")); + DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_DATE_FORMAT")); for(Event e : coming){ - player.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName()); + sender.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName()); if(now.isBefore(e.getDeadline().toInstant())) - player.prefixless("EVENT_COMING_DEADLINE", e.getDeadline()); + sender.prefixless("EVENT_COMING_DEADLINE", e.getDeadline()); SchematicType schemType = e.getSchematicType(); if (schemType != null && schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) - player.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline()); + sender.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline()); Set teams = TeamTeilnahme.getTeams(e.getEventID()); if(!teams.isEmpty()) - player.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> player.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" "))); + sender.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> sender.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" "))); } } @Register - public void eventOverview(@Validator(value = "noEvent", invert = true) CommandSender sender) { - Chatter player = Chatter.of(sender); - player.system("EVENT_USAGE"); + public void eventOverview(@Validator(value = "noEvent", invert = true) Chatter sender) { + sender.system("EVENT_USAGE"); Event currentEvent = Event.get(); - player.system("EVENT_CURRENT_EVENT", currentEvent.getEventName()); + sender.system("EVENT_CURRENT_EVENT", currentEvent.getEventName()); - DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_TIME_FORMAT")); + DateTimeFormatter format = DateTimeFormatter.ofPattern(sender.parseToPlain("EVENT_TIME_FORMAT")); for(EventFight fight : EventFight.getEvent(currentEvent.getEventID())){ Team blue = Team.get(fight.getTeamBlue()); Team red = Team.get(fight.getTeamRed()); - StringBuilder fline = new StringBuilder(player.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel())); + StringBuilder fline = new StringBuilder(sender.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel())); if(fight.hasFinished()){ switch(fight.getErgebnis()){ case 1: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel())); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel())); break; case 2: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel())); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel())); break; default: - fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW")); + fline.append(sender.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW")); } } - player.prefixless("PLAIN_STRING", fline.toString()); + sender.prefixless("PLAIN_STRING", fline.toString()); } } @Register - public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) { - Chatter sender = Chatter.of(player); + public void eventWithTeam(@Validator(value = "noEvent", invert = true) PlayerChatter sender, @ErrorMessage("EVENT_NO_TEAM") Team team) { Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ sender.system("EVENT_NO_FIGHT_TEAM"); return; } if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { - SubserverSystem.sendPlayer(eventArena, player); + SubserverSystem.sendPlayer(eventArena, sender.getPlayer()); } } } diff --git a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java index d2d65383..edb82f79 100644 --- a/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventRescheduleCommand.java @@ -25,7 +25,6 @@ import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; -import net.md_5.bungee.api.CommandSender; import java.sql.Timestamp; import java.util.Date; @@ -39,12 +38,10 @@ public class EventRescheduleCommand extends SWCommand { } @Register - public void reschedule(CommandSender sender, Team teamBlue, Team teamRed) { - Chatter player = Chatter.of(sender); - + public void reschedule(Chatter sender, Team teamBlue, Team teamRed) { Event event = Event.get(); if(event == null){ - player.system("EVENTRESCHEDULE_UNKNOWN_TEAM"); + sender.system("EVENTRESCHEDULE_UNKNOWN_TEAM"); return; } @@ -57,13 +54,13 @@ public class EventRescheduleCommand extends SWCommand { continue; if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){ - player.system("EVENTRESCHEDULE_STARTING"); + sender.system("EVENTRESCHEDULE_STARTING"); fight.reschedule(); EventFight.loadAllComingFights(); return; } } - player.system("EVENTRESCHEDULE_NO_FIGHT"); + sender.system("EVENTRESCHEDULE_NO_FIGHT"); } } diff --git a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java index 1e419e73..df1e9d47 100644 --- a/src/de/steamwar/bungeecore/commands/EventreloadCommand.java +++ b/src/de/steamwar/bungeecore/commands/EventreloadCommand.java @@ -20,9 +20,9 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; -import de.steamwar.sql.EventFight; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.EventFight; public class EventreloadCommand extends SWCommand { public EventreloadCommand() { @@ -30,7 +30,7 @@ public class EventreloadCommand extends SWCommand { } @Register - public void execute(CommandSender sender) { + public void execute(Chatter sender) { EventFight.loadAllComingFights(); } } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 61e7bb58..76c9dbb3 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -58,20 +59,18 @@ public class FightCommand extends SWCommand { sender.sendMessage(ChatMessageType.SYSTEM, start); } - private static boolean alreadyInArena(ProxiedPlayer player){ - Subserver subserver = Subserver.getSubserver(player); + private static boolean alreadyInArena(PlayerChatter sender){ + Subserver subserver = Subserver.getSubserver(sender.getPlayer()); if(subserver != null && subserver.getType() == Servertype.ARENA){ - Chatter.of(player).system("FIGHT_IN_ARENA"); + sender.system("FIGHT_IN_ARENA"); return true; } return false; } - static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { - Chatter sender = Chatter.of(player); - - if(alreadyInArena(player)) + static void createArena(PlayerChatter sender, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { + if(alreadyInArena(sender)) return; if (arenaMode == null) { @@ -83,13 +82,13 @@ public class FightCommand extends SWCommand { map = arenaMode.getRandomMap(); if (!allowMerging) { - callback.run(player, arenaMode, map); + callback.run(sender, arenaMode, map); } else { - suggestMerging(player, arenaMode, map, callback); + suggestMerging(sender, arenaMode, map, callback); } } - public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) { + private static void suggestMerging(PlayerChatter sender, ArenaMode mode, String map, FightCallback declineMerge) { Arenaserver mergable = null; synchronized (Subserver.getServerList()) { for (Subserver subserver : Subserver.getServerList()) { @@ -104,15 +103,14 @@ public class FightCommand extends SWCommand { } if(mergable == null) { - declineMerge.run(player, mode, map); + declineMerge.run(sender, mode, map); return; } - Chatter chatter = Chatter.of(player); - SWInventory inventory = new SWInventory(chatter, 9, new Message("FIGHT_MERGE_TITLE")); + SWInventory inventory = new SWInventory(sender, 9, new Message("FIGHT_MERGE_TITLE")); inventory.addItem(0, new SWItem(new Message("FIGHT_MERGE_DECLINE"), 1), click -> { inventory.close(); - declineMerge.run(player, mode, map); + declineMerge.run(sender, mode, map); }); Arenaserver finalMergable = mergable; SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.getDisplayName(), finalMergable.getMap()), 11); @@ -120,25 +118,25 @@ public class FightCommand extends SWCommand { inventory.addItem(4, item, click -> {}); inventory.addItem(8, new SWItem(new Message("FIGHT_MERGE_ACCEPT"), 10), click -> { if(Subserver.getServerList().contains(finalMergable)) { - finalMergable.sendPlayer(player); + finalMergable.sendPlayer(sender.getPlayer()); } else { - chatter.system("FIGHT_MERGE_OFFLINE"); - declineMerge.run(player, mode, map); + sender.system("FIGHT_MERGE_OFFLINE"); + declineMerge.run(sender, mode, map); } }); inventory.open(); } @Register - public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - createArena(player, "/fight ", true, arenaMode, map, false, - (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + public void fight(@Validator("arenaPlayer") PlayerChatter sender, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(sender, "/fight ", true, arenaMode, map, false, + (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( + arena -> Chatter.broadcast().system("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getPlayer().getName()) ).start() ); } public interface FightCallback { - void run(ProxiedPlayer player, ArenaMode mode, String map); + void run(PlayerChatter player, ArenaMode mode, String map); } } diff --git a/src/de/steamwar/bungeecore/commands/GDPRQuery.java b/src/de/steamwar/bungeecore/commands/GDPRQuery.java index 0158edfc..2baf0d4d 100644 --- a/src/de/steamwar/bungeecore/commands/GDPRQuery.java +++ b/src/de/steamwar/bungeecore/commands/GDPRQuery.java @@ -1,12 +1,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.sql.internal.Statement; -import de.steamwar.sql.SteamwarUser; +import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.internal.Statement; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.*; import java.util.zip.ZipEntry; @@ -15,48 +16,42 @@ import java.util.zip.ZipOutputStream; public class GDPRQuery extends SWCommand { public GDPRQuery() { - super("gdprquery", "bungeecore.softreload"); + super("gdprquery", ConnectionListener.SOFTRELOAD_PERMISSION); } @Register - public void generate(ProxiedPlayer player) { - generate(player, player); + public void generate(PlayerChatter sender) { + generate(sender, sender.user()); } @Register - public void generate(ProxiedPlayer player, ProxiedPlayer forPlayer) { - SteamwarUser user = SteamwarUser.get(forPlayer.getUniqueId()); - if(user == null) { - Message.send("UNKNOWN_PLAYER", player); - return; - } - + public void generate(Chatter sender, SteamwarUser user) { BungeeCord.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { try { - createZip(player, user); + createZip(sender, user); } catch (IOException e) { throw new SecurityException("Could not create zip", e); } }); } - private void createZip(ProxiedPlayer player, SteamwarUser user) throws IOException { - printUpdate(player, "GDPR_STATUS_WEBSITE"); + private void createZip(Chatter sender, SteamwarUser user) throws IOException { + sender.system("GDPR_STATUS_WEBSITE"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(user.getUserName() + ".zip")); copy(getClass().getClassLoader().getResourceAsStream("GDPRQueryREADME.md"), out, "README.md"); copy(getClass().getClassLoader().getResourceAsStream("GDPRQueryREADME.md"), out, "README.txt"); - printUpdate(player, "GDPR_STATUS_WORLD"); + sender.system("GDPR_STATUS_WORLD"); copyBauwelt(user, out, "/home/minecraft/userworlds/" + user.getUUID().toString(), "BuildWorld12"); copyBauwelt(user, out, "/home/minecraft/userworlds15/" + user.getId(), "BuildWorld15"); - printUpdate(player, "GDPR_STATUS_INVENTORIES"); + sender.system("GDPR_STATUS_INVENTORIES"); copyPlayerdata(user, out, "/home/minecraft/userworlds", "BuildInventories12"); copyPlayerdata(user, out, "/home/minecraft/userworlds15", "BuildInventories15"); - printUpdate(player, "GDPR_STATUS_DATABASE"); + sender.system("GDPR_STATUS_DATABASE"); sqlCSV(user, out, bannedIPs, "BannedIPs.csv"); sqlCSV(user, out, bauweltMember, "BuildMember.csv"); sqlCSV(user, out, bauweltMembers, "BuildMembers.csv"); @@ -78,11 +73,11 @@ public class GDPRQuery extends SWCommand { schematics(user, out); userConfig(user, out); - printUpdate(player, "GDPR_STATUS_LOGS"); + sender.system("GDPR_STATUS_LOGS"); copyLogs(user, out, new File("/logs"), "logs"); out.close(); - printUpdate(player, "GDPR_STATUS_FINISHED"); + sender.system("GDPR_STATUS_FINISHED"); } private static final Statement bannedIPs = new Statement("SELECT Timestamp, IP FROM BannedUserIPs WHERE UserID = ?"); @@ -233,11 +228,6 @@ public class GDPRQuery extends SWCommand { } } - private void printUpdate(ProxiedPlayer player, String message) { - if (player.isConnected()) - Message.send(message, player); - } - private void copy(File file, ZipOutputStream out, String path) throws IOException { try(FileInputStream in = new FileInputStream(file)) { copy(in, out, path); diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index 36b9d7e8..e46da5a0 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -23,7 +23,6 @@ import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class HelpCommand extends SWCommand { @@ -32,9 +31,7 @@ public class HelpCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter sender = Chatter.of(player); - + public void genericCommand(Chatter sender) { printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_LOBBY", "/l", "HELP_BAU", "/build", @@ -48,33 +45,32 @@ public class HelpCommand extends SWCommand { } @Register({"build","world"}) - public void buildWorld(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); + public void buildWorld(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_WORLD_TITLE", "HELP_TNT", "HELP_FIRE", "HELP_FREEZE", "HELP_TPSLIMIT", "HELP_PROTECT", "HELP_RESET"); } @Register({"build","player"}) - public void buildPlayer(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); + public void buildPlayer(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_PLAYER_TITLE", "HELP_SPEED", "HELP_NV", "HELP_WV", "HELP_DEBUGSTICK", "HELP_TRACE", "HELP_LOADER"); } @Register({"build","worldedit"}) @Register({"build","we"}) @Register({"build","world-edit"}) @Register({"build","edit"}) - public void buildWorldedit(ProxiedPlayer player) { - printPage(Chatter.of(player), "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); + public void buildWorldedit(Chatter sender) { + printPage(sender, "HELP_BAU_GROUP_WE_TITLE", "HELP_WE_POS1", "HELP_WE_POS2", "HELP_WE_COPY", "HELP_WE_PASTE", "HELP_WE_FLOPY", "HELP_WE_FLOPYP", "HELP_WE_ROTATE_90", "HELP_WE_ROTATE_180", "HELP_WE_ROTATE_N90"); } @Register({"build","other"}) - public void buildOther(ProxiedPlayer player) { - Chatter sender = Chatter.of(player); + public void buildOther(Chatter sender) { printPage(sender, "HELP_BAU_GROUP_OTHER_TITLE", "HELP_TESTBLOCK", "HELP_SKULL", "HELP_BAUINFO"); sender.prefixless("HELP_SCHEMSUBMIT", new Message("HELP_SCHEMSUBMIT_HOVER"), new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.youtube.com/watch?v=9QrQ3UBWveE")); } @Register("build") - public void sendBauHelpGroup(ProxiedPlayer player) { - printPage(Chatter.of(player), ClickEvent.Action.RUN_COMMAND, + public void sendBauHelpGroup(Chatter sender) { + printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_BAU_GROUP_ADMIN", "/help build admin", "HELP_BAU_GROUP_WORLD", "/help build world", "HELP_BAU_GROUP_PLAYER", "/help build player", @@ -86,8 +82,8 @@ public class HelpCommand extends SWCommand { @Register({"build","admin"}) @Register({"build","owner"}) @Register({"build","bauwelt"}) - public void sendBauHelp(ProxiedPlayer player) { - printPage(Chatter.of(player), ClickEvent.Action.SUGGEST_COMMAND, + public void sendBauHelp(Chatter sender) { + printPage(sender, ClickEvent.Action.SUGGEST_COMMAND, "HELP_BAU_TP", "/build tp ", "HELP_BAU_ADDMEMBER", "/build addmember ", "HELP_BAU_DELMEMBER", "/build delmember ", diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index e7f74511..c44e0427 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -23,8 +23,8 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class HistoricCommand extends SWCommand { public HistoricCommand() { @@ -32,9 +32,9 @@ public class HistoricCommand extends SWCommand { } @Register - public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback( - arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) + public void historic(@Validator("arenaPlayer") PlayerChatter player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p.getPlayer()).callback( + arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getPlayer().getName()) ).start()); } } diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index 47ba16af..2a094600 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -23,7 +23,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class IgnoreCommand extends SWCommand { @@ -32,8 +31,7 @@ public class IgnoreCommand extends SWCommand { } @Register(description = "USAGE_IGNORE") - public void genericCommand(ProxiedPlayer p, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { - Chatter player = Chatter.of(p); + public void genericCommand(Chatter player, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { SteamwarUser user = player.user(); if(target.equals(user)){ diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index aa894e57..3df9bf84 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -22,8 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; public class JoinmeCommand extends SWCommand { @@ -32,7 +32,7 @@ public class JoinmeCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player, player.getServer().getInfo().getName()); + public void genericCommand(PlayerChatter sender) { + Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + sender.getPlayer().getName()), sender, sender.getPlayer().getServer().getInfo().getName()); } } diff --git a/src/de/steamwar/bungeecore/commands/KickCommand.java b/src/de/steamwar/bungeecore/commands/KickCommand.java index 7a0b8730..08176abe 100644 --- a/src/de/steamwar/bungeecore/commands/KickCommand.java +++ b/src/de/steamwar/bungeecore/commands/KickCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; public class KickCommand extends SWCommand { @@ -32,12 +31,12 @@ public class KickCommand extends SWCommand { } @Register(description = "KICK_USAGE") - public void genericCommand(CommandSender sender, @ErrorMessage("KICK_OFFLINE") ProxiedPlayer target, String... message) { + public void genericCommand(Chatter sender, @ErrorMessage("KICK_OFFLINE") ProxiedPlayer target, String... message) { if (message.length == 0) { Chatter.disconnect(target).system("KICK_NORMAL"); } else { Chatter.disconnect(target).system("KICK_CUSTOM", String.join(" ", message)); } - Chatter.of(sender).system("KICK_CONFIRM", target); + sender.system("KICK_CONFIRM", target); } } diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index f1e31af1..bba9ff3b 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -62,16 +62,14 @@ public class ListCommand extends SWCommand { } @Register - public void list(CommandSender sender) { - Chatter chatter = Chatter.of(sender); - + public void list(Chatter sender) { TreeMap> playerMap = getCustomTablist(); for (String server : playerMap.navigableKeySet()) { String serverName = server; if (server.equals("Bau")) { - serverName = chatter.parseToLegacy("TABLIST_BAU"); + serverName = sender.parseToLegacy("TABLIST_BAU"); } - chatter.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); + sender.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); } } } diff --git a/src/de/steamwar/bungeecore/commands/LocalCommand.java b/src/de/steamwar/bungeecore/commands/LocalCommand.java index ab77eb3e..862ba772 100644 --- a/src/de/steamwar/bungeecore/commands/LocalCommand.java +++ b/src/de/steamwar/bungeecore/commands/LocalCommand.java @@ -21,8 +21,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.PlayerChatter; public class LocalCommand extends SWCommand { @@ -31,7 +30,7 @@ public class LocalCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player, String... message) { + public void genericCommand(PlayerChatter player, String... message) { ChatListener.localChat(player, String.join(" ", message)); } } diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index 59fd46cd..4af186d5 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -27,8 +27,8 @@ import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Mod; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.HashMap; import java.util.Map; @@ -45,12 +45,12 @@ public class ModCommand extends SWCommand { public static final Map playerFilterType = new HashMap<>(); @Register - public void mods(ProxiedPlayer p) { - playerFilterType.putIfAbsent(p.getUniqueId(), Mod.ModType.UNKLASSIFIED); - openGui(Chatter.of(p)); + public void mods(PlayerChatter sender) { + playerFilterType.putIfAbsent(sender.getPlayer().getUniqueId(), Mod.ModType.UNKLASSIFIED); + openGui(sender); } - private void openGui(Chatter player) { + private void openGui(PlayerChatter player) { SWStreamInv swStreamInv = new SWStreamInv<>(player, new Message("MOD_COMMAND_GUI_TITLE"), (click, mod) -> openTypeGUI(player, "MOD_COMMAND_CLASSICIATION_GUI", type -> { mod.setModType(type); SWInventory.close(player); @@ -68,7 +68,7 @@ public class ModCommand extends SWCommand { swStreamInv.open(); } - private void openTypeGUI(Chatter player, String title, Consumer function) { + private void openTypeGUI(PlayerChatter player, String title, Consumer function) { SWInventory inv = new SWInventory(player, 9, new Message(title)); inv.addItem(1, new SWItem(new Message("MOD_UNCLASSIFIED"), 8), click -> function.accept(Mod.ModType.UNKLASSIFIED)); @@ -86,39 +86,36 @@ public class ModCommand extends SWCommand { } @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") - public void set(ProxiedPlayer p, String modName, Mod.Platform platform, Mod.ModType newModType) { - Chatter player = Chatter.of(p); + public void set(Chatter sender, String modName, Mod.Platform platform, Mod.ModType newModType) { Mod mod = Mod.get(modName, platform); if(mod == null) { - player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); + sender.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } mod.setModType(newModType); - player.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name()); + sender.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name()); } @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") - public void get(ProxiedPlayer p, String modName, Mod.Platform platform) { - Chatter player = Chatter.of(p); + public void get(Chatter sender, String modName, Mod.Platform platform) { Mod mod = Mod.get(modName, platform); if(mod == null) { - player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); + sender.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name()); return; } - player.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name()); + sender.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name()); } @Register(value = {"next"}) - public void next(ProxiedPlayer p) { - Chatter player = Chatter.of(p); + public void next(Chatter sender) { Mod mod = Mod.findFirstMod(); if(mod == null) { - player.system("MOD_NO_MORE_UNCLASSIFIED_MODS"); + sender.system("MOD_NO_MORE_UNCLASSIFIED_MODS"); return; } - player.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name()); + sender.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name()); } } diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index b25ea63e..0816b3b0 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.IgnoreSystem; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -35,26 +36,25 @@ public class MsgCommand extends SWCommand { } @Register(description = "MSG_USAGE") - public void genericCommand(ProxiedPlayer sender, @ErrorMessage(value = "MSG_OFFLINE") ProxiedPlayer target, @ErrorMessage(value = "MSG_USAGE", allowEAs = false) String... message) { + public void genericCommand(PlayerChatter sender, @ErrorMessage(value = "MSG_OFFLINE") ProxiedPlayer target, @ErrorMessage(value = "MSG_USAGE", allowEAs = false) String... message) { msg(sender, target, message); } - public static void msg(ProxiedPlayer player, ProxiedPlayer target, String[] args) { - Chatter sender = Chatter.of(player); + public static void msg(PlayerChatter sender, ProxiedPlayer target, String[] args) { if(target == null || !target.isConnected()) { sender.system("MSG_OFFLINE"); return; } - if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) { + if (IgnoreSystem.isIgnored(target.getUniqueId(), sender.user().getUUID())) { sender.system("MSG_IGNORED"); return; } Chatter receiver = Chatter.of(target); ChatListener.sendChat(sender, new ChatterGroup(sender, receiver), "CHAT_MSG", receiver, String.join(" ", args)); - lastChats.put(player, target); - lastChats.put(target, player); + lastChats.put(sender.getPlayer(), target); + lastChats.put(target, sender.getPlayer()); } public static void remove(ProxiedPlayer player){ diff --git a/src/de/steamwar/bungeecore/commands/PingCommand.java b/src/de/steamwar/bungeecore/commands/PingCommand.java index 707eef50..c6342f9a 100644 --- a/src/de/steamwar/bungeecore/commands/PingCommand.java +++ b/src/de/steamwar/bungeecore/commands/PingCommand.java @@ -20,8 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.command.SWCommand; -import de.steamwar.messages.Chatter; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.PlayerChatter; public class PingCommand extends SWCommand { @@ -30,7 +29,7 @@ public class PingCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - Chatter.of(player).system("PING_RESPONSE", player.getPing()); + public void genericCommand(PlayerChatter sender) { + sender.system("PING_RESPONSE", sender.getPlayer().getPing()); } } diff --git a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java index 6323fb1d..a5be015a 100644 --- a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java +++ b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java @@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.text.NumberFormat; @@ -33,12 +32,12 @@ public class PlaytimeCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + public void genericCommand(Chatter sender) { + SteamwarUser user = sender.user(); NumberFormat format = NumberFormat.getNumberInstance(user.getLocale()); format.setMaximumFractionDigits(2); String formattedText = format.format((user.getOnlinetime() / (double) 3600)); - Chatter.of(player).system("HOURS_PLAYED", formattedText); + sender.system("HOURS_PLAYED", formattedText); } } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 6cae84db..cb944d91 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -19,13 +19,11 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.sql.PollAnswer; -import de.steamwar.sql.SteamwarUser; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.PollAnswer; public class PollCommand extends SWCommand { @@ -34,39 +32,33 @@ public class PollCommand extends SWCommand { } @Register - public void genericCommand(ProxiedPlayer player) { - PollSystem.sendPoll(player); + public void genericCommand(Chatter sender) { + PollSystem.sendPoll(sender); } @Register(noTabComplete = true) - public void answerPoll(@Validator ProxiedPlayer player, String answerString) { + public void answerPoll(@Validator Chatter sender, String answerString) { int answer; try { answer = Integer.parseUnsignedInt(answerString); if(answer < 1 || answer > PollSystem.answers()) throw new NumberFormatException(); }catch(NumberFormatException e){ - Message.send("POLL_NO_ANSWER", player); + sender.system("POLL_NO_ANSWER"); return; } - PollAnswer pollAnswer = PollAnswer.get(SteamwarUser.get(player.getUniqueId()).getId()); + PollAnswer pollAnswer = PollAnswer.get(sender.user().getId()); if(pollAnswer.hasAnswered()) - Message.send("POLL_ANSWER_REFRESH", player); + sender.system("POLL_ANSWER_REFRESH"); else - Message.send("POLL_ANSWER_NEW", player); + sender.system("POLL_ANSWER_NEW"); pollAnswer.setAnswer(answer); } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator noPoll() { - return (sender, value, messageSender) -> { - if(PollSystem.noCurrentPoll()){ - messageSender.send("POLL_NO_POLL"); - return false; - } - return true; - }; + @ClassValidator(value = Chatter.class, local = true) + public TypeValidator noPoll() { + return PollSystem.noPoll(); } } diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index 4e62b4c2..9b4d0828 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -19,13 +19,12 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.PollSystem; -import de.steamwar.sql.PollAnswer; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; -import net.md_5.bungee.api.connection.ProxiedPlayer; +import de.steamwar.messages.Chatter; +import de.steamwar.sql.PollAnswer; import java.util.Map; @@ -36,22 +35,16 @@ public class PollresultCommand extends SWCommand { } @Register - public void genericCommand(@Validator ProxiedPlayer player) { + public void genericCommand(@Validator Chatter sender) { Map voted = PollAnswer.getCurrentResults(); - Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll()); + sender.system("POLLRESULT_HEADER", voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll()); for (Map.Entry e: voted.entrySet()) { - Message.send("POLLRESULT_LIST", player, PollSystem.getAnswer(e.getKey()), e.getValue()); + sender.prefixless("POLLRESULT_LIST", PollSystem.getAnswer(e.getKey()), e.getValue()); } } - @ClassValidator(value = ProxiedPlayer.class, local = true) - public TypeValidator noPoll() { - return (sender, value, messageSender) -> { - if (PollSystem.noCurrentPoll()) { - messageSender.send("POLL_NO_POLL"); - return false; - } - return true; - }; + @ClassValidator(value = Chatter.class, local = true) + public TypeValidator noPoll() { + return PollSystem.noPoll(); } } diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index d279492d..44f5855a 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -54,7 +54,6 @@ import java.util.stream.Collectors; public class PunishmentCommand { private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; - private static final JsonParser jsonParser = new JsonParser(); public static SteamwarUser getOrCreateOfflinePlayer(String name) { SteamwarUser user = SteamwarUser.get(name); @@ -73,7 +72,7 @@ public class PunishmentCommand { private static UUID getUUIDofOfflinePlayer(String playerName) { try { final URL url = new URL(API_URL + playerName); - String uuid = jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); + String uuid = JsonParser.parseString(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString(); return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); } catch (NoSuchElementException e) { // ignore, player does not exist @@ -93,8 +92,6 @@ public class PunishmentCommand { } public static void ban(SteamwarUser user, Timestamp time, String banReason, SteamwarUser punisher, boolean perma) { - user.punish(Punishment.PunishmentType.Ban, time, banReason, punisher.getId(), perma); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); if (player != null) { String ip = IPSanitizer.getTrueAddress(player.getPendingConnection()).getHostAddress(); @@ -119,94 +116,17 @@ public class PunishmentCommand { } public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { - new SWCommand(command, ConnectionListener.BAN_PERMISSION) { + new PunishCommand(command, punishmentType); - @Register - public void genericCommand(ProxiedPlayer player, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) { - SteamwarUser punisher = SteamwarUser.get(player.getUniqueId()); - if (punishmentType.isNeedsAdmin() && !punisher.hasPerm(UserPerm.MODERATION)) { - return; - } + if (punishmentType.getUnpunishmentMessage() == null) + return; - SteamwarUser target = unsafeUser(player, toPunish); - if (target == null) - return; - - Timestamp banTime = parseTime(player, date); - if (banTime == null) - return; - - boolean isPerma = date.equalsIgnoreCase("perma"); - String msg = String.join(" ", message); - if(punishmentType == Punishment.PunishmentType.Ban) - ban(target, banTime, msg, punisher, isPerma); - else - target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); - Chatter.serverteam().system(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); - } - - @Register - public void genericError(ProxiedPlayer player, String... args) { - Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); - } - - @Mapper(value = "toPunish", local = true) - public TypeMapper allUsers() { - return new TypeMapper() { - @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { - return s; - } - - @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { - List players = BungeeCord.getInstance().getPlayers().stream() - .map(CommandSender::getName) - .collect(Collectors.toList()); - players.add(s); - return players; - } - }; - } - }; - - if (punishmentType.getUnpunishmentMessage() == null) return; - String antiCommand = "un" + command; - new SWCommand(antiCommand, ConnectionListener.BAN_PERMISSION) { - @Register - public void genericCommand(ProxiedPlayer player, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { - if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.MODERATION)) { - return; - } - - if (!target.isPunished(punishmentType)) { - Message.send(punishmentType.getUsageNotPunished(), player); - return; - } - - Message.send(punishmentType.getUnpunishmentMessage(), player, target.getUserName()); - target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(player.getName()).getId(), false); - if(punishmentType == Punishment.PunishmentType.Ban) - BannedUserIPs.unbanIPs(target.getId()); - } - - @Register - public void genericError(ProxiedPlayer player, String... args) { - Chatter.of(player).send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", antiCommand)); - } - }; + new UnpunishCommand("un" + command, punishmentType); } - protected SteamwarUser unsafeUser(CommandSender sender, String arg){ - SteamwarUser target = getOrCreateOfflinePlayer(arg); - if(target == null) - Message.send("UNKNOWN_PLAYER", sender); - return target; - } + private static final Pattern RELATIVE_PATTERN = Pattern.compile("([1-9]\\d*[hdwmy])+"); - private static Pattern RELATIVE_PATTERN = Pattern.compile("([1-9]\\d*[hdwmy])+"); - - public static Timestamp parseTime(CommandSender sender, String arg) { + public static Timestamp parseTime(Chatter player, String arg) { if (arg.equalsIgnoreCase("perma")) { return Punishment.PERMA_TIME; } else { @@ -251,12 +171,109 @@ public class PunishmentCommand { Date parsedDate = dateFormat.parse(arg.split("_")[0]); return new java.sql.Timestamp(parsedDate.getTime()); } catch (ParseException exception) { - if (sender != null) { - Message.send("INVALID_TIME", sender); - } + player.system("INVALID_TIME"); return null; } } } } + + private static class PunishCommand extends SWCommand { + + private final String command; + private final Punishment.PunishmentType punishmentType; + + private PunishCommand(String command, Punishment.PunishmentType punishmentType) { + super(command, ConnectionListener.BAN_PERMISSION); + this.command = command; + this.punishmentType = punishmentType; + } + + private SteamwarUser unsafeUser(Chatter sender, String arg) { + SteamwarUser target = getOrCreateOfflinePlayer(arg); + if(target == null) + sender.system("UNKNOWN_PLAYER"); + return target; + } + + @Register + public void genericCommand(Chatter sender, @Mapper("toPunish") String toPunish, String date, @ErrorMessage(allowEAs = false, value = "PUNISHMENT_USAGE_REASON") String... message) { + SteamwarUser punisher = sender.user(); + if (punishmentType.isNeedsAdmin() && !punisher.hasPerm(UserPerm.MODERATION)) + return; + + SteamwarUser target = unsafeUser(sender, toPunish); + if (target == null) + return; + + Timestamp banTime = parseTime(sender, date); + if (banTime == null) + return; + + boolean isPerma = date.equalsIgnoreCase("perma"); + String msg = String.join(" ", message); + target.punish(punishmentType, banTime, msg, punisher.getId(), isPerma); + if(punishmentType == Punishment.PunishmentType.Ban) + ban(target, banTime, msg, punisher, isPerma); + Chatter.serverteam().system(punishmentType.getTeamMessage(), new Message("PREFIX"), target, sender, new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg); + } + + @Register + public void genericError(Chatter sender, String... args) { + sender.send(true, ChatMessageType.CHAT, null, null, new Message("PUNISHMENT_USAGE", command)); + } + + @Mapper(value = "toPunish", local = true) + public TypeMapper allUsers() { + return new TypeMapper() { + @Override + public String map(Chatter sender, PreviousArguments previousArguments, String s) { + return s; + } + + @Override + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { + List players = BungeeCord.getInstance().getPlayers().stream() + .map(CommandSender::getName) + .collect(Collectors.toList()); + players.add(s); + return players; + } + }; + } + } + + private static class UnpunishCommand extends SWCommand { + + private final String command; + private final Punishment.PunishmentType punishmentType; + + private UnpunishCommand(String command, Punishment.PunishmentType punishmentType) { + super(command, ConnectionListener.BAN_PERMISSION); + this.command = command; + this.punishmentType = punishmentType; + } + + @Register + public void genericCommand(Chatter sender, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { + if (punishmentType.isNeedsAdmin() && !sender.user().hasPerm(UserPerm.MODERATION)) + return; + + if (!target.isPunished(punishmentType)) { + sender.system(punishmentType.getUsageNotPunished()); + return; + } + + target.punish(punishmentType, Timestamp.from(new Date().toInstant()), command, sender.user().getId(), false); + if(punishmentType == Punishment.PunishmentType.Ban) + BannedUserIPs.unbanIPs(target.getId()); + + sender.system(punishmentType.getUnpunishmentMessage(), target.getUserName()); + } + + @Register + public void genericError(Chatter sender, String... args) { + sender.send(true, ChatMessageType.CHAT, null, null, new Message("UNPUNISHMENT_USAGE", command)); + } + } } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 549f1975..d2efdb99 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -24,6 +24,7 @@ import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.CommandSender; @@ -41,15 +42,8 @@ public class TypeMappers { SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - private static TypeValidator arenaPlayer() { - return (sender, value, messageSender) -> { - Chatter player = Chatter.of(value); - if (PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { - return false; - } - - return true; - }; + private static TypeValidator arenaPlayer() { + return (sender, player, messageSender) -> !PunishmentCommand.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer); } private static TypeMapper arenaModeTypeMapper(boolean historic) { diff --git a/src/de/steamwar/bungeecore/inventory/SWInventory.java b/src/de/steamwar/bungeecore/inventory/SWInventory.java index a100f2dc..51024444 100644 --- a/src/de/steamwar/bungeecore/inventory/SWInventory.java +++ b/src/de/steamwar/bungeecore/inventory/SWInventory.java @@ -66,6 +66,7 @@ public class SWInventory { addItem(pos, item, new ArrayList<>(), callback); } + @Deprecated public void addItem(int pos, SWItem item, List lore, InvCallback callback) { item.setCallback(callback); item.setLore(lore); diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 72701650..fc14d034 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.util.Chat19; import de.steamwar.messages.Chatter; import de.steamwar.messages.ChatterGroup; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.PingPacket; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; @@ -122,20 +123,19 @@ public class ChatListener extends BasicListener { } } - public static void localChat(ProxiedPlayer player, String message) { - Chatter sender = Chatter.of(player); + public static void localChat(PlayerChatter sender, String message) { if(message.length() == 0){ sender.system("CHAT_BC_USAGE"); return; } - if(ChatListener.filteredCommand(player, message)) + if(ChatListener.filteredCommand(sender.getPlayer(), message)) return; if(!message.startsWith("/") && chatFilter(sender, message)) return; - Chat19.chat(player, message); + Chat19.chat(sender.getPlayer(), message); } private static boolean chatFilter(Chatter sender, String message) { diff --git a/src/de/steamwar/bungeecore/listeners/PollSystem.java b/src/de/steamwar/bungeecore/listeners/PollSystem.java index b0bf9527..4814c642 100644 --- a/src/de/steamwar/bungeecore/listeners/PollSystem.java +++ b/src/de/steamwar/bungeecore/listeners/PollSystem.java @@ -20,10 +20,10 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.Message; +import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; import de.steamwar.sql.PollAnswer; -import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; @@ -47,29 +47,37 @@ public class PollSystem extends BasicListener { @EventHandler public void onPostLogin(PostLoginEvent event){ - ProxiedPlayer player = event.getPlayer(); - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + Chatter player = Chatter.of(event.getPlayer()); - PollAnswer answer = PollAnswer.get(user.getId()); + PollAnswer answer = PollAnswer.get(player.user().getId()); if(answer.hasAnswered()) return; sendPoll(player); } - public static void sendPoll(ProxiedPlayer player){ - Message.send("POLL_HEADER", player); - Message.sendPrefixless("POLL_HEADER2", player); - Message.sendPrefixless("POLL_QUESTION", player, question); + public static void sendPoll(Chatter player) { + player.system("POLL_HEADER"); + player.prefixless("POLL_HEADER2"); + player.prefixless("POLL_QUESTION", question); - for(int i = 1; i <= answers.size(); i++){ - Message.send("POLL_ANWSER", player, Message.parse("POLL_ANWSER_HOVER", player, answers.get(i-1)), - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1)); + for(int i = 1; i <= answers.size(); i++) { + player.prefixless("POLL_ANSWER", new Message("POLL_ANSWER_HOVER", answers.get(i-1)), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1)); } } public static boolean noCurrentPoll(){ - return question == null || question.equals(""); + return question == null || question.isEmpty(); + } + + public static TypeValidator noPoll() { + return (sender, value, messageSender) -> { + if (PollSystem.noCurrentPoll()) { + sender.system("POLL_NO_POLL"); + return false; + } + return true; + }; } public static int answers(){ diff --git a/src/de/steamwar/bungeecore/util/BauLock.java b/src/de/steamwar/bungeecore/util/BauLock.java index fe0a5a4c..00073819 100644 --- a/src/de/steamwar/bungeecore/util/BauLock.java +++ b/src/de/steamwar/bungeecore/util/BauLock.java @@ -19,27 +19,22 @@ package de.steamwar.bungeecore.util; -import de.steamwar.bungeecore.Message; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ProxiedPlayer; @UtilityClass public class BauLock { private static final String BAU_LOCK_CONFIG_NAME = "baulockstate"; - public static void setLocked(ProxiedPlayer p, BauLockState state) { - SteamwarUser owner = SteamwarUser.get(p.getUniqueId()); - UserConfig.updatePlayerConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); - Message.send("BAU_LOCKED_" + state.name(), p); + public static void setLocked(Chatter owner, BauLockState state) { + UserConfig.updatePlayerConfig(owner.user().getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name()); + owner.system("BAU_LOCKED_" + state.name()); } - public static boolean checkNotifyLocked(SteamwarUser owner, ProxiedPlayer player) { - Chatter sender = Chatter.of(player); + public static boolean checkNotifyLocked(SteamwarUser owner, Chatter sender) { SteamwarUser target = sender.user(); if (owner.getId() == target.getId()) return false; @@ -69,10 +64,7 @@ public class BauLock { if(locked) { sender.system("BAU_LOCKED_NOALLOWED"); - - ProxiedPlayer ownerPlayer = ProxyServer.getInstance().getPlayer(owner.getUUID()); - if(ownerPlayer != null) - Chatter.of(ownerPlayer).system("BAU_LOCK_BLOCKED", player.getName()); + Chatter.of(owner.getUUID()).system("BAU_LOCK_BLOCKED", sender); } return locked; diff --git a/src/de/steamwar/command/CommandRegistering.java b/src/de/steamwar/command/CommandRegistering.java deleted file mode 100644 index b6a49948..00000000 --- a/src/de/steamwar/command/CommandRegistering.java +++ /dev/null @@ -1,37 +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.command; - -import de.steamwar.bungeecore.BungeeCore; -import lombok.experimental.UtilityClass; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.plugin.Command; - -@UtilityClass -class CommandRegistering { - - static void unregister(Command command) { - ProxyServer.getInstance().getPluginManager().unregisterCommand(command); - } - - static void register(Command command) { - ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command); - } -} diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 536a891a..a6a50d9b 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -23,27 +23,28 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.messages.Chatter; 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.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.logging.Level; -public class SWCommand extends AbstractSWCommand { +public class SWCommand extends AbstractSWCommand { static { TypeUtils.init(); } - private String permission; + private final String permission; private Command command; - private List defaultHelpMessages = new ArrayList<>(); + private final List defaultHelpMessages = new ArrayList<>(); protected SWCommand(String command) { this(command, null); @@ -54,7 +55,7 @@ public class SWCommand extends AbstractSWCommand { } protected SWCommand(String command, String permission, String... aliases) { - super(CommandSender.class, command, aliases); + super(Chatter.class, command, aliases); this.permission = permission; create = true; createAndSafeCommand(command, aliases); @@ -70,12 +71,12 @@ public class SWCommand extends AbstractSWCommand { this.command = new TabCompletableCommand(command, permission, aliases) { @Override public void execute(CommandSender commandSender, String[] strings) { - SWCommand.this.execute(commandSender, null, strings); + SWCommand.this.execute(Chatter.of(commandSender), null, strings); } @Override public Iterable onTabComplete(CommandSender commandSender, String[] strings) { - return SWCommand.this.tabComplete(commandSender, null, strings); + return SWCommand.this.tabComplete(Chatter.of(commandSender), null, strings); } }; } @@ -89,19 +90,19 @@ public class SWCommand extends AbstractSWCommand { @Override public void unregister() { if (command == null) return; - CommandRegistering.unregister(this.command); + ProxyServer.getInstance().getPluginManager().unregisterCommand(this.command); } @Override public void register() { if (command == null) return; - CommandRegistering.register(this.command); + ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), this.command); } @Override - protected void commandSystemError(CommandSender sender, CommandFrameworkException e) { + protected void commandSystemError(Chatter sender, CommandFrameworkException e) { BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e); - Chatter.of(sender).prefixless("COMMAND_SYSTEM_ERROR"); + sender.prefixless("COMMAND_SYSTEM_ERROR"); } @Override @@ -114,16 +115,15 @@ public class SWCommand extends AbstractSWCommand { } @Override - protected void sendMessage(CommandSender sender, String message, Object[] args) { - Chatter.of(sender).system(message, args); + protected void sendMessage(Chatter sender, String message, Object[] args) { + sender.system(message, args); } @Register(noTabComplete = true) - public void internalHelp(ProxiedPlayer p, String... args) { - Chatter chatter = Chatter.of(p); + public void internalHelp(Chatter sender, String... args) { try { - chatter.prefixless("COMMAND_HELP_HEAD", command.getName()); - defaultHelpMessages.forEach(chatter::prefixless); + sender.prefixless("COMMAND_HELP_HEAD", command.getName()); + defaultHelpMessages.forEach(sender::prefixless); } catch (Exception e) { BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e); return; @@ -131,7 +131,7 @@ public class SWCommand extends AbstractSWCommand { AtomicInteger atomicInteger = new AtomicInteger(); if (args.length != 0) { commandList.forEach(subCommand -> { - List tabCompletes = subCommand.tabComplete(p, args); + List tabCompletes = subCommand.tabComplete(sender, args); if (tabCompletes == null || tabCompletes.isEmpty()) { atomicInteger.incrementAndGet(); return; @@ -139,7 +139,7 @@ public class SWCommand extends AbstractSWCommand { boolean hasTabCompletes = tabCompletes.stream() .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { - send(chatter, subCommand); + send(sender, subCommand); } else { atomicInteger.incrementAndGet(); } @@ -147,14 +147,14 @@ public class SWCommand extends AbstractSWCommand { } if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { - if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) { - send(chatter, subCommand); + if (subCommand.validator == null || subCommand.validator.validate(sender, sender, (s, args1) -> {})) { + send(sender, subCommand); } }); } } - private void send(Chatter chatter, SubCommand subCommand) { + private void send(Chatter chatter, SubCommand subCommand) { try { for (String s : subCommand.description) { String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); @@ -162,7 +162,7 @@ public class SWCommand extends AbstractSWCommand { chatter.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); } } catch (Exception e) { - BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + Arrays.toString(subCommand.description) + "'", e); } } } diff --git a/src/de/steamwar/command/TypeMapper.java b/src/de/steamwar/command/TypeMapper.java index 1d9cb72c..5b592260 100644 --- a/src/de/steamwar/command/TypeMapper.java +++ b/src/de/steamwar/command/TypeMapper.java @@ -19,11 +19,11 @@ package de.steamwar.command; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; -public interface TypeMapper extends AbstractTypeMapper { +public interface TypeMapper extends AbstractTypeMapper { /** * The CommandSender can be null! */ - T map(CommandSender commandSender, String[] previousArguments, String s); + T map(Chatter sender, PreviousArguments previousArguments, String s); } diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index 2a6d7a73..8b834e55 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -21,11 +21,11 @@ package de.steamwar.command; import de.steamwar.bungeecore.ServerVersion; import de.steamwar.bungeecore.commands.TypeMappers; +import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Collection; @@ -41,9 +41,10 @@ public class TypeUtils { SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper() { @Override - public ServerVersion map(CommandSender sender, String[] previousArguments, String s) { - if (sender instanceof ProxiedPlayer && s.isEmpty()) { - int version = ((ProxiedPlayer) sender).getPendingConnection().getVersion(); + public ServerVersion map(Chatter sender, PreviousArguments previousArguments, String s) { + ProxiedPlayer player = sender.getPlayer(); + if(player != null && s.isEmpty()) { + int version = player.getPendingConnection().getVersion(); if (version > 762) { // Version > 1.19.4 return ServerVersion.PAPER_20; } else if (version > 578) { // Version > 1.15.2 @@ -59,7 +60,7 @@ public class TypeUtils { } @Override - public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return ServerVersion.chatVersions(); } }); diff --git a/src/de/steamwar/command/TypeValidator.java b/src/de/steamwar/command/TypeValidator.java index 6bb76f66..2986b7da 100644 --- a/src/de/steamwar/command/TypeValidator.java +++ b/src/de/steamwar/command/TypeValidator.java @@ -19,7 +19,6 @@ package de.steamwar.command; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.messages.Chatter; -public interface TypeValidator extends AbstractValidator { -} +public interface TypeValidator extends AbstractValidator {} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 64c80e45..7f092d61 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -569,8 +569,8 @@ EVENTMODE_KICK=§cYou are not an event participant. POLL_HEADER=§e§lPoll POLL_HEADER2=§7Click the answer you like! POLL_QUESTION=§e{0} -POLL_ANWSER=§7{0} -POLL_ANWSER_HOVER=§eChoose {0} +POLL_ANSWER=§7{0} +POLL_ANSWER_HOVER=§eChoose {0} #TablistManager TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 40a350b0..b90367a1 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -545,8 +545,8 @@ EVENTMODE_KICK=§cDu bist kein Eventteilnehmer. POLL_HEADER=§e§lUmfrage POLL_HEADER2=§7Klicke die Antwort an, die dir gefällt! POLL_QUESTION=§e{0} -POLL_ANWSER=§7{0} -POLL_ANWSER_HOVER=§e{0} §ewählen +POLL_ANSWER=§7{0} +POLL_ANSWER_HOVER=§e{0} §ewählen #TablistManager TABLIST_PHASE_WEBSITE=§8Website: https://§eSteam§8War.de diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java index fc122406..8e9f2c7f 100644 --- a/src/de/steamwar/messages/Chatter.java +++ b/src/de/steamwar/messages/Chatter.java @@ -44,8 +44,9 @@ import java.util.Date; import java.util.Locale; import java.util.ResourceBundle; import java.util.UUID; -import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Stream; @@ -78,11 +79,25 @@ public interface Chatter { Locale getLocale(); boolean chatShown(); - void sendMessage(ChatMessageType type, BaseComponent... msg); - void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord); + void sendMessage(ChatMessageType type, BaseComponent msg); + ProxiedPlayer getPlayer(); + default T withPlayerOrOffline(Function withPlayer, Supplier withOffline) { + ProxiedPlayer player = getPlayer(); + if(player == null) + return withOffline.get(); + else + return withPlayer.apply(player); + } + default void withPlayerOrOffline(Consumer withPlayer, Runnable withOffline) { + ProxiedPlayer player = getPlayer(); + if(player == null) + withOffline.run(); + else + withPlayer.accept(player); + } default void withPlayer(Consumer function) { - withPlayerOrDiscord(function, user -> {}); + withPlayerOrOffline(function, () -> {}); } default void chat(Message message) { @@ -164,41 +179,12 @@ public interface Chatter { return TextComponent.fromLegacy(format.format(params)); } - static Chatter ofProxiedPlayer(ProxiedPlayer player, BiConsumer sendMessage) { - return new Chatter() { - @Override - public SteamwarUser user() { - return SteamwarUser.get(player.getUniqueId()); - } - - @Override - public Locale getLocale() { - return user().getLocale(); - } - - @Override - public boolean chatShown() { - return player.getChatMode() == ProxiedPlayer.ChatMode.SHOWN; - } - - @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { - sendMessage.accept(type, msg); - } - - @Override - public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { - withPlayer.accept(player); - } - }; + static PlayerChatter of(ProxiedPlayer player) { + return new PlayerChatter(player, player::sendMessage); } - static Chatter of(ProxiedPlayer player) { - return ofProxiedPlayer(player, player::sendMessage); - } - - static Chatter disconnect(ProxiedPlayer player) { - return ofProxiedPlayer(player, (type, msg) -> player.disconnect(msg)); + static PlayerChatter disconnect(ProxiedPlayer player) { + return new PlayerChatter(player, (type, msg) -> player.disconnect(msg)); } static Chatter of(CommandSender sender) { @@ -218,12 +204,16 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { sender.sendMessage(msg); } }; } + static Chatter of(SteamwarUser user) { + return of(user.getUUID()); + } + static Chatter of(UUID uuid) { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if(player != null) @@ -241,7 +231,7 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { // Nowhere to send } }; @@ -264,8 +254,9 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { - event.setCancelReason(msg); + public void sendMessage(ChatMessageType type, BaseComponent msg) { + event.setReason(msg); + event.setCancelled(true); } }; } @@ -283,9 +274,9 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { try { - channel.send(" " + new TextComponent(msg).toPlainText()); + channel.send(" " + msg.toPlainText()); } catch (Exception e) { BungeeCore.get().getLogger().log(Level.SEVERE, "Could not send chat message to discord", e); } @@ -306,7 +297,7 @@ public interface Chatter { } @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { try { message.delete().queue(); } catch (Exception e) { @@ -319,12 +310,12 @@ public interface Chatter { abstract class PlayerlessChatter implements Chatter { @Override public Locale getLocale() { - return Locale.getDefault(); + return user().getLocale(); } @Override - public void withPlayerOrDiscord(Consumer withPlayer, Consumer withDiscord) { - withDiscord.accept(user()); + public ProxiedPlayer getPlayer() { + return ProxyServer.getInstance().getPlayer(user().getUUID()); } } } diff --git a/src/de/steamwar/messages/ChatterGroup.java b/src/de/steamwar/messages/ChatterGroup.java index ebdd92a3..d2d5289e 100644 --- a/src/de/steamwar/messages/ChatterGroup.java +++ b/src/de/steamwar/messages/ChatterGroup.java @@ -27,11 +27,10 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import java.util.Arrays; -import java.util.Locale; import java.util.stream.Stream; @Getter -public class ChatterGroup implements Chatter { +public class ChatterGroup extends Chatter.PlayerlessChatter { final Chatter[] chatters; @@ -60,12 +59,7 @@ public class ChatterGroup implements Chatter { } @Override - public Locale getLocale() { - throw new UnsupportedOperationException(); - } - - @Override - public void sendMessage(ChatMessageType type, BaseComponent... msg) { + public void sendMessage(ChatMessageType type, BaseComponent msg) { throw new UnsupportedOperationException(); } } diff --git a/src/de/steamwar/messages/PlayerChatter.java b/src/de/steamwar/messages/PlayerChatter.java new file mode 100644 index 00000000..b2720d67 --- /dev/null +++ b/src/de/steamwar/messages/PlayerChatter.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.messages; + +import de.steamwar.sql.SteamwarUser; +import lombok.AllArgsConstructor; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.Locale; +import java.util.function.BiConsumer; + +@AllArgsConstructor +public class PlayerChatter implements Chatter { + + private final ProxiedPlayer player; + private final BiConsumer sendMessage; + + @Override + public SteamwarUser user() { + return SteamwarUser.get(player.getUniqueId()); + } + + @Override + public Locale getLocale() { + return user().getLocale(); + } + + @Override + public boolean chatShown() { + return player.getChatMode() == ProxiedPlayer.ChatMode.SHOWN; + } + + @Override + public void sendMessage(ChatMessageType type, BaseComponent msg) { + sendMessage.accept(type, msg); + } + + @Override + public ProxiedPlayer getPlayer() { + return player; + } +} From c39e2a056697b70328eca731bdbfe32079b391fc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 15 Jun 2024 12:16:18 +0200 Subject: [PATCH 04/22] Message deprecation, Discord refactoring Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/Broadcaster.java | 5 +- src/de/steamwar/bungeecore/BungeeCore.java | 131 +---- src/de/steamwar/bungeecore/Message.java | 118 ----- .../steamwar/bungeecore/SubserverSystem.java | 14 +- .../steamwar/bungeecore/bot/AuthManager.java | 81 ---- .../bungeecore/bot/SteamwarDiscordBot.java | 166 ------- .../bungeecore/bot/commands/BanCommand.java | 67 --- .../bot/commands/BasicDiscordCommand.java | 54 --- .../bungeecore/bot/commands/ListCommand.java | 43 -- .../bungeecore/bot/commands/MuteCommand.java | 68 --- .../bungeecore/bot/commands/TeamCommand.java | 96 ---- .../bungeecore/bot/commands/UnbanCommand.java | 62 --- .../bungeecore/bot/commands/WhoisCommand.java | 94 ---- .../bot/listeners/AnnouncementListener.java | 50 -- .../bot/listeners/BasicDiscordListener.java | 30 -- .../bot/listeners/DiscordAuthListener.java | 59 --- .../bot/listeners/DiscordChatListener.java | 71 --- .../bot/listeners/DiscordEventListener.java | 93 ---- .../bot/listeners/DiscordTicketListener.java | 158 ------ .../bot/listeners/PrivateMessageListener.java | 80 --- .../RolesInteractionButtonListener.java | 42 -- .../bot/listeners/SlashCommandListener.java | 32 -- .../bungeecore/bot/util/DiscordRanks.java | 69 --- .../bot/util/DiscordRolesMessage.java | 61 --- .../bot/util/DiscordRulesMessage.java | 68 --- .../bot/util/DiscordTicketMessage.java | 76 --- .../bungeecore/commands/AlertCommand.java | 8 +- .../bungeecore/commands/ArenaCommand.java | 2 +- .../bungeecore/commands/BauCommand.java | 5 +- .../bungeecore/commands/ChallengeCommand.java | 1 + .../bungeecore/commands/CheckCommand.java | 3 +- .../bungeecore/commands/FightCommand.java | 1 + .../bungeecore/commands/HelpCommand.java | 2 +- .../bungeecore/commands/ModCommand.java | 2 +- .../commands/PunishmentCommand.java | 2 +- .../bungeecore/commands/RCommand.java | 6 +- .../bungeecore/commands/RankCommand.java | 29 +- .../bungeecore/commands/RegelnCommand.java | 42 -- .../bungeecore/commands/ReplayCommand.java | 43 +- .../RulesCommand.java} | 33 +- .../commands/ServerSwitchCommand.java | 6 +- .../commands/ServerTeamchatCommand.java | 5 +- .../bungeecore/commands/SetLocaleCommand.java | 8 +- .../bungeecore/commands/StatCommand.java | 10 +- .../bungeecore/commands/TeamCommand.java | 458 +++++++----------- .../bungeecore/commands/TeamchatCommand.java | 4 +- .../bungeecore/commands/TpCommand.java | 44 +- .../bungeecore/commands/TutorialCommand.java | 85 ++-- .../bungeecore/commands/TypeMappers.java | 19 +- .../bungeecore/commands/UnIgnoreCommand.java | 19 +- .../bungeecore/commands/VerifyCommand.java | 30 +- .../commands/WebpasswordCommand.java | 11 +- .../bungeecore/commands/WhoisCommand.java | 79 ++- .../bungeecore/discord/DiscordBot.java | 208 ++++++++ .../channels/ChecklistChannel.java} | 37 +- .../discord/channels/DiscordChannel.java | 103 ++++ .../discord/channels/DiscordChatRoom.java | 53 ++ .../channels/EventChannel.java} | 76 +-- .../discord/channels/InteractionReply.java | 65 +++ .../channels/StaticMessageChannel.java | 69 +++ .../config/DiscordConfig.java} | 54 +-- .../{bot => discord}/config/DiscordRole.java | 2 +- .../config/DiscordTicketType.java | 25 +- .../discord/listeners/ChannelListener.java | 83 ++++ .../discord/listeners/DiscordSchemUpload.java | 90 ++++ .../discord/listeners/DiscordTeamEvent.java | 65 +++ .../listeners/DiscordTicketHandler.java | 157 ++++++ .../bungeecore/discord/util/AuthManager.java | 72 +++ .../{bot => discord}/util/DiscordAlert.java | 36 +- .../bungeecore/discord/util/DiscordRanks.java | 56 +++ .../bungeecore/inventory/InvCallback.java | 2 +- .../bungeecore/inventory/SWInventory.java | 21 +- .../steamwar/bungeecore/inventory/SWItem.java | 57 +-- .../bungeecore/inventory/SWListInv.java | 39 +- .../bungeecore/inventory/SWStreamInv.java | 23 +- .../bungeecore/listeners/BanListener.java | 7 +- .../bungeecore/listeners/BasicListener.java | 2 +- .../bungeecore/listeners/ChatListener.java | 31 +- .../bungeecore/listeners/CheckListener.java | 17 +- .../listeners/ConnectionListener.java | 90 ++-- .../listeners/EventModeListener.java | 19 +- .../bungeecore/listeners/PluginMessage.java | 2 +- .../bungeecore/listeners/PollSystem.java | 2 +- src/de/steamwar/bungeecore/mods/FML.java | 3 +- src/de/steamwar/bungeecore/mods/ModUtils.java | 12 +- .../network/BungeeNetworkHandler.java | 36 -- .../bungeecore/network/NetworkSender.java | 2 + .../bungeecore/network/ServerMetaInfo.java | 14 +- .../network/handlers/EloPlayerHandler.java | 34 +- .../network/handlers/EloSchemHandler.java | 14 +- .../handlers/InventoryCallbackHandler.java | 7 +- .../steamwar/bungeecore/tablist/Tablist.java | 2 +- .../bungeecore/tablist/TablistPart.java | 2 +- src/de/steamwar/command/SWCommand.java | 17 +- .../steamwar/messages/BungeeCore.properties | 31 +- .../messages/BungeeCore_de.properties | 30 +- src/de/steamwar/messages/Chatter.java | 64 +-- src/de/steamwar/messages/ChatterGroup.java | 1 - src/de/steamwar/messages/Message.java | 34 ++ .../messages/SteamwarResourceBundle.java | 2 - 100 files changed, 1806 insertions(+), 2907 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/Message.java delete mode 100644 src/de/steamwar/bungeecore/bot/AuthManager.java delete mode 100644 src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/BanCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/ListCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/MuteCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/TeamCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java delete mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordRanks.java delete mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java delete mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java delete mode 100644 src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java delete mode 100644 src/de/steamwar/bungeecore/commands/RegelnCommand.java rename src/de/steamwar/bungeecore/{bot/config/DiscordRulesLink.java => commands/RulesCommand.java} (51%) create mode 100644 src/de/steamwar/bungeecore/discord/DiscordBot.java rename src/de/steamwar/bungeecore/{bot/events/SchematicsManager.java => discord/channels/ChecklistChannel.java} (54%) create mode 100644 src/de/steamwar/bungeecore/discord/channels/DiscordChannel.java create mode 100644 src/de/steamwar/bungeecore/discord/channels/DiscordChatRoom.java rename src/de/steamwar/bungeecore/{bot/events/EventManager.java => discord/channels/EventChannel.java} (63%) create mode 100644 src/de/steamwar/bungeecore/discord/channels/InteractionReply.java create mode 100644 src/de/steamwar/bungeecore/discord/channels/StaticMessageChannel.java rename src/de/steamwar/bungeecore/{bot/config/SteamwarDiscordBotConfig.java => discord/config/DiscordConfig.java} (70%) rename src/de/steamwar/bungeecore/{bot => discord}/config/DiscordRole.java (96%) rename src/de/steamwar/bungeecore/{bot => discord}/config/DiscordTicketType.java (60%) create mode 100644 src/de/steamwar/bungeecore/discord/listeners/ChannelListener.java create mode 100644 src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java create mode 100644 src/de/steamwar/bungeecore/discord/listeners/DiscordTeamEvent.java create mode 100644 src/de/steamwar/bungeecore/discord/listeners/DiscordTicketHandler.java create mode 100644 src/de/steamwar/bungeecore/discord/util/AuthManager.java rename src/de/steamwar/bungeecore/{bot => discord}/util/DiscordAlert.java (55%) create mode 100644 src/de/steamwar/bungeecore/discord/util/DiscordRanks.java delete mode 100644 src/de/steamwar/bungeecore/network/BungeeNetworkHandler.java create mode 100644 src/de/steamwar/messages/Message.java diff --git a/src/de/steamwar/bungeecore/Broadcaster.java b/src/de/steamwar/bungeecore/Broadcaster.java index 3020d013..6a06f7f0 100644 --- a/src/de/steamwar/bungeecore/Broadcaster.java +++ b/src/de/steamwar/bungeecore/Broadcaster.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore; +import de.steamwar.messages.Chatter; import net.md_5.bungee.api.ProxyServer; import java.util.concurrent.TimeUnit; @@ -28,10 +29,10 @@ class Broadcaster { private static String [] broadCastMsgs; private int lastBroadCast = 0; - Broadcaster(){ + Broadcaster() { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { if(!ProxyServer.getInstance().getPlayers().isEmpty() && broadCastMsgs.length > 0) - BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + broadCastMsgs[lastBroadCast]); + Chatter.broadcast().system("PLAIN_STRING", broadCastMsgs[lastBroadCast]); lastBroadCast++; if(lastBroadCast == broadCastMsgs.length){ lastBroadCast = 0; diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index f005033b..1dd3eae6 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -19,29 +19,23 @@ package de.steamwar.bungeecore; -import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.commands.*; +import de.steamwar.bungeecore.discord.DiscordBot; +import de.steamwar.bungeecore.discord.config.DiscordConfig; import de.steamwar.bungeecore.listeners.*; -import de.steamwar.bungeecore.mods.ServerListPing; import de.steamwar.bungeecore.mods.*; -import de.steamwar.bungeecore.network.BungeeNetworkHandler; +import de.steamwar.bungeecore.network.handlers.*; import de.steamwar.bungeecore.tablist.TablistManager; import de.steamwar.command.*; import de.steamwar.messages.Chatter; +import de.steamwar.network.packets.PacketHandler; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import de.steamwar.sql.UserElo; import de.steamwar.sql.internal.Statement; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.CommandSender; +import lombok.Getter; 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.config.ServerInfo; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; @@ -58,18 +52,19 @@ import java.util.logging.Level; public class BungeeCore extends Plugin { public static boolean MAIN_SERVER; - - @Deprecated - public static String CHAT_PREFIX; - public static String LOBBY_SERVER; public static boolean EVENT_MODE; + public static String LOBBY_SERVER; + private static BungeeCore instance; public static Node local; private ErrorLogger errorLogger; private TablistManager tablistManager; + @Getter + private TeamCommand teamCommand; + @Override public void onEnable(){ setInstance(this); @@ -120,7 +115,7 @@ public class BungeeCore extends Plugin { new JoinmeCommand(); new TpCommand(); HelpCommand helpCommand = new HelpCommand(); - new TeamCommand(); + teamCommand = new TeamCommand(); new ServerTeamchatCommand(); new DevCommand(); new EventCommand(); @@ -129,7 +124,7 @@ public class BungeeCore extends Plugin { new PollCommand(); new BugCommand(); new WhoisCommand(); - new RegelnCommand(); + new RulesCommand(); new IgnoreCommand(); new UnIgnoreCommand(); new PollresultCommand(); @@ -143,6 +138,7 @@ public class BungeeCore extends Plugin { new LocalCommand(); new SetLocaleCommand(); new BuilderCloudCommand(); + new CheckCommand(); new ModCommand(); @@ -163,7 +159,6 @@ public class BungeeCore extends Plugin { new FightCommand(); new ChallengeCommand(); new HistoricCommand(); - new CheckCommand(); new ReplayCommand(); new TutorialCommand(); @@ -172,9 +167,14 @@ public class BungeeCore extends Plugin { new EventModeListener(); } + for(PacketHandler handler : new PacketHandler[] { + new EloPlayerHandler(), new EloSchemHandler(), new ExecuteCommandHandler(), new FightInfoHandler(), + new ImALobbyHandler(), new InventoryCallbackHandler(), new PrepareSchemHandler() + }) + handler.register(); + new EventStarter(); new SessionManager(); - BungeeNetworkHandler.register(); tablistManager = new TablistManager(); new SettingsChangedListener(); @@ -184,9 +184,9 @@ public class BungeeCore extends Plugin { Team.clear(); }, 1, 1, TimeUnit.HOURS); - if (SteamwarDiscordBotConfig.loaded) { + if (DiscordConfig.loaded) { try { - new SteamwarDiscordBot(); + new DiscordBot(); } catch (Throwable e) { getLogger().log(Level.SEVERE, "Could not initialize discord bot", e); } @@ -195,12 +195,10 @@ public class BungeeCore extends Plugin { @Override public void onDisable(){ - if (SteamwarDiscordBotConfig.loaded) { - try { - SteamwarDiscordBot.instance().getJda().shutdown(); - } catch (Throwable e) { - getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e); - } + try { + DiscordBot.withBot(bot -> bot.getJda().shutdown()); + } catch (Throwable e) { + getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e); } if(tablistManager != null) @@ -213,73 +211,6 @@ public class BungeeCore extends Plugin { return instance; } - @Deprecated - public static TextComponent stringToText(String msg){ - return new TextComponent(TextComponent.fromLegacyText(msg)); - } - @Deprecated - public static void send(ProxiedPlayer player, String msg){ - send(player, msg, null, null); - } - @Deprecated - public static void send(CommandSender sender, String msg){ - sender.sendMessage(stringToText(msg)); - } - @Deprecated - public static void send(ProxiedPlayer player, ChatMessageType type, String msg){ - send(player, type, msg, null, null); - } - @Deprecated - public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){ - send(player, ChatMessageType.SYSTEM, msg, onHover, onClick); - } - @Deprecated - public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){ - if(type == ChatMessageType.CHAT && player.getChatMode() != ProxiedPlayer.ChatMode.SHOWN) - return; - TextComponent message = stringToText(msg); - if(onHover != null) - message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); - if(onClick != null) - message.setClickEvent(onClick); - player.sendMessage(type, message); - } - @Deprecated - public static void broadcast(String msg){ - ProxyServer.getInstance().broadcast(stringToText(msg)); - } - @Deprecated - public static void broadcast(String msg, String onHover, ClickEvent onClick){ - TextComponent message = stringToText(msg); - if(onHover != null) - message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); - if(onClick != null) - message.setClickEvent(onClick); - ProxyServer.getInstance().broadcast(message); - } - - @Deprecated - public static void log(final ServerInfo server, final String msg){ - log(server.getName() + ": " + msg); - } - @Deprecated - public static void log(final ProxiedPlayer player, final String msg){ - log(player.getName() + ": " + msg); - } - @Deprecated - public static void log(final String msg){ - log(Level.INFO, msg); - } - @Deprecated - public static void log(final Level logLevel, final String msg){ - get().getLogger().log(logLevel, msg); - } - @Deprecated - public static void log(final String msg, final Throwable e){ - get().getLogger().log(Level.SEVERE, msg, e); - } - - private static void loadConfig(){ Configuration config; try{ @@ -296,12 +227,11 @@ public class BungeeCore extends Plugin { } config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); }catch(Exception e){ - log("Could not save/load config.yml", e); + get().getLogger().log(Level.SEVERE, "Could not save/load config.yml", e); ProxyServer.getInstance().stop(); return; } - CHAT_PREFIX = config.getString("prefix"); LOBBY_SERVER = config.getString("lobbyserver"); EVENT_MODE = config.getBoolean("eventmode"); Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1])); @@ -322,15 +252,6 @@ public class BungeeCore extends Plugin { cmds.toArray(new String[0]) ); } - - File discordFile = new File(System.getProperty("user.home"), "discord.yml"); - if(discordFile.exists() && !EVENT_MODE) { - try { - SteamwarDiscordBotConfig.loadConfig(ConfigurationProvider.getProvider(YamlConfiguration.class).load(discordFile)); - } catch (IOException e) { - get().getLogger().log(Level.SEVERE, "Could not load discord bot configuration", e); - } - } } private static void setInstance(BungeeCore core){ diff --git a/src/de/steamwar/bungeecore/Message.java b/src/de/steamwar/bungeecore/Message.java deleted file mode 100644 index e1073667..00000000 --- a/src/de/steamwar/bungeecore/Message.java +++ /dev/null @@ -1,118 +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; - -import de.steamwar.messages.Chatter; -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.chat.ClickEvent; - -import java.text.DateFormat; -import java.text.MessageFormat; -import java.util.Date; -import java.util.Locale; -import java.util.ResourceBundle; - -public class Message { - - @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 Chatter.of(sender).getLocale(); - } - - @Deprecated - private static String parse(String message, boolean prefixed, Locale locale, Object... params){ - if(locale == null) - locale = Locale.getDefault(); - ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale); - String pattern = ""; - if(prefixed) - pattern = resourceBundle.getObject("PREFIX") + " "; - pattern += (String)resourceBundle.getObject(message); - - MessageFormat format = new MessageFormat(pattern, locale); - for (int i = 0; i < params.length; i++) { - if(params[i] instanceof Message) { - Message msg = (Message) params[i]; - 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]); - } - } - 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); - } - - @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); - } - - @Deprecated - private static void send(String message, boolean prefixed, CommandSender s, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){ - Chatter sender = Chatter.of(s); - if(type == ChatMessageType.CHAT && !sender.chatShown()) - return; - - sender.send(prefixed, type, onHover != null ? new Message("PLAIN_STRING", onHover) : null, onClick, new Message(message, params)); - } - - private final String format; - private final Object[] params; - - public Message(String format, Object... params) { - this.format = format; - this.params = params; - } - - public String getFormat() { - return format; - } - - public Object[] getParams() { - return params; - } - -} \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index b134e6d3..13321a1f 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -22,10 +22,10 @@ package de.steamwar.bungeecore; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.handlers.FightInfoHandler; import de.steamwar.messages.Chatter; +import de.steamwar.messages.Message; import de.steamwar.network.packets.server.StartingServerPacket; import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -38,22 +38,20 @@ public class SubserverSystem { node.execute("rm", "-r", worldName); } - public static void sendDeniedMessage(Chatter p, UUID owner){ - ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner); - if(o == null) - return; + public static void sendDeniedMessage(Chatter p, UUID owner) { if(IgnoreSystem.isIgnored(owner, p.user().getUUID())){ p.system("SERVER_IGNORED"); return; } - Message.send("SERVER_ADD_MEMBER", o, p); - Message.sendPrefixless("SERVER_ADD_MESSAGE", o, "SERVER_ADD_MESSAGE_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.user().getUserName())); + Chatter o = Chatter.of(owner); + o.system("SERVER_ADD_MEMBER", p); + o.prefixless("SERVER_ADD_MESSAGE", new Message("SERVER_ADD_MESSAGE_HOVER"), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.user().getUserName())); } public static void sendPlayer(Subserver subserver, ProxiedPlayer player) { subserver.sendPlayer(player); - if(!subserver.hasStarted() && FightInfoHandler.onLobby(player)) + if(!subserver.isStarted() && FightInfoHandler.onLobby(player)) NetworkSender.send(player, new StartingServerPacket(SteamwarUser.get(player.getUniqueId()).getId())); } } diff --git a/src/de/steamwar/bungeecore/bot/AuthManager.java b/src/de/steamwar/bungeecore/bot/AuthManager.java deleted file mode 100644 index 8500f12a..00000000 --- a/src/de/steamwar/bungeecore/bot/AuthManager.java +++ /dev/null @@ -1,81 +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; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; - -import java.util.*; -import java.util.concurrent.TimeUnit; - -public class AuthManager { - - private static final Map TOKENS = new HashMap<>(); - private static final Random rand = new Random(); - - public static String createDiscordAuthToken(Member member) { - if(TOKENS.containsValue(member.getIdLong())) return null; - - byte[] randBytes = new byte[16]; - rand.nextBytes(randBytes); - randBytes[0] = 'D'; - randBytes[1] = 'C'; - String code = Base64.getEncoder().encodeToString(randBytes); - - TOKENS.put(code, member.getIdLong()); - BungeeCore.log("Created Discord Auth-Token: " + code + " for: " + member.getUser().getAsTag()); - BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> TOKENS.remove(code), 10, TimeUnit.MINUTES); - return code; - } - - public static Member connectAuth(SteamwarUser user, String code) { - if (TOKENS.containsKey(code)) { - Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete(); - if(member == null) return null; - user.setDiscordId(member.getIdLong()); - MessageBuilder builder = new MessageBuilder(); - builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft"); - builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht"))); - - try { - member.getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue()); - if (member.getNickname() == null) { - try { - member.getGuild().modifyNickname(member, user.getUserName()).queue(); - } catch (Exception e) { - // Ignored - } - } - TOKENS.remove(code); - return member; - } catch (Exception e) { - return null; - } - } else { - return null; - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java deleted file mode 100644 index c9628e76..00000000 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ /dev/null @@ -1,166 +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; - -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.bot.commands.*; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.bot.events.EventManager; -import de.steamwar.bungeecore.bot.events.SchematicsManager; -import de.steamwar.bungeecore.bot.listeners.*; -import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; -import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; -import de.steamwar.bungeecore.bot.util.DiscordTicketMessage; -import de.steamwar.messages.Chatter; -import de.steamwar.sql.Event; -import lombok.Getter; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.JDABuilder; -import net.dv8tion.jda.api.OnlineStatus; -import net.dv8tion.jda.api.entities.Activity; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.exceptions.ErrorResponseException; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; -import net.dv8tion.jda.api.utils.MemberCachePolicy; -import net.md_5.bungee.api.ProxyServer; - -import javax.security.auth.login.LoginException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; - -public class SteamwarDiscordBot { - - private static SteamwarDiscordBot INSTANCE; - - public static SteamwarDiscordBot instance() { - return INSTANCE; - } - - @Getter - private volatile AnnouncementListener announcementListener; - - @Getter - private volatile DiscordChatListener ingameChatListener; - - @Getter - private volatile DiscordChatListener serverTeamChatListener; - - @Getter - private final JDA jda; - - @Getter - private static Map discordCommandMap = new HashMap<>(); - - public SteamwarDiscordBot() { - INSTANCE = this; - JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN); - builder.setStatus(OnlineStatus.ONLINE); - builder.setMemberCachePolicy(MemberCachePolicy.ONLINE); - try { - jda = builder.build(); - } catch (LoginException e) { - throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e); - } - ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - try { - jda.awaitReady(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - try { - activity(); - } catch (Exception e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not set initial activity to discord", e); - } - EventManager.update(); - SchematicsManager.update(); - ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - try { - activity(); - EventManager.update(); - SchematicsManager.update(); - } catch (ErrorResponseException e) { - //ignored - } - }, 30, 30, TimeUnit.SECONDS); - DiscordRolesMessage.sendMessage(); - DiscordRulesMessage.sendMessage(); - DiscordTicketMessage.sendMessage(); - new RolesInteractionButtonListener(); - new DiscordTicketListener(); - new DiscordAuthListener(); - new DiscordEventListener(); - new PrivateMessageListener(); - announcementListener = new AnnouncementListener(); - ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL", Chatter::broadcast); - serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM", Chatter::serverteam); - new SlashCommandListener(); - jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue()); - - Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD); - guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete()); - CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands(); - addCommand(commands, new MuteCommand()); - addCommand(commands, new BanCommand()); - addCommand(commands, new WhoisCommand()); - addCommand(commands, new TeamCommand()); - addCommand(commands, new ListCommand()); - addCommand(commands, new UnbanCommand()); - commands.complete(); - }); - } - - private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) { - commands.addCommands(basicDiscordCommand); - discordCommandMap.put(basicDiscordCommand.getName(), basicDiscordCommand); - } - - private int index = 0; - - private void activity() { - switch (index) { - case 0: - Event event = Event.get(); - if (event != null) { - jda.getPresence().setActivity(Activity.competing("dem Event " + event.getEventName())); - } else { - jda.getPresence().setActivity(Activity.playing("auf SteamWar.de")); - } - break; - case 1: - int count = BungeeCore.get().getProxy().getOnlineCount(); - if (count == 1) { - jda.getPresence().setActivity(Activity.playing("mit 1 Spieler")); - } else { - jda.getPresence().setActivity(Activity.playing("mit " + count + " Spielern")); - } - index = 0; - return; - } - index++; - } - - public void addListener(ListenerAdapter listenerAdapter) { - jda.addEventListener(listenerAdapter); - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java deleted file mode 100644 index 987866cf..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java +++ /dev/null @@ -1,67 +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.commands; - -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.commands.PunishmentCommand; -import de.steamwar.messages.Chatter; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionType; - -import java.sql.Timestamp; - -public class BanCommand extends BasicDiscordCommand { - - public BanCommand() { - super("ban", "Banne einen Nutzer, wenn du die Rechte hast."); - - addOption(OptionType.STRING, "user", "Der Benutzer", true); - addOption(OptionType.STRING, "time", "Bis Wann", true); - addOption(OptionType.STRING, "reason", "Warum", true); - } - - @Override - public void run(SlashCommandEvent event) { - if (!testPermission(event)) { - return; - } - - SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); - if (target == null) { - event.reply("Angegebener User invalide").setEphemeral(true).queue(); - return; - } - - Timestamp time = PunishmentCommand.parseTime(null, event.getOption("time").getAsString()); - if (time == null) { - event.reply("Angegebene Zeit invalide").setEphemeral(true).queue(); - return; - } - - String msg = event.getOption("reason").getAsString(); - boolean isPerma = event.getOption("time").getAsString().equals("perma"); - - PunishmentCommand.ban(target, time, msg, sender, isPerma); - Chatter.serverteam().system("BAN_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); - event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java deleted file mode 100644 index 16df83d2..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java +++ /dev/null @@ -1,54 +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.commands; - -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.build.CommandData; - -public abstract class BasicDiscordCommand extends CommandData { - - protected BasicDiscordCommand(String name, String description) { - super(name, description); - } - - public abstract void run(SlashCommandEvent event); - - protected SteamwarUser getSteamwarUser(SlashCommandEvent event) { - Member member = event.getMember(); - SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); - if (steamwarUser == null) { - return null; - } - return steamwarUser; - } - - protected boolean testPermission(SlashCommandEvent event) { - Member member = event.getMember(); - SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); - if (steamwarUser == null || (!steamwarUser.hasPerm(UserPerm.TEAM))) { - event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).queue(); - return false; - } - return true; - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/ListCommand.java b/src/de/steamwar/bungeecore/bot/commands/ListCommand.java deleted file mode 100644 index 746bb026..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/ListCommand.java +++ /dev/null @@ -1,43 +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.commands; - -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; - -import java.util.stream.Collectors; - -public class ListCommand extends BasicDiscordCommand { - - public ListCommand() { - super("list", "Gebe eine Liste aller online Spieler"); - } - - @Override - public void run(SlashCommandEvent event) { - de.steamwar.bungeecore.commands.ListCommand.getCustomTablist(); - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setTitle("List"); - de.steamwar.bungeecore.commands.ListCommand.getCustomTablist().forEach((s, proxiedPlayers) -> { - embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true); - }); - event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java deleted file mode 100644 index 154152fa..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java +++ /dev/null @@ -1,68 +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.commands; - -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.commands.PunishmentCommand; -import de.steamwar.messages.Chatter; -import de.steamwar.sql.Punishment; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionType; - -import java.sql.Timestamp; - -public class MuteCommand extends BasicDiscordCommand { - - public MuteCommand() { - super("mute", "Mute einen Nutzer, wenn du die Rechte hast."); - - addOption(OptionType.STRING, "user", "Der Benutzer", true); - addOption(OptionType.STRING, "time", "Bis Wann", true); - addOption(OptionType.STRING, "reason", "Warum", true); - } - - @Override - public void run(SlashCommandEvent event) { - if (!testPermission(event)) { - return; - } - - SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); - if (target == null) { - event.reply("Angegebener User invalide").setEphemeral(true).complete(); - return; - } - - Timestamp time = PunishmentCommand.parseTime(null, event.getOption("time").getAsString()); - if (time == null) { - event.reply("Angegebene Zeit invalide").setEphemeral(true).complete(); - return; - } - - String msg = event.getOption("reason").getAsString(); - boolean isPerma = event.getOption("time").getAsString().equals("perma"); - - target.punish(Punishment.PunishmentType.Mute, time, msg, sender.getId(), isPerma); - Chatter.serverteam().system("MUTE_TEAM", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg); - event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java deleted file mode 100644 index c07dbf2f..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java +++ /dev/null @@ -1,96 +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.commands; - -import de.steamwar.sql.Event; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; -import de.steamwar.sql.TeamTeilnahme; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionMapping; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; -import net.md_5.bungee.api.ProxyServer; - -import java.awt.*; -import java.util.List; -import java.util.stream.Collectors; - -public class TeamCommand extends BasicDiscordCommand { - - public TeamCommand() { - super("team", "Alle Team bezogenen Befehle"); - - addSubcommands(new SubcommandData("info", "Infos über das Team oder deins") - .addOption(OptionType.STRING, "team", "Name oder Kuerzel", false) - ); - } - - private Emoji emoji = Emoji.fromUnicode("U+1F7E2"); - - @Override - public void run(SlashCommandEvent event) { - SteamwarUser steamwarUser = getSteamwarUser(event); - - if (event.getSubcommandName() != null) { - switch (event.getSubcommandName()) { - case "info": - OptionMapping optionMapping = event.getOption("team"); - Team team; - if (optionMapping == null) { - if (steamwarUser == null) { - event.reply("Dein Discord ist nicht verknüpft").setEphemeral(true).queue(); - return; - } - if (steamwarUser.getTeam() == 0) { - event.reply("Du bist in keinem Team").setEphemeral(true).queue(); - return; - } - team = Team.get(steamwarUser.getTeam()); - } else { - team = Team.get(optionMapping.getAsString()); - } - if (team == null) { - event.reply("Unbekanntes Team").setEphemeral(true).queue(); - return; - } - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setTitle("Team: " + team.getTeamName() + " [" + team.getTeamKuerzel() + "]"); - embedBuilder.setColor(Color.GRAY); - List members = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList()); - - embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false); - embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false); - embedBuilder.addField("Events", "`" + TeamTeilnahme.getEvents(team.getTeamId()).stream().map(Event::getEventName).collect(Collectors.joining("` `")) + "`", false); - event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue(); - return; - default: - event.reply("Unbekannter Befehl").setEphemeral(true).queue(); - return; - } - } - } - - private boolean isOnline(SteamwarUser user) { - return ProxyServer.getInstance().getPlayer(user.getUUID()) != null; - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java deleted file mode 100644 index 61d5c0de..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java +++ /dev/null @@ -1,62 +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.commands; - -import de.steamwar.bungeecore.commands.PunishmentCommand; -import de.steamwar.sql.BannedUserIPs; -import de.steamwar.sql.Punishment; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionType; - -import java.sql.Timestamp; -import java.util.Date; - -public class UnbanCommand extends BasicDiscordCommand { - - public UnbanCommand() { - super("unban", "Entbannt einen Nutzer, wenn du die Rechte hast."); - - addOption(OptionType.STRING, "user", "Der Benutzer", true); - } - - @Override - public void run(SlashCommandEvent event) { - if (!testPermission(event)) { - return; - } - - SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong()); - SteamwarUser target = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString()); - if (target == null) { - event.reply("Angegebener User invalide").setEphemeral(true).queue(); - return; - } - - if (!target.isPunished(Punishment.PunishmentType.Ban)) { - event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).queue(); - return; - } - - target.punish(Punishment.PunishmentType.Ban, Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false); - BannedUserIPs.unbanIPs(target.getId()); - event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java deleted file mode 100644 index d2533727..00000000 --- a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java +++ /dev/null @@ -1,94 +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.commands; - -import de.steamwar.sql.Punishment; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionType; - -import java.sql.Timestamp; -import java.text.DecimalFormat; -import java.util.List; - -public class WhoisCommand extends BasicDiscordCommand { - - public WhoisCommand() { - super("whois", "Der whois Befehl"); - - addOption(OptionType.STRING, "user", "Der Benutzer", true); - } - - @Override - public void run(SlashCommandEvent event) { - if (!testPermission(event)) { - return; - } - - String s = event.getOption("user").getAsString(); - - SteamwarUser user = SteamwarUser.get(s); - if (user == null) { - try { - int id = Integer.parseInt(s); - user = SteamwarUser.get(id); - } catch (NumberFormatException ignored) { - // Ignored - } - } - if (user == null) { - try { - long id = Long.parseLong(s); - user = SteamwarUser.get(id); - } catch (NumberFormatException ignored) { - // Ignored - } - } - - if (user == null) { - event.reply("Der angegebene Spieler ist unbekannt").setEphemeral(true).complete(); - return; - } - - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setTitle("Whois: " + user.getUserName()); - StringBuilder st = new StringBuilder(); - st.append("UUID: ").append(user.getUUID()).append("\n"); - st.append("ID: ").append(user.getId()).append("\n"); - if (user.getDiscordId() != null) { - st.append("DiscordID: ").append(user.getDiscordId()).append("\n"); - } - Timestamp timestamp = user.getFirstjoin(); - st.append("Beigetreten am: ").append(timestamp == null ? "0000-00-00 00:00:00" : timestamp.toString()).append("\n"); - st.append("Online Time: ").append(new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)).append("h\n"); - Team team = Team.get(user.getTeam()); - st.append("Team: [").append(team.getTeamKuerzel()).append("] ").append(team.getTeamName()); - embedBuilder.addField("Daten:", st.toString(), false); - - List punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId()); - for (Punishment punishment : punishmentList) { - embedBuilder.addField(punishment.getType().name() + " von " + SteamwarUser.get(punishment.getPunisher()).getUserName(), "Von: " + punishment.getBantime(punishment.getStartTime(), false) + "\nBis: " + punishment.getBantime(punishment.getEndTime(), punishment.isPerma()) + "\nGrund: " + punishment.getReason(), true); - } - - event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java b/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java deleted file mode 100644 index 5a72baeb..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java +++ /dev/null @@ -1,50 +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.messages.Chatter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; -import org.jetbrains.annotations.NotNull; - -public class AnnouncementListener extends BasicDiscordListener { - - @Override - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { - if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL)) { - return; - } - if (event.getAuthor().isBot()) { - return; - } - Chatter.broadcast().system("ALERT", event.getMessage().getContentDisplay()); - } - - public void announce(String message) { - TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL); - assert textChannel != null; - MessageBuilder messageBuilder = new MessageBuilder(); - messageBuilder.append(message.replace("&", "")); - textChannel.sendMessage(messageBuilder.build()).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java b/src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java deleted file mode 100644 index 1c8a5ffd..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java +++ /dev/null @@ -1,30 +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 net.dv8tion.jda.api.hooks.ListenerAdapter; - -public abstract class BasicDiscordListener extends ListenerAdapter { - - BasicDiscordListener() { - SteamwarDiscordBot.instance().addListener(this); - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java deleted file mode 100644 index 947ed5e5..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java +++ /dev/null @@ -1,59 +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.AuthManager; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.interactions.InteractionType; -import org.jetbrains.annotations.NotNull; - -public class DiscordAuthListener extends BasicDiscordListener { - - @Override - public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) { - if(event.getType() == InteractionType.COMPONENT) { - if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.RULES_CHANNEL) && event.getComponentId().equals("auth")) { - String authMessage = AuthManager.createDiscordAuthToken(event.getMember()); - if(authMessage != null) { - event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + authMessage + "`` auf dem Minecraft Server ein").setEphemeral(true).queue(); - } else { - event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).queue(); - } - } - - if(event.getComponentId().equals("tada") && event.getChannelType() == ChannelType.PRIVATE) { - event.reply(":tada:").setEphemeral(false).queue(); - } - - if(event.getComponentId().equals("invalid") && event.getChannelType() == ChannelType.PRIVATE) { - SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong()); - if(user == null) { - event.reply(":question: Da ist keine verknüpfung?").setEphemeral(false).queue(); - } else { - user.setDiscordId(null); - event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).queue(); - } - } - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java deleted file mode 100644 index 1803d94b..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java +++ /dev/null @@ -1,71 +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.listeners.ChatListener; -import de.steamwar.messages.Chatter; -import de.steamwar.messages.ChatterGroup; -import de.steamwar.sql.Punishment; -import de.steamwar.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; - -import java.util.function.Supplier; - -public class DiscordChatListener extends BasicDiscordListener { - - private final String channel; - private final String format; - - private final Supplier targets; - - public DiscordChatListener(String channel, String format, Supplier targets) { - this.channel = channel; - this.format = format; - this.targets = targets; - } - - @Override - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { - if (!event.getChannel().getId().equals(channel) || 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(Chatter.of(event.getMessage(), steamwarUser), targets.get(), format, null, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' ')); - } - } - - public void send(String message) { - 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`")); - textChannel.sendMessage(messageBuilder.build()).queue(); - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java deleted file mode 100644 index b21f427c..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordEventListener.java +++ /dev/null @@ -1,93 +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.config.SteamwarDiscordBotConfig; -import de.steamwar.bungeecore.bot.events.EventManager; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Team; -import de.steamwar.sql.TeamTeilnahme; -import de.steamwar.sql.Event; -import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; -import net.dv8tion.jda.api.interactions.components.Component; -import org.jetbrains.annotations.NotNull; - -import java.time.Instant; - -public class DiscordEventListener extends BasicDiscordListener { - - - @Override - public void onSelectionMenu(@NotNull SelectionMenuEvent event) { - if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.EVENTS_CHANNEL) && event.getComponentType() == Component.Type.SELECTION_MENU) { - if(event.getSelectedOptions().isEmpty()) { - event.deferReply(true).queue(); - return; - } - if(event.getSelectedOptions().get(0).getValue().matches("([0-9]+)")) { - SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong()); - if(user == null) { - event.reply("Du hast dein Minecraft nicht verknüpft").setEphemeral(true).queue(); - return; - } - - if(user.getTeam() == 0) { - event.reply("Du bist in keinem Team").setEphemeral(true).queue(); - return; - } - - if(!user.isLeader()) { - event.reply("Du bist kein Leader in deinem Team").setEphemeral(true).queue(); - return; - } - - if(Event.get() != null) { - event.reply("Du kannst dich nicht während einem Event an einem Event anmelden").setEphemeral(true).queue(); - return; - } - - Event swEvent = Event.get(Integer.decode(event.getSelectedOptions().get(0).getValue())); - if(swEvent == null){ - event.reply("Das Event gibt es nicht").setEphemeral(true).queue(); - return; - } - - if(Instant.now().isAfter(swEvent.getDeadline().toInstant())){ - event.reply("Du kannst dich nicht mehr an diesen Event anmelden").setEphemeral(true).queue(); - return; - } - - Team team = Team.get(user.getTeam()); - - if(TeamTeilnahme.nimmtTeil(team.getTeamId(), swEvent.getEventID())){ - TeamTeilnahme.notTeilnehmen(team.getTeamId(), swEvent.getEventID()); - event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun nicht mehr an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue(); - }else{ - TeamTeilnahme.teilnehmen(team.getTeamId(), swEvent.getEventID()); - event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue(); - } - - EventManager.update(); - } else { - event.reply("Lefuq?").setEphemeral(true).queue(); - } - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java deleted file mode 100644 index c6bb73ca..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ /dev/null @@ -1,158 +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.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.bot.config.DiscordTicketType; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.messages.Chatter; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; -import net.dv8tion.jda.api.interactions.InteractionType; -import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; -import net.md_5.bungee.api.chat.ClickEvent; -import org.jetbrains.annotations.NotNull; - -import java.awt.*; -import java.time.Instant; -import java.util.LinkedList; - -public class DiscordTicketListener extends BasicDiscordListener { - - @Override - public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) { - if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getParent() != null && event.getTextChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) { - if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) { - DiscordTicketType ticketType = SteamwarDiscordBotConfig.TICKET_TYPES.get(event.getComponentId()); - Category ct = event.getGuild().getCategoryById(SteamwarDiscordBotConfig.TICKET_CATEGORY); - SteamwarUser swUser = SteamwarUser.get(event.getUser().getIdLong()); - TextChannel ticketChannel = ct.createTextChannel((swUser == null?event.getUser().getName():swUser.getUserName()) + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete(); - ticketChannel.createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL, - Permission.MESSAGE_WRITE, - Permission.MESSAGE_ATTACH_FILES, - Permission.MESSAGE_ADD_REACTION, - Permission.MESSAGE_READ, - Permission.MESSAGE_EMBED_LINKS, - Permission.MESSAGE_HISTORY).complete(); - ticketChannel.getManager().setTopic(event.getUser().getId()).complete(); - - MessageBuilder messageBuilder = new MessageBuilder(); - EmbedBuilder builder = new EmbedBuilder(); - builder.setDescription(ticketType.getPreMessage()); - builder.setTitle("Steamwar Ticket"); - builder.setColor(Color.GREEN); - - Button closeButton = Button.danger("close-" + ticketChannel.getName(), "Schließen").withEmoji(Emoji.fromUnicode("U+26A0")); - messageBuilder.setEmbeds(builder.build()); - messageBuilder.setActionRows(ActionRow.of(closeButton)); - - ticketChannel.sendMessage(messageBuilder.build()).complete(); - event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete(); - Chatter.serverteam().prefixless("DISCORD_TICKET_NEW", ticketChannel.getName()); - } else if(event.getComponentId().startsWith("close-")) { - TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG); - - LinkedList stringBuilders = new LinkedList<>(); - stringBuilders.add(new StringBuilder()); - - new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> { - if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return; - StringBuilder currentBuilder = new StringBuilder(); - currentBuilder.append(" ") - .append("**") - .append(message.getAuthor().getName()) - .append("**: ") - .append(message.getContentRaw()); - if(!message.getAttachments().isEmpty()) { - currentBuilder.append("\n") - .append("Files: ").append("\n"); - message.getAttachments().forEach(attachment -> currentBuilder.append(attachment.getUrl()).append("\n")); - } - - currentBuilder.append("\n"); - if(currentBuilder.length() >= 4096) { - stringBuilders.getLast().append(currentBuilder.substring(0, 4090)); - stringBuilders.add(new StringBuilder(currentBuilder.substring(4090, currentBuilder.length() - 1))); - } else if (currentBuilder.length() + stringBuilders.getLast().length() >= 4096) { - stringBuilders.add(new StringBuilder(currentBuilder.toString())); - } else { - stringBuilders.getLast().append(currentBuilder); - } - }); - - String footer = " **" + event.getUser().getName() + "**: Ticket geschlossen"; - if(stringBuilders.getLast().length() + footer.length() > 4090) { - stringBuilders.add(new StringBuilder(footer)); - } else { - stringBuilders.getLast().append(footer); - } - - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setColor(Color.GREEN); - User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete(); - SteamwarUser swuser = SteamwarUser.get(user.getIdLong()); - - embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl()); - embedBuilder.setTimestamp(Instant.now()); - embedBuilder.setTitle(event.getTextChannel().getName()); - stringBuilders.forEach(stringBuilder -> { - embedBuilder.setDescription(stringBuilder.toString()); - MessageBuilder builder = new MessageBuilder(); - builder.setEmbeds(embedBuilder.build()); - - logChannel.sendMessage(builder.build()).queue(); - }); - - Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", event.getTextChannel().getName()); - event.getTextChannel().delete().reason("Closed").queue(); - } - } - } - - @Override - public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) { - if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) { - if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) { - BungeeCore.get().getProxy().getPlayers().forEach(player -> { - if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return; - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - boolean sendMessage; - if(user.getDiscordId() == null) { - sendMessage = user.hasPerm(UserPerm.CHECK); - } else { - if(event.getAuthor().getId().equals(user.getDiscordId())) return; - sendMessage = user.getDiscordId().equals(event.getChannel().getTopic()) || user.hasPerm(UserPerm.CHECK); - } - if(sendMessage) { - Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw()); - } - }); - } - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java b/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java deleted file mode 100644 index 58800d0c..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/PrivateMessageListener.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is a part of the SteamWar software. - *

- * Copyright (C) 2021 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.BungeeCore; -import de.steamwar.sql.NodeData; -import de.steamwar.sql.Punishment; -import de.steamwar.sql.SchematicNode; -import de.steamwar.sql.SteamwarUser; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; - -import java.io.InputStream; - -public class PrivateMessageListener extends BasicDiscordListener { - - @Override - public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) { - if(!event.getMessage().getAttachments().isEmpty()) { - SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong()); - if (user == null) { - event.getMessage().reply("Du must dein Minecraft Account mit dem Bot verbinden, gehe dazu auf dem SteamWar Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`").complete(); - return; - } - - if(user.isPunished(Punishment.PunishmentType.NoSchemReceiving)) { - event.getMessage().reply("Du darfst keine Schematics hochladen").complete(); - return; - } - - for (Message.Attachment attachment : event.getMessage().getAttachments()) { - if(attachment.getFileExtension() == null || - (!attachment.getFileExtension().equalsIgnoreCase("schem") && - !attachment.getFileExtension().equalsIgnoreCase("schematic"))) { - event.getMessage().reply("`" + attachment.getFileName() + "` wird ignoriert, da die Datei keine Schematic ist").queue(); - continue; - } - - boolean newFormat = attachment.getFileExtension().equalsIgnoreCase("schem"); - int dot = attachment.getFileName().lastIndexOf("."); - String name = attachment.getFileName().substring(0, dot); - if(SchematicNode.invalidSchemName(new String[] {name})) { - event.getMessage().reply("`" + name + "` hat nicht zugelassene Zeichen im Namen").queue(); - continue; - } - - SchematicNode node = SchematicNode.getSchematicNode(user.getId(), name, (Integer) null); - if(node == null) { - node = SchematicNode.createSchematic(user.getId(), name, null); - } - - try { - InputStream in = attachment.retrieveInputStream().get(); - NodeData.get(node).saveFromStream(in, newFormat); - in.close(); - event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue(); - } catch (Exception e) { - event.getMessage().reply("`" + name + "` konnte nicht hochgeladen werden, bitte versuche es später nochmal oder wende dich an einen Developer").queue(); - BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"", e); - } - } - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java b/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java deleted file mode 100644 index ae0e44de..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java +++ /dev/null @@ -1,42 +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.config.SteamwarDiscordBotConfig; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; -import net.dv8tion.jda.api.interactions.InteractionType; -import org.jetbrains.annotations.NotNull; - -public class RolesInteractionButtonListener extends BasicDiscordListener { - - @Override - public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) { - if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) { - if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) { - event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete(); - event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue(); - } else { - event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete(); - event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue(); - } - } - } -} diff --git a/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java b/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java deleted file mode 100644 index 565ca442..00000000 --- a/src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java +++ /dev/null @@ -1,32 +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 net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import org.jetbrains.annotations.NotNull; - -public class SlashCommandListener extends BasicDiscordListener { - - @Override - public void onSlashCommand(@NotNull SlashCommandEvent event) { - SteamwarDiscordBot.getDiscordCommandMap().get(event.getName()).run(event); - } -} diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java deleted file mode 100644 index f62dea0f..00000000 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java +++ /dev/null @@ -1,69 +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.util; - -import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import de.steamwar.sql.SteamwarUser; -import lombok.experimental.UtilityClass; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.exceptions.ErrorResponseException; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -@UtilityClass -public class DiscordRanks { - - public void update(SteamwarUser steamwarUser) { - if (steamwarUser.getDiscordId() == null) { - return; - } - Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD); - guild.retrieveMemberById(steamwarUser.getDiscordId()).queue(member -> { - List roleList = member.getRoles(); - Set strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values()); - String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.prefix()); - for (Role role : roleList) { - if (!strings.contains(role.getId())) { - continue; - } - if (role.getId().equals(needed)) { - needed = ""; - continue; - } - guild.removeRoleFromMember(member, role).complete(); - } - - if (needed != null && !needed.isEmpty()) { - guild.addRoleToMember(member, guild.getRoleById(needed)).complete(); - } - }, throwable -> { - if(throwable instanceof ErrorResponseException) { - ErrorResponseException e = (ErrorResponseException) throwable; - if(e.getErrorCode() == 10007) { - steamwarUser.setDiscordId(null); - } - } - }); - } -} diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java deleted file mode 100644 index 1486debd..00000000 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java +++ /dev/null @@ -1,61 +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.util; - -import de.steamwar.bungeecore.bot.SteamwarDiscordBot; -import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; -import lombok.experimental.UtilityClass; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; - -import java.util.ArrayList; -import java.util.List; - -@UtilityClass -public class DiscordRolesMessage { - - - public void sendMessage() { - TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL); - assert channel != null; - - MessageBuilder builder = new MessageBuilder(); - builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE); - List