Archiviert
1
0

Add SchematicsManager

Fix '1 Spielern' to '1 Spieler'
Dieser Commit ist enthalten in:
yoyosource 2021-07-29 18:14:29 +02:00
Ursprung 54499a7c3e
Commit 1a8e8690ac
5 geänderte Dateien mit 91 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -158,8 +158,8 @@ public class BungeeCore extends Plugin {
public void onDisable(){ public void onDisable(){
ErrorLogger.stop(); ErrorLogger.stop();
SQL.close(); SQL.close();
SteamwarDiscordBot.instance().getJda().shutdownNow();
try { try {
SteamwarDiscordBot.instance().getJda().shutdownNow();
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN); SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
} catch (Exception e) { } catch (Exception e) {
// Ignored // Ignored

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bungeecore.bot.commands.BanCommand;
import de.steamwar.bungeecore.bot.commands.MuteCommand; import de.steamwar.bungeecore.bot.commands.MuteCommand;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.bot.events.EventManager; 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.listeners.*;
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
@ -79,9 +80,11 @@ public class SteamwarDiscordBot {
} }
activity(); activity();
EventManager.update(); EventManager.update();
SchematicsManager.update();
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
activity(); activity();
EventManager.update(); EventManager.update();
SchematicsManager.update();
}, 30, 30, TimeUnit.SECONDS); }, 30, 30, TimeUnit.SECONDS);
DiscordRolesMessage.sendMessage(); DiscordRolesMessage.sendMessage();
DiscordRulesMessage.sendMessage(); DiscordRulesMessage.sendMessage();
@ -113,7 +116,12 @@ public class SteamwarDiscordBot {
} }
break; break;
case 1: 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; index = 0;
return; return;
} }

Datei anzeigen

@ -35,6 +35,7 @@ public class SteamwarDiscordBotConfig {
public static String EVENTS_CHANNEL; public static String EVENTS_CHANNEL;
public static String INGAME_CHANNEL; public static String INGAME_CHANNEL;
public static String SERVER_TEAM_CHANNEL; public static String SERVER_TEAM_CHANNEL;
public static String SCHEMATICS_CHANNEL;
public static String ROLES_CHANNEL; public static String ROLES_CHANNEL;
public static String ROLES_BASE_MESSAGE; public static String ROLES_BASE_MESSAGE;
public static String ROLES_ADDED; public static String ROLES_ADDED;
@ -59,6 +60,7 @@ public class SteamwarDiscordBotConfig {
EVENTS_CHANNEL = config.getString("events-channel"); EVENTS_CHANNEL = config.getString("events-channel");
INGAME_CHANNEL = config.getString("ingame-channel"); INGAME_CHANNEL = config.getString("ingame-channel");
SERVER_TEAM_CHANNEL = config.getString("server-team-channel"); SERVER_TEAM_CHANNEL = config.getString("server-team-channel");
SCHEMATICS_CHANNEL = config.getString("schematics-channel");
Configuration rolesSection = config.getSection("roles-claim"); Configuration rolesSection = config.getSection("roles-claim");
ROLES_CHANNEL = rolesSection.getString("channel"); ROLES_CHANNEL = rolesSection.getString("channel");
ROLES_BASE_MESSAGE = rolesSection.getString("base"); ROLES_BASE_MESSAGE = rolesSection.getString("base");

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}
}

Datei anzeigen

@ -111,7 +111,7 @@ public class CheckCommand extends BasicCommand {
} }
} }
private static List<Schematic> getSchemsToCheck(){ public static List<Schematic> getSchemsToCheck(){
List<Schematic> schematicList = new LinkedList<>(); List<Schematic> schematicList = new LinkedList<>();
for (SchematicType type : SchematicType.values()) { for (SchematicType type : SchematicType.values()) {
@ -121,6 +121,11 @@ public class CheckCommand extends BasicCommand {
return schematicList; 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) { private void list(ProxiedPlayer player) {
List<Schematic> schematicList = getSchemsToCheck(); List<Schematic> schematicList = getSchemsToCheck();