diff --git a/src/main/java/cc/fascinated/Aetheria.java b/src/main/java/cc/fascinated/Aetheria.java index b30e636..8128e84 100644 --- a/src/main/java/cc/fascinated/Aetheria.java +++ b/src/main/java/cc/fascinated/Aetheria.java @@ -8,6 +8,7 @@ import cc.fascinated.commandspy.CommandSpyManager; import cc.fascinated.config.Config; import cc.fascinated.config.Lang; import cc.fascinated.event.EventManager; +import cc.fascinated.joinlogs.JoinLogManager; import cc.fascinated.metrics.MetricManager; import cc.fascinated.misc.RenderDistanceManager; import cc.fascinated.motd.MotdManager; @@ -34,6 +35,10 @@ public class Aetheria extends JavaPlugin { * The instance of the plugin. */ public static Aetheria INSTANCE; + + /** + * Thread pool executor for async tasks. + */ public static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); @@ -62,6 +67,7 @@ public class Aetheria extends JavaPlugin { new VoteManager(); new StaffChatManager(); new TipManager(); + new JoinLogManager(); new DiscordBot(); } diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index 45c325f..3f37fd7 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -110,8 +110,8 @@ public class Account { this.name = name; // Update the name // Load profiles - this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId)); - this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId)); + this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId, false)); + this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId, false)); this.lastHash = this.hashCode(); @@ -125,7 +125,7 @@ public class Account { * @param key the key to save the profile under */ private void saveProfile(Profile profile, String key) { - profile.save(this.getProfileSection(key)); + profile.save(this.getProfileSection(key, true)); } /** @@ -134,8 +134,12 @@ public class Account { * @param key the key to get the profile section for * @return the profile section */ - private ConfigurationSection getProfileSection(String key) { - return this.config.getConfigurationSection(key); + private ConfigurationSection getProfileSection(String key, boolean create) { + ConfigurationSection section = this.config.getConfigurationSection(key); + if (section == null && create) { + section = this.config.createSection(key); + } + return section; } /** diff --git a/src/main/java/cc/fascinated/account/AccountManager.java b/src/main/java/cc/fascinated/account/AccountManager.java index 5a0d4a6..e540625 100644 --- a/src/main/java/cc/fascinated/account/AccountManager.java +++ b/src/main/java/cc/fascinated/account/AccountManager.java @@ -5,7 +5,6 @@ import cc.fascinated.account.command.DeleteAccountCommand; 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; @@ -25,6 +24,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.awt.*; +import java.nio.file.Files; import java.util.List; import java.util.*; import java.util.concurrent.TimeUnit; @@ -118,14 +118,13 @@ public class AccountManager extends Manager implements Listener { 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()); - log.info("Deleted account for {}", account.getUuid()); - } - - @Override - public Priority getPriority() { - return Priority.LOWEST; + try { + Files.delete(account.getFile().toPath()); + ACCOUNTS.remove(account.getUuid()); + log.info("Deleted account for {}", account.getUuid()); + } catch (Exception ex) { + log.error("Failed to delete account for {}", account.getUuid()); + } } /** @@ -156,8 +155,8 @@ public class AccountManager extends Manager implements Listener { if (!account.getPlayer().hasPlayedBefore()) { joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString(); - DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder() - .setThumbnail("https://crafatar.com/avatars/" + account.getUuid() + ".png") + DiscordBot.sendEmbed(DiscordChannel.NEW_PLAYER_LOGS, new EmbedBuilder() + .setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString()) .setColor(Color.GREEN) .setTitle("New Player Joined") .addField("Player", account.getName(), true) @@ -188,4 +187,9 @@ public class AccountManager extends Manager implements Listener { public void onAetheriaDisable() { saveAccounts(); // Save the accounts to disk } + + @Override + public Priority getPriority() { + return Priority.LOWEST; + } } diff --git a/src/main/java/cc/fascinated/bot/DiscordChannel.java b/src/main/java/cc/fascinated/bot/DiscordChannel.java index ecdb8c3..4e6df86 100644 --- a/src/main/java/cc/fascinated/bot/DiscordChannel.java +++ b/src/main/java/cc/fascinated/bot/DiscordChannel.java @@ -6,8 +6,9 @@ import lombok.RequiredArgsConstructor; @Getter @RequiredArgsConstructor public enum DiscordChannel { - PLAYER_LOGS("1223161810157568020"), - VOTE_LOGS("1225868584522219570"); + NEW_PLAYER_LOGS("1228383457361661975"), + PLAYER_LOGS("1228383471437615114"), + VOTE_LOGS("1228383490874277948"); /** * The ID of the Discord channel. diff --git a/src/main/java/cc/fascinated/chat/ChatManager.java b/src/main/java/cc/fascinated/chat/ChatManager.java index 663e554..a8cffb6 100644 --- a/src/main/java/cc/fascinated/chat/ChatManager.java +++ b/src/main/java/cc/fascinated/chat/ChatManager.java @@ -15,16 +15,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import java.util.HashMap; import java.util.regex.Pattern; -@RequiredArgsConstructor -@Getter -enum BlockReason { - DOMAIN("Domain was detected in the message."), - DUPLICATE("Duplicate message was detected."), - IP("IP address was detected in the message."); - - private final String reason; -} - public class ChatManager extends Manager { private final HashMap lastMessage = new HashMap<>(); @@ -79,4 +69,14 @@ public class ChatManager extends Manager { }); lastMessage.put(account, messageContent); } + + @RequiredArgsConstructor + @Getter + private enum BlockReason { + DOMAIN("Domain was detected in the message."), + DUPLICATE("Duplicate message was detected."), + IP("IP address was detected in the message."); + + private final String reason; + } } diff --git a/src/main/java/cc/fascinated/config/Lang.java b/src/main/java/cc/fascinated/config/Lang.java index 85a0b7c..9e660a6 100644 --- a/src/main/java/cc/fascinated/config/Lang.java +++ b/src/main/java/cc/fascinated/config/Lang.java @@ -27,6 +27,9 @@ public enum Lang { VOTE_STATS_COMMAND("vote-stats-command"), SAVE_ACCOUNTS_COMMAND_SAVING("save-accounts-command.saving"), SAVE_ACCOUNTS_COMMAND_SAVED("save-accounts-command.saved"), + PLAYER_COLOR_COMMAND_USAGE("player-color-command.usage"), + PLAYER_COLOR_COMMAND_INVALID_COLOR("player-color-command.invalid-color"), + PLAYER_COLOR_COMMAND_COLOR_CHANGED("player-color-command.color-changed"), DISCORD_COMMAND("discord-command"), BLOCKED_MESSAGE("blocked-message"), BLOCKED_MESSAGE_ALERT("blocked-message-alert"), @@ -50,10 +53,12 @@ public enum Lang { * Cache of the lang values. */ private static final HashMap cache = new HashMap<>(); + /** * The path of the lang in the lang.yml file. */ private final String path; + /** * The lang configuration. */ diff --git a/src/main/java/cc/fascinated/joinlogs/JoinLogManager.java b/src/main/java/cc/fascinated/joinlogs/JoinLogManager.java new file mode 100644 index 0000000..e7da50a --- /dev/null +++ b/src/main/java/cc/fascinated/joinlogs/JoinLogManager.java @@ -0,0 +1,36 @@ +package cc.fascinated.joinlogs; + +import cc.fascinated.account.Account; +import cc.fascinated.bot.DiscordBot; +import cc.fascinated.bot.DiscordChannel; +import cc.fascinated.utils.Manager; +import net.dv8tion.jda.api.EmbedBuilder; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.awt.*; + +public class JoinLogManager extends Manager { + + @Override + public void onPlayerJoin(Account account, PlayerJoinEvent event) { + DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder() + .setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString()) + .setColor(Color.GREEN) + .setTitle("Player Joined") + .addField("Player", account.getName(), true) + .addField("UUID", account.getUuid().toString(), true) + ); + } + + @Override + public void onPlayerQuit(Account account, PlayerQuitEvent event) { + DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder() + .setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString()) + .setColor(Color.RED) + .setTitle("Player Left") + .addField("Player", account.getName(), true) + .addField("UUID", account.getUuid().toString(), true) + ); + } +} diff --git a/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java b/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java index 5eb481b..49dd07a 100644 --- a/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java +++ b/src/main/java/cc/fascinated/playercolor/command/PlayerColorCommand.java @@ -2,6 +2,7 @@ package cc.fascinated.playercolor.command; import cc.fascinated.account.Account; import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; import cc.fascinated.playercolor.PlayerColorManager; import cc.fascinated.playercolor.PlayerColorProfile; import net.kyori.adventure.text.Component; @@ -22,30 +23,29 @@ public class PlayerColorCommand extends Command { PlayerColorProfile playerColorProfile = account.getPlayerColorProfile(); if (args.length == 0) { - account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour current color is: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor()))); - Component validColorsComponent = Component.text("§fValid colors: "); - for (NamedTextColor validColor : validColors) { - validColorsComponent = validColorsComponent.append(Component.text(validColor.toString() + ", ").color(validColor)); + account.sendMessage(Lang.PLAYER_COLOR_COMMAND_USAGE.getAsString()); + + Component colors = Component.text("Colors: "); + for (NamedTextColor color : validColors) { + colors = colors.append(Component.text(color.toString()).color(color)).append(Component.text(", ")); } - validColorsComponent = validColorsComponent.append(Component.text("random.").color(NamedTextColor.WHITE)); - account.sendMessage(validColorsComponent); + colors = colors.append(Component.text("random")); + account.sendMessage(colors); return; } - if (args[0].equalsIgnoreCase("random")) { - playerColorProfile.setColor(validColors.get((int) (Math.random() * validColors.size()))); - account.sendMessage("§b§lPLAYERCOLOR §7» §fYour color has been set to: " + playerColorProfile.getColor() + "§f."); - return; - } - - NamedTextColor color = PlayerColorManager.getColor(args[0]); + NamedTextColor color = args[0].equalsIgnoreCase("random") ? + PlayerColorManager.getRandomColor() : PlayerColorManager.getColor(args[0]); if (color == null) { - account.sendMessage("§b§lPLAYERCOLOR §7» §cInvalid color."); + account.sendMessage(Lang.PLAYER_COLOR_COMMAND_INVALID_COLOR.getAsString()); return; } playerColorProfile.setColor(color); - account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour color has been set to: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor()))); + account.sendMessage(Lang.PLAYER_COLOR_COMMAND_COLOR_CHANGED.getAsString() + .replace("%color%", playerColorProfile.getColor().toString()) + .replace("new-color", playerColorProfile.getColor().toString()) + ); } @Override diff --git a/src/main/java/cc/fascinated/vote/VoteManager.java b/src/main/java/cc/fascinated/vote/VoteManager.java index 20615fd..6a97621 100644 --- a/src/main/java/cc/fascinated/vote/VoteManager.java +++ b/src/main/java/cc/fascinated/vote/VoteManager.java @@ -35,6 +35,7 @@ public class VoteManager extends Manager { ); DiscordBot.sendEmbed(DiscordChannel.VOTE_LOGS, new EmbedBuilder() + .setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString()) .setTitle("Player Voted") .setColor(Color.GREEN) .addField("Player", account.getPlayer().getName(), true) diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 686aa15..fd89316 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -75,3 +75,7 @@ vote-stats-command: - " Total Votes: %total-votes%" - " Vote Tokens: %vote-tokens%" discord-command: "Join our Discord server: %invite-url%" +player-color-command: + usage: "Usage: /playercolor [color]" + invalid-color: "Invalid color. Use a valid color code." + color-changed: "Your player color has been changed to %color%" \ No newline at end of file