Re-Add old API to prevent some plugin break

This commit is contained in:
Xephi59 2015-07-13 06:07:48 +02:00
parent 5f77d50aae
commit 869b89adac
3 changed files with 215 additions and 40 deletions

View File

@ -35,6 +35,7 @@ import com.maxmind.geoip.LookupService;
import com.onarandombox.MultiverseCore.MultiverseCore;
import fr.xephi.authme.api.API;
import fr.xephi.authme.api.NewAPI;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.backup.FileCache;
@ -92,7 +93,7 @@ public class AuthMe extends JavaPlugin {
public double ChestShop = 0;
public boolean BungeeCord = false;
public Essentials ess;
public API api;
public NewAPI api;
public Management management;
public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<String, Integer>();
public ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<String, String>();
@ -206,7 +207,8 @@ public class AuthMe extends JavaPlugin {
dataManager = new DataManager(this);
// Setup API
api = new API(this);
api = new NewAPI(this);
new API(this);
// Setup Management
management = new Management(this);

View File

@ -4,13 +4,11 @@ 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.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
@ -21,38 +19,27 @@ import fr.xephi.authme.settings.Settings;
public class API {
public static final String newline = System.getProperty("line.separator");
public static API singleton;
public AuthMe plugin;
public static AuthMe instance;
public API(AuthMe plugin) {
this.plugin = plugin;
}
public API(Server serv) {
this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe");
public API(AuthMe instance) {
API.instance = instance;
}
/**
* Hook into AuthMe
*
* @return
*
* @return AuthMe plugin
* @return AuthMe instance
*/
public static API getInstance() {
if (singleton != null)
return singleton;
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (p == null || !(p instanceof AuthMe)) {
public static AuthMe hookAuthMe() {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (plugin == null || !(plugin instanceof AuthMe)) {
return null;
}
AuthMe authme = (AuthMe) p;
singleton = (new API(authme));
return singleton;
return (AuthMe) plugin;
}
public AuthMe getPlugin() {
return plugin;
return instance;
}
/**
@ -60,17 +47,29 @@ public class API {
* @param player
* @return true if player is authenticate
*/
public boolean isAuthenticated(Player player) {
public static boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName());
}
/**
*
* @param player
* @return true if player is a npc
*/
@Deprecated
public boolean isaNPC(Player player) {
if (instance.getCitizensCommunicator().isNPC(player))
return true;
return CombatTagComunicator.isNPC(player);
}
/**
*
* @param player
* @return true if player is a npc
*/
public boolean isNPC(Player player) {
if (plugin.getCitizensCommunicator().isNPC(player))
if (instance.getCitizensCommunicator().isNPC(player))
return true;
return CombatTagComunicator.isNPC(player);
}
@ -80,11 +79,11 @@ public class API {
* @param player
* @return true if the player is unrestricted
*/
public boolean isUnrestricted(Player player) {
public static boolean isUnrestricted(Player player) {
return Utils.getInstance().isUnrestricted(player);
}
public Location getLastLocation(Player player) {
public static Location getLastLocation(Player player) {
try {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
@ -100,13 +99,12 @@ public class API {
}
}
public void setPlayerInventory(Player player, ItemStack[] content,
public static void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) {
try {
player.getInventory().setContents(content);
player.getInventory().setArmorContents(armor);
} catch (Exception npe) {
ConsoleLogger.showError("Some error appear while trying to set inventory for " + player.getName());
} catch (NullPointerException npe) {
}
}
@ -115,9 +113,9 @@ public class API {
* @param playerName
* @return true if player is registered
*/
public boolean isRegistered(String playerName) {
public static boolean isRegistered(String playerName) {
String player = playerName.toLowerCase();
return plugin.database.isAuthAvailable(player);
return instance.database.isAuthAvailable(player);
}
/**
@ -125,11 +123,12 @@ public class API {
* playerName, String passwordToCheck
* @return true if the password is correct , false else
*/
public boolean checkPassword(String playerName, String passwordToCheck) {
public static boolean checkPassword(String playerName,
String passwordToCheck) {
if (!isRegistered(playerName))
return false;
String player = playerName.toLowerCase();
PlayerAuth auth = plugin.database.getAuth(player);
PlayerAuth auth = instance.database.getAuth(player);
try {
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
} catch (NoSuchAlgorithmException e) {
@ -144,15 +143,15 @@ public class API {
* playerName, String password
* @return true if the player is register correctly
*/
public boolean registerPlayer(String playerName, String password) {
public static boolean registerPlayer(String playerName, String password) {
try {
String name = playerName.toLowerCase();
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
if (isRegistered(name)) {
return false;
}
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com");
if (!plugin.database.saveAuth(auth)) {
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com");
if (!instance.database.saveAuth(auth)) {
return false;
}
return true;
@ -167,8 +166,8 @@ public class API {
* @param Player
* player
*/
public void forceLogin(Player player) {
plugin.management.performLogin(player, "dontneed", true);
public static void forceLogin(Player player) {
instance.management.performLogin(player, "dontneed", true);
}
}

View File

@ -0,0 +1,174 @@
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.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
public class NewAPI {
public static final String newline = System.getProperty("line.separator");
public static NewAPI singleton;
public AuthMe plugin;
public NewAPI(AuthMe plugin) {
this.plugin = plugin;
}
public NewAPI(Server serv) {
this.plugin = (AuthMe) serv.getPluginManager().getPlugin("AuthMe");
}
/**
* Hook into AuthMe
*
* @return
*
* @return AuthMe plugin
*/
public static NewAPI getInstance() {
if (singleton != null)
return singleton;
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (p == null || !(p instanceof AuthMe)) {
return null;
}
AuthMe authme = (AuthMe) p;
singleton = (new NewAPI(authme));
return singleton;
}
public AuthMe getPlugin() {
return plugin;
}
/**
*
* @param player
* @return true if player is authenticate
*/
public boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName());
}
/**
*
* @param player
* @return true if player is a npc
*/
public boolean isNPC(Player player) {
if (plugin.getCitizensCommunicator().isNPC(player))
return true;
return CombatTagComunicator.isNPC(player);
}
/**
*
* @param player
* @return true if the player is unrestricted
*/
public boolean isUnrestricted(Player player) {
return Utils.getInstance().isUnrestricted(player);
}
public Location getLastLocation(Player player) {
try {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
if (auth != null) {
Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
return loc;
} else {
return null;
}
} catch (NullPointerException ex) {
return null;
}
}
public void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) {
try {
player.getInventory().setContents(content);
player.getInventory().setArmorContents(armor);
} catch (Exception npe) {
ConsoleLogger.showError("Some error appear while trying to set inventory for " + player.getName());
}
}
/**
*
* @param playerName
* @return true if player is registered
*/
public boolean isRegistered(String playerName) {
String player = playerName.toLowerCase();
return plugin.database.isAuthAvailable(player);
}
/**
* @param String
* playerName, String passwordToCheck
* @return true if the password is correct , false else
*/
public boolean checkPassword(String playerName, String passwordToCheck) {
if (!isRegistered(playerName))
return false;
String player = playerName.toLowerCase();
PlayerAuth auth = plugin.database.getAuth(player);
try {
return PasswordSecurity.comparePasswordWithHash(passwordToCheck, auth.getHash(), playerName);
} catch (NoSuchAlgorithmException e) {
return false;
}
}
/**
* Register a player
*
* @param String
* playerName, String password
* @return true if the player is register correctly
*/
public boolean registerPlayer(String playerName, String password) {
try {
String name = playerName.toLowerCase();
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
if (isRegistered(name)) {
return false;
}
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0, "your@email.com");
if (!plugin.database.saveAuth(auth)) {
return false;
}
return true;
} catch (NoSuchAlgorithmException ex) {
return false;
}
}
/**
* Force a player to login
*
* @param Player
* player
*/
public void forceLogin(Player player) {
plugin.management.performLogin(player, "dontneed", true);
}
}