Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/main/java/uk/org/whoami/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onEnable() {
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener,
Priority.Lowest, this);

this.getCommand("authme").setExecutor(new AdminCommand(database));
this.getCommand("authme").setExecutor(new AdminCommand(this, database));
this.getCommand("register").setExecutor(new RegisterCommand(this, database));
this.getCommand("login").setExecutor(new LoginCommand(database));
this.getCommand("changepassword").setExecutor(new ChangePasswordCommand(database));
Expand Down Expand Up @@ -193,15 +193,17 @@ public DataSource getAuthDatabase() {

private void onReload(Player[] players) {
for (Player player : players) {
String uuid = player.getUniqueId().toString();
String name = player.getName().toLowerCase();
String ip = player.getAddress().getAddress().getHostAddress();

boolean authAvail = database.isAuthAvailable(name);
boolean authAvail = database.isAuthAvailable(uuid);

if (authAvail) {
if (settings.isSessionsEnabled()) {
PlayerAuth auth = database.getAuth(name);
if (auth.getNickname().equals(name) && auth.getIp().equals(ip)) {
PlayerAuth auth = database.getAuth(uuid);
if (auth != null && auth.getUuid().equals(uuid) && auth.getIp().equals(ip)) {
auth.setUsername(name);
PlayerCache.getInstance().addPlayer(auth);
player.sendMessage(m._("valid_session"));
break;
Expand All @@ -227,10 +229,10 @@ private void onReload(Player[] players) {
int msgInterval = settings.getWarnMessageInterval();
BukkitScheduler sched = this.getServer().getScheduler();
if (time != 0) {
int id = sched.scheduleSyncDelayedTask(this, new TimeoutTask(this, name), time);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
int id = sched.scheduleSyncDelayedTask(this, new TimeoutTask(this, uuid), time);
LimboCache.getInstance().getLimboPlayer(uuid).setTimeoutTaskId(id);
}
sched.scheduleSyncDelayedTask(this, new MessageTask(this, name, msg, msgInterval));
sched.scheduleSyncDelayedTask(this, new MessageTask(this, uuid, msg, msgInterval));
}
}

Expand Down
30 changes: 20 additions & 10 deletions src/main/java/uk/org/whoami/authme/cache/auth/PlayerAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,34 @@

public class PlayerAuth {

private String nickname;
private final String uuid;
private String username;
private String hash;
private String ip;
private long lastLogin;

public PlayerAuth(String nickname, String hash, String ip, long lastLogin) {
this.nickname = nickname;
public PlayerAuth(String uuid, String username, String hash, String ip, long lastLogin) {
this.uuid = uuid;
this.username = username;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
}

public String getIp() {
return ip;
public String getUuid() {
return uuid;
}

public String getNickname() {
return nickname;
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getIp() {
return ip;
}

public String getHash() {
Expand Down Expand Up @@ -64,14 +74,14 @@ public boolean equals(Object obj) {
return false;
}
PlayerAuth other = (PlayerAuth) obj;
return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);

return other.getIp().equals(this.ip) && other.getUuid().equals(this.uuid);
}

@Override
public int hashCode() {
int hashCode = 7;
hashCode = 71 * hashCode + (this.nickname != null ? this.nickname.hashCode() : 0);
hashCode = 71 * hashCode + (this.uuid != null ? this.uuid.hashCode() : 0);
hashCode = 71 * hashCode + (this.ip != null ? this.ip.hashCode() : 0);
return hashCode;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/uk/org/whoami/authme/cache/auth/PlayerCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ private PlayerCache() {
}

public void addPlayer(PlayerAuth auth) {
cache.put(auth.getNickname(), auth);
cache.put(auth.getUuid(), auth);
}

public void updatePlayer(PlayerAuth auth) {
cache.remove(auth.getNickname());
cache.put(auth.getNickname(), auth);
cache.remove(auth.getUuid());
cache.put(auth.getUuid(), auth);
}

public void removePlayer(String user) {
cache.remove(user);
public void removePlayer(String uuid) {
cache.remove(uuid);
}

public boolean isAuthenticated(String user) {
return cache.containsKey(user);
public boolean isAuthenticated(String uuid) {
return cache.containsKey(uuid);
}

public PlayerAuth getAuth(String user) {
return cache.get(user);
public PlayerAuth getAuth(String uuid) {
return cache.get(uuid);
}

public static PlayerCache getInstance() {
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/uk/org/whoami/authme/cache/limbo/LimboCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ private LimboCache() {
}

public void addLimboPlayer(Player player) {
String uuid = player.getUniqueId().toString();
String name = player.getName().toLowerCase();
Location loc = player.getLocation();
ItemStack[] inv = player.getInventory().getContents();
ItemStack[] arm = player.getInventory().getArmorContents();
//int gameMode = player.getGameMode().getValue();

cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm));
cache.put(uuid, new LimboPlayer(uuid, name, loc, inv, arm));
}

public void deleteLimboPlayer(String name) {
cache.remove(name);
public void deleteLimboPlayer(String uuid) {
cache.remove(uuid);
}

public LimboPlayer getLimboPlayer(String name) {
return cache.get(name);
public LimboPlayer getLimboPlayer(String uuid) {
return cache.get(uuid);
}

public boolean hasLimboPlayer(String name) {
return cache.containsKey(name);
public boolean hasLimboPlayer(String uuid) {
return cache.containsKey(uuid);
}

public static LimboCache getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@

public class LimboPlayer {

private final String uuid;
private String name;
private ItemStack[] inventory;
private ItemStack[] armour;
private Location loc;
private int timeoutTaskId = -1;
private int gameMode = 0;

public LimboPlayer(String name, Location loc, ItemStack[] inventory, ItemStack[] armour) {
public LimboPlayer(String uuid, String name, Location loc, ItemStack[] inventory, ItemStack[] armour) {
this.uuid = uuid;
this.name = name;
this.loc = loc;
this.inventory = inventory;
this.armour = armour;
this.gameMode = gameMode;
}

public String getUuid() {
return uuid;
}

public String getName() {
return name;
}
Expand Down
Loading