geforkt von SteamWar/BungeeCore
Add DiscordRanks
Dieser Commit ist enthalten in:
Ursprung
c9a5f468da
Commit
2579e7adcb
@ -47,6 +47,7 @@ public class SteamwarDiscordBotConfig {
|
||||
public static String TICKET_CREATED;
|
||||
public static String TICKET_LOG;
|
||||
public static Map<String, DiscordTicketType> TICKET_TYPES;
|
||||
public static Map<String, String> RANKS;
|
||||
|
||||
public static void loadConfig(Configuration config) {
|
||||
TOKEN = config.getString("token");
|
||||
@ -96,5 +97,11 @@ public class SteamwarDiscordBotConfig {
|
||||
type.getString("color"),
|
||||
type.getString("pre")));
|
||||
}
|
||||
|
||||
RANKS = new HashMap<>();
|
||||
Configuration ranksSections = config.getSection("ranks");
|
||||
for (String type : ranksSections.getKeys()) {
|
||||
RANKS.put(type, ranksSections.getString(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
58
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
58
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserGroup;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class DiscordRanks {
|
||||
|
||||
public void update(SteamwarUser steamwarUser) {
|
||||
if (steamwarUser.getDiscordId() == null) {
|
||||
return;
|
||||
}
|
||||
Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
Member member = guild.getMemberById(steamwarUser.getDiscordId());
|
||||
if (member == null) {
|
||||
return;
|
||||
}
|
||||
Set<String> toRemove = new HashSet<>(SteamwarDiscordBotConfig.RANKS.keySet());
|
||||
if (steamwarUser.getUserGroup() != UserGroup.Member) {
|
||||
toRemove.remove(steamwarUser.getUserGroup().name().toLowerCase());
|
||||
}
|
||||
for (String s : toRemove) {
|
||||
String roleId = SteamwarDiscordBotConfig.RANKS.get(s);
|
||||
guild.removeRoleFromMember(member, guild.getRoleById(roleId)).complete();
|
||||
}
|
||||
if (steamwarUser.getUserGroup() != UserGroup.Member) {
|
||||
guild.addRoleToMember(member, guild.getRoleById(SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup().name())));
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Servertype;
|
||||
import de.steamwar.bungeecore.Subserver;
|
||||
import de.steamwar.bungeecore.bot.util.DiscordRanks;
|
||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||
import de.steamwar.bungeecore.commands.MsgCommand;
|
||||
@ -94,6 +95,8 @@ public class ConnectionListener extends BasicListener {
|
||||
Message.broadcast("JOIN_FIRST", player.getName());
|
||||
newPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
DiscordRanks.update(user);
|
||||
}
|
||||
|
||||
/** To redirect players to the lobby in case of server closure. */
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren