stuff
This commit is contained in:
@ -14,6 +14,7 @@ import cc.fascinated.motd.MotdManager;
|
||||
import cc.fascinated.placeholder.PlaceholderManager;
|
||||
import cc.fascinated.playercolor.PlayerColorManager;
|
||||
import cc.fascinated.staffchat.StaffChatManager;
|
||||
import cc.fascinated.tips.TipManager;
|
||||
import cc.fascinated.utils.BuildData;
|
||||
import cc.fascinated.vote.VoteManager;
|
||||
import cc.fascinated.worldsize.WorldSizeManager;
|
||||
@ -60,6 +61,8 @@ public class Aetheria extends JavaPlugin {
|
||||
new RenderDistanceManager();
|
||||
new VoteManager();
|
||||
new StaffChatManager();
|
||||
new TipManager();
|
||||
|
||||
new DiscordBot();
|
||||
}
|
||||
}
|
@ -29,30 +29,36 @@ public class Account {
|
||||
*/
|
||||
private static final String playerColorProfileId = "playerColorProfile";
|
||||
private static final String voteProfileId = "voteProfile";
|
||||
|
||||
/**
|
||||
* The UUID of the player.
|
||||
*/
|
||||
@EqualsAndHashCode.Exclude
|
||||
private final UUID uuid;
|
||||
|
||||
/**
|
||||
* The name of the player.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The file for this account.
|
||||
*/
|
||||
@EqualsAndHashCode.Exclude
|
||||
private final File file;
|
||||
|
||||
/**
|
||||
* The configuration for this account.
|
||||
*/
|
||||
@EqualsAndHashCode.Exclude
|
||||
private final FileConfiguration config;
|
||||
|
||||
/**
|
||||
* Account profiles.
|
||||
*/
|
||||
private final PlayerColorProfile playerColorProfile;
|
||||
private final VoteProfile voteProfile;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
@ -60,10 +66,12 @@ public class Account {
|
||||
*/
|
||||
@EqualsAndHashCode.Exclude
|
||||
private int lastHash;
|
||||
|
||||
/**
|
||||
* The first time the player joined the server.
|
||||
*/
|
||||
private long firstJoin;
|
||||
|
||||
/**
|
||||
* The last time the player logged in.
|
||||
*/
|
||||
@ -83,7 +91,7 @@ public class Account {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
@ -92,8 +100,7 @@ public class Account {
|
||||
if (newAccount) {
|
||||
this.firstJoin = 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");
|
||||
@ -217,10 +224,9 @@ public class Account {
|
||||
/**
|
||||
* Saves the account to disk.
|
||||
*
|
||||
* @param saveProfiles if the profiles should be saved
|
||||
* @return true if the account was saved, false otherwise
|
||||
*/
|
||||
public boolean save(boolean saveProfiles) {
|
||||
public boolean save() {
|
||||
if (this.lastHash == this.hashCode()) {
|
||||
return false; // No changes have been made
|
||||
}
|
||||
@ -228,28 +234,17 @@ public class Account {
|
||||
this.config.set("firstJoin", this.firstJoin);
|
||||
this.config.set("lastLogin", this.lastLogin);
|
||||
|
||||
if (saveProfiles) {
|
||||
this.saveProfile(this.playerColorProfile, playerColorProfileId);
|
||||
this.saveProfile(this.voteProfile, voteProfileId);
|
||||
}
|
||||
this.saveProfile(this.playerColorProfile, playerColorProfileId);
|
||||
this.saveProfile(this.voteProfile, voteProfileId);
|
||||
|
||||
try {
|
||||
this.config.save(this.file); // Save the account to disk
|
||||
} catch (Exception ex) {
|
||||
log.warn("Failed to save account for " + this.uuid);
|
||||
log.warn("Failed to save account for {}", this.uuid);
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
this.lastHash = this.hashCode(); // Update the last hash
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import cc.fascinated.utils.Style;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
public Priority getPriority() {
|
||||
return Priority.LOWEST;
|
||||
|
@ -6,7 +6,8 @@ import cc.fascinated.command.Command;
|
||||
public class DeleteAccountCommand extends Command {
|
||||
|
||||
public DeleteAccountCommand() {
|
||||
super("deleteaccount", "aetheria.command.deleteaccount");
|
||||
super("deleteaccount");
|
||||
super.setPermission("aetheria.command.deleteaccount");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,8 @@ import cc.fascinated.config.Lang;
|
||||
public class SaveAccountsCommand extends Command {
|
||||
|
||||
public SaveAccountsCommand() {
|
||||
super("saveaccounts", "command.aetheria.saveaccounts");
|
||||
super("saveaccounts");
|
||||
super.setPermission("command.aetheria.saveaccounts");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,25 +13,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public abstract class Command implements CommandExecutor, TabCompleter {
|
||||
public abstract class Command extends org.bukkit.command.Command {
|
||||
|
||||
/**
|
||||
* The command 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;
|
||||
public Command(@NotNull String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,26 +39,18 @@ public abstract class Command implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @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;
|
||||
}
|
||||
|
||||
public final boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
|
||||
Player player = (Player) commandSender;
|
||||
Account account = AccountManager.getAccount(player.getUniqueId());
|
||||
|
||||
this.execute(account, strings);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (this.permission != null && !commandSender.hasPermission(permission)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player player = (Player) commandSender;
|
||||
public final @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
||||
Player player = (Player) sender;
|
||||
Account account = AccountManager.getAccount(player.getUniqueId());
|
||||
return this.tabComplete(account, strings);
|
||||
return this.tabComplete(account, args);
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,24 @@ package cc.fascinated.command;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.command.impl.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
private static final List<Command> COMMANDS = new ArrayList<>();
|
||||
|
||||
public CommandManager() {
|
||||
registerCommand(new TotalJoinsCommand());
|
||||
registerCommand(new HelpCommand());
|
||||
registerCommand(new SeedCommand());
|
||||
registerCommand(new VoteCommand());
|
||||
registerCommand(new GitCommand());
|
||||
registerCommand(new DiscordCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -19,16 +27,18 @@ public class CommandManager {
|
||||
*
|
||||
* @param command The command to register.
|
||||
*/
|
||||
public static void registerCommand(Command command) {
|
||||
if (command == null) {
|
||||
throw new IllegalArgumentException("Command cannot be null.");
|
||||
}
|
||||
public static void registerCommand(@NotNull Command command) {
|
||||
Bukkit.getCommandMap().register(Aetheria.INSTANCE.getName(), command);
|
||||
COMMANDS.add(command);
|
||||
}
|
||||
|
||||
PluginCommand pluginCommand = Aetheria.INSTANCE.getCommand(command.getCommand());
|
||||
if (pluginCommand == null) {
|
||||
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist.");
|
||||
}
|
||||
pluginCommand.setExecutor(command);
|
||||
pluginCommand.setTabCompleter(command);
|
||||
/**
|
||||
* Unregisters a command.
|
||||
*
|
||||
* @param command The command to unregister.
|
||||
*/
|
||||
public static void unregisterCommand(@NotNull Command command) {
|
||||
command.unregister(Bukkit.getCommandMap());
|
||||
COMMANDS.remove(command);
|
||||
}
|
||||
}
|
||||
|
20
src/main/java/cc/fascinated/command/impl/DiscordCommand.java
Normal file
20
src/main/java/cc/fascinated/command/impl/DiscordCommand.java
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
@ -12,7 +12,8 @@ import java.util.List;
|
||||
public class GitCommand extends Command {
|
||||
|
||||
public GitCommand() {
|
||||
super("git", "aetheria.command.git");
|
||||
super("git");
|
||||
super.setPermission("aetheria.command.git");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,7 +7,8 @@ import cc.fascinated.config.Lang;
|
||||
public class TotalJoinsCommand extends Command {
|
||||
|
||||
public TotalJoinsCommand() {
|
||||
super("totaljoins", "aetheria.command.totaljoins");
|
||||
super("totaljoins");
|
||||
super.setPermission("aetheria.command.totaljoins");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,8 @@ import cc.fascinated.config.Lang;
|
||||
public class CommandSpyCommand extends Command {
|
||||
|
||||
public CommandSpyCommand() {
|
||||
super("commandspy", "aetheria.command.commandspy");
|
||||
super("commandspy");
|
||||
super.setPermission("aetheria.command.commandspy");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,11 +15,13 @@ public enum Config {
|
||||
INFLUXDB_ORG("influxdb.org"),
|
||||
INFLUXDB_BUCKET("influxdb.bucket"),
|
||||
DISCORD_TOKEN("discord.token"),
|
||||
DISCORD_INVITE_URL("discord.invite-url"),
|
||||
MOTD_HEADER("motd.header"),
|
||||
MOTD_FORMAT("motd.format"),
|
||||
MOTD_LIST("motd.motds"),
|
||||
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.
|
||||
|
@ -27,6 +27,7 @@ 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"),
|
||||
DISCORD_COMMAND("discord-command"),
|
||||
BLOCKED_MESSAGE("blocked-message"),
|
||||
BLOCKED_MESSAGE_ALERT("blocked-message-alert"),
|
||||
CHAT_FORMAT("chat-format"),
|
||||
@ -40,7 +41,10 @@ public enum Lang {
|
||||
VOTE_VOTED("vote.voted"),
|
||||
VOTE_BROADCAST("vote.broadcast"),
|
||||
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.
|
||||
|
@ -5,7 +5,6 @@ import cc.fascinated.account.AccountManager;
|
||||
import cc.fascinated.config.Lang;
|
||||
import cc.fascinated.staffchat.command.StaffChatCommand;
|
||||
import cc.fascinated.utils.Manager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class StaffChatManager extends Manager {
|
||||
|
||||
|
@ -8,7 +8,8 @@ import cc.fascinated.staffchat.StaffChatManager;
|
||||
public class StaffChatCommand extends Command {
|
||||
|
||||
public StaffChatCommand() {
|
||||
super("staffchat", "aetheria.command.staffchat");
|
||||
super("staffchat");
|
||||
super.setPermission("aetheria.command.staffchat");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
42
src/main/java/cc/fascinated/tips/TipManager.java
Normal file
42
src/main/java/cc/fascinated/tips/TipManager.java
Normal 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());
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package cc.fascinated.worldsize;
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.command.CommandManager;
|
||||
import cc.fascinated.placeholder.PlaceholderManager;
|
||||
import cc.fascinated.worldsize.impl.WorldSizeCommand;
|
||||
import cc.fascinated.worldsize.command.WorldSizeCommand;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.fascinated.worldsize.impl;
|
||||
package cc.fascinated.worldsize.command;
|
||||
|
||||
import cc.fascinated.account.Account;
|
||||
import cc.fascinated.command.Command;
|
@ -6,11 +6,14 @@ influxdb:
|
||||
|
||||
discord:
|
||||
token: "MTEyOTEyMDY0NTk3Mjc2Njc3MA.G7VXPL.8iDzdTxScweAKByKnwY6PFcK07AehFfNvf_2Hk"
|
||||
invite-url: "https://discord.gg/8qMjSXHGEw"
|
||||
|
||||
version-warning:
|
||||
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."
|
||||
|
||||
tip-interval: 30 # in minutes
|
||||
|
||||
motd:
|
||||
header: "<yellow>Aetheria</yellow>"
|
||||
format: "<gray>%motd%</gray>"
|
||||
|
@ -25,6 +25,18 @@ staff-chat:
|
||||
usage: "<prefix>Usage: /staffchat <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:
|
||||
- "<prefix>Commands:"
|
||||
- "<yellow>/kill <gray>- <white>Kills you"
|
||||
@ -61,4 +73,5 @@ save-accounts-command:
|
||||
vote-stats-command:
|
||||
- "<prefix>Your vote statistics:"
|
||||
- " <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%"
|
||||
|
@ -5,40 +5,4 @@ api-version: 1.20
|
||||
author: Fascinated
|
||||
depend:
|
||||
- PlaceholderAPI
|
||||
- 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
|
||||
- ViaVersion
|
Reference in New Issue
Block a user