Archiviert
1
0

Merge pull request 'Long DiscordId' (#242) from long_discord into master

Reviewed-on: SteamWar/BungeeCore#242
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-09-30 12:20:26 +02:00
Commit abd5aab9bf
2 geänderte Dateien mit 13 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -27,7 +27,6 @@ import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button; import net.dv8tion.jda.api.interactions.components.Button;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -56,7 +55,7 @@ public class AuthManager {
if (TOKENS.containsKey(code)) { if (TOKENS.containsKey(code)) {
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete(); Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
if(member == null) return null; if(member == null) return null;
user.setDiscordId(member.getId()); user.setDiscordId(member.getIdLong());
MessageBuilder builder = new MessageBuilder(); MessageBuilder builder = new MessageBuilder();
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft"); 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"))); builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));

Datei anzeigen

@ -63,7 +63,7 @@ public class SteamwarUser {
private static final Map<String, SteamwarUser> usersByName = new HashMap<>(); private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>(); private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>(); private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final Map<String, SteamwarUser> usersByDiscord = new HashMap<>(); private static final Map<Long, SteamwarUser> usersByDiscord = new HashMap<>();
private static final InetAddress LIXFEL_DE; private static final InetAddress LIXFEL_DE;
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/"; private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
private static final JsonParser jsonParser = new JsonParser(); private static final JsonParser jsonParser = new JsonParser();
@ -75,7 +75,7 @@ public class SteamwarUser {
private int team; private int team;
private boolean leader; private boolean leader;
private final Map<Punishment.PunishmentType, Punishment> punishments; private final Map<Punishment.PunishmentType, Punishment> punishments;
private String discordId; private Long discordId;
static { static {
try { try {
@ -93,12 +93,16 @@ public class SteamwarUser {
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
team = rs.getInt("Team"); team = rs.getInt("Team");
leader = rs.getBoolean("Leader"); leader = rs.getBoolean("Leader");
discordId = rs.getString("DiscordId"); discordId = rs.getLong("DiscordId");
if(rs.wasNull()) {
discordId = null;
}
usersById.put(id, this); usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this); usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this); usersByUUID.put(uuid, this);
if(discordId != null) if(discordId != null) {
usersByDiscord.put(discordId, this); usersByDiscord.put(discordId, this);
}
punishments = Punishment.getPunishmentsOfPlayer(id); punishments = Punishment.getPunishmentsOfPlayer(id);
} }
@ -178,8 +182,8 @@ public class SteamwarUser {
} }
public static SteamwarUser get(Long discordId) { public static SteamwarUser get(Long discordId) {
if(usersByDiscord.containsKey(discordId.toString())) if(usersByDiscord.containsKey(discordId))
return usersByDiscord.get(discordId.toString()); return usersByDiscord.get(discordId);
return byDiscord.select(rs -> { return byDiscord.select(rs -> {
if(rs.next()) if(rs.next())
return new SteamwarUser(rs); return new SteamwarUser(rs);
@ -235,11 +239,11 @@ public class SteamwarUser {
return punishments.getOrDefault(type, null); return punishments.getOrDefault(type, null);
} }
public String getDiscordId() { public Long getDiscordId() {
return discordId; return discordId;
} }
public void setDiscordId(String discordId) { public void setDiscordId(Long discordId) {
usersByDiscord.remove(this.discordId); usersByDiscord.remove(this.discordId);
this.discordId = discordId; this.discordId = discordId;
updateDiscord.update(discordId, id); updateDiscord.update(discordId, id);