Added support of detecting name changes (Fixes #18)

This commit is contained in:
games647 committed 2016-06-01 14:42:48 +02:00
1 parent cb876a52bd
commit 51d0aefbf3
15 files changed
+186 -49

No files matched your search

@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Achievement;
import org.bukkit.Effect;
import org.bukkit.EntityEffect;
@@ -71,7 +71,7 @@ public class LoginSecurityHook implements BukkitAuthPlugin {
}
@Override
public boolean forceRegister(final Player player, final String password) {
public boolean forceRegister(Player player, String password) {
DataManager dataManager = securityPlugin.data;
UUID playerUUID = player.getUniqueId();
@@ -1,7 +1,7 @@
package com.github.games647.fastlogin.bukkit.listener;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import com.github.games647.fastlogin.core.PlayerProfile;
@@ -40,20 +40,31 @@ public class ProtocolSupportListener implements Listener {
return;
}
PlayerProfile playerProfile = plugin.getCore().getStorage().loadProfile(username);
if (playerProfile != null) {
if (playerProfile.isPremium()) {
if (playerProfile.getUserId() != -1) {
startPremiumSession(username, loginStartEvent, true, playerProfile);
PlayerProfile profile = plugin.getCore().getStorage().loadProfile(username);
if (profile != null) {
if (profile.isPremium()) {
if (profile.getUserId() != -1) {
startPremiumSession(username, loginStartEvent, true, profile);
}
} else if (playerProfile.getUserId() == -1) {
} else if (profile.getUserId() == -1) {
//user not exists in the db
try {
if (plugin.getConfig().getBoolean("nameChangeCheck")) {
UUID premiumUUID = plugin.getCore().getMojangApiConnector().getPremiumUUID(username);
if (premiumUUID != null) {
profile = plugin.getCore().getStorage().loadProfile(premiumUUID);
if (profile != null) {
plugin.getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID);
startPremiumSession(username, loginStartEvent, false, profile);
}
}
}
if (plugin.getConfig().getBoolean("autoRegister") && !authPlugin.isRegistered(username)) {
UUID premiumUUID = plugin.getCore().getMojangApiConnector().getPremiumUUID(username);
if (premiumUUID != null) {
plugin.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
startPremiumSession(username, loginStartEvent, false, playerProfile);
startPremiumSession(username, loginStartEvent, false, profile);
}
}
} catch (Exception ex) {
@@ -75,8 +86,7 @@ public class ProtocolSupportListener implements Listener {
}
}
private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered
, PlayerProfile playerProfile) {
private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered, PlayerProfile playerProfile) {
loginStartEvent.setOnlineMode(true);
InetSocketAddress address = loginStartEvent.getAddress();
@@ -5,8 +5,8 @@ import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import com.github.games647.fastlogin.core.PlayerProfile;
@@ -92,6 +92,17 @@ public class StartPacketListener extends PacketAdapter {
} else if (profile.getUserId() == -1) {
//user not exists in the db
try {
if (plugin.getConfig().getBoolean("nameChangeCheck")) {
UUID premiumUUID = plugin.getCore().getMojangApiConnector().getPremiumUUID(username);
if (premiumUUID != null) {
profile = plugin.getCore().getStorage().loadProfile(premiumUUID);
if (profile != null) {
plugin.getLogger().log(Level.FINER, "Player {0} changed it's username", premiumUUID);
enablePremiumLogin(username, profile, sessionKey, player, packetEvent, false);
}
}
}
if (plugin.getConfig().getBoolean("autoRegister") && !authPlugin.isRegistered(username)) {
UUID premiumUUID = plugin.getCore().getMojangApiConnector().getPremiumUUID(username);
if (premiumUUID != null) {