mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Add support for new authme API
This commit is contained in:
@ -3,6 +3,7 @@ package com.github.games647.fastlogin.bukkit.hooks;
|
|||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
|
|
||||||
import fr.xephi.authme.api.NewAPI;
|
import fr.xephi.authme.api.NewAPI;
|
||||||
|
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -17,13 +18,35 @@ import org.bukkit.entity.Player;
|
|||||||
*/
|
*/
|
||||||
public class AuthMeHook implements AuthPlugin<Player> {
|
public class AuthMeHook implements AuthPlugin<Player> {
|
||||||
|
|
||||||
|
private final boolean v3APIAvailable;
|
||||||
|
|
||||||
|
public AuthMeHook() {
|
||||||
|
boolean apiAvailable = true;
|
||||||
|
try {
|
||||||
|
Class.forName("fr.xephi.authme.api.v3.AuthMeApi");
|
||||||
|
} catch (ClassNotFoundException classNotFoundEx) {
|
||||||
|
apiAvailable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.v3APIAvailable = apiAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceLogin(Player player) {
|
public boolean forceLogin(Player player) {
|
||||||
//skips registration and login
|
if (v3APIAvailable) {
|
||||||
if (NewAPI.getInstance().isAuthenticated(player)) {
|
//skips registration and login
|
||||||
return false;
|
if (AuthMeApi.getInstance().isAuthenticated(player)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AuthMeApi.getInstance().forceLogin(player);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
NewAPI.getInstance().forceLogin(player);
|
//skips registration and login
|
||||||
|
if (NewAPI.getInstance().isAuthenticated(player)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
NewAPI.getInstance().forceLogin(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -31,13 +54,22 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) throws Exception {
|
||||||
|
if (v3APIAvailable) {
|
||||||
|
return AuthMeApi.getInstance().isRegistered(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
return NewAPI.getInstance().isRegistered(playerName);
|
return NewAPI.getInstance().isRegistered(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forceRegister(Player player, String password) {
|
public boolean forceRegister(Player player, String password) {
|
||||||
//this automatically registers the player too
|
//this automatically registers the player too
|
||||||
NewAPI.getInstance().forceRegister(player, password);
|
if (v3APIAvailable) {
|
||||||
|
AuthMeApi.getInstance().forceRegister(player, password);
|
||||||
|
} else {
|
||||||
|
NewAPI.getInstance().forceRegister(player, password);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user