From 6490ce28488015f777c6aa431b7b844a0fe0e9ac Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 8 Sep 2021 13:51:42 +0200 Subject: [PATCH 1/2] Long DiscordId Signed-off-by: Chaoscaot --- src/de/steamwar/bungeecore/bot/AuthManager.java | 2 +- src/de/steamwar/bungeecore/sql/SteamwarUser.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/AuthManager.java b/src/de/steamwar/bungeecore/bot/AuthManager.java index 7d8b005..a2facf0 100644 --- a/src/de/steamwar/bungeecore/bot/AuthManager.java +++ b/src/de/steamwar/bungeecore/bot/AuthManager.java @@ -56,7 +56,7 @@ public class AuthManager { if (TOKENS.containsKey(code)) { Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete(); if(member == null) return null; - user.setDiscordId(member.getId()); + user.setDiscordId(member.getIdLong()); MessageBuilder builder = new MessageBuilder(); builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft"); builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht"))); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 67c3596..e09bbc8 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -63,7 +63,7 @@ public class SteamwarUser { private static final Map usersByName = new HashMap<>(); private static final Map usersByUUID = new HashMap<>(); private static final Map usersById = new HashMap<>(); - private static final Map usersByDiscord = new HashMap<>(); + private static final Map usersByDiscord = new HashMap<>(); private static final InetAddress LIXFEL_DE; private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; private static final JsonParser jsonParser = new JsonParser(); @@ -75,7 +75,7 @@ public class SteamwarUser { private int team; private boolean leader; private final Map punishments; - private String discordId; + private Long discordId; static { try { @@ -93,7 +93,7 @@ public class SteamwarUser { userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); team = rs.getInt("Team"); leader = rs.getBoolean("Leader"); - discordId = rs.getString("DiscordId"); + discordId = rs.getLong("DiscordId"); usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); @@ -178,8 +178,8 @@ public class SteamwarUser { } public static SteamwarUser get(Long discordId) { - if(usersByDiscord.containsKey(discordId.toString())) - return usersByDiscord.get(discordId.toString()); + if(usersByDiscord.containsKey(discordId)) + return usersByDiscord.get(discordId); return byDiscord.select(rs -> { if(rs.next()) return new SteamwarUser(rs); @@ -235,11 +235,11 @@ public class SteamwarUser { return punishments.getOrDefault(type, null); } - public String getDiscordId() { + public Long getDiscordId() { return discordId; } - public void setDiscordId(String discordId) { + public void setDiscordId(Long discordId) { usersByDiscord.remove(this.discordId); this.discordId = discordId; updateDiscord.update(discordId, id); -- 2.39.2 From d41bb58fac07425676ea44118505b2db85dd4703 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 16 Sep 2021 22:21:36 +0200 Subject: [PATCH 2/2] Fix null Issues Signed-off-by: Chaoscaot --- src/de/steamwar/bungeecore/bot/AuthManager.java | 1 - src/de/steamwar/bungeecore/sql/SteamwarUser.java | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/AuthManager.java b/src/de/steamwar/bungeecore/bot/AuthManager.java index a2facf0..ac4f553 100644 --- a/src/de/steamwar/bungeecore/bot/AuthManager.java +++ b/src/de/steamwar/bungeecore/bot/AuthManager.java @@ -27,7 +27,6 @@ import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; -import net.md_5.bungee.api.scheduler.ScheduledTask; import java.util.*; import java.util.concurrent.TimeUnit; diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index e09bbc8..2643d62 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -94,11 +94,15 @@ public class SteamwarUser { team = rs.getInt("Team"); leader = rs.getBoolean("Leader"); discordId = rs.getLong("DiscordId"); + if(rs.wasNull()) { + discordId = null; + } usersById.put(id, this); usersByName.put(userName.toLowerCase(), this); usersByUUID.put(uuid, this); - if(discordId != null) + if(discordId != null) { usersByDiscord.put(discordId, this); + } punishments = Punishment.getPunishmentsOfPlayer(id); } -- 2.39.2