cleanup
This commit is contained in:
@ -1,19 +1,15 @@
|
|||||||
package cc.fascinated.account;
|
package cc.fascinated.account;
|
||||||
|
|
||||||
import cc.fascinated.Aetheria;
|
import cc.fascinated.Aetheria;
|
||||||
import cc.fascinated.utils.io.Config;
|
|
||||||
import cc.fascinated.utils.Manager;
|
import cc.fascinated.utils.Manager;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -27,7 +23,7 @@ public class AccountManager extends Manager {
|
|||||||
|
|
||||||
public AccountManager() {
|
public AccountManager() {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
registerAccount(player);
|
registerAccount(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
||||||
@ -42,17 +38,31 @@ public class AccountManager extends Manager {
|
|||||||
* @return the account
|
* @return the account
|
||||||
*/
|
*/
|
||||||
public static Account getAccount(UUID uuid) {
|
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.
|
* 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) {
|
private static Account registerAccount(UUID uuid) {
|
||||||
Account account = new Account(player.getUniqueId());
|
Account account = new Account(uuid);
|
||||||
ACCOUNTS.put(player.getUniqueId(), account);
|
ACCOUNTS.put(uuid, account);
|
||||||
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,9 +78,10 @@ public class AccountManager extends Manager {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
if (getAccount(event.getPlayer().getUniqueId()) == null) {
|
if (accountRegistered(event.getPlayer().getUniqueId())) { // Account already registered
|
||||||
registerAccount(event.getPlayer());
|
return;
|
||||||
}
|
}
|
||||||
|
registerAccount(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.fascinated.account;
|
package cc.fascinated.account;
|
||||||
|
|
||||||
import cc.fascinated.account.Account;
|
|
||||||
import cc.fascinated.utils.Manager;
|
import cc.fascinated.utils.Manager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
@ -3,7 +3,6 @@ package cc.fascinated.command.impl;
|
|||||||
import cc.fascinated.Aetheria;
|
import cc.fascinated.Aetheria;
|
||||||
import cc.fascinated.account.Account;
|
import cc.fascinated.account.Account;
|
||||||
import cc.fascinated.command.Command;
|
import cc.fascinated.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import cc.fascinated.Aetheria;
|
|||||||
import cc.fascinated.account.Account;
|
import cc.fascinated.account.Account;
|
||||||
import cc.fascinated.command.Command;
|
import cc.fascinated.command.Command;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class TotalJoinsCommand extends Command {
|
public class TotalJoinsCommand extends Command {
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package cc.fascinated.metrics;
|
package cc.fascinated.metrics;
|
||||||
|
|
||||||
import com.influxdb.client.write.Point;
|
import com.influxdb.client.write.Point;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class Metric {
|
public abstract class Metric {
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package cc.fascinated.playercolor;
|
|||||||
|
|
||||||
import cc.fascinated.account.Account;
|
import cc.fascinated.account.Account;
|
||||||
import cc.fascinated.account.Profile;
|
import cc.fascinated.account.Profile;
|
||||||
import cc.fascinated.utils.Manager;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
@ -15,8 +14,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
public class PlayerColor extends Profile {
|
public class PlayerColor extends Profile {
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ import cc.fascinated.command.Command;
|
|||||||
import cc.fascinated.playercolor.PlayerColor;
|
import cc.fascinated.playercolor.PlayerColor;
|
||||||
import cc.fascinated.playercolor.PlayerColorManager;
|
import cc.fascinated.playercolor.PlayerColorManager;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.checkerframework.checker.units.qual.A;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import cc.fascinated.utils.FormatterUtils;
|
|||||||
import cc.fascinated.utils.TimeUtils;
|
import cc.fascinated.utils.TimeUtils;
|
||||||
import cc.fascinated.worldsize.WorldSizeManager;
|
import cc.fascinated.worldsize.WorldSizeManager;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user