fix logs and first join message
This commit is contained in:
@ -23,7 +23,7 @@ public class AccountManager extends Manager {
|
||||
|
||||
public AccountManager() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
registerAccount(player.getUniqueId());
|
||||
registerAccount(player);
|
||||
}
|
||||
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
||||
@ -34,12 +34,13 @@ public class AccountManager extends Manager {
|
||||
/**
|
||||
* Gets the account for the specified player.
|
||||
*
|
||||
* @param uuid the UUID of the player
|
||||
* @param player the player
|
||||
* @return the account
|
||||
*/
|
||||
public static Account getAccount(UUID uuid) {
|
||||
public static Account getAccount(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!ACCOUNTS.containsKey(uuid)) {
|
||||
return registerAccount(uuid);
|
||||
return registerAccount(player);
|
||||
}
|
||||
return ACCOUNTS.get(uuid);
|
||||
}
|
||||
@ -47,20 +48,21 @@ public class AccountManager extends Manager {
|
||||
/**
|
||||
* Checks if an account is already registered for the specified player.
|
||||
*
|
||||
* @param uuid the UUID of the player
|
||||
* @param player the player
|
||||
* @return true if the account is already registered, false otherwise
|
||||
*/
|
||||
private boolean accountRegistered(UUID uuid) {
|
||||
return ACCOUNTS.containsKey(uuid);
|
||||
private boolean accountRegistered(Player player) {
|
||||
return ACCOUNTS.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an account for the specified player.
|
||||
*
|
||||
* @param uuid the UUID of the player
|
||||
* @param player the player
|
||||
*/
|
||||
private static Account registerAccount(UUID uuid) {
|
||||
Account account = new Account(uuid);
|
||||
private static Account registerAccount(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
Account account = new Account(player);
|
||||
ACCOUNTS.put(uuid, account);
|
||||
return account;
|
||||
}
|
||||
@ -79,18 +81,20 @@ public class AccountManager extends Manager {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
if (accountRegistered(event.getPlayer().getUniqueId())) { // Account already registered
|
||||
Player player = event.getPlayer();
|
||||
if (accountRegistered(player)) { // Account already registered
|
||||
return;
|
||||
}
|
||||
registerAccount(event.getPlayer().getUniqueId());
|
||||
registerAccount(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Account account = getAccount(event.getPlayer().getUniqueId());
|
||||
Player player = event.getPlayer();
|
||||
Account account = getAccount(player);
|
||||
account.save(true);
|
||||
|
||||
ACCOUNTS.remove(event.getPlayer().getUniqueId());
|
||||
ACCOUNTS.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Reference in New Issue
Block a user