From 3b5be809dd13f19b8429c930d7eed61ad49c9046 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 12 May 2024 21:24:15 +0200 Subject: [PATCH] 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 f6de66b..56dbe30 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 eb132e2..30b548e 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 e4bfab4..4fd86ee 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 0000000..1625071 --- /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 0000000..62c0368 --- /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 b0f48eb..0000000 --- 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 7f6503f..10bac32 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 60872e6..39388ff 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 64a6507..8cf195c 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 9b98373..3ab407c 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 f5ceb7e..0386006 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 3bf2a07..d2d6538 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 6e61332..61e7bb5 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 f61ca16..e7f7451 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 3a4ee62..47ba16a 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 a7b9efb..aa894e5 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 6caa4a1..f1e31af 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 e82b1b4..59fd46c 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 04c22fa..707eef5 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 bbe0dda..6323fb1 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 0f8e77e..1ede5f0 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 d7bce43..229fae8 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 637668c..a100f2d 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 f5a4476..41aa10b 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 8636054..8547e5b 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 1235de0..a744044 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 b83cb96..2a6d7a7 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 8d2ea6f..64c80e4 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 178abd5..40a350b 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 b116644..fc12240 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()); } } }