From c82586b02a07ffef6091779ad909906784a8fbd0 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 3 Mar 2022 17:24:15 -0600 Subject: [PATCH] Plex 0.7 Backport changes from 1.18.2 --- build.gradle | 2 +- src/main/java/dev/plex/Plex.java | 8 +++- .../dev/plex/command/impl/SurvivalCMD.java | 1 + src/main/java/dev/plex/config/Config.java | 2 + .../plex/punishment/PunishmentManager.java | 4 +- .../dev/plex/punishment/PunishmentType.java | 2 +- .../dev/plex/services/AbstractService.java | 4 +- .../dev/plex/services/ServiceManager.java | 2 + .../services/impl/UpdateCheckerService.java | 32 +++++++++++++ .../dev/plex/storage/MongoConnection.java | 5 +- .../java/dev/plex/util/UpdateChecker.java | 47 +++++++++++++++++++ src/main/java/dev/plex/world/CustomWorld.java | 6 ++- src/main/resources/messages.yml | 2 +- 13 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 src/main/java/dev/plex/services/impl/UpdateCheckerService.java create mode 100644 src/main/java/dev/plex/util/UpdateChecker.java diff --git a/build.gradle b/build.gradle index 0f1cdef..a4f786f 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ dependencies { } group = "dev.plex" -version = "0.7-SNAPSHOT" +version = "0.7" description = "Plex" shadowJar { diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 9e04cc9..343a36b 100644 --- a/src/main/java/dev/plex/Plex.java +++ b/src/main/java/dev/plex/Plex.java @@ -20,6 +20,7 @@ import dev.plex.storage.SQLConnection; import dev.plex.storage.StorageType; import dev.plex.util.PlexLog; import dev.plex.util.PlexUtils; +import dev.plex.util.UpdateChecker; import dev.plex.world.CustomWorld; import java.util.UUID; import lombok.Getter; @@ -52,6 +53,8 @@ public class Plex extends JavaPlugin private AdminList adminList; + private UpdateChecker updateChecker; + private String system; public static Plex get() @@ -91,6 +94,9 @@ public class Plex extends JavaPlugin e.printStackTrace(); } + updateChecker = new UpdateChecker(); + PlexLog.log("Update checking enabled"); + // https://bstats.org/plugin/bukkit/Plex/14143 Metrics metrics = new Metrics(this, 14143); PlexLog.log("Enabled Metrics"); @@ -126,14 +132,12 @@ public class Plex extends JavaPlugin punishmentManager = new PunishmentManager(); punishmentManager.mergeIndefiniteBans(); -// banManager = new BanManager(); PlexLog.log("Punishment System initialized"); generateWorlds(); serviceManager = new ServiceManager(); PlexLog.log("Service Manager initialized"); - serviceManager.startServices(); PlexLog.log("Started " + serviceManager.serviceCount() + " services."); diff --git a/src/main/java/dev/plex/command/impl/SurvivalCMD.java b/src/main/java/dev/plex/command/impl/SurvivalCMD.java index 5191c52..8dd4a3f 100644 --- a/src/main/java/dev/plex/command/impl/SurvivalCMD.java +++ b/src/main/java/dev/plex/command/impl/SurvivalCMD.java @@ -32,6 +32,7 @@ public class SurvivalCMD extends PlexCommand throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); } Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL)); + return null; } if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others")) diff --git a/src/main/java/dev/plex/config/Config.java b/src/main/java/dev/plex/config/Config.java index 0b27b2f..7c0132f 100644 --- a/src/main/java/dev/plex/config/Config.java +++ b/src/main/java/dev/plex/config/Config.java @@ -68,6 +68,7 @@ public class Config extends YamlConfiguration if (!externalYamlConfig.contains(string)) { // If it doesn't contain the key, we set the key based off what was found inside the plugin jar + externalYamlConfig.setComments(string, internalYamlConfig.getComments(string)); externalYamlConfig.set(string, internalYamlConfig.get(string)); PlexLog.log("Setting key: " + string + " in " + this.name + " to the default value(s) since it does not exist!"); added = true; @@ -77,6 +78,7 @@ public class Config extends YamlConfiguration { externalYamlConfig.save(file); PlexLog.log("Saving new file..."); + added = false; } super.load(file); } diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index 5ab1adb..ebe37be 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -58,11 +58,11 @@ public class PunishmentManager extends PlexBase this.bannedIPs.addAll(Plex.get().indefBans.getStringList("ips")); this.bannedUsernames.addAll(Plex.get().indefBans.getStringList("usernames")); - PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) into the indefinite banned list", this.bannedUUIDs.size(), this.bannedIPs.size(), this.bannedUsernames.size()); + PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) as indefinitely banned", this.bannedUUIDs.size(), this.bannedIPs.size(), this.bannedUsernames.size()); if (Plex.get().getRedisConnection().isEnabled()) { - PlexLog.log("Resetting redis indefinite bans lists and asynchronously uploading from configuration"); + PlexLog.log("Asynchronously uploading all indefinite bans to Redis"); Plex.get().getRedisConnection().runAsync(jedis -> { jedis.set("indefbanned-uuids", new Gson().toJson(this.bannedUUIDs)); jedis.set("indefbanned-ips", new Gson().toJson(this.bannedIPs)); diff --git a/src/main/java/dev/plex/punishment/PunishmentType.java b/src/main/java/dev/plex/punishment/PunishmentType.java index 22961a4..f16c9f9 100644 --- a/src/main/java/dev/plex/punishment/PunishmentType.java +++ b/src/main/java/dev/plex/punishment/PunishmentType.java @@ -2,5 +2,5 @@ package dev.plex.punishment; public enum PunishmentType { - MUTE, FREEZE, BAN, KICK; + MUTE, FREEZE, BAN, KICK } diff --git a/src/main/java/dev/plex/services/AbstractService.java b/src/main/java/dev/plex/services/AbstractService.java index e9ad154..5ea2edf 100644 --- a/src/main/java/dev/plex/services/AbstractService.java +++ b/src/main/java/dev/plex/services/AbstractService.java @@ -1,6 +1,8 @@ package dev.plex.services; -public abstract class AbstractService implements IService +import dev.plex.PlexBase; + +public abstract class AbstractService extends PlexBase implements IService { private boolean asynchronous; private boolean repeating; diff --git a/src/main/java/dev/plex/services/ServiceManager.java b/src/main/java/dev/plex/services/ServiceManager.java index 90e0934..4577ad7 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -4,6 +4,7 @@ import com.google.common.collect.Lists; import dev.plex.Plex; import dev.plex.services.impl.BanService; import dev.plex.services.impl.GameRuleService; +import dev.plex.services.impl.UpdateCheckerService; import java.util.List; import org.bukkit.Bukkit; @@ -15,6 +16,7 @@ public class ServiceManager { registerService(new BanService()); registerService(new GameRuleService()); + registerService(new UpdateCheckerService()); } public void startServices() diff --git a/src/main/java/dev/plex/services/impl/UpdateCheckerService.java b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java new file mode 100644 index 0000000..b398ab6 --- /dev/null +++ b/src/main/java/dev/plex/services/impl/UpdateCheckerService.java @@ -0,0 +1,32 @@ +package dev.plex.services.impl; + +import dev.plex.services.AbstractService; + +public class UpdateCheckerService extends AbstractService +{ + public UpdateCheckerService() + { + super(true, true); + } + + private boolean newVersion = false; + + @Override + public void run() + { + if (!newVersion) + { + if (plugin.getUpdateChecker().check()) + { + newVersion = true; + } + } + } + + @Override + public int repeatInSeconds() + { + // Every 30 minutes + return 1800; + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/storage/MongoConnection.java b/src/main/java/dev/plex/storage/MongoConnection.java index fcb7e1d..699856c 100644 --- a/src/main/java/dev/plex/storage/MongoConnection.java +++ b/src/main/java/dev/plex/storage/MongoConnection.java @@ -6,14 +6,13 @@ import dev.morphia.Datastore; import dev.morphia.Morphia; import dev.morphia.mapping.MapperOptions; import dev.plex.Plex; +import dev.plex.PlexBase; import dev.plex.player.PlexPlayer; -public class MongoConnection +public class MongoConnection extends PlexBase { // USE MORPHIA API FOR MONGO <3 - private final Plex plugin = Plex.get(); - public Datastore getDatastore() { if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("mongodb")) diff --git a/src/main/java/dev/plex/util/UpdateChecker.java b/src/main/java/dev/plex/util/UpdateChecker.java new file mode 100644 index 0000000..77d2494 --- /dev/null +++ b/src/main/java/dev/plex/util/UpdateChecker.java @@ -0,0 +1,47 @@ +package dev.plex.util; + +import dev.plex.PlexBase; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import org.bukkit.ChatColor; + +public class UpdateChecker extends PlexBase +{ + private final String currentVersion = plugin.getDescription().getVersion(); + + public boolean check() + { + try + { + String versionLink = "https://plex.us.org/updater/check/"; + URL url = new URL(versionLink); + URLConnection con = url.openConnection(); + InputStreamReader isr = new InputStreamReader(con.getInputStream()); + BufferedReader reader = new BufferedReader(isr); + if (!reader.ready()) + { + return false; + } + String newVersion = reader.readLine(); + reader.close(); + + if (!newVersion.equals(currentVersion)) + { + PlexLog.log(ChatColor.RED + "There is a new version of Plex available: " + newVersion); + return true; + } + else + { + return false; + } + } + catch (IOException e) + { + PlexLog.error("There was an error checking for updates!"); + return false; + } + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/world/CustomWorld.java b/src/main/java/dev/plex/world/CustomWorld.java index e6b574f..355c406 100644 --- a/src/main/java/dev/plex/world/CustomWorld.java +++ b/src/main/java/dev/plex/world/CustomWorld.java @@ -3,6 +3,7 @@ package dev.plex.world; import dev.plex.Plex; import java.io.File; import java.util.Objects; +import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -45,8 +46,9 @@ public class CustomWorld extends WorldCreator if (state instanceof Sign) { Sign sign = (Sign)state; - sign.setLine(1, Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name"))); - sign.setLine(2, "- 0, 0 -"); + sign.line(1, Component.text( + Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name")))); + sign.line(2, Component.text("- 0, 0 -")); sign.update(); } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 47f83e5..49c557e 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -119,7 +119,7 @@ teleportedToWorldSpawn: "Teleporting to the local spawn" toggleCommandSpy: "CommandSpy has been" enabled: "enabled." disabled: "disabled." -adminChatFormat: '&8[&9AdminChat&8] &4 &7» &6' +adminChatFormat: '[AdminChat] » ' maximumPrefixLength: "The maximum length for a tag may only be ." prefixCleared: "Your prefix has been cleared." otherPrefixCleared: "You have cleared 's prefix."