From 66aae8170df57cb0c598feff0c8545bbf7392d86 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 1 Apr 2024 12:46:15 +0100 Subject: [PATCH] use custom join messages --- .../java/cc/fascinated/account/Account.java | 4 -- .../cc/fascinated/account/AccountManager.java | 50 +++++++++++-------- src/main/java/cc/fascinated/config/Lang.java | 4 +- src/main/resources/lang.yml | 4 +- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index e8c6f71..d7bd960 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -1,10 +1,7 @@ package cc.fascinated.account; import cc.fascinated.Aetheria; -import cc.fascinated.config.Config; -import cc.fascinated.config.Lang; import cc.fascinated.playercolor.PlayerColor; -import cc.fascinated.utils.DiscordWebhook; import cc.fascinated.utils.Style; import lombok.Getter; import lombok.SneakyThrows; @@ -18,7 +15,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import java.io.File; -import java.io.IOException; import java.util.UUID; @Getter @Log4j2 public class Account { diff --git a/src/main/java/cc/fascinated/account/AccountManager.java b/src/main/java/cc/fascinated/account/AccountManager.java index f090178..874969b 100644 --- a/src/main/java/cc/fascinated/account/AccountManager.java +++ b/src/main/java/cc/fascinated/account/AccountManager.java @@ -86,30 +86,32 @@ public class AccountManager extends Manager { @Override public void onPlayerJoin(Account account, PlayerJoinEvent event) { Player player = event.getPlayer(); - if (player.hasPlayedBefore()) { - return; + String joinMessage = Lang.JOIN_MESSAGE.getAsString(); + + if (!player.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", player.getName(), true); + embed.addField("UUID", player.getUniqueId().toString(), true); + + discordWebhook.addEmbed(embed); + try { + discordWebhook.execute(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); } - - event.joinMessage(null); // Remove the join message so we can send our own - Bukkit.broadcast(Style.getMiniMessage().deserialize(Lang.FIRST_JOIN_MESSAGE.getAsString() + event.joinMessage(Style.getMiniMessage().deserialize(joinMessage .replace("%player%", player.getName()) + .replace("player-color", account.getPlayerColorProfile().getColor().toString()) )); - - 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", player.getName(), true); - embed.addField("UUID", player.getUniqueId().toString(), true); - - discordWebhook.addEmbed(embed); - try { - discordWebhook.execute(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); } @Override @@ -123,9 +125,13 @@ public class AccountManager extends Manager { @Override public void onPlayerQuit(Account account, PlayerQuitEvent event) { - account.save(true); + account.save(true); // Save the account ACCOUNTS.remove(account.getUuid()); + event.quitMessage(Style.getMiniMessage().deserialize(Lang.QUIT_MESSAGE.getAsString() + .replace("%player%", event.getPlayer().getName()) + .replace("player-color", account.getPlayerColorProfile().getColor().toString()) + )); } @Override diff --git a/src/main/java/cc/fascinated/config/Lang.java b/src/main/java/cc/fascinated/config/Lang.java index 7066660..1ed61cb 100644 --- a/src/main/java/cc/fascinated/config/Lang.java +++ b/src/main/java/cc/fascinated/config/Lang.java @@ -26,7 +26,9 @@ public enum Lang { BLOCKED_MESSAGE("blocked-message"), BLOCKED_MESSAGE_ALERT("blocked-message-alert"), CHAT_FORMAT("chat-format"), - FIRST_JOIN_MESSAGE("first-join-message"); + FIRST_JOIN_MESSAGE("first-join-message"), + JOIN_MESSAGE("join-message"), + QUIT_MESSAGE("quit-message"); /** * The path of the lang in the lang.yml file. diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 83f4ce9..f496217 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -5,7 +5,9 @@ chat-format: "<<%chatcolor%>%name%> Your message has been blocked." blocked-message-alert: "%player% tried to send a blocked message: %message%" -first-join-message: "%player% joined for the first time!" +first-join-message: "%player% joined for the first time!" +join-message: "%player% joined the game" +quit-message: "%player% left the game" help-command: - "Commands:"