From 0b5425b8d2a4aa03864726976fd4f1e1d0c5e9f1 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 3 Mar 2022 15:45:19 -0600 Subject: [PATCH 1/3] Begin work on 1.18.2 - Add update checking - World generation is broken - Won't compile unless 1.18.2 is in your local Maven repository - No longer need MiniMessage bundled in Plex - Customizable namehistory - Set comments in config.yml if they're missing --- build.gradle | 10 +--- src/main/java/dev/plex/Plex.java | 9 ++-- .../java/dev/plex/command/PlexCommand.java | 2 +- .../java/dev/plex/command/impl/LockupCMD.java | 2 +- .../dev/plex/command/impl/NameHistoryCMD.java | 12 ++--- .../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 | 4 ++ .../dev/plex/services/impl/BanService.java | 5 +- .../services/impl/UpdateCheckerService.java | 32 +++++++++++++ .../dev/plex/storage/MongoConnection.java | 5 +- src/main/java/dev/plex/util/PlexUtils.java | 2 +- .../java/dev/plex/util/UpdateChecker.java | 47 +++++++++++++++++++ src/main/resources/messages.yml | 44 ++++++++--------- 17 files changed, 131 insertions(+), 56 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..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." From e258e278145cd781e555584891f6dd11e336ebdd Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 3 Mar 2022 16:56:52 -0600 Subject: [PATCH 2/3] Replace with Kyori --- src/main/java/dev/plex/world/CustomWorld.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/plex/world/CustomWorld.java b/src/main/java/dev/plex/world/CustomWorld.java index e6b574f..55c8dce 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; @@ -37,16 +38,17 @@ public class CustomWorld extends WorldCreator { boolean existed = new File(name).exists(); World world = super.generate(); + if (!existed) { Block block = world.getBlockAt(0, world.getHighestBlockYAt(0, 0) + 1, 0); block.setType(Material.OAK_SIGN); BlockState state = block.getState(); - if (state instanceof Sign) + if (state instanceof Sign 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(); } } From 14fb24a380c88481f537bddeae4a1eeebb778764 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 3 Mar 2022 19:51:07 -0600 Subject: [PATCH 3/3] Bump to 0.8-SNAPSHOT --- build.gradle | 2 +- src/main/java/dev/plex/admin/Admin.java | 14 ++++++-------- src/main/java/dev/plex/admin/AdminList.java | 11 +++++------ src/main/java/dev/plex/command/impl/AdminCMD.java | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 9e01637..9af156a 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ dependencies { } group = "dev.plex" -version = "0.7-SNAPSHOT" +version = "0.8-SNAPSHOT" description = "Plex" shadowJar { diff --git a/src/main/java/dev/plex/admin/Admin.java b/src/main/java/dev/plex/admin/Admin.java index a3d0c16..e67b21e 100644 --- a/src/main/java/dev/plex/admin/Admin.java +++ b/src/main/java/dev/plex/admin/Admin.java @@ -29,19 +29,19 @@ public class Admin /** * Returns if the admin has command spy or not *
- * Contains a #isCommandSpy and #setCommandSpy by lombok + * Contains a #isCommandSpy and #setCommandSpy by Lombok */ - private boolean commandSpy = true; + private boolean commandSpy = false; /** - * Returns if the admin has staff chat toggled or not + * Returns if the admin has admin chat toggled or not *
- * Contains a #isStaffChat and #setStaffChat by lombok + * Contains a #isAdminChat and #setAdminChat by Lombok */ - private boolean staffChat = false; + private boolean adminChat = false; /** - * Creates an admin with the startig ADMIN rank + * Creates an admin with the ADMIN rank as the default rank * * @param uuid * @see UUID @@ -52,6 +52,4 @@ public class Admin this.uuid = uuid; this.rank = Rank.ADMIN; } - - } diff --git a/src/main/java/dev/plex/admin/AdminList.java b/src/main/java/dev/plex/admin/AdminList.java index b954716..1224ca3 100644 --- a/src/main/java/dev/plex/admin/AdminList.java +++ b/src/main/java/dev/plex/admin/AdminList.java @@ -5,6 +5,7 @@ import com.google.common.collect.Maps; import dev.morphia.Datastore; import dev.morphia.query.Query; import dev.plex.Plex; +import dev.plex.PlexBase; import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; import dev.plex.storage.StorageType; @@ -23,7 +24,7 @@ import java.util.stream.Collectors; * @see Admin */ -public class AdminList +public class AdminList extends PlexBase { /** * Key/Value storage, where the key is the unique ID of the admin @@ -59,15 +60,15 @@ public class AdminList public List getAllAdmins() { List admins = Lists.newArrayList(); - if (Plex.get().getStorageType() == StorageType.MONGODB) + if (plugin.getStorageType() == StorageType.MONGODB) { - Datastore store = Plex.get().getMongoConnection().getDatastore(); + Datastore store = plugin.getMongoConnection().getDatastore(); Query query = store.find(PlexPlayer.class); admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN)).map(PlexPlayer::getName).collect(Collectors.toList())); } else { - try (Connection con = Plex.get().getSqlConnection().getCon()) + try (Connection con = plugin.getSqlConnection().getCon()) { PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)"); statement.setString(1, Rank.ADMIN.name().toLowerCase()); @@ -79,7 +80,6 @@ public class AdminList { admins.add(set.getString("name")); } - } catch (SQLException throwables) { @@ -88,5 +88,4 @@ public class AdminList } return admins; } - } diff --git a/src/main/java/dev/plex/command/impl/AdminCMD.java b/src/main/java/dev/plex/command/impl/AdminCMD.java index 60c3c33..e941a95 100644 --- a/src/main/java/dev/plex/command/impl/AdminCMD.java +++ b/src/main/java/dev/plex/command/impl/AdminCMD.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) -@CommandParameters(name = "admin", usage = "/ [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins") +@CommandParameters(name = "admin", usage = "/ | remove | setrank | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins") public class AdminCMD extends PlexCommand { //TODO: Better return messages