cleanup
This commit is contained in:
@ -1,19 +1,15 @@
|
||||
package cc.fascinated.account;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.utils.io.Config;
|
||||
import cc.fascinated.utils.Manager;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -27,7 +23,7 @@ public class AccountManager extends Manager {
|
||||
|
||||
public AccountManager() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
registerAccount(player);
|
||||
registerAccount(player.getUniqueId());
|
||||
}
|
||||
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
||||
@ -42,17 +38,31 @@ public class AccountManager extends Manager {
|
||||
* @return the account
|
||||
*/
|
||||
public static Account getAccount(UUID uuid) {
|
||||
return ACCOUNTS.get(uuid); // todo: load account if not found
|
||||
if (!ACCOUNTS.containsKey(uuid)) {
|
||||
return registerAccount(uuid);
|
||||
}
|
||||
return ACCOUNTS.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an account is already registered for the specified player.
|
||||
*
|
||||
* @param uuid the UUID of the player
|
||||
* @return true if the account is already registered, false otherwise
|
||||
*/
|
||||
private boolean accountRegistered(UUID uuid) {
|
||||
return ACCOUNTS.containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an account for the specified player.
|
||||
*
|
||||
* @param player the player to register the account for
|
||||
* @param uuid the UUID of the player
|
||||
*/
|
||||
private void registerAccount(Player player) {
|
||||
Account account = new Account(player.getUniqueId());
|
||||
ACCOUNTS.put(player.getUniqueId(), account);
|
||||
private static Account registerAccount(UUID uuid) {
|
||||
Account account = new Account(uuid);
|
||||
ACCOUNTS.put(uuid, account);
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,9 +78,10 @@ public class AccountManager extends Manager {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
if (getAccount(event.getPlayer().getUniqueId()) == null) {
|
||||
registerAccount(event.getPlayer());
|
||||
if (accountRegistered(event.getPlayer().getUniqueId())) { // Account already registered
|
||||
return;
|
||||
}
|
||||
registerAccount(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Reference in New Issue
Block a user