diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index d16ad0b..58fb6b0 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -21,13 +21,12 @@ import dev.plex.storage.player.MongoPlayerData; import dev.plex.storage.player.SQLPlayerData; import dev.plex.storage.punishment.SQLNotes; import dev.plex.storage.punishment.SQLPunishment; +import dev.plex.util.BuildInfo; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import dev.plex.util.UpdateChecker; import dev.plex.world.CustomWorld; import java.io.File; -import java.io.InputStream; -import java.util.Properties; import lombok.Getter; import lombok.Setter; import net.milkbowl.vault.permission.Permission; @@ -40,7 +39,6 @@ import org.bukkit.plugin.java.JavaPlugin; @Setter public class Plex extends JavaPlugin { - public static final BuildProperties build = new BuildProperties(); private static Plex plugin; public Config config; @@ -51,6 +49,8 @@ public class Plex extends JavaPlugin public File modulesFolder; private StorageType storageType = StorageType.SQLITE; + public static final BuildInfo build = new BuildInfo(); + private SQLConnection sqlConnection; private MongoConnection mongoConnection; private RedisConnection redisConnection; @@ -241,37 +241,6 @@ public class Plex extends JavaPlugin }); } - public static class BuildProperties - { - public String number; - public String author; - public String date; - public String head; - - public void load(Plex plugin) - { - try - { - final Properties props; - - try (InputStream in = plugin.getResource("build.properties")) - { - props = new Properties(); - props.load(in); - } - - number = props.getProperty("buildNumber", "unknown"); - author = props.getProperty("buildAuthor", "unknown"); - date = props.getProperty("buildDate", "unknown"); - head = props.getProperty("buildHead", "unknown"); - } - catch (Exception ex) - { - PlexLog.error("Could not load build properties! Did you compile with NetBeans/Maven?"); - } - } - } - public boolean setupPermissions() { RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Permission.class); diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index 0012fff..b217013 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -1,6 +1,5 @@ package dev.plex.command.impl; -import dev.plex.Plex; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; @@ -9,6 +8,7 @@ import dev.plex.command.source.RequiredCommandSource; import dev.plex.module.PlexModule; import dev.plex.module.PlexModuleFile; import dev.plex.rank.enums.Rank; +import dev.plex.util.BuildInfo; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; import java.util.Arrays; @@ -34,9 +34,9 @@ public class PlexCMD extends PlexCommand if (args.length == 0) { send(sender, mmString("Plex - A new freedom plugin.")); - send(sender, mmString("Plugin version: " + plugin.getDescription().getVersion() + " #" + Plex.build.number + " Git: " + Plex.build.head)); + send(sender, mmString("Plugin version: " + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " Git: " + BuildInfo.getHead())); send(sender, mmString("Authors: Telesphoreo, Taahh")); - send(sender, mmString("Built by: " + Plex.build.author + " on " + Plex.build.date)); + send(sender, mmString("Built by: " + BuildInfo.getAuthor() + " on " + BuildInfo.getDate())); send(sender, mmString("Run /plex modules to see a list of modules.")); plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2); return null; diff --git a/src/main/java/dev/plex/listener/impl/ServerListener.java b/src/main/java/dev/plex/listener/impl/ServerListener.java index 713647e..94b54fe 100644 --- a/src/main/java/dev/plex/listener/impl/ServerListener.java +++ b/src/main/java/dev/plex/listener/impl/ServerListener.java @@ -2,10 +2,12 @@ package dev.plex.listener.impl; import com.destroystokyo.paper.event.server.PaperServerListPingEvent; import dev.plex.listener.PlexListener; +import dev.plex.util.PlexUtils; import dev.plex.util.RandomUtil; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -20,16 +22,17 @@ public class ServerListener extends PlexListener baseMotd = baseMotd.replace("%mcversion%", Bukkit.getBukkitVersion().split("-")[0]); if (plugin.config.getBoolean("server.colorize_motd")) { - final StringBuilder motd = new StringBuilder(); + AtomicReference motd = new AtomicReference<>(Component.empty()); for (final String word : baseMotd.split(" ")) { - motd.append(RandomUtil.getRandomColor()).append(word).append(" "); + motd.get().append(Component.text(word).color(RandomUtil.getRandomColor())); + motd.get().append(Component.space()); } - event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(motd.toString().trim())); + event.motd(motd.get()); } else { - event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(baseMotd.trim())); + event.motd(PlexUtils.mmDeserialize(baseMotd.trim())); } if (plugin.config.contains("server.sample")) { diff --git a/src/main/java/dev/plex/util/BuildInfo.java b/src/main/java/dev/plex/util/BuildInfo.java new file mode 100644 index 0000000..c72c6f9 --- /dev/null +++ b/src/main/java/dev/plex/util/BuildInfo.java @@ -0,0 +1,39 @@ +package dev.plex.util; + +import dev.plex.Plex; +import java.io.InputStream; +import java.util.Properties; +import lombok.Getter; + +public class BuildInfo +{ + @Getter + public static String number; + @Getter + public static String author; + @Getter + public static String date; + @Getter + public static String head; + + public void load(Plex plugin) + { + try + { + Properties props; + try (InputStream in = plugin.getResource("build.properties")) + { + props = new Properties(); + props.load(in); + } + + number = props.getProperty("buildNumber", "unknown"); + author = props.getProperty("buildAuthor", "unknown"); + date = props.getProperty("buildDate", "unknown"); + head = props.getProperty("buildHead", "unknown"); + } + catch (Exception ignored) + { + } + } +}