From 398b3e9b5a67300dca40e43fec2dfd919db268c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Jul 2021 20:41:46 +0200 Subject: [PATCH] Add DiscordRanks --- .../bot/config/SteamwarDiscordBotConfig.java | 5 +++-- .../bungeecore/bot/util/DiscordRanks.java | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java index 700909cd..14f1efbd 100644 --- a/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java +++ b/src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.bot.config; +import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.config.Configuration; import java.util.ArrayList; @@ -47,7 +48,7 @@ public class SteamwarDiscordBotConfig { public static String TICKET_CREATED; public static String TICKET_LOG; public static Map TICKET_TYPES; - public static Map RANKS; + public static Map RANKS; public static void loadConfig(Configuration config) { TOKEN = config.getString("token"); @@ -101,7 +102,7 @@ public class SteamwarDiscordBotConfig { RANKS = new HashMap<>(); Configuration ranksSections = config.getSection("ranks"); for (String type : ranksSections.getKeys()) { - RANKS.put(type, ranksSections.getString(type)); + RANKS.put(UserGroup.getUsergroup(type), ranksSections.getString(type)); } } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java index 495d227d..118a02c0 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java @@ -43,16 +43,18 @@ public class DiscordRanks { if (member == null) { return; } - Set 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); + Set toRemove = new HashSet<>(SteamwarDiscordBotConfig.RANKS.keySet()); + toRemove.remove(steamwarUser.getUserGroup()); + + for (UserGroup userGroup : toRemove) { + System.out.println(steamwarUser + " REMOVING"); + String roleId = SteamwarDiscordBotConfig.RANKS.get(userGroup); guild.removeRoleFromMember(member, guild.getRoleById(roleId)).complete(); } + if (steamwarUser.getUserGroup() != UserGroup.Member) { - guild.addRoleToMember(member, guild.getRoleById(SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup().name()))); + System.out.println(steamwarUser + " ADDING"); + guild.addRoleToMember(member, guild.getRoleById(SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup()))); } } }