1
0

mini message!! woop!!

This commit is contained in:
Lee
2024-03-28 18:13:15 +00:00
parent 2ea78e5462
commit adeaeb13c0
13 changed files with 161 additions and 28 deletions

View File

@ -3,12 +3,27 @@ package cc.fascinated;
import cc.fascinated.account.AccountManager;
import cc.fascinated.chat.ChatManager;
import cc.fascinated.command.CommandManager;
import cc.fascinated.config.Lang;
import cc.fascinated.metrics.MetricManager;
import cc.fascinated.placeholder.PlaceholderManager;
import cc.fascinated.playercolor.PlayerColorManager;
import cc.fascinated.utils.BuildData;
import cc.fascinated.worldsize.WorldSizeManager;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -22,6 +37,8 @@ public class Aetheria extends JavaPlugin {
public static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
@Getter private static final BuildData buildData = new BuildData();
public Aetheria() {
INSTANCE = this;
}

View File

@ -2,10 +2,12 @@ package cc.fascinated.account;
import cc.fascinated.Aetheria;
import cc.fascinated.playercolor.PlayerColor;
import cc.fascinated.utils.Style;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
@ -48,7 +50,7 @@ public class Account {
private final PlayerColor playerColorProfile;
public Account(UUID uuid) {
log.info("Loading account for " + uuid);
//log.info("Loading account for " + uuid);
boolean newAccount = false;
this.uuid = uuid;
@ -61,6 +63,7 @@ public class Account {
try {
file.createNewFile();
} catch (Exception e) {
log.warn("Failed to create account file for " + this.uuid);
e.printStackTrace();
}
}
@ -81,7 +84,7 @@ public class Account {
// Load profiles
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));
log.info("Loaded account for " + this.uuid);
//log.info("Loaded account for " + this.uuid);
}
/**
@ -117,7 +120,7 @@ public class Account {
* @param message the message to send
*/
public void sendMessage(String message) {
this.sendMessage(Component.text(message));
this.sendMessage(Style.getMiniMessage().deserialize(message));
}
/**

View File

@ -69,11 +69,12 @@ public class AccountManager extends Manager {
* Save all accounts to disk.
*/
private void saveAccounts() {
long before = System.currentTimeMillis();
log.info("Saving accounts...");
for (Account account : ACCOUNTS.values()) {
account.save(true); // Save the account
}
log.info("Saved " + ACCOUNTS.size() + " accounts.");
log.info("Saved {} accounts. ({}ms)", ACCOUNTS.size(), System.currentTimeMillis() - before);
}
@EventHandler

View File

@ -1,10 +1,7 @@
package cc.fascinated.command;
import cc.fascinated.Aetheria;
import cc.fascinated.command.impl.HelpCommand;
import cc.fascinated.command.impl.SeedCommand;
import cc.fascinated.command.impl.TotalJoinsCommand;
import cc.fascinated.command.impl.VoteCommand;
import cc.fascinated.command.impl.*;
import org.bukkit.command.PluginCommand;
public class CommandManager {
@ -14,12 +11,14 @@ public class CommandManager {
registerCommand(new HelpCommand());
registerCommand(new SeedCommand());
registerCommand(new VoteCommand());
registerCommand(new GitCommand());
}
public static void registerCommand(Command command) {
if (command == null) {
throw new IllegalArgumentException("Command cannot be null.");
}
PluginCommand pluginCommand = Aetheria.INSTANCE.getCommand(command.getCommand());
if (pluginCommand == null) {
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist.");

View File

@ -0,0 +1,32 @@
package cc.fascinated.command.impl;
import cc.fascinated.Aetheria;
import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.BuildData;
import cc.fascinated.utils.ChatUtils;
import net.kyori.adventure.text.Component;
import java.util.List;
public class GitCommand extends Command {
public GitCommand() {
super("git", "aetheria.command.git");
}
@Override
public void execute(Account account, String[] args) {
BuildData buildData = Aetheria.getBuildData();
List<String> voteLinks = Lang.GIT_COMMAND.getAsStringList();
for (String line : voteLinks) {
account.sendMessage(Component.text(ChatUtils.color(line)
.replace("%version%", buildData.getBuildVersion())
.replace("%build%", buildData.getBuildId())
.replace("%date%", buildData.getBuildDate())
));
}
}
}

View File

@ -2,6 +2,7 @@ package cc.fascinated.command.impl;
import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import cc.fascinated.config.Lang;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
@ -13,9 +14,6 @@ public class SeedCommand extends Command {
@Override
public void execute(Account account, String[] args) {
account.sendMessage(Component.text("§b§lSEED §7» §fThe seed of this world is: " + account.getPlayer().getWorld().getSeed() + ".")
.hoverEvent(Component.text("Click to copy the seed.").color(net.kyori.adventure.text.format.NamedTextColor.GRAY))
.clickEvent(ClickEvent.copyToClipboard(String.valueOf(account.getPlayer().getWorld().getSeed())))
);
account.sendMessage(Lang.SEED_COMMAND.getAsString().replace("%seed%", account.getPlayer().getWorld().getSeed() + ""));
}
}

View File

@ -4,6 +4,7 @@ import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.ChatUtils;
import cc.fascinated.utils.Style;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
@ -20,10 +21,10 @@ public class VoteCommand extends Command {
account.sendMessage(ChatUtils.color(Lang.VOTE_HEADER.getAsString()));
List<String> voteLinks = Lang.VOTE_LINKS.getAsStringList();
for (String link : voteLinks) {
account.sendMessage(Component.text(ChatUtils.color(Lang.VOTE_FORMAT.getAsString())
account.sendMessage(Style.getMiniMessage().deserialize(Lang.VOTE_FORMAT.getAsString()
.replace("%link%", link)
.replace("%number%", String.valueOf(voteLinks.indexOf(link) + 1))
).clickEvent(ClickEvent.openUrl(link)));
));
}
}
}

View File

@ -15,7 +15,9 @@ public enum Lang {
HELP_COMMAND("help-command"),
VOTE_HEADER("vote.header"),
VOTE_FORMAT("vote.format"),
VOTE_LINKS("vote.links");
VOTE_LINKS("vote.links"),
GIT_COMMAND("git-command"),
SEED_COMMAND("seed-command");
/**
* The path of the lang in the lang.yml file.

View File

@ -20,6 +20,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Log4j2
@ -77,20 +78,30 @@ public class MetricManager implements Listener {
* Collect all metrics and write them to influx
*/
public void collectMetrics() {
log.info("Collecting metrics");
log.info("Collecting metrics...");
long before = System.currentTimeMillis();
HashMap<Metric, Long> times = new HashMap<>();
// collect all the metrics
List<Point> points = new ArrayList<>();
for (Metric metric : metrics) {
long start = System.currentTimeMillis();
points.add(metric.toPoint());
log.info("Collected metric {} in {}ms", metric.getName(), System.currentTimeMillis() - start);
times.put(metric, System.currentTimeMillis());
}
// write the points async
Aetheria.EXECUTOR.execute(() -> {
writeApi.writePoints(points, new WriteParameters(WritePrecision.MS, WriteConsistency.ONE));
log.info("Wrote {} points to influx ({}ms)", points.size(), System.currentTimeMillis() - before);
});
// get the top 3 slowest metrics that are above 50ms and log them
times.entrySet().stream()
.filter(entry -> System.currentTimeMillis() - entry.getValue() > 50)
.sorted((entry1, entry2) -> Long.compare(entry2.getValue(), entry1.getValue()))
.limit(3)
.forEach(entry -> log.warn("Metric {} took {}ms to collect", entry.getKey().getName(), System.currentTimeMillis() - entry.getValue()));
}
/**

View File

@ -0,0 +1,28 @@
package cc.fascinated.utils;
import lombok.Getter;
import java.io.IOException;
import java.util.Properties;
@Getter
public class BuildData {
private final String buildId;
private final String buildVersion;
private final String buildDate;
public BuildData() {
// get git.properties from resources
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"));
} catch (IOException e) {
e.printStackTrace();
}
this.buildId = properties.getProperty("git.commit.id.abbrev");
this.buildVersion = properties.getProperty("git.build.version");
this.buildDate = properties.getProperty("git.build.time");
}
}

View File

@ -0,0 +1,32 @@
package cc.fascinated.utils;
import cc.fascinated.config.Lang;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import java.util.ArrayList;
import java.util.List;
public class Style {
@Getter
private static final MiniMessage miniMessage;
static {
List<TagResolver> tagResolvers = new ArrayList<>();
tagResolvers.add(TagResolver.resolver("prefix", (context, argumentQueue) -> {
return Tag.inserting(MiniMessage.miniMessage().deserialize(Lang.PREFIX.getAsString()));
}));
miniMessage = MiniMessage.builder()
.tags(TagResolver.builder()
.resolver(StandardTags.defaults())
.resolvers(tagResolvers)
.build()
).build();
}
}

View File

@ -1,15 +1,21 @@
prefix: "&6&lAetheria &7» &f"
prefix: "<gold><bold>AETHERIA</bold></gold> <gray>»</gray> <white>"
help-command:
- "&6&lAetheria &7» &fCommands:"
- "&e/kill &7- &fKills you"
- "&e/worldsize &7- &fShows the total file size of all worlds"
- "&e/playercolor [color] &7- &fChange your player name color"
- "&e/seed &7- &fShows you the world seed"
- "<prefix>Commands:"
- "<yellow>/kill <gray>- <white>Kills you"
- "<yellow>/worldsize <gray>- <white>Shows the total file size of all worlds"
- "<yellow>/playercolor [color] <gray>- <white>Change your player name color"
- "<yellow>/seed <gray>- <white>Shows you the world seed"
git-command:
- "<prefix>Build information:"
- " <yellow>Version: <white>%version%"
- " <yellow>Build: <white>%build%"
- " <yellow>Build date: <white>%date%"
seed-command: "<prefix>The seed is: <hover:show_text:Click to copy the seed><click:copy_to_clipboard:%seed%><yellow>%seed%"
vote:
header: "&6&lAetheria &7» &fVote for us on the following websites:"
format: "&e%number%. &f%link%"
header: "<prefix>Vote for us on the following websites:"
format: "<yellow>%number%. <hover:show_text:Click to copy the url><click:open_url:%link%><white>%link%"
links:
- "https://minecraft.menu/server-aetheria-anarchy.2827/vote"
- "https://topg.org/minecraft-servers/server-662463"
@ -17,4 +23,4 @@ vote:
- "https://minecraftservers.org/vote/650863"
- "https://servers-minecraft.net/server-aetheria.24701"
- "https://topminecraftservers.org/vote/33565"
- "https://best-minecraft-servers.co/server-aetheria.16373/vote"
- "https://best-minecraft-servers.co/server-aetheria.16373/vote"

View File

@ -23,4 +23,7 @@ commands:
usage: "/seed"
vote:
description: "Shows the vote links"
usage: "/vote"
usage: "/vote"
git:
description: "Shows the git information"
usage: "/git"