Merge pull request #18 from Xephi/master

Up
This commit is contained in:
Gabriele C. 2015-07-31 01:05:15 +02:00
commit 4568b11664
2 changed files with 94 additions and 98 deletions

View File

@ -30,6 +30,7 @@ public class API {
*
* @return AuthMe instance
*/
@Deprecated
public static AuthMe hookAuthMe() {
if (instance != null)
return instance;
@ -41,6 +42,7 @@ public class API {
return instance;
}
@Deprecated
public AuthMe getPlugin() {
return instance;
}
@ -50,6 +52,7 @@ public class API {
* @param player
* @return true if player is authenticate
*/
@Deprecated
public static boolean isAuthenticated(Player player) {
return PlayerCache.getInstance().isAuthenticated(player.getName());
}
@ -71,6 +74,7 @@ public class API {
* @param player
* @return true if player is a npc
*/
@Deprecated
public boolean isNPC(Player player) {
if (instance.getCitizensCommunicator().isNPC(player))
return true;
@ -82,10 +86,12 @@ public class API {
* @param player
* @return true if the player is unrestricted
*/
@Deprecated
public static boolean isUnrestricted(Player player) {
return Utils.getInstance().isUnrestricted(player);
}
@Deprecated
public static Location getLastLocation(Player player) {
try {
PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
@ -102,6 +108,7 @@ public class API {
}
}
@Deprecated
public static void setPlayerInventory(Player player, ItemStack[] content,
ItemStack[] armor) {
try {
@ -116,6 +123,7 @@ public class API {
* @param playerName
* @return true if player is registered
*/
@Deprecated
public static boolean isRegistered(String playerName) {
String player = playerName.toLowerCase();
return instance.database.isAuthAvailable(player);
@ -126,6 +134,7 @@ public class API {
* playerName, String passwordToCheck
* @return true if the password is correct , false else
*/
@Deprecated
public static boolean checkPassword(String playerName,
String passwordToCheck) {
if (!isRegistered(playerName))
@ -146,6 +155,7 @@ public class API {
* playerName, String password
* @return true if the player is register correctly
*/
@Deprecated
public static boolean registerPlayer(String playerName, String password) {
try {
String name = playerName.toLowerCase();
@ -169,6 +179,7 @@ public class API {
* @param Player
* player
*/
@Deprecated
public static void forceLogin(Player player) {
instance.management.performLogin(player, "dontneed", true);
}

View File

@ -22,9 +22,9 @@ import com.comphenix.attribute.Attributes.Operation;
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.settings.Settings;
import fr.xephi.authme.Utils;
public class FileCache {
@ -217,108 +217,93 @@ public class FileCache {
boolean op = false;
boolean flying = false;
Scanner reader = null;
try {
reader = new Scanner(file);
Scanner reader = new Scanner(file);
int i = 0;
int a = 0;
while (reader.hasNextLine()) {
String line = reader.nextLine();
int i = 0;
int a = 0;
while (reader.hasNextLine()) {
String line = reader.nextLine();
if (!line.contains(":")) {
// the fist line represent the player group,
// operator
// status
// and flying status
final String[] playerInfo = line.split(";");
group = playerInfo[0];
if (!line.contains(":")) {
// the fist line represent the player group,
// operator
// status
// and flying status
final String[] playerInfo = line.split(";");
group = playerInfo[0];
if (Integer.parseInt(playerInfo[1]) == 1) {
op = true;
} else op = false;
if (playerInfo.length > 2) {
if (Integer.parseInt(playerInfo[2]) == 1)
flying = true;
else flying = false;
}
continue;
if (Integer.parseInt(playerInfo[1]) == 1) {
op = true;
} else op = false;
if (playerInfo.length > 2) {
if (Integer.parseInt(playerInfo[2]) == 1)
flying = true;
else flying = false;
}
if (!line.startsWith("i") && !line.startsWith("w")) {
continue;
}
String lores = "";
String name = "";
if (line.split("\\*").length > 1) {
lores = line.split("\\*")[1];
line = line.split("\\*")[0];
}
if (line.split(";").length > 1) {
name = line.split(";")[1];
line = line.split(";")[0];
}
final String[] in = line.split(":");
// can enchant item? size ofstring in file - 4 all / 2 =
// number
// of enchant
if (in[0].equals("i")) {
stacki[i] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
if (in.length > 4 && !in[4].isEmpty()) {
for (int k = 4; k < in.length - 1; k++) {
stacki[i].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
k++;
}
}
try {
ItemMeta meta = plugin.getServer().getItemFactory().getItemMeta(stacki[i].getType());
if (!name.isEmpty()) {
meta.setDisplayName(name);
}
if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) {
loreList.add(s);
}
meta.setLore(loreList);
}
if (meta != null)
stacki[i].setItemMeta(meta);
} catch (Exception e) {
}
i++;
} else {
stacka[a] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
if (in.length > 4 && !in[4].isEmpty()) {
for (int k = 4; k < in.length - 1; k++) {
stacka[a].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
k++;
}
}
try {
ItemMeta meta = plugin.getServer().getItemFactory().getItemMeta(stacka[a].getType());
if (!name.isEmpty())
meta.setDisplayName(name);
if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) {
loreList.add(s);
}
meta.setLore(loreList);
}
if (meta != null)
stacki[i].setItemMeta(meta);
} catch (Exception e) {
}
a++;
}
continue;
}
} catch (final Exception e) {
ConsoleLogger.showError("Error on creating a file cache for " + player.getName() + ", maybe wipe inventory...");
} finally {
if (reader != null) {
reader.close();
if (!line.startsWith("i") && !line.startsWith("w")) {
continue;
}
String lores = "";
String name = "";
if (line.split("\\*").length > 1) {
lores = line.split("\\*")[1];
line = line.split("\\*")[0];
}
if (line.split(";").length > 1) {
name = line.split(";")[1];
line = line.split(";")[0];
}
final String[] in = line.split(":");
// can enchant item? size ofstring in file - 4 all / 2 =
// number
// of enchant
if (in[0].equals("i")) {
stacki[i] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
if (in.length > 4 && !in[4].isEmpty()) {
for (int k = 4; k < in.length - 1; k++) {
stacki[i].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
k++;
}
}
ItemMeta meta = stacki[i].getItemMeta();
if (!name.isEmpty()) {
meta.setDisplayName(name);
}
if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) {
loreList.add(s);
}
meta.setLore(loreList);
}
if (meta != null)
stacki[i].setItemMeta(meta);
i++;
} else {
stacka[a] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3])));
if (in.length > 4 && !in[4].isEmpty()) {
for (int k = 4; k < in.length - 1; k++) {
stacka[a].addUnsafeEnchantment(Enchantment.getByName(in[k]), Integer.parseInt(in[k + 1]));
k++;
}
}
ItemMeta meta = stacka[a].getItemMeta();
if (!name.isEmpty())
meta.setDisplayName(name);
if (!lores.isEmpty()) {
List<String> loreList = new ArrayList<String>();
for (String s : lores.split("%newline%")) {
loreList.add(s);
}
meta.setLore(loreList);
}
if (meta != null)
stacki[i].setItemMeta(meta);
a++;
}
}
return new DataFileCache(stacki, stacka, group, op, flying);
@ -548,7 +533,7 @@ public class FileCache {
file.delete();
} else {
file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + player.getName().toLowerCase() + ".cache");
if(file.isFile()){
if (file.isFile()) {
file.delete();
} else {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache, it doesn't exist!");