stuff
This commit is contained in:
@ -2,16 +2,18 @@ package cc.fascinated.account;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.account.command.SaveAccountsCommand;
|
||||
import cc.fascinated.bot.DiscordBot;
|
||||
import cc.fascinated.bot.DiscordChannel;
|
||||
import cc.fascinated.command.CommandManager;
|
||||
import cc.fascinated.config.Config;
|
||||
import cc.fascinated.config.Lang;
|
||||
import cc.fascinated.playercolor.PlayerColorProfile;
|
||||
import cc.fascinated.utils.DiscordWebhook;
|
||||
import cc.fascinated.utils.Manager;
|
||||
import cc.fascinated.utils.Priority;
|
||||
import cc.fascinated.utils.Style;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -20,7 +22,8 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -38,7 +41,7 @@ public class AccountManager extends Manager implements Listener {
|
||||
if (isAccountLoaded(player.getUniqueId())) { // Don't load the account if it's already loaded
|
||||
continue;
|
||||
}
|
||||
loadAccount(player.getUniqueId());
|
||||
loadAccount(player.getUniqueId(), player.getName());
|
||||
}
|
||||
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
|
||||
@ -46,6 +49,21 @@ public class AccountManager extends Manager implements Listener {
|
||||
}, SAVE_INTERVAL, SAVE_INTERVAL, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all online accounts.
|
||||
*
|
||||
* @return the online accounts
|
||||
*/
|
||||
public static List<Account> getOnlineAccounts() {
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
for (Account account : ACCOUNTS.values()) {
|
||||
if (account.isOnline()) {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
return accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the account for the specified player.
|
||||
*
|
||||
@ -60,9 +78,10 @@ public class AccountManager extends Manager implements Listener {
|
||||
* Registers an account for the specified player.
|
||||
*
|
||||
* @param uuid the player's UUID
|
||||
* @param name the player's name
|
||||
*/
|
||||
private static void loadAccount(UUID uuid) {
|
||||
Account account = new Account(uuid);
|
||||
private static void loadAccount(UUID uuid, String name) {
|
||||
Account account = new Account(uuid, name);
|
||||
ACCOUNTS.put(uuid, account);
|
||||
}
|
||||
|
||||
@ -105,10 +124,11 @@ public class AccountManager extends Manager implements Listener {
|
||||
@EventHandler
|
||||
public void onAsyncPlayerPreLoginEvent(AsyncPlayerPreLoginEvent event) {
|
||||
UUID uuid = event.getUniqueId();
|
||||
String name = event.getName();
|
||||
if (isAccountLoaded(uuid)) { // Account already loaded
|
||||
return;
|
||||
}
|
||||
loadAccount(uuid); // Load the account into memory
|
||||
loadAccount(uuid, name); // Load the account into memory
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,22 +139,13 @@ public class AccountManager extends Manager implements Listener {
|
||||
if (!account.getPlayer().hasPlayedBefore()) {
|
||||
joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString();
|
||||
|
||||
// Send a notification to the discord log channel
|
||||
Aetheria.EXECUTOR.execute(() -> {
|
||||
// todo: re-code this it's so ugly
|
||||
DiscordWebhook discordWebhook = new DiscordWebhook(Config.DISCORD_LOG_WEBHOOK.getAsString());
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject();
|
||||
embed.setTitle("New Player Joined");
|
||||
embed.addField("Name", account.getName(), true);
|
||||
embed.addField("UUID", account.getUuid().toString(), true);
|
||||
|
||||
discordWebhook.addEmbed(embed);
|
||||
try {
|
||||
discordWebhook.execute();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder()
|
||||
.setThumbnail("https://crafatar.com/avatars/" + account.getUuid())
|
||||
.setColor(Color.GREEN)
|
||||
.setTitle("New Player Joined")
|
||||
.addField("Player", account.getName(), true)
|
||||
.addField("UUID", account.getUuid().toString(), true)
|
||||
);
|
||||
}
|
||||
event.joinMessage(Style.getMiniMessage().deserialize(joinMessage
|
||||
.replace("%player%", account.getName())
|
||||
|
Reference in New Issue
Block a user