1
0

use custom join messages

This commit is contained in:
Lee
2024-04-01 12:46:15 +01:00
parent 3702bc30c9
commit 66aae8170d
4 changed files with 34 additions and 28 deletions

View File

@ -1,10 +1,7 @@
package cc.fascinated.account; package cc.fascinated.account;
import cc.fascinated.Aetheria; import cc.fascinated.Aetheria;
import cc.fascinated.config.Config;
import cc.fascinated.config.Lang;
import cc.fascinated.playercolor.PlayerColor; import cc.fascinated.playercolor.PlayerColor;
import cc.fascinated.utils.DiscordWebhook;
import cc.fascinated.utils.Style; import cc.fascinated.utils.Style;
import lombok.Getter; import lombok.Getter;
import lombok.SneakyThrows; import lombok.SneakyThrows;
@ -18,7 +15,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.UUID; import java.util.UUID;
@Getter @Log4j2 @Getter @Log4j2
public class Account { public class Account {

View File

@ -86,15 +86,12 @@ public class AccountManager extends Manager {
@Override @Override
public void onPlayerJoin(Account account, PlayerJoinEvent event) { public void onPlayerJoin(Account account, PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPlayedBefore()) { String joinMessage = Lang.JOIN_MESSAGE.getAsString();
return;
}
event.joinMessage(null); // Remove the join message so we can send our own if (!player.hasPlayedBefore()) {
Bukkit.broadcast(Style.getMiniMessage().deserialize(Lang.FIRST_JOIN_MESSAGE.getAsString() joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString();
.replace("%player%", player.getName())
));
// Send a notification to the discord log channel
Aetheria.EXECUTOR.execute(() -> { Aetheria.EXECUTOR.execute(() -> {
// todo: re-code this it's so ugly // todo: re-code this it's so ugly
DiscordWebhook discordWebhook = new DiscordWebhook(Config.DISCORD_LOG_WEBHOOK.getAsString()); DiscordWebhook discordWebhook = new DiscordWebhook(Config.DISCORD_LOG_WEBHOOK.getAsString());
@ -111,6 +108,11 @@ public class AccountManager extends Manager {
} }
}); });
} }
event.joinMessage(Style.getMiniMessage().deserialize(joinMessage
.replace("%player%", player.getName())
.replace("player-color", account.getPlayerColorProfile().getColor().toString())
));
}
@Override @Override
public void onPlayerLogin(Account account, PlayerLoginEvent event) { public void onPlayerLogin(Account account, PlayerLoginEvent event) {
@ -123,9 +125,13 @@ public class AccountManager extends Manager {
@Override @Override
public void onPlayerQuit(Account account, PlayerQuitEvent event) { public void onPlayerQuit(Account account, PlayerQuitEvent event) {
account.save(true); account.save(true); // Save the account
ACCOUNTS.remove(account.getUuid()); 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 @Override

View File

@ -26,7 +26,9 @@ public enum Lang {
BLOCKED_MESSAGE("blocked-message"), BLOCKED_MESSAGE("blocked-message"),
BLOCKED_MESSAGE_ALERT("blocked-message-alert"), BLOCKED_MESSAGE_ALERT("blocked-message-alert"),
CHAT_FORMAT("chat-format"), 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. * The path of the lang in the lang.yml file.

View File

@ -5,7 +5,9 @@ chat-format: "<<%chatcolor%>%name%</%chatcolor%>> <hover:show_text:Click to mess
blocked-message: "<prefix><hover:show_text:%reason%><red>Your message has been blocked." blocked-message: "<prefix><hover:show_text:%reason%><red>Your message has been blocked."
blocked-message-alert: "<admin-prefix><red>%player% <grey>tried to send a blocked message: <white>%message%" blocked-message-alert: "<admin-prefix><red>%player% <grey>tried to send a blocked message: <white>%message%"
first-join-message: "<yellow>%player% <white>joined for the first time!" first-join-message: "<player-color>%player% <yellow>joined for the first time!"
join-message: "<player-color>%player% <yellow>joined the game"
quit-message: "<player-color>%player% <yellow>left the game"
help-command: help-command:
- "<prefix>Commands:" - "<prefix>Commands:"