Stuff from the common floobits workspace

Author:    AuthMe-Team <AuthMeTeam@123NoEmail.com>
This commit is contained in:
AuthMe-Team
2015-11-23 20:20:42 +01:00
committed by Gabriele C
parent 69a09aec17
commit 9ec2d6d059
169 changed files with 5161 additions and 4806 deletions
+158 -122
View File
@@ -22,10 +22,11 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param ip String
*
* @param nickname String
* @param ip String
* @param lastLogin long
* @param realName String
* @param realName String
*/
public PlayerAuth(String nickname, String ip, long lastLogin, String realName) {
this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@@ -33,11 +34,12 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
*
* @param nickname String
* @param x double
* @param y double
* @param z double
* @param world String
* @param x double
* @param y double
* @param z double
* @param world String
* @param realName String
*/
public PlayerAuth(String nickname, double x, double y, double z, String world, String realName) {
@@ -46,11 +48,12 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param ip String
*
* @param nickname String
* @param hash String
* @param ip String
* @param lastLogin long
* @param realName String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) {
this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@@ -58,12 +61,13 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param ip String
*
* @param nickname String
* @param hash String
* @param ip String
* @param lastLogin long
* @param email String
* @param realName String
* @param email String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) {
this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
@@ -71,12 +75,13 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param salt String
* @param ip String
*
* @param nickname String
* @param hash String
* @param salt String
* @param ip String
* @param lastLogin long
* @param realName String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, String realName) {
this(nickname, hash, salt, -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@@ -84,16 +89,17 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param ip String
*
* @param nickname String
* @param hash String
* @param ip String
* @param lastLogin long
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this(nickname, hash, "", -1, ip, lastLogin, x, y, z, world, email, realName);
@@ -101,17 +107,18 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param salt String
* @param ip String
*
* @param nickname String
* @param hash String
* @param salt String
* @param ip String
* @param lastLogin long
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this(nickname, hash, salt, -1, ip, lastLogin, x, y, z, world, email, realName);
@@ -119,13 +126,14 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param salt String
* @param groupId int
* @param ip String
*
* @param nickname String
* @param hash String
* @param salt String
* @param groupId int
* @param ip String
* @param lastLogin long
* @param realName String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, String realName) {
this(nickname, hash, salt, groupId, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
@@ -133,18 +141,19 @@ public class PlayerAuth {
/**
* Constructor for PlayerAuth.
* @param nickname String
* @param hash String
* @param salt String
* @param groupId int
* @param ip String
*
* @param nickname String
* @param hash String
* @param salt String
* @param groupId int
* @param ip String
* @param lastLogin long
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
* @param x double
* @param y double
* @param z double
* @param world String
* @param email String
* @param realName String
*/
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this.nickname = nickname;
@@ -163,6 +172,7 @@ public class PlayerAuth {
/**
* Method set.
*
* @param auth PlayerAuth
*/
public void set(PlayerAuth auth) {
@@ -181,6 +191,7 @@ public class PlayerAuth {
/**
* Method setName.
*
* @param nickname String
*/
public void setName(String nickname) {
@@ -189,22 +200,25 @@ public class PlayerAuth {
/**
* Method getNickname.
* @return String */
*
* @return String
*/
public String getNickname() {
return nickname;
}
/**
* Method getRealName.
* @return String */
*
* @return String
*/
public String getRealName() {
return realName;
}
/**
* Method setRealName.
*
* @param realName String
*/
public void setRealName(String realName) {
@@ -213,14 +227,25 @@ public class PlayerAuth {
/**
* Method getGroupId.
* @return int */
*
* @return int
*/
public int getGroupId() {
return groupId;
}
/**
* Method getQuitLocX.
*
* @return double
*/
public double getQuitLocX() {
return x;
}
/**
* Method setQuitLocX.
*
* @param d double
*/
public void setQuitLocX(double d) {
@@ -228,15 +253,17 @@ public class PlayerAuth {
}
/**
* Method getQuitLocX.
* @return double */
public double getQuitLocX() {
return x;
* Method getQuitLocY.
*
* @return double
*/
public double getQuitLocY() {
return y;
}
/**
* Method setQuitLocY.
*
* @param d double
*/
public void setQuitLocY(double d) {
@@ -244,15 +271,17 @@ public class PlayerAuth {
}
/**
* Method getQuitLocY.
* @return double */
public double getQuitLocY() {
return y;
* Method getQuitLocZ.
*
* @return double
*/
public double getQuitLocZ() {
return z;
}
/**
* Method setQuitLocZ.
*
* @param d double
*/
public void setQuitLocZ(double d) {
@@ -260,15 +289,17 @@ public class PlayerAuth {
}
/**
* Method getQuitLocZ.
* @return double */
public double getQuitLocZ() {
return z;
* Method getWorld.
*
* @return String
*/
public String getWorld() {
return world;
}
/**
* Method setWorld.
*
* @param world String
*/
public void setWorld(String world) {
@@ -276,15 +307,17 @@ public class PlayerAuth {
}
/**
* Method getWorld.
* @return String */
public String getWorld() {
return world;
* Method getIp.
*
* @return String
*/
public String getIp() {
return ip;
}
/**
* Method setIp.
*
* @param ip String
*/
public void setIp(String ip) {
@@ -292,15 +325,17 @@ public class PlayerAuth {
}
/**
* Method getIp.
* @return String */
public String getIp() {
return ip;
* Method getLastLogin.
*
* @return long
*/
public long getLastLogin() {
return lastLogin;
}
/**
* Method setLastLogin.
*
* @param lastLogin long
*/
public void setLastLogin(long lastLogin) {
@@ -308,15 +343,17 @@ public class PlayerAuth {
}
/**
* Method getLastLogin.
* @return long */
public long getLastLogin() {
return lastLogin;
* Method getEmail.
*
* @return String
*/
public String getEmail() {
return email;
}
/**
* Method setEmail.
*
* @param email String
*/
public void setEmail(String email) {
@@ -324,41 +361,28 @@ public class PlayerAuth {
}
/**
* Method getEmail.
* @return String */
public String getEmail() {
return email;
* Method getSalt.
*
* @return String
*/
public String getSalt() {
return this.salt;
}
/**
* Method setSalt.
*
* @param salt String
*/
public void setSalt(String salt) {
this.salt = salt;
}
/**
* Method getSalt.
* @return String */
public String getSalt() {
return this.salt;
}
/**
* Method setHash.
* @param hash String
*/
public void setHash(String hash) {
this.hash = hash;
}
/**
* Method getHash.
* @return String */
*
* @return String
*/
public String getHash() {
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
@@ -368,11 +392,21 @@ public class PlayerAuth {
return hash;
}
/**
* Method setHash.
*
* @param hash String
*/
public void setHash(String hash) {
this.hash = hash;
}
/**
* Method equals.
*
* @param obj Object
* @return boolean */
* @return boolean
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PlayerAuth)) {
@@ -384,8 +418,9 @@ public class PlayerAuth {
/**
* Method hashCode.
* @return int */
*
* @return int
*/
@Override
public int hashCode() {
int hashCode = 7;
@@ -396,8 +431,9 @@ public class PlayerAuth {
/**
* Method toString.
* @return String */
*
* @return String
*/
@Override
public String toString() {
return ("Player : " + nickname + " | " + realName
+27 -19
View File
@@ -13,8 +13,21 @@ public class PlayerCache {
cache = new ConcurrentHashMap<>();
}
/**
* Method getInstance.
*
* @return PlayerCache
*/
public static PlayerCache getInstance() {
if (singleton == null) {
singleton = new PlayerCache();
}
return singleton;
}
/**
* Method addPlayer.
*
* @param auth PlayerAuth
*/
public void addPlayer(PlayerAuth auth) {
@@ -23,6 +36,7 @@ public class PlayerCache {
/**
* Method updatePlayer.
*
* @param auth PlayerAuth
*/
public void updatePlayer(PlayerAuth auth) {
@@ -32,6 +46,7 @@ public class PlayerCache {
/**
* Method removePlayer.
*
* @param user String
*/
public void removePlayer(String user) {
@@ -40,45 +55,38 @@ public class PlayerCache {
/**
* Method isAuthenticated.
*
* @param user String
* @return boolean */
* @return boolean
*/
public boolean isAuthenticated(String user) {
return cache.containsKey(user.toLowerCase());
}
/**
* Method getAuth.
*
* @param user String
* @return PlayerAuth */
* @return PlayerAuth
*/
public PlayerAuth getAuth(String user) {
return cache.get(user.toLowerCase());
}
/**
* Method getInstance.
* @return PlayerCache */
public static PlayerCache getInstance() {
if (singleton == null) {
singleton = new PlayerCache();
}
return singleton;
}
/**
* Method getLogged.
* @return int */
*
* @return int
*/
public int getLogged() {
return cache.size();
}
/**
* Method getCache.
* @return ConcurrentHashMap<String,PlayerAuth> */
*
* @return ConcurrentHashMap<String,PlayerAuth>
*/
public ConcurrentHashMap<String, PlayerAuth> getCache() {
return this.cache;
}
@@ -10,9 +10,10 @@ public class DataFileCache {
/**
* Constructor for DataFileCache.
* @param group String
*
* @param group String
* @param operator boolean
* @param flying boolean
* @param flying boolean
*/
public DataFileCache(String group, boolean operator, boolean flying) {
this.group = group;
@@ -22,24 +23,27 @@ public class DataFileCache {
/**
* Method getGroup.
* @return String */
*
* @return String
*/
public String getGroup() {
return group;
}
/**
* Method getOperator.
* @return boolean */
*
* @return boolean
*/
public boolean getOperator() {
return operator;
}
/**
* Method isFlying.
* @return boolean */
*
* @return boolean
*/
public boolean isFlying() {
return flying;
}
+67 -73
View File
@@ -1,27 +1,17 @@
package fr.xephi.authme.cache.backup;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.*;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import org.bukkit.entity.Player;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
/**
*/
public class JsonCache {
@@ -43,7 +33,8 @@ public class JsonCache {
/**
* Method createCache.
* @param player Player
*
* @param player Player
* @param playerData DataFileCache
*/
public void createCache(Player player, DataFileCache playerData) {
@@ -77,9 +68,10 @@ public class JsonCache {
/**
* Method readCache.
*
* @param player Player
* @return DataFileCache */
* @return DataFileCache
*/
public DataFileCache readCache(Player player) {
String path;
try {
@@ -103,24 +95,41 @@ public class JsonCache {
}
/**
* Method removeCache.
*
* @param player Player
*/
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
* @return JsonElement */
@Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("flying", dataFileCache.isFlying());
return jsonObject;
public void removeCache(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path);
if (file.exists()) {
Utils.purgeDirectory(file);
if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
}
}
}
/**
* Method doesCacheExist.
*
* @param player Player
* @return boolean
*/
public boolean doesCacheExist(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path + File.separator + "cache.json");
return file.exists();
}
/**
@@ -128,13 +137,12 @@ public class JsonCache {
private static class PlayerDataDeserializer implements JsonDeserializer<DataFileCache> {
/**
* Method deserialize.
* @param jsonElement JsonElement
* @param type Type
*
* @param jsonElement JsonElement
* @param type Type
* @param jsonDeserializationContext JsonDeserializationContext
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) */
* @return DataFileCache * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)
*/
@Override
public DataFileCache deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject();
@@ -161,39 +169,25 @@ public class JsonCache {
}
/**
* Method removeCache.
* @param player Player
*/
public void removeCache(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
}
File file = new File(cacheDir, path);
if (file.exists()) {
Utils.purgeDirectory(file);
if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
}
}
}
private class PlayerDataSerializer implements JsonSerializer<DataFileCache> {
/**
* Method serialize.
*
* @param dataFileCache DataFileCache
* @param type Type
* @param jsonSerializationContext JsonSerializationContext
* @return JsonElement
*/
@Override
public JsonElement serialize(DataFileCache dataFileCache, Type type, JsonSerializationContext jsonSerializationContext) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("group", dataFileCache.getGroup());
jsonObject.addProperty("operator", dataFileCache.getOperator());
jsonObject.addProperty("flying", dataFileCache.isFlying());
/**
* Method doesCacheExist.
* @param player Player
* @return boolean */
public boolean doesCacheExist(Player player) {
String path;
try {
path = player.getUniqueId().toString();
} catch (Exception | Error e) {
path = player.getName().toLowerCase();
return jsonObject;
}
File file = new File(cacheDir, path + File.separator + "cache.json");
return file.exists();
}
}
+33 -27
View File
@@ -1,19 +1,18 @@
package fr.xephi.authme.cache.limbo;
import java.util.concurrent.ConcurrentHashMap;
import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.backup.DataFileCache;
import fr.xephi.authme.cache.backup.JsonCache;
import fr.xephi.authme.events.ResetInventoryEvent;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.concurrent.ConcurrentHashMap;
/**
*/
@@ -21,11 +20,12 @@ public class LimboCache {
private volatile static LimboCache singleton;
public ConcurrentHashMap<String, LimboPlayer> cache;
private JsonCache playerData;
public AuthMe plugin;
private JsonCache playerData;
/**
* Constructor for LimboCache.
*
* @param plugin AuthMe
*/
private LimboCache(AuthMe plugin) {
@@ -34,6 +34,18 @@ public class LimboCache {
this.playerData = new JsonCache();
}
/**
* Method getInstance.
*
* @return LimboCache
*/
public static LimboCache getInstance() {
if (singleton == null) {
singleton = new LimboCache(AuthMe.getInstance());
}
return singleton;
}
/**
* Add a limbo player.
*
@@ -49,7 +61,7 @@ public class LimboCache {
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = this.plugin.getPermissionsManager();
if(permsMan == null)
if (permsMan == null)
ConsoleLogger.showError("Unable to access permissions manager!");
assert permsMan != null;
@@ -65,7 +77,7 @@ public class LimboCache {
flying = player.isFlying();
// Check whether groups are supported
if(permsMan.hasGroupSupport())
if (permsMan.hasGroupSupport())
playerGroup = permsMan.getPrimaryGroup(player);
}
@@ -91,8 +103,9 @@ public class LimboCache {
/**
* Method addLimboPlayer.
*
* @param player Player
* @param group String
* @param group String
*/
public void addLimboPlayer(Player player, String group) {
cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group));
@@ -100,6 +113,7 @@ public class LimboCache {
/**
* Method deleteLimboPlayer.
*
* @param name String
*/
public void deleteLimboPlayer(String name) {
@@ -108,35 +122,27 @@ public class LimboCache {
/**
* Method getLimboPlayer.
*
* @param name String
* @return LimboPlayer */
* @return LimboPlayer
*/
public LimboPlayer getLimboPlayer(String name) {
return cache.get(name);
}
/**
* Method hasLimboPlayer.
*
* @param name String
* @return boolean */
* @return boolean
*/
public boolean hasLimboPlayer(String name) {
return cache.containsKey(name);
}
/**
* Method getInstance.
* @return LimboCache */
public static LimboCache getInstance() {
if (singleton == null) {
singleton = new LimboCache(AuthMe.getInstance());
}
return singleton;
}
/**
* Method updateLimboPlayer.
*
* @param player Player
*/
public void updateLimboPlayer(Player player) {
+43 -31
View File
@@ -19,15 +19,16 @@ public class LimboPlayer {
/**
* Constructor for LimboPlayer.
* @param name String
* @param loc Location
*
* @param name String
* @param loc Location
* @param gameMode GameMode
* @param operator boolean
* @param group String
* @param flying boolean
* @param group String
* @param flying boolean
*/
public LimboPlayer(String name, Location loc, GameMode gameMode,
boolean operator, String group, boolean flying) {
boolean operator, String group, boolean flying) {
this.name = name;
this.loc = loc;
this.gameMode = gameMode;
@@ -38,7 +39,8 @@ public class LimboPlayer {
/**
* Constructor for LimboPlayer.
* @param name String
*
* @param name String
* @param group String
*/
public LimboPlayer(String name, String group) {
@@ -48,46 +50,61 @@ public class LimboPlayer {
/**
* Method getName.
* @return String */
*
* @return String
*/
public String getName() {
return name;
}
/**
* Method getLoc.
* @return Location */
*
* @return Location
*/
public Location getLoc() {
return loc;
}
/**
* Method getGameMode.
* @return GameMode */
*
* @return GameMode
*/
public GameMode getGameMode() {
return gameMode;
}
/**
* Method getOperator.
* @return boolean */
*
* @return boolean
*/
public boolean getOperator() {
return operator;
}
/**
* Method getGroup.
* @return String */
*
* @return String
*/
public String getGroup() {
return group;
}
/**
* Method getTimeoutTaskId.
*
* @return BukkitTask
*/
public BukkitTask getTimeoutTaskId() {
return timeoutTaskId;
}
/**
* Method setTimeoutTaskId.
*
* @param i BukkitTask
*/
public void setTimeoutTaskId(BukkitTask i) {
@@ -97,15 +114,17 @@ public class LimboPlayer {
}
/**
* Method getTimeoutTaskId.
* @return BukkitTask */
public BukkitTask getTimeoutTaskId() {
return timeoutTaskId;
* Method getMessageTaskId.
*
* @return BukkitTask
*/
public BukkitTask getMessageTaskId() {
return messageTaskId;
}
/**
* Method setMessageTaskId.
*
* @param messageTaskId BukkitTask
*/
public void setMessageTaskId(BukkitTask messageTaskId) {
@@ -114,18 +133,11 @@ public class LimboPlayer {
this.messageTaskId = messageTaskId;
}
/**
* Method getMessageTaskId.
* @return BukkitTask */
public BukkitTask getMessageTaskId() {
return messageTaskId;
}
/**
* Method isFlying.
* @return boolean */
*
* @return boolean
*/
public boolean isFlying() {
return flying;
}