From 58ac73a5a9b71ca139679ae7a18773d136c7222c Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 31 Aug 2016 13:29:06 +0200 Subject: [PATCH] Fix update username in FastLogin database after nameChange (Fixes #67) --- CHANGELOG.md | 1 + .../bukkit/listener/protocollib/NameCheckTask.java | 4 ++++ .../listener/protocolsupport/ProtocolSupportListener.java | 4 ++++ .../fastlogin/bungee/tasks/AsyncPremiumCheck.java | 4 ++++ .../com/github/games647/fastlogin/core/PlayerProfile.java | 8 ++++++-- 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccf3bc2c..56dd140a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Added second attempt login -> cracked login * Fix ProtocolSupport autoRegister +* Fix update username in FastLogin database after nameChange ######1.8 diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index dad9d4f4..1fe86992 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -78,6 +78,10 @@ public class NameCheckTask implements Runnable { PlayerProfile uuidProfile = plugin.getCore().getStorage().loadProfile(premiumUUID); if (uuidProfile != null) { plugin.getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID); + + //update the username to the new one in the database + uuidProfile.setPlayerName(username); + enablePremiumLogin(uuidProfile, false); return; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index e77404a3..bbbf6a56 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -70,6 +70,10 @@ public class ProtocolSupportListener implements Listener { PlayerProfile uuidProfile = plugin.getCore().getStorage().loadProfile(premiumUUID); if (uuidProfile != null) { plugin.getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID); + + //update the username to the new one in the database + uuidProfile.setPlayerName(username); + startPremiumSession(username, loginStartEvent, false, uuidProfile); return; } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java index 7b7475a4..ed7c7214 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java @@ -88,6 +88,10 @@ public class AsyncPremiumCheck implements Runnable { if (profile != null) { //uuid exists in the database plugin.getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID); + + //update the username to the new one in the database + profile.setPlayerName(username); + requestPremiumLogin(connection, profile, username, false); return true; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java index 1db2bcb6..9ad52351 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java @@ -4,7 +4,7 @@ import java.util.UUID; public class PlayerProfile { - private final String playerName; + private String playerName; private long userId; @@ -32,10 +32,14 @@ public class PlayerProfile { this.lastIp = lastIp; } - public String getPlayerName() { + public synchronized String getPlayerName() { return playerName; } + public synchronized void setPlayerName(String playerName) { + this.playerName = playerName; + } + public synchronized long getUserId() { return userId; }