From 1a8e8690ac897fc43e84d51715943ae0f1d87e05 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Jul 2021 18:14:29 +0200 Subject: [PATCH] Add SchematicsManager Fix '1 Spielern' to '1 Spieler' --- src/de/steamwar/bungeecore/BungeeCore.java | 2 +- .../bungeecore/bot/SteamwarDiscordBot.java | 10 ++- .../bot/config/SteamwarDiscordBotConfig.java | 2 + .../bot/events/SchematicsManager.java | 73 +++++++++++++++++++ .../bungeecore/commands/CheckCommand.java | 7 +- 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/de/steamwar/bungeecore/bot/events/SchematicsManager.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 76a9c0b..f2bd01f 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -158,8 +158,8 @@ public class BungeeCore extends Plugin { public void onDisable(){ ErrorLogger.stop(); SQL.close(); - SteamwarDiscordBot.instance().getJda().shutdownNow(); try { + SteamwarDiscordBot.instance().getJda().shutdownNow(); SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN); } catch (Exception e) { // Ignored diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index f4c2830..ac50e53 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.commands.BanCommand; import de.steamwar.bungeecore.bot.commands.MuteCommand; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.events.EventManager; +import de.steamwar.bungeecore.bot.events.SchematicsManager; import de.steamwar.bungeecore.bot.listeners.*; import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; @@ -79,9 +80,11 @@ public class SteamwarDiscordBot { } activity(); EventManager.update(); + SchematicsManager.update(); ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { activity(); EventManager.update(); + SchematicsManager.update(); }, 30, 30, TimeUnit.SECONDS); DiscordRolesMessage.sendMessage(); DiscordRulesMessage.sendMessage(); @@ -113,7 +116,12 @@ public class SteamwarDiscordBot { } break; case 1: - jda.getPresence().setActivity(Activity.playing("mit " + BungeeCore.get().getProxy().getOnlineCount() + " Spielern")); + int count = BungeeCore.get().getProxy().getOnlineCount(); + if (count == 1) { + jda.getPresence().setActivity(Activity.playing("mit 1 Spieler")); + } else { + jda.getPresence().setActivity(Activity.playing("mit " + count + " Spielern")); + } index = 0; return; } diff --git a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java index cefedcc..f69a3ac 100644 --- a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java +++ b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java @@ -35,6 +35,7 @@ public class SteamwarDiscordBotConfig { public static String EVENTS_CHANNEL; public static String INGAME_CHANNEL; public static String SERVER_TEAM_CHANNEL; + public static String SCHEMATICS_CHANNEL; public static String ROLES_CHANNEL; public static String ROLES_BASE_MESSAGE; public static String ROLES_ADDED; @@ -59,6 +60,7 @@ public class SteamwarDiscordBotConfig { EVENTS_CHANNEL = config.getString("events-channel"); INGAME_CHANNEL = config.getString("ingame-channel"); SERVER_TEAM_CHANNEL = config.getString("server-team-channel"); + SCHEMATICS_CHANNEL = config.getString("schematics-channel"); Configuration rolesSection = config.getSection("roles-claim"); ROLES_CHANNEL = rolesSection.getString("channel"); ROLES_BASE_MESSAGE = rolesSection.getString("base"); diff --git a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java new file mode 100644 index 0000000..86b2257 --- /dev/null +++ b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java @@ -0,0 +1,73 @@ +/* + * 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.events; + +import de.steamwar.bungeecore.bot.SteamwarDiscordBot; +import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; +import de.steamwar.bungeecore.commands.CheckCommand; +import de.steamwar.bungeecore.sql.SteamwarUser; +import lombok.experimental.UtilityClass; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; + +import java.awt.*; + +@UtilityClass +public class SchematicsManager { + + private Message message; + private TextChannel textChannel; + + static { + textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SCHEMATICS_CHANNEL); + assert textChannel != null; + if(textChannel.hasLatestMessage()) { + message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); + } + } + + public void update() { + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setColor(Color.GRAY); + embedBuilder.setTitle("Check List"); + embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de"); + + CheckCommand.getSchemsToCheck().forEach(schematic -> { + StringBuilder st = new StringBuilder(); + st.append("Typ: ").append(schematic.getSchemType().getKuerzel()); + st.append("\nVon: ").append(SteamwarUser.get(schematic.getSchemOwner()).getUserName()); + String checker = CheckCommand.getChecker(schematic); + if (checker != null) { + st.append("\nGeprüft durch: ").append(checker); + } + embedBuilder.addField(schematic.getSchemName(), st.toString(), true); + }); + + MessageBuilder messageBuilder = new MessageBuilder(); + messageBuilder.setEmbeds(embedBuilder.build()); + if (message == null) { + message = textChannel.sendMessage(messageBuilder.build()).complete(); + } else { + message.editMessage(messageBuilder.build()).complete(); + } + } +} diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index 27f5947..c110b3c 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -111,7 +111,7 @@ public class CheckCommand extends BasicCommand { } } - private static List getSchemsToCheck(){ + public static List getSchemsToCheck(){ List schematicList = new LinkedList<>(); for (SchematicType type : SchematicType.values()) { @@ -121,6 +121,11 @@ public class CheckCommand extends BasicCommand { return schematicList; } + public static String getChecker(Schematic schematic) { + if (currentSchems.get(schematic.getSchemID()) == null) return null; + return currentSchems.get(schematic.getSchemID()).checker.getName(); + } + private void list(ProxiedPlayer player) { List schematicList = getSchemsToCheck();