1
0

fix new accounts and add DeleteAccountCommand

This commit is contained in:
Lee
2024-04-05 22:19:22 +01:00
parent 872279a9c5
commit 6d2d658440
3 changed files with 28 additions and 10 deletions

View File

@ -128,10 +128,14 @@ public class Account {
profile.save(this.getProfileSection(key)); profile.save(this.getProfileSection(key));
} }
/**
* Gets the profile section.
*
* @param key the key to get the profile section for
* @return the profile section
*/
private ConfigurationSection getProfileSection(String key) { private ConfigurationSection getProfileSection(String key) {
return this.config.getConfigurationSection(key) != null return this.config.getConfigurationSection(key);
? this.config.getConfigurationSection(key)
: this.config.createSection(key);
} }
/** /**
@ -167,7 +171,9 @@ public class Account {
* @param component the message to send * @param component the message to send
*/ */
public void sendMessage(Component component) { public void sendMessage(Component component) {
getPlayer().sendMessage(component); if (this.isOnline()) {
this.getPlayer().sendMessage(component);
}
} }
/** /**

View File

@ -1,6 +1,7 @@
package cc.fascinated.account; package cc.fascinated.account;
import cc.fascinated.Aetheria; import cc.fascinated.Aetheria;
import cc.fascinated.account.command.DeleteAccountCommand;
import cc.fascinated.account.command.SaveAccountsCommand; import cc.fascinated.account.command.SaveAccountsCommand;
import cc.fascinated.bot.DiscordBot; import cc.fascinated.bot.DiscordBot;
import cc.fascinated.bot.DiscordChannel; import cc.fascinated.bot.DiscordChannel;
@ -35,7 +36,8 @@ public class AccountManager extends Manager implements Listener {
private final long SAVE_INTERVAL = 5; // in minutes private final long SAVE_INTERVAL = 5; // in minutes
public AccountManager() { public AccountManager() {
CommandManager.registerCommand(new SaveAccountsCommand()); registerCommand(new SaveAccountsCommand());
registerCommand(new DeleteAccountCommand());
Aetheria.INSTANCE.getServer().getPluginManager().registerEvents(this, Aetheria.INSTANCE); Aetheria.INSTANCE.getServer().getPluginManager().registerEvents(this, Aetheria.INSTANCE);
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
@ -113,11 +115,11 @@ public class AccountManager extends Manager implements Listener {
* *
* @param account the account to delete * @param account the account to delete
*/ */
public void deleteAccount(Account account) { public static void deleteAccount(Account account) {
account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect."));
account.getFile().delete(); account.getFile().delete();
ACCOUNTS.remove(account.getUuid()); ACCOUNTS.remove(account.getUuid());
account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect."));
log.info("Deleted account for {}", account.getUuid()); log.info("Deleted account for {}", account.getUuid());
} }
@ -155,7 +157,7 @@ public class AccountManager extends Manager implements Listener {
joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString(); joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString();
DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder() DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder()
.setThumbnail("https://crafatar.com/avatars/" + account.getUuid()) .setThumbnail("https://crafatar.com/avatars/" + account.getUuid() + ".png")
.setColor(Color.GREEN) .setColor(Color.GREEN)
.setTitle("New Player Joined") .setTitle("New Player Joined")
.addField("Player", account.getName(), true) .addField("Player", account.getName(), true)

View File

@ -1,7 +1,10 @@
package cc.fascinated.account.command; package cc.fascinated.account.command;
import cc.fascinated.account.Account; import cc.fascinated.account.Account;
import cc.fascinated.account.AccountManager;
import cc.fascinated.command.Command; import cc.fascinated.command.Command;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class DeleteAccountCommand extends Command { public class DeleteAccountCommand extends Command {
@ -12,6 +15,13 @@ public class DeleteAccountCommand extends Command {
@Override @Override
public void execute(Account account, String[] args) { public void execute(Account account, String[] args) {
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
Account targetAccount = AccountManager.getAccount(target.getUniqueId());
if (targetAccount == null) {
account.sendMessage("That account does not exist.");
return;
}
AccountManager.deleteAccount(targetAccount);
account.sendMessage("Successfully deleted the account of " + target.getName() + ".");
} }
} }