mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
IMPORTANT : Change how API works !
This commit is contained in:
parent
627a57615a
commit
d22607e8bd
@ -1,11 +1,14 @@
|
||||
package fr.xephi.authme.api;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -18,29 +21,41 @@ import fr.xephi.authme.settings.Settings;
|
||||
public class API {
|
||||
|
||||
public static final String newline = System.getProperty("line.separator");
|
||||
public static AuthMe instance;
|
||||
public static DataSource database;
|
||||
public static API singleton;
|
||||
public AuthMe plugin;
|
||||
public DataSource database;
|
||||
|
||||
public API(AuthMe instance, DataSource database) {
|
||||
API.instance = instance;
|
||||
API.database = database;
|
||||
public API(AuthMe plugin, DataSource database) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public API(Server serv) {
|
||||
this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe");
|
||||
this.database = this.plugin.database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into AuthMe
|
||||
*
|
||||
* @return AuthMe instance
|
||||
* @return
|
||||
*
|
||||
* @return AuthMe plugin
|
||||
*/
|
||||
public static AuthMe hookAuthMe() {
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
||||
if (plugin == null || !(plugin instanceof AuthMe)) {
|
||||
public static API getInstance() {
|
||||
if (singleton != null)
|
||||
return singleton;
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
|
||||
if (p == null || !(p instanceof AuthMe)) {
|
||||
return null;
|
||||
}
|
||||
return (AuthMe) plugin;
|
||||
AuthMe authme = (AuthMe) p;
|
||||
singleton = (new API(authme, authme.database));
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public AuthMe getPlugin() {
|
||||
return instance;
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +63,7 @@ public class API {
|
||||
* @param player
|
||||
* @return true if player is authenticate
|
||||
*/
|
||||
public static boolean isAuthenticated(Player player) {
|
||||
public boolean isAuthenticated(Player player) {
|
||||
return PlayerCache.getInstance().isAuthenticated(player.getName());
|
||||
}
|
||||
|
||||
@ -59,7 +74,7 @@ public class API {
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isaNPC(Player player) {
|
||||
if (instance.getCitizensCommunicator().isNPC(player, instance))
|
||||
if (plugin.getCitizensCommunicator().isNPC(player, plugin))
|
||||
return true;
|
||||
return CombatTagComunicator.isNPC(player);
|
||||
}
|
||||
@ -70,7 +85,7 @@ public class API {
|
||||
* @return true if player is a npc
|
||||
*/
|
||||
public boolean isNPC(Player player) {
|
||||
if (instance.getCitizensCommunicator().isNPC(player, instance))
|
||||
if (plugin.getCitizensCommunicator().isNPC(player, plugin))
|
||||
return true;
|
||||
return CombatTagComunicator.isNPC(player);
|
||||
}
|
||||
@ -80,11 +95,11 @@ public class API {
|
||||
* @param player
|
||||
* @return true if the player is unrestricted
|
||||
*/
|
||||
public static boolean isUnrestricted(Player player) {
|
||||
public boolean isUnrestricted(Player player) {
|
||||
return Utils.getInstance().isUnrestricted(player);
|
||||
}
|
||||
|
||||
public static Location getLastLocation(Player player) {
|
||||
public Location getLastLocation(Player player) {
|
||||
try {
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
|
||||
|
||||
@ -100,7 +115,7 @@ public class API {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPlayerInventory(Player player, ItemStack[] content,
|
||||
public void setPlayerInventory(Player player, ItemStack[] content,
|
||||
ItemStack[] armor) {
|
||||
try {
|
||||
player.getInventory().setContents(content);
|
||||
@ -114,7 +129,7 @@ public class API {
|
||||
* @param playerName
|
||||
* @return true if player is registered
|
||||
*/
|
||||
public static boolean isRegistered(String playerName) {
|
||||
public boolean isRegistered(String playerName) {
|
||||
String player = playerName.toLowerCase();
|
||||
return database.isAuthAvailable(player);
|
||||
}
|
||||
@ -124,8 +139,7 @@ public class API {
|
||||
* playerName, String passwordToCheck
|
||||
* @return true if the password is correct , false else
|
||||
*/
|
||||
public static boolean checkPassword(String playerName,
|
||||
String passwordToCheck) {
|
||||
public boolean checkPassword(String playerName, String passwordToCheck) {
|
||||
if (!isRegistered(playerName))
|
||||
return false;
|
||||
String player = playerName.toLowerCase();
|
||||
@ -144,7 +158,7 @@ public class API {
|
||||
* playerName, String password
|
||||
* @return true if the player is register correctly
|
||||
*/
|
||||
public static boolean registerPlayer(String playerName, String password) {
|
||||
public boolean registerPlayer(String playerName, String password) {
|
||||
try {
|
||||
String name = playerName.toLowerCase();
|
||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
@ -167,8 +181,8 @@ public class API {
|
||||
* @param Player
|
||||
* player
|
||||
*/
|
||||
public static void forceLogin(Player player) {
|
||||
instance.management.performLogin(player, "dontneed", true);
|
||||
public void forceLogin(Player player) {
|
||||
plugin.management.performLogin(player, "dontneed", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
@ -405,6 +404,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
if (player == null)
|
||||
return;
|
||||
final String name = player.getName().toLowerCase();
|
||||
boolean isAuthAvailable = data.isAuthAvailable(name);
|
||||
|
||||
if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
|
||||
return;
|
||||
@ -412,7 +412,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
if (Settings.enablePasspartu && !Settings.countriesBlacklist.isEmpty()) {
|
||||
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
||||
if (((code == null) || (Settings.countriesBlacklist.contains(code) && !isAuthAvailable)) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
||||
event.setKickMessage(m.send("country_banned")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
@ -420,7 +420,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
if (Settings.enableProtection && !Settings.countries.isEmpty()) {
|
||||
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (((code == null) || (!Settings.countries.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
||||
if (((code == null) || (!Settings.countries.contains(code) && !isAuthAvailable)) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
||||
event.setKickMessage(m.send("country_banned")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
@ -441,7 +441,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.isAuthAvailable(name) && LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (isAuthAvailable && LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (Settings.isSessionsEnabled)
|
||||
if (PlayerCache.getInstance().isAuthenticated(name))
|
||||
if (!Settings.sessionExpireOnIpChange)
|
||||
|
@ -17,7 +17,6 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.Utils.groupType;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.backup.DataFileCache;
|
||||
@ -255,7 +254,7 @@ public class AsyncronousJoin {
|
||||
if (!Settings.noConsoleSpam)
|
||||
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
||||
} else {
|
||||
API.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor());
|
||||
plugin.api.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor());
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.Utils;
|
||||
import fr.xephi.authme.Utils.groupType;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.backup.FileCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
@ -91,7 +90,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
API.setPlayerInventory(player, event.getInventory(), event.getArmor());
|
||||
plugin.api.setPlayerInventory(player, event.getInventory(), event.getArmor());
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +145,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
} else {
|
||||
teleportBackFromSpawn();
|
||||
}
|
||||
} else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
||||
} else
|
||||
if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
|
||||
teleportToSpawn();
|
||||
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
|
||||
packQuitLocation();
|
||||
|
@ -82,6 +82,6 @@ public class AsyncronousQuit {
|
||||
PlayerCache.getInstance().removePlayer(name);
|
||||
database.setUnlogged(name);
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(player, inv, armor, isOp, isFlying, needToChange));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange));
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,13 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||
|
||||
protected AuthMe plugin;
|
||||
protected Player player;
|
||||
protected boolean isOp;
|
||||
protected boolean isFlying;
|
||||
@ -17,9 +18,10 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||
protected ItemStack[] armor;
|
||||
protected boolean needToChange;
|
||||
|
||||
public ProcessSyncronousPlayerQuit(Player player, ItemStack[] inv,
|
||||
ItemStack[] armor, boolean isOp, boolean isFlying,
|
||||
public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player,
|
||||
ItemStack[] inv, ItemStack[] armor, boolean isOp, boolean isFlying,
|
||||
boolean needToChange) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.isOp = isOp;
|
||||
this.isFlying = isFlying;
|
||||
@ -34,7 +36,7 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor);
|
||||
player.getServer().getPluginManager().callEvent(ev);
|
||||
if (!ev.isCancelled()) {
|
||||
API.setPlayerInventory(player, ev.getInventory(), ev.getArmor());
|
||||
plugin.api.setPlayerInventory(player, ev.getInventory(), ev.getArmor());
|
||||
}
|
||||
}
|
||||
if (needToChange) {
|
||||
|
Loading…
Reference in New Issue
Block a user