diff --git a/build.gradle b/build.gradle index 0f1cdef..9e01637 100644 --- a/build.gradle +++ b/build.gradle @@ -19,10 +19,6 @@ repositories { url = uri("https://repo.maven.apache.org/maven2/") } - maven { - name = "sonatype-oss-snapshots" - url = uri("https://oss.sonatype.org/content/repositories/snapshots/") - } mavenCentral() } @@ -36,13 +32,9 @@ dependencies { library "org.mariadb.jdbc:mariadb-java-client:3.0.3" library "org.apache.httpcomponents:httpclient:4.5.13" library "org.apache.commons:commons-lang3:3.12.0" - compileOnly "io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT" + compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT" implementation "org.bstats:bstats-base:3.0.0" implementation "org.bstats:bstats-bukkit:3.0.0" - implementation("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") { - exclude group: "net.kyori", module: "adventure-api" - exclude group: "org.jetbrains", module: "annotations" - } } group = "dev.plex" diff --git a/src/main/java/dev/plex/Plex.java b/src/main/java/dev/plex/Plex.java index 9e04cc9..bd9a346 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"); @@ -117,7 +123,6 @@ public class Plex extends JavaPlugin new ListenerHandler(); new CommandHandler(); - rankManager = new RankManager(); rankManager.generateDefaultRanks(); rankManager.importDefaultRanks(); @@ -126,14 +131,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/PlexCommand.java b/src/main/java/dev/plex/command/PlexCommand.java index ba29da4..93d92ba 100644 --- a/src/main/java/dev/plex/command/PlexCommand.java +++ b/src/main/java/dev/plex/command/PlexCommand.java @@ -516,7 +516,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC */ protected Component mmString(String s) { - return MiniMessage.miniMessage().parse(s); + return MiniMessage.miniMessage().deserialize(s); } public Rank getLevel() diff --git a/src/main/java/dev/plex/command/impl/LockupCMD.java b/src/main/java/dev/plex/command/impl/LockupCMD.java index 717f71d..5778778 100644 --- a/src/main/java/dev/plex/command/impl/LockupCMD.java +++ b/src/main/java/dev/plex/command/impl/LockupCMD.java @@ -49,7 +49,7 @@ public class LockupCMD extends PlexCommand } punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp()); - PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedUpPlayer", sender.getName(), player.getName())); + PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", sender.getName(), player.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java index 6d3d008..adee199 100644 --- a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java +++ b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java @@ -49,11 +49,9 @@ public class NameHistoryCMD extends PlexCommand if (history.getLocalDateTime() != null) { historyList.add( - Component.text(history.getUsername()).color(NamedTextColor.GOLD) - .append(Component.space()) - .append(Component.text("-").color(NamedTextColor.DARK_GRAY)) - .append(Component.space()) - .append(Component.text(DATE_FORMAT.format(history.getLocalDateTime())).color(NamedTextColor.GOLD))); + messageComponent("nameHistoryBody", + history.getUsername(), + DATE_FORMAT.format(history.getLocalDateTime()))); } else { @@ -62,8 +60,8 @@ public class NameHistoryCMD extends PlexCommand .append(Component.space())); } }); - send(sender, Component.text("Name History (" + username + ")").color(NamedTextColor.GOLD)); - send(sender, Component.text("-----------------------------").color(NamedTextColor.GOLD).decoration(TextDecoration.STRIKETHROUGH, true)); + send(sender, messageComponent("nameHistoryTitle", username)); + send(sender, messageComponent("nameHistorySeparator")); historyList.forEach(component -> send(sender, component)); return null; } 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 d775025..4577ad7 100644 --- a/src/main/java/dev/plex/services/ServiceManager.java +++ b/src/main/java/dev/plex/services/ServiceManager.java @@ -2,7 +2,9 @@ package dev.plex.services; 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; @@ -12,7 +14,9 @@ public class ServiceManager public ServiceManager() { + registerService(new BanService()); registerService(new GameRuleService()); + registerService(new UpdateCheckerService()); } public void startServices() diff --git a/src/main/java/dev/plex/services/impl/BanService.java b/src/main/java/dev/plex/services/impl/BanService.java index 3b76753..8af43c2 100644 --- a/src/main/java/dev/plex/services/impl/BanService.java +++ b/src/main/java/dev/plex/services/impl/BanService.java @@ -22,8 +22,6 @@ public class BanService extends AbstractService if (LocalDateTime.now().isAfter(punishment.getEndDate())) { Plex.get().getPunishmentManager().unban(punishment); -// Plex.get().getBanManager().unban(ban.getId()); -// Bukkit.broadcastMessage("Plex - Unbanned " + Bukkit.getOfflinePlayer(ban.getUuid()).getName()); Bukkit.broadcast(Component.text("Plex - Unbanned " + Bukkit.getOfflinePlayer(punishment.getPunished()).getName())); } } @@ -32,6 +30,7 @@ public class BanService extends AbstractService @Override public int repeatInSeconds() { - return 1; + // Every 5 minutes + return 300; } } 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..31f7abe --- /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; + } +} 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/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index ec1633c..03adb43 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -131,7 +131,7 @@ public class PlexUtils extends PlexBase public static Component messageComponent(String entry, Object... objects) { - return MiniMessage.miniMessage().parse(LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(messageString(entry, objects)))); + return MiniMessage.miniMessage().deserialize(LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(messageString(entry, objects)))); } public static String messageString(String entry, Object... objects) 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..ccc0bb1 --- /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; + } + } +} diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 47f83e5..b0752f8 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -15,14 +15,13 @@ # 3. Expiry # 4. Punisher banMessage: "You have been banned! You may appeal at .\nReason: \nEnd date: \nBanned by: " -indefBanMessage: "Your is currently banned! You may appeal at ." -test: "this is a test message!" -# 1. The command sender's username -variableTest: "variable test with !" -playerNotFound: "Player not found!" -worldNotFound: "World not found!" +# The type of indefinite ban +# Appeal URL +indefBanMessage: "Your is indefinitely banned! You may appeal at ." +playerNotFound: "Player not found!" +worldNotFound: "World not found!" # 1. The world you have been teleported to -playerWorldTeleport: "You have been teleported to ." +playerWorldTeleport: "You have been teleported to ." # 1. The sender who opped everyone oppedAllPlayers: " - Opped all players on the server" # 1. The sender who de-opped everyone @@ -50,8 +49,7 @@ unmutedPlayer: " - Unmuted " lockedUpPlayer: " - Locking up " # 1. The person who is unlocking # 2. The person who has been unlocked -unlockedUpPlayer: " - Unlocking " -noPermission: "You cannot use this command!" +unlockedPlayer: " - Unlocking " # 1. The rank required to use the command noPermissionRank: "You must be at least to use this command!" # 1. The permission node required to use the command @@ -59,25 +57,23 @@ noPermissionNode: "You must have the permission: to use this command!" noPermissionInGame: "You must be in console to use this command!" noPermissionConsole: "You must be in-game to use this command!" # 1. The username of the name history -nameHistoryTitle: "Name History of " -# 1. A username of the found user -# 2. When the user changed to that username -nameHistoryBody: " - ()" -# 1. The username that failed -nameHistoryFail: "Something went wrong while trying to retrieve name history of ! Try again later!" -nameHistoryDoesntExist: "Couldn't find this user! Please check if your spelling was correct and this player exists" +nameHistoryTitle: "Name History of " +nameHistorySeparator: "-----------------------------" +# 1. The name +# 2. The date and time of the name change +nameHistoryBody: " - " # 1. The gamemode -gameModeSetTo: "Your gamemode has been set to ." +gameModeSetTo: "Your gamemode has been set to ." # 1. The player's name # 2. The gamemode -setOtherPlayerGameModeTo: "You set 's gamemode to ." +setOtherPlayerGameModeTo: "You set 's gamemode to ." # 1. The command sender # 2. The gamemode -playerSetOtherGameMode: " set your gamemode to ." +playerSetOtherGameMode: " set your gamemode to ." # 1. The command sender # 2. The gamemode setEveryoneGameMode: " - Changing everyone's gamemode to " -consoleMustDefinePlayer: "You must define a player since you are running this command from console." +consoleMustDefinePlayer: "You must define a player since you are running this command from console." # 1. The command sender # 2. The player newAdminAdded: " - Adding to the admin list" @@ -116,10 +112,10 @@ playerLockedUp: "That player is already locked up!" muted: "You are currently muted - STFU!" kickedPlayer: " - Kicking " teleportedToWorldSpawn: "Teleporting to the local spawn" -toggleCommandSpy: "CommandSpy has been" -enabled: "enabled." -disabled: "disabled." -adminChatFormat: '&8[&9AdminChat&8] &4 &7» &6' +toggleCommandSpy: "CommandSpy has been" +enabled: "enabled." +disabled: "disabled." +adminChatFormat: '[AdminChat] » ' maximumPrefixLength: "The maximum length for a tag may only be ." prefixCleared: "Your prefix has been cleared." otherPrefixCleared: "You have cleared 's prefix."