1
0

update channel ids and add join and leave logs

This commit is contained in:
Lee
2024-04-12 17:42:48 +01:00
parent 6d2d658440
commit 2ec1b25611
10 changed files with 104 additions and 43 deletions

View File

@ -8,6 +8,7 @@ import cc.fascinated.commandspy.CommandSpyManager;
import cc.fascinated.config.Config; import cc.fascinated.config.Config;
import cc.fascinated.config.Lang; import cc.fascinated.config.Lang;
import cc.fascinated.event.EventManager; import cc.fascinated.event.EventManager;
import cc.fascinated.joinlogs.JoinLogManager;
import cc.fascinated.metrics.MetricManager; import cc.fascinated.metrics.MetricManager;
import cc.fascinated.misc.RenderDistanceManager; import cc.fascinated.misc.RenderDistanceManager;
import cc.fascinated.motd.MotdManager; import cc.fascinated.motd.MotdManager;
@ -34,6 +35,10 @@ public class Aetheria extends JavaPlugin {
* The instance of the plugin. * The instance of the plugin.
*/ */
public static Aetheria INSTANCE; public static Aetheria INSTANCE;
/**
* Thread pool executor for async tasks.
*/
public static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 8, 0L, public static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 8, 0L,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
@ -62,6 +67,7 @@ public class Aetheria extends JavaPlugin {
new VoteManager(); new VoteManager();
new StaffChatManager(); new StaffChatManager();
new TipManager(); new TipManager();
new JoinLogManager();
new DiscordBot(); new DiscordBot();
} }

View File

@ -110,8 +110,8 @@ public class Account {
this.name = name; // Update the name this.name = name; // Update the name
// Load profiles // Load profiles
this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId)); this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId, false));
this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId)); this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId, false));
this.lastHash = this.hashCode(); this.lastHash = this.hashCode();
@ -125,7 +125,7 @@ public class Account {
* @param key the key to save the profile under * @param key the key to save the profile under
*/ */
private void saveProfile(Profile profile, String key) { 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 * @param key the key to get the profile section for
* @return the profile section * @return the profile section
*/ */
private ConfigurationSection getProfileSection(String key) { private ConfigurationSection getProfileSection(String key, boolean create) {
return this.config.getConfigurationSection(key); ConfigurationSection section = this.config.getConfigurationSection(key);
if (section == null && create) {
section = this.config.createSection(key);
}
return section;
} }
/** /**

View File

@ -5,7 +5,6 @@ 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;
import cc.fascinated.command.CommandManager;
import cc.fascinated.config.Config; import cc.fascinated.config.Config;
import cc.fascinated.config.Lang; import cc.fascinated.config.Lang;
import cc.fascinated.playercolor.PlayerColorProfile; import cc.fascinated.playercolor.PlayerColorProfile;
@ -25,6 +24,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.awt.*; import java.awt.*;
import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -118,14 +118,13 @@ public class AccountManager extends Manager implements Listener {
public static void deleteAccount(Account account) { public static void deleteAccount(Account account) {
account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect.")); account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect."));
account.getFile().delete(); try {
ACCOUNTS.remove(account.getUuid()); Files.delete(account.getFile().toPath());
log.info("Deleted account for {}", account.getUuid()); ACCOUNTS.remove(account.getUuid());
} log.info("Deleted account for {}", account.getUuid());
} catch (Exception ex) {
@Override log.error("Failed to delete account for {}", account.getUuid());
public Priority getPriority() { }
return Priority.LOWEST;
} }
/** /**
@ -156,8 +155,8 @@ public class AccountManager extends Manager implements Listener {
if (!account.getPlayer().hasPlayedBefore()) { if (!account.getPlayer().hasPlayedBefore()) {
joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString(); joinMessage = Lang.FIRST_JOIN_MESSAGE.getAsString();
DiscordBot.sendEmbed(DiscordChannel.PLAYER_LOGS, new EmbedBuilder() DiscordBot.sendEmbed(DiscordChannel.NEW_PLAYER_LOGS, new EmbedBuilder()
.setThumbnail("https://crafatar.com/avatars/" + account.getUuid() + ".png") .setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString())
.setColor(Color.GREEN) .setColor(Color.GREEN)
.setTitle("New Player Joined") .setTitle("New Player Joined")
.addField("Player", account.getName(), true) .addField("Player", account.getName(), true)
@ -188,4 +187,9 @@ public class AccountManager extends Manager implements Listener {
public void onAetheriaDisable() { public void onAetheriaDisable() {
saveAccounts(); // Save the accounts to disk saveAccounts(); // Save the accounts to disk
} }
@Override
public Priority getPriority() {
return Priority.LOWEST;
}
} }

View File

@ -6,8 +6,9 @@ import lombok.RequiredArgsConstructor;
@Getter @RequiredArgsConstructor @Getter @RequiredArgsConstructor
public enum DiscordChannel { public enum DiscordChannel {
PLAYER_LOGS("1223161810157568020"), NEW_PLAYER_LOGS("1228383457361661975"),
VOTE_LOGS("1225868584522219570"); PLAYER_LOGS("1228383471437615114"),
VOTE_LOGS("1228383490874277948");
/** /**
* The ID of the Discord channel. * The ID of the Discord channel.

View File

@ -15,16 +15,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.HashMap; import java.util.HashMap;
import java.util.regex.Pattern; 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 { public class ChatManager extends Manager {
private final HashMap<Account, String> lastMessage = new HashMap<>(); private final HashMap<Account, String> lastMessage = new HashMap<>();
@ -79,4 +69,14 @@ public class ChatManager extends Manager {
}); });
lastMessage.put(account, messageContent); 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;
}
} }

View File

@ -27,6 +27,9 @@ public enum Lang {
VOTE_STATS_COMMAND("vote-stats-command"), VOTE_STATS_COMMAND("vote-stats-command"),
SAVE_ACCOUNTS_COMMAND_SAVING("save-accounts-command.saving"), SAVE_ACCOUNTS_COMMAND_SAVING("save-accounts-command.saving"),
SAVE_ACCOUNTS_COMMAND_SAVED("save-accounts-command.saved"), 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"), DISCORD_COMMAND("discord-command"),
BLOCKED_MESSAGE("blocked-message"), BLOCKED_MESSAGE("blocked-message"),
BLOCKED_MESSAGE_ALERT("blocked-message-alert"), BLOCKED_MESSAGE_ALERT("blocked-message-alert"),
@ -50,10 +53,12 @@ public enum Lang {
* Cache of the lang values. * Cache of the lang values.
*/ */
private static final HashMap<String, Object> cache = new HashMap<>(); private static final HashMap<String, Object> cache = new HashMap<>();
/** /**
* The path of the lang in the lang.yml file. * The path of the lang in the lang.yml file.
*/ */
private final String path; private final String path;
/** /**
* The lang configuration. * The lang configuration.
*/ */

View File

@ -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)
);
}
}

