forked from TuxCoding/FastLogin
@ -1,10 +1,20 @@
|
||||
package com.github.games647.fastlogin.bukkit.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import fr.xephi.authme.events.RestoreSessionEvent;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
/**
|
||||
* Github: https://github.com/Xephi/AuthMeReloaded/
|
||||
@ -15,12 +25,31 @@ import org.bukkit.entity.Player;
|
||||
* <p>
|
||||
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
|
||||
*/
|
||||
public class AuthMeHook implements AuthPlugin<Player> {
|
||||
public class AuthMeHook implements AuthPlugin<Player>, Listener {
|
||||
|
||||
private final Set<UUID> sessionLogins = Sets.newConcurrentHashSet();
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
public AuthMeHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onRestoreSession(RestoreSessionEvent restoreSessionEvent) {
|
||||
UUID uniqueId = restoreSessionEvent.getPlayer().getUniqueId();
|
||||
sessionLogins.add(uniqueId);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent quitEvent) {
|
||||
UUID uniqueId = quitEvent.getPlayer().getUniqueId();
|
||||
sessionLogins.remove(uniqueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceLogin(Player player) {
|
||||
//skips registration and login
|
||||
if (AuthMeApi.getInstance().isAuthenticated(player)) {
|
||||
if (AuthMeApi.getInstance().isAuthenticated(player) || sessionLogins.contains(player.getUniqueId())) {
|
||||
return false;
|
||||
} else {
|
||||
AuthMeApi.getInstance().forceLogin(player);
|
||||
@ -38,7 +67,6 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
||||
public boolean forceRegister(Player player, String password) {
|
||||
//this automatically registers the player too
|
||||
AuthMeApi.getInstance().forceRegister(player, password);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.games647.fastlogin.bukkit.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import de.st_ddt.crazylogin.CrazyLogin;
|
||||
@ -26,13 +27,19 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class CrazyLoginHook implements AuthPlugin<Player> {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
private final CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
|
||||
private final PlayerListener playerListener = getListener();
|
||||
|
||||
public CrazyLoginHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceLogin(Player player) {
|
||||
//not thread-safe operation
|
||||
Future<Optional<LoginPlayerData>> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin, () -> {
|
||||
Future<Optional<LoginPlayerData>> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player);
|
||||
if (playerData != null) {
|
||||
//mark the account as logged in
|
||||
@ -71,7 +78,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
|
||||
return true;
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -105,7 +112,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
|
||||
try {
|
||||
listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true);
|
||||
} catch (IllegalAccessException ex) {
|
||||
crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
|
||||
listener = null;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.games647.fastlogin.bukkit.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -23,11 +24,16 @@ import ultraauth.managers.PlayerManager;
|
||||
public class UltraAuthHook implements AuthPlugin<Player> {
|
||||
|
||||
private final Plugin ultraAuthPlugin = Main.main;
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
public UltraAuthHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceLogin(Player player) {
|
||||
//not thread-safe
|
||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, () -> {
|
||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||
if (UltraAuthAPI.isAuthenticated(player)) {
|
||||
return true;
|
||||
}
|
||||
@ -39,7 +45,7 @@ public class UltraAuthHook implements AuthPlugin<Player> {
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
ultraAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.games647.fastlogin.bukkit.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import de.luricos.bukkit.xAuth.xAuth;
|
||||
@ -22,11 +23,16 @@ import org.bukkit.entity.Player;
|
||||
public class xAuthHook implements AuthPlugin<Player> {
|
||||
|
||||
private final xAuth xAuthPlugin = xAuth.getPlugin();
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
public xAuthHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceLogin(Player player) {
|
||||
//not thread-safe
|
||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
|
||||
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(plugin, () -> {
|
||||
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
|
||||
if (xAuthPlayer != null) {
|
||||
if (xAuthPlayer.isAuthenticated()) {
|
||||
@ -46,7 +52,7 @@ public class xAuthHook implements AuthPlugin<Player> {
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
xAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -74,7 +80,7 @@ public class xAuthHook implements AuthPlugin<Player> {
|
||||
//login in the player after registration
|
||||
return future.get() && forceLogin(player);
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
xAuthPlugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to forceLogin", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user