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