diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index 6401806..45c325f 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -128,10 +128,14 @@ public class Account { 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) { - return this.config.getConfigurationSection(key) != null - ? this.config.getConfigurationSection(key) - : this.config.createSection(key); + return this.config.getConfigurationSection(key); } /** @@ -167,7 +171,9 @@ public class Account { * @param component the message to send */ public void sendMessage(Component component) { - getPlayer().sendMessage(component); + if (this.isOnline()) { + this.getPlayer().sendMessage(component); + } } /** diff --git a/src/main/java/cc/fascinated/account/AccountManager.java b/src/main/java/cc/fascinated/account/AccountManager.java index b227211..5a0d4a6 100644 --- a/src/main/java/cc/fascinated/account/AccountManager.java +++ b/src/main/java/cc/fascinated/account/AccountManager.java @@ -1,6 +1,7 @@ package cc.fascinated.account; import cc.fascinated.Aetheria; +import cc.fascinated.account.command.DeleteAccountCommand; import cc.fascinated.account.command.SaveAccountsCommand; import cc.fascinated.bot.DiscordBot; import cc.fascinated.bot.DiscordChannel; @@ -35,7 +36,8 @@ public class AccountManager extends Manager implements Listener { private final long SAVE_INTERVAL = 5; // in minutes public AccountManager() { - CommandManager.registerCommand(new SaveAccountsCommand()); + registerCommand(new SaveAccountsCommand()); + registerCommand(new DeleteAccountCommand()); Aetheria.INSTANCE.getServer().getPluginManager().registerEvents(this, Aetheria.INSTANCE); for (Player player : Bukkit.getOnlinePlayers()) { @@ -113,11 +115,11 @@ public class AccountManager extends Manager implements Listener { * * @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(); ACCOUNTS.remove(account.getUuid()); - - account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect.")); log.info("Deleted account for {}", account.getUuid()); } @@ -155,7 +157,7 @@ public class AccountManager extends Manager implements Listener { joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString(); 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) .setTitle("New Player Joined") .addField("Player", account.getName(), true) diff --git a/src/main/java/cc/fascinated/account/command/DeleteAccountCommand.java b/src/main/java/cc/fascinated/account/command/DeleteAccountCommand.java index 3f6567a..495716b 100644 --- a/src/main/java/cc/fascinated/account/command/DeleteAccountCommand.java +++ b/src/main/java/cc/fascinated/account/command/DeleteAccountCommand.java @@ -1,7 +1,10 @@ package cc.fascinated.account.command; import cc.fascinated.account.Account; +import cc.fascinated.account.AccountManager; import cc.fascinated.command.Command; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; public class DeleteAccountCommand extends Command { @@ -12,6 +15,13 @@ public class DeleteAccountCommand extends Command { @Override 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() + "."); } }