1
0
This commit is contained in:
Lee
2024-04-05 21:43:32 +01:00
parent 0d329cfead
commit 872279a9c5
21 changed files with 162 additions and 109 deletions

View File

@ -14,6 +14,7 @@ import cc.fascinated.motd.MotdManager;
import cc.fascinated.placeholder.PlaceholderManager; import cc.fascinated.placeholder.PlaceholderManager;
import cc.fascinated.playercolor.PlayerColorManager; import cc.fascinated.playercolor.PlayerColorManager;
import cc.fascinated.staffchat.StaffChatManager; import cc.fascinated.staffchat.StaffChatManager;
import cc.fascinated.tips.TipManager;
import cc.fascinated.utils.BuildData; import cc.fascinated.utils.BuildData;
import cc.fascinated.vote.VoteManager; import cc.fascinated.vote.VoteManager;
import cc.fascinated.worldsize.WorldSizeManager; import cc.fascinated.worldsize.WorldSizeManager;
@ -60,6 +61,8 @@ public class Aetheria extends JavaPlugin {
new RenderDistanceManager(); new RenderDistanceManager();
new VoteManager(); new VoteManager();
new StaffChatManager(); new StaffChatManager();
new TipManager();
new DiscordBot(); new DiscordBot();
} }
} }

View File

