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.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();
}

View File

@ -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;
}
/**

View File

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

View File

@ -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.

View File

@ -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<Account, String> 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;
}
}

View File

@ -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<String, Object> cache = new HashMap<>();
/**
* The path of the lang in the lang.yml file.
*/
private final String path;
/**
* 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.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

View File

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

View File

@ -75,3 +75,7 @@ vote-stats-command:
- " <yellow>Total Votes: <white>%total-votes%"
- " <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%"
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%"