View File

@ -2,6 +2,7 @@ package cc.fascinated.playercolor.command;
import cc.fascinated.account.Account; import cc.fascinated.account.Account;
import cc.fascinated.command.Command; import cc.fascinated.command.Command;
import cc.fascinated.config.Lang;
import cc.fascinated.playercolor.PlayerColorManager; import cc.fascinated.playercolor.PlayerColorManager;
import cc.fascinated.playercolor.PlayerColorProfile; import cc.fascinated.playercolor.PlayerColorProfile;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -22,30 +23,29 @@ public class PlayerColorCommand extends Command {
PlayerColorProfile playerColorProfile = account.getPlayerColorProfile(); PlayerColorProfile playerColorProfile = account.getPlayerColorProfile();
if (args.length == 0) { if (args.length == 0) {
account.sendMessage(Component.text("§b§lPLAYERCOLOR §7» §fYour current color is: ").append(Component.text(playerColorProfile.getColor().toString()).color(playerColorProfile.getColor()))); account.sendMessage(Lang.PLAYER_COLOR_COMMAND_USAGE.getAsString());
Component validColorsComponent = Component.text("§fValid colors: ");
for (NamedTextColor validColor : validColors) { Component colors = Component.text("Colors: ");
validColorsComponent = validColorsComponent.append(Component.text(validColor.toString() + ", ").color(validColor)); 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)); colors = colors.append(Component.text("random"));
account.sendMessage(validColorsComponent); account.sendMessage(colors);
return; return;
} }
if (args[0].equalsIgnoreCase("random")) { NamedTextColor color = args[0].equalsIgnoreCase("random") ?
playerColorProfile.setColor(validColors.get((int) (Math.random() * validColors.size()))); PlayerColorManager.getRandomColor() : PlayerColorManager.getColor(args[0]);
account.sendMessage("§b§lPLAYERCOLOR §7» §fYour color has been set to: " + playerColorProfile.getColor() + "§f.");
return;
}
NamedTextColor color = PlayerColorManager.getColor(args[0]);
if (color == null) { if (color == null) {
account.sendMessage("§b§lPLAYERCOLOR §7» §cInvalid color."); account.sendMessage(Lang.PLAYER_COLOR_COMMAND_INVALID_COLOR.getAsString());
return; return;
} }
playerColorProfile.setColor(color); 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 @Override

View File

@ -35,6 +35,7 @@ public class VoteManager extends Manager {
); );
DiscordBot.sendEmbed(DiscordChannel.VOTE_LOGS, new EmbedBuilder() DiscordBot.sendEmbed(DiscordChannel.VOTE_LOGS, new EmbedBuilder()
.setThumbnail("https://mc.fascinated.cc/player/head/" + account.getUuid().toString())
.setTitle("Player Voted") .setTitle("Player Voted")
.setColor(Color.GREEN) .setColor(Color.GREEN)
.addField("Player", account.getPlayer().getName(), true) .addField("Player", account.getPlayer().getName(), true)

View File

@ -75,3 +75,7 @@ vote-stats-command:
- " <yellow>Total Votes: <white>%total-votes%" - " <yellow>Total Votes: <white>%total-votes%"
- " <yellow>Vote Tokens: <white>%vote-tokens%" - " <yellow>Vote Tokens: <white>%vote-tokens%"
discord-command: "<prefix>Join our Discord server: <hover:show_text:Click to open the link><click:open_url:%invite-url%><yellow>%invite-url%" discord-command: "<prefix>Join our Discord server: <hover:show_text:Click to open the link><click:open_url:%invite-url%><yellow>%invite-url%"
player-color-command:
usage: "<prefix>Usage: /playercolor [color]"
invalid-color: "<prefix>Invalid color. Use a valid color code."
color-changed: "<prefix>Your player color has been changed to <new-color>%color%"