@ -29,30 +29,36 @@ public class Account {
*/ */
private static final String playerColorProfileId = "playerColorProfile"; private static final String playerColorProfileId = "playerColorProfile";
private static final String voteProfileId = "voteProfile"; private static final String voteProfileId = "voteProfile";
/** /**
* The UUID of the player. * The UUID of the player.
*/ */
@EqualsAndHashCode.Exclude @EqualsAndHashCode.Exclude
private final UUID uuid; private final UUID uuid;
/** /**
* The name of the player. * The name of the player.
*/ */
private final String name; private final String name;
/** /**
* The file for this account. * The file for this account.
*/ */
@EqualsAndHashCode.Exclude @EqualsAndHashCode.Exclude
private final File file; private final File file;
/** /**
* The configuration for this account. * The configuration for this account.
*/ */
@EqualsAndHashCode.Exclude @EqualsAndHashCode.Exclude
private final FileConfiguration config; private final FileConfiguration config;
/** /**
* Account profiles. * Account profiles.
*/ */
private final PlayerColorProfile playerColorProfile; private final PlayerColorProfile playerColorProfile;
private final VoteProfile voteProfile; private final VoteProfile voteProfile;
/** /**
* The last hashcode of the account. This is used to check if any changes * The last hashcode of the account. This is used to check if any changes
* have been made to the account. If no changes have been made, * have been made to the account. If no changes have been made,
@ -60,10 +66,12 @@ public class Account {
*/ */
@EqualsAndHashCode.Exclude @EqualsAndHashCode.Exclude
private int lastHash; private int lastHash;
/** /**
* The first time the player joined the server. * The first time the player joined the server.
*/ */
private long firstJoin; private long firstJoin;
/** /**
* The last time the player logged in. * The last time the player logged in.
*/ */
@ -83,7 +91,7 @@ public class Account {
try { try {
file.createNewFile(); file.createNewFile();
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to create account file for " + this.uuid); log.warn("Failed to create account file for {}", this.uuid);
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -92,8 +100,7 @@ public class Account {
if (newAccount) { if (newAccount) {
this.firstJoin = System.currentTimeMillis(); this.firstJoin = System.currentTimeMillis();
this.lastLogin = System.currentTimeMillis(); this.lastLogin = System.currentTimeMillis();
this.save(false); // Save default values log.info("Created new account for {}", this.uuid);
log.info("Created new account for " + this.uuid);
} }
this.firstJoin = config.getLong("firstJoin"); this.firstJoin = config.getLong("firstJoin");
@ -217,10 +224,9 @@ public class Account {
/** /**
* Saves the account to disk. * Saves the account to disk.
* *
* @param saveProfiles if the profiles should be saved
* @return true if the account was saved, false otherwise * @return true if the account was saved, false otherwise
*/ */
public boolean save(boolean saveProfiles) { public boolean save() {
if (this.lastHash == this.hashCode()) { if (this.lastHash == this.hashCode()) {
return false; // No changes have been made return false; // No changes have been made
} }
@ -228,28 +234,17 @@ public class Account {
this.config.set("firstJoin", this.firstJoin); this.config.set("firstJoin", this.firstJoin);
this.config.set("lastLogin", this.lastLogin); this.config.set("lastLogin", this.lastLogin);
if (saveProfiles) { this.saveProfile(this.playerColorProfile, playerColorProfileId);
this.saveProfile(this.playerColorProfile, playerColorProfileId); this.saveProfile(this.voteProfile, voteProfileId);
this.saveProfile(this.voteProfile, voteProfileId);
}
try { try {
this.config.save(this.file); // Save the account to disk this.config.save(this.file); // Save the account to disk
} catch (Exception ex) { } catch (Exception ex) {
log.warn("Failed to save account for " + this.uuid); log.warn("Failed to save account for {}", this.uuid);
ex.printStackTrace(); ex.printStackTrace();
return false; return false;
} }
this.lastHash = this.hashCode(); // Update the last hash this.lastHash = this.hashCode(); // Update the last hash
return true; return true;
} }
/**
* Saves the account and profiles to disk.
*
* @return true if the account was saved, false otherwise
*/
public boolean save() {
return this.save(true);
}
} }

View File

@ -14,6 +14,7 @@ import cc.fascinated.utils.Style;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -106,6 +107,20 @@ public class AccountManager extends Manager implements Listener {
log.info("Saved {}/{} accounts. ({}ms)", saved, ACCOUNTS.size(), System.currentTimeMillis() - before); log.info("Saved {}/{} accounts. ({}ms)", saved, ACCOUNTS.size(), System.currentTimeMillis() - before);
} }
/**
* Deletes an account from the server.
* This will remove the account from memory and delete the account file.
*
* @param account the account to delete
*/
public void deleteAccount(Account account) {
account.getFile().delete();
ACCOUNTS.remove(account.getUuid());
account.getPlayer().kick(Component.text("Your account has been deleted. Please reconnect."));
log.info("Deleted account for {}", account.getUuid());
}
@Override @Override
public Priority getPriority() { public Priority getPriority() {
return Priority.LOWEST; return Priority.LOWEST;

View File

@ -6,7 +6,8 @@ import cc.fascinated.command.Command;
public class DeleteAccountCommand extends Command { public class DeleteAccountCommand extends Command {
public DeleteAccountCommand() { public DeleteAccountCommand() {
super("deleteaccount", "aetheria.command.deleteaccount"); super("deleteaccount");
super.setPermission("aetheria.command.deleteaccount");
} }
@Override @Override

View File

@ -8,7 +8,8 @@ import cc.fascinated.config.Lang;
public class SaveAccountsCommand extends Command { public class SaveAccountsCommand extends Command {
public SaveAccountsCommand() { public SaveAccountsCommand() {
super("saveaccounts", "command.aetheria.saveaccounts"); super("saveaccounts");
super.setPermission("command.aetheria.saveaccounts");
} }
@Override @Override

View File

@ -13,25 +13,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@Getter @Getter
public abstract class Command implements CommandExecutor, TabCompleter { public abstract class Command extends org.bukkit.command.Command {
/** public Command(@NotNull String name) {
* The command name super(name);
*/
private final String command;
/**
* The permission required to execute the command.
*/
private String permission;
public Command(String command, String permissions) {
this.command = command;
this.permission = permissions;
}
public Command(String command) {
this.command = command;
} }
/** /**
@ -54,26 +39,18 @@ public abstract class Command implements CommandExecutor, TabCompleter {
} }
@Override @Override
public final boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { public final boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
if (this.permission != null && !commandSender.hasPermission(permission)) {
commandSender.sendMessage("§cYou do not have permission to execute this command.");
return true;
}
Player player = (Player) commandSender; Player player = (Player) commandSender;
Account account = AccountManager.getAccount(player.getUniqueId()); Account account = AccountManager.getAccount(player.getUniqueId());
this.execute(account, strings); this.execute(account, strings);
return true; return true;
} }
@Override @Override
public final @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { public final @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
if (this.permission != null && !commandSender.hasPermission(permission)) { Player player = (Player) sender;
return null;
}
Player player = (Player) commandSender;
Account account = AccountManager.getAccount(player.getUniqueId()); Account account = AccountManager.getAccount(player.getUniqueId());
return this.tabComplete(account, strings); return this.tabComplete(account, args);
} }
} }

View File

@ -2,16 +2,24 @@ package cc.fascinated.command;
import cc.fascinated.Aetheria; import cc.fascinated.Aetheria;
import cc.fascinated.command.impl.*; import cc.fascinated.command.impl.*;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class CommandManager { public class CommandManager {
private static final List<Command> COMMANDS = new ArrayList<>();
public CommandManager() { public CommandManager() {
registerCommand(new TotalJoinsCommand()); registerCommand(new TotalJoinsCommand());
registerCommand(new HelpCommand()); registerCommand(new HelpCommand());
registerCommand(new SeedCommand()); registerCommand(new SeedCommand());
registerCommand(new VoteCommand()); registerCommand(new VoteCommand());
registerCommand(new GitCommand()); registerCommand(new GitCommand());
registerCommand(new DiscordCommand());
} }
/** /**
@ -19,16 +27,18 @@ public class CommandManager {
* *
* @param command The command to register. * @param command The command to register.
*/ */
public static void registerCommand(Command command) { public static void registerCommand(@NotNull Command command) {
if (command == null) { Bukkit.getCommandMap().register(Aetheria.INSTANCE.getName(), command);
throw new IllegalArgumentException("Command cannot be null."); COMMANDS.add(command);
} }
PluginCommand pluginCommand = Aetheria.INSTANCE.getCommand(command.getCommand()); /**
if (pluginCommand == null) { * Unregisters a command.
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist."); *
} * @param command The command to unregister.
pluginCommand.setExecutor(command); */
pluginCommand.setTabCompleter(command); public static void unregisterCommand(@NotNull Command command) {
command.unregister(Bukkit.getCommandMap());
COMMANDS.remove(command);
} }
} }

View File

@ -0,0 +1,20 @@
package cc.fascinated.command.impl;
import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import cc.fascinated.config.Config;
import cc.fascinated.config.Lang;
public class DiscordCommand extends Command {
public DiscordCommand() {
super("discord");
}
@Override
public void execute(Account account, String[] args) {
account.sendMessage(Lang.DISCORD_COMMAND.getAsString()
.replace("%invite-url%", Config.DISCORD_INVITE_URL.getAsString())
);
}
}

View File

@ -12,7 +12,8 @@ import java.util.List;
public class GitCommand extends Command { public class GitCommand extends Command {
public GitCommand() { public GitCommand() {
super("git", "aetheria.command.git"); super("git");
super.setPermission("aetheria.command.git");
} }
@Override @Override

View File

@ -7,7 +7,8 @@ import cc.fascinated.config.Lang;
public class TotalJoinsCommand extends Command { public class TotalJoinsCommand extends Command {
public TotalJoinsCommand() { public TotalJoinsCommand() {
super("totaljoins", "aetheria.command.totaljoins"); super("totaljoins");
super.setPermission("aetheria.command.totaljoins");
} }
@Override @Override

View File

@ -8,7 +8,8 @@ import cc.fascinated.config.Lang;
public class CommandSpyCommand extends Command { public class CommandSpyCommand extends Command {
public CommandSpyCommand() { public CommandSpyCommand() {
super("commandspy", "aetheria.command.commandspy"); super("commandspy");
super.setPermission("aetheria.command.commandspy");
} }
@Override @Override

View File

@ -15,11 +15,13 @@ public enum Config {
INFLUXDB_ORG("influxdb.org"), INFLUXDB_ORG("influxdb.org"),
INFLUXDB_BUCKET("influxdb.bucket"), INFLUXDB_BUCKET("influxdb.bucket"),
DISCORD_TOKEN("discord.token"), DISCORD_TOKEN("discord.token"),
DISCORD_INVITE_URL("discord.invite-url"),
MOTD_HEADER("motd.header"), MOTD_HEADER("motd.header"),
MOTD_FORMAT("motd.format"), MOTD_FORMAT("motd.format"),
MOTD_LIST("motd.motds"), MOTD_LIST("motd.motds"),
VERSION_WARNING_VERSION("version-warning.min-version"), VERSION_WARNING_VERSION("version-warning.min-version"),
VERSION_WARNING_MESSAGE("version-warning.message"); VERSION_WARNING_MESSAGE("version-warning.message"),
TIP_INTERVAL("tip-interval");
/** /**
* Cache of the config values. * Cache of the config values.

View File

@ -27,6 +27,7 @@ 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"),
DISCORD_COMMAND("discord-command"),
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"),
@ -40,7 +41,10 @@ public enum Lang {
VOTE_VOTED("vote.voted"), VOTE_VOTED("vote.voted"),
VOTE_BROADCAST("vote.broadcast"), VOTE_BROADCAST("vote.broadcast"),
STAFF_CHAT_FORMAT("staff-chat.format"), STAFF_CHAT_FORMAT("staff-chat.format"),
STAFF_CHAT_USAGE("staff-chat.usage"); STAFF_CHAT_USAGE("staff-chat.usage"),
TIPS_FORMAT("tips.format"),
TIPS_LIST("tips.tips"),
TIPS_LOGIN_NOTIFICATION("tips.login-notification");
/** /**
* Cache of the lang values. * Cache of the lang values.

View File

@ -5,7 +5,6 @@ import cc.fascinated.account.AccountManager;
import cc.fascinated.config.Lang; import cc.fascinated.config.Lang;
import cc.fascinated.staffchat.command.StaffChatCommand; import cc.fascinated.staffchat.command.StaffChatCommand;
import cc.fascinated.utils.Manager; import cc.fascinated.utils.Manager;
import org.bukkit.Bukkit;
public class StaffChatManager extends Manager { public class StaffChatManager extends Manager {

View File

@ -8,7 +8,8 @@ import cc.fascinated.staffchat.StaffChatManager;
public class StaffChatCommand extends Command { public class StaffChatCommand extends Command {
public StaffChatCommand() { public StaffChatCommand() {
super("staffchat", "aetheria.command.staffchat"); super("staffchat");
super.setPermission("aetheria.command.staffchat");
} }
@Override @Override

View File

@ -0,0 +1,42 @@
package cc.fascinated.tips;
import cc.fascinated.Aetheria;
import cc.fascinated.account.Account;
import cc.fascinated.config.Config;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.Manager;
import cc.fascinated.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class TipManager extends Manager {
public TipManager() {
Bukkit.getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> {
MessageUtils.broadcast(Lang.TIPS_FORMAT.getAsString()
.replace("%tip%", this.getRandomTip())
);
}, 0, Config.TIP_INTERVAL.getAsInt() , TimeUnit.MINUTES);
}
/**
* Get a random tip.
*
* @return the random tip
*/
private String getRandomTip() {
List<String> tips = Lang.TIPS_LIST.getAsStringList();
return tips.get((int) (Math.random() * tips.size()));
}
@Override
public void onPlayerJoin(Account account, PlayerJoinEvent event) {
account.sendMessage(Lang.TIPS_FORMAT.getAsString()
.replace("%tip%", this.getRandomTip())
);
account.sendMessage(Lang.TIPS_LOGIN_NOTIFICATION.getAsString());
}
}

View File

@ -3,7 +3,7 @@ package cc.fascinated.worldsize;
import cc.fascinated.Aetheria; import cc.fascinated.Aetheria;
import cc.fascinated.command.CommandManager; import cc.fascinated.command.CommandManager;
import cc.fascinated.placeholder.PlaceholderManager; import cc.fascinated.placeholder.PlaceholderManager;
import cc.fascinated.worldsize.impl.WorldSizeCommand; import cc.fascinated.worldsize.command.WorldSizeCommand;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;

View File

@ -1,4 +1,4 @@
package cc.fascinated.worldsize.impl; package cc.fascinated.worldsize.command;
import cc.fascinated.account.Account; import cc.fascinated.account.Account;
import cc.fascinated.command.Command; import cc.fascinated.command.Command;

View File

@ -6,11 +6,14 @@ influxdb:
discord: discord:
token: "MTEyOTEyMDY0NTk3Mjc2Njc3MA.G7VXPL.8iDzdTxScweAKByKnwY6PFcK07AehFfNvf_2Hk" token: "MTEyOTEyMDY0NTk3Mjc2Njc3MA.G7VXPL.8iDzdTxScweAKByKnwY6PFcK07AehFfNvf_2Hk"
invite-url: "https://discord.gg/8qMjSXHGEw"
version-warning: version-warning:
min-version: 763 # 1.20 min-version: 763 # 1.20
message: "<red><bold>WARNING!</bold></red> <white>You are using an outdated version of Minecraft. Please update to the latest version to avoid any issues." message: "<red><bold>WARNING!</bold></red> <white>You are using an outdated version of Minecraft. Please update to the latest version to avoid any issues."
tip-interval: 30 # in minutes
motd: motd:
header: "<yellow>Aetheria</yellow>" header: "<yellow>Aetheria</yellow>"
format: "<gray>%motd%</gray>" format: "<gray>%motd%</gray>"

View File

@ -25,6 +25,18 @@ staff-chat:
usage: "<prefix>Usage: /staffchat <message>" usage: "<prefix>Usage: /staffchat <message>"
format: "<grey>[</grey><bold><red>SC</red></bold><grey>]</grey> <white><player-color>%player% <gray>» <white>%message%" format: "<grey>[</grey><bold><red>SC</red></bold><grey>]</grey> <white><player-color>%player% <gray>» <white>%message%"
tips:
format: "<gold><bold>TIP!</bold></gold> <white>%tip%"
login-notification: "<gray><italic>When you login, you will see a random tip."
tips:
- "Make sure to vote for the server to get rewards! <yellow>/vote"
- "You can change your player name color with <yellow>/playercolor"
- "You can see the world seed with <yellow>/seed"
- "You can see the total file size of all worlds with <yellow>/worldsize"
- "You can kill yourself with <yellow>/kill"
- "View your vote stats with <yellow>/votestats"
- "Join our Discord using <yellow>/discord"
help-command: help-command:
- "<prefix>Commands:" - "<prefix>Commands:"
- "<yellow>/kill <gray>- <white>Kills you" - "<yellow>/kill <gray>- <white>Kills you"
@ -61,4 +73,5 @@ save-accounts-command:
vote-stats-command: vote-stats-command:
- "<prefix>Your vote statistics:" - "<prefix>Your vote statistics:"
- " <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%"

View File

@ -5,40 +5,4 @@ api-version: 1.20
author: Fascinated author: Fascinated
depend: depend:
- PlaceholderAPI - PlaceholderAPI
- ViaVersion - ViaVersion
commands:
totaljoins:
description: "Shows the total amount of joins"
usage: "/totaljoins"
worldsize:
description: "Shows the size of all worlds"
usage: "/worldsize"
help:
description: "Shows the help message"
usage: "/help"
playercolor:
description: "Changes your player color"
usage: "/playercolor <color>"
seed:
description: "Shows the seed of the world"
usage: "/seed"
vote:
description: "Shows the vote links"
usage: "/vote"
git:
description: "Shows the git information"
usage: "/git"
saveaccounts:
description: "Saves the accounts"
usage: "/saveaccounts"
commandspy:
description: "Toggles command spy"
usage: "/commandspy"
votestats:
description: "Shows your vote stats"
usage: "/votestats"
staffchat:
description: "Toggles staff chat"
usage: "/staffchat <message>"
aliases:
- sc