From 9fa8d822178a0953482656fcae6cd859f44e714d Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Tue, 19 May 2026 12:32:56 -0400 Subject: [PATCH] Begin work on the Plex API --- api/build.gradle.kts | 23 ++ .../java/dev/plex/api/ApiCompatibility.java | 12 + api/src/main/java/dev/plex/api/PlexApi.java | 55 ++++ .../java/dev/plex/api/command/CommandApi.java | 10 + .../dev/plex/api/config/ConfigurationApi.java | 15 + .../dev/plex/api/config/ModuleConfigApi.java | 8 + .../plex/api/config/ModuleConfiguration.java | 9 + .../plex/api/config/PlexConfiguration.java | 23 ++ .../dev/plex/api/listener/ListenerApi.java | 10 + .../java/dev/plex/api/logging/LoggingApi.java | 9 + .../java/dev/plex/api/message/MessageApi.java | 15 + .../java/dev/plex/api/module/ModulesApi.java | 25 ++ .../java/dev/plex/api/player/PlayersApi.java | 12 + .../dev/plex/api/player/PlexPlayerView.java | 18 ++ .../api/punishment/IndefiniteBanView.java | 12 + .../api/punishment/PunishmentRequest.java | 10 + .../plex/api/punishment/PunishmentType.java | 11 + .../plex/api/punishment/PunishmentView.java | 19 ++ .../plex/api/punishment/PunishmentsApi.java | 13 + .../dev/plex/api/scheduler/SchedulerApi.java | 8 + .../java/dev/plex/api/storage/StorageApi.java | 15 + .../java/dev/plex/command/PlexCommand.java | 262 ++++++++++++++++++ .../command/annotation/CommandParameters.java | 13 + .../annotation/CommandPermissions.java | 12 + .../exception/CommandFailException.java | 14 + .../ConsoleMustDefinePlayerException.java | 11 +- .../exception/ConsoleOnlyException.java | 11 +- .../exception/PlayerNotBannedException.java | 11 +- .../exception/PlayerNotFoundException.java | 11 +- .../command/source/RequiredCommandSource.java | 6 +- .../java/dev/plex/config/ModuleConfig.java | 87 ++++++ .../java/dev/plex/listener/PlexListener.java | 10 + .../main/java/dev/plex/module/PlexModule.java | 172 ++++++++++++ .../java/dev/plex/module/PlexModuleFile.java | 60 ++++ proxy/build.gradle.kts | 1 + proxy/src/main/java/dev/plex/Plex.java | 5 + .../api/impl/DefaultApiCompatibility.java | 19 ++ .../api/impl/DefaultConfigurationApi.java | 39 +++ .../dev/plex/api/impl/DefaultModulesApi.java | 23 ++ .../dev/plex/api/impl/DefaultPlexApi.java | 48 ++++ .../api/impl/DefaultPlexConfiguration.java | 59 ++++ .../{PlexCommand.java => ProxyCommand.java} | 12 +- .../command/annotation/CommandParameters.java | 39 --- .../annotation/CommandPermissions.java | 27 -- .../command/source/RequiredCommandSource.java | 8 - .../dev/plex/handlers/ListenerHandler.java | 6 +- .../{PlexListener.java => ProxyListener.java} | 4 +- .../listener/impl/ConnectionListener.java | 4 +- .../plex/listener/impl/ServerListener.java | 4 +- server/build.gradle.kts | 1 + server/src/main/java/dev/plex/Plex.java | 60 ++++ .../api/impl/DefaultApiCompatibility.java | 19 ++ .../dev/plex/api/impl/DefaultCommandApi.java | 28 ++ .../api/impl/DefaultConfigurationApi.java | 39 +++ .../api/impl/DefaultIndefiniteBanView.java | 14 + .../dev/plex/api/impl/DefaultListenerApi.java | 19 ++ .../dev/plex/api/impl/DefaultLoggingApi.java | 12 + .../dev/plex/api/impl/DefaultMessageApi.java | 17 ++ .../plex/api/impl/DefaultModuleConfigApi.java | 14 + .../dev/plex/api/impl/DefaultModulesApi.java | 36 +++ .../dev/plex/api/impl/DefaultPlayersApi.java | 27 ++ .../dev/plex/api/impl/DefaultPlexApi.java | 61 ++++ .../api/impl/DefaultPlexConfiguration.java | 58 ++++ .../plex/api/impl/DefaultPlexPlayerView.java | 20 ++ .../plex/api/impl/DefaultPunishmentView.java | 22 ++ .../plex/api/impl/DefaultPunishmentsApi.java | 40 +++ .../plex/api/impl/DefaultSchedulerApi.java | 15 + .../dev/plex/api/impl/DefaultStorageApi.java | 22 ++ .../impl/ServerModuleConfiguration.java} | 74 +---- .../{PlexCommand.java => ServerCommand.java} | 60 +++- .../command/annotation/CommandParameters.java | 39 --- .../annotation/CommandPermissions.java | 28 -- .../exception/CommandFailException.java | 9 - .../dev/plex/command/impl/AdminChatCMD.java | 4 +- .../dev/plex/command/impl/AdminworldCMD.java | 4 +- .../dev/plex/command/impl/AdventureCMD.java | 4 +- .../java/dev/plex/command/impl/BanCMD.java | 4 +- .../dev/plex/command/impl/BanListCommand.java | 4 +- .../command/impl/BcastLoginMessageCMD.java | 4 +- .../dev/plex/command/impl/BlockEditCMD.java | 4 +- .../dev/plex/command/impl/CommandSpyCMD.java | 4 +- .../dev/plex/command/impl/ConsoleSayCMD.java | 4 +- .../dev/plex/command/impl/CreativeCMD.java | 4 +- .../java/dev/plex/command/impl/DebugCMD.java | 4 +- .../dev/plex/command/impl/EntityWipeCMD.java | 4 +- .../dev/plex/command/impl/FlatlandsCMD.java | 4 +- .../java/dev/plex/command/impl/FreezeCMD.java | 4 +- .../dev/plex/command/impl/GamemodeCMD.java | 4 +- .../java/dev/plex/command/impl/KickCMD.java | 4 +- .../java/dev/plex/command/impl/ListCMD.java | 4 +- .../dev/plex/command/impl/LocalSpawnCMD.java | 4 +- .../java/dev/plex/command/impl/LockupCMD.java | 4 +- .../command/impl/MasterbuilderworldCMD.java | 4 +- .../dev/plex/command/impl/MobLimitCMD.java | 4 +- .../dev/plex/command/impl/MobPurgeCMD.java | 4 +- .../java/dev/plex/command/impl/MuteCMD.java | 4 +- .../java/dev/plex/command/impl/NotesCMD.java | 4 +- .../java/dev/plex/command/impl/PlexCMD.java | 4 +- .../dev/plex/command/impl/PunishmentsCMD.java | 4 +- .../java/dev/plex/command/impl/RawSayCMD.java | 4 +- .../command/impl/RemoveLoginMessageCMD.java | 4 +- .../java/dev/plex/command/impl/SayCMD.java | 4 +- .../plex/command/impl/SetLoginMessageCMD.java | 4 +- .../java/dev/plex/command/impl/SmiteCMD.java | 4 +- .../dev/plex/command/impl/SpectatorCMD.java | 4 +- .../dev/plex/command/impl/SurvivalCMD.java | 4 +- .../java/dev/plex/command/impl/TagCMD.java | 4 +- .../dev/plex/command/impl/TempbanCMD.java | 4 +- .../dev/plex/command/impl/TempmuteCMD.java | 4 +- .../java/dev/plex/command/impl/ToggleCMD.java | 4 +- .../java/dev/plex/command/impl/UnbanCMD.java | 4 +- .../dev/plex/command/impl/UnfreezeCMD.java | 4 +- .../java/dev/plex/command/impl/UnmuteCMD.java | 4 +- .../java/dev/plex/command/impl/WhoHasCMD.java | 4 +- .../java/dev/plex/command/impl/WorldCMD.java | 4 +- .../dev/plex/config/ConfigDefaultsMerger.java | 6 +- .../dev/plex/handlers/CommandHandler.java | 6 +- .../dev/plex/handlers/ListenerHandler.java | 6 +- ...xListener.java => ServerListenerBase.java} | 6 +- .../plex/listener/impl/AntiNukerListener.java | 4 +- .../plex/listener/impl/AntiSpamListener.java | 4 +- .../dev/plex/listener/impl/BanListener.java | 4 +- .../dev/plex/listener/impl/BlockListener.java | 4 +- .../dev/plex/listener/impl/BookListener.java | 4 +- .../dev/plex/listener/impl/ChatListener.java | 4 +- .../plex/listener/impl/CommandListener.java | 4 +- .../dev/plex/listener/impl/DropListener.java | 4 +- .../plex/listener/impl/FreezeListener.java | 4 +- .../plex/listener/impl/GameModeListener.java | 4 +- .../dev/plex/listener/impl/MenuListener.java | 4 +- .../dev/plex/listener/impl/MobListener.java | 4 +- .../dev/plex/listener/impl/MuteListener.java | 4 +- .../plex/listener/impl/PlayerListener.java | 4 +- .../plex/listener/impl/ServerListener.java | 4 +- .../dev/plex/listener/impl/TabListener.java | 4 +- .../plex/listener/impl/TogglesListener.java | 4 +- .../plex/listener/impl/VanishListener.java | 4 +- .../dev/plex/listener/impl/WorldListener.java | 4 +- .../java/dev/plex/module/ModuleManager.java | 39 ++- .../main/java/dev/plex/module/PlexModule.java | 154 ---------- .../java/dev/plex/module/PlexModuleFile.java | 19 -- settings.gradle.kts | 2 +- 142 files changed, 1960 insertions(+), 566 deletions(-) create mode 100644 api/build.gradle.kts create mode 100644 api/src/main/java/dev/plex/api/ApiCompatibility.java create mode 100644 api/src/main/java/dev/plex/api/PlexApi.java create mode 100644 api/src/main/java/dev/plex/api/command/CommandApi.java create mode 100644 api/src/main/java/dev/plex/api/config/ConfigurationApi.java create mode 100644 api/src/main/java/dev/plex/api/config/ModuleConfigApi.java create mode 100644 api/src/main/java/dev/plex/api/config/ModuleConfiguration.java create mode 100644 api/src/main/java/dev/plex/api/config/PlexConfiguration.java create mode 100644 api/src/main/java/dev/plex/api/listener/ListenerApi.java create mode 100644 api/src/main/java/dev/plex/api/logging/LoggingApi.java create mode 100644 api/src/main/java/dev/plex/api/message/MessageApi.java create mode 100644 api/src/main/java/dev/plex/api/module/ModulesApi.java create mode 100644 api/src/main/java/dev/plex/api/player/PlayersApi.java create mode 100644 api/src/main/java/dev/plex/api/player/PlexPlayerView.java create mode 100644 api/src/main/java/dev/plex/api/punishment/IndefiniteBanView.java create mode 100644 api/src/main/java/dev/plex/api/punishment/PunishmentRequest.java create mode 100644 api/src/main/java/dev/plex/api/punishment/PunishmentType.java create mode 100644 api/src/main/java/dev/plex/api/punishment/PunishmentView.java create mode 100644 api/src/main/java/dev/plex/api/punishment/PunishmentsApi.java create mode 100644 api/src/main/java/dev/plex/api/scheduler/SchedulerApi.java create mode 100644 api/src/main/java/dev/plex/api/storage/StorageApi.java create mode 100644 api/src/main/java/dev/plex/command/PlexCommand.java create mode 100644 api/src/main/java/dev/plex/command/annotation/CommandParameters.java create mode 100644 api/src/main/java/dev/plex/command/annotation/CommandPermissions.java create mode 100644 api/src/main/java/dev/plex/command/exception/CommandFailException.java rename {server => api}/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java (53%) rename {server => api}/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java (53%) rename {server => api}/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java (53%) rename {server => api}/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java (53%) rename {server => api}/src/main/java/dev/plex/command/source/RequiredCommandSource.java (78%) create mode 100644 api/src/main/java/dev/plex/config/ModuleConfig.java create mode 100644 api/src/main/java/dev/plex/listener/PlexListener.java create mode 100644 api/src/main/java/dev/plex/module/PlexModule.java create mode 100644 api/src/main/java/dev/plex/module/PlexModuleFile.java create mode 100644 proxy/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java create mode 100644 proxy/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java create mode 100644 proxy/src/main/java/dev/plex/api/impl/DefaultModulesApi.java create mode 100644 proxy/src/main/java/dev/plex/api/impl/DefaultPlexApi.java create mode 100644 proxy/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java rename proxy/src/main/java/dev/plex/command/{PlexCommand.java => ProxyCommand.java} (89%) delete mode 100644 proxy/src/main/java/dev/plex/command/annotation/CommandParameters.java delete mode 100644 proxy/src/main/java/dev/plex/command/annotation/CommandPermissions.java delete mode 100644 proxy/src/main/java/dev/plex/command/source/RequiredCommandSource.java rename proxy/src/main/java/dev/plex/listener/{PlexListener.java => ProxyListener.java} (77%) create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultCommandApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultIndefiniteBanView.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultListenerApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultLoggingApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultMessageApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultModuleConfigApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultModulesApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPlayersApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPlexApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPlexPlayerView.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPunishmentView.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultPunishmentsApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultSchedulerApi.java create mode 100644 server/src/main/java/dev/plex/api/impl/DefaultStorageApi.java rename server/src/main/java/dev/plex/{config/ModuleConfig.java => api/impl/ServerModuleConfiguration.java} (56%) rename server/src/main/java/dev/plex/command/{PlexCommand.java => ServerCommand.java} (90%) delete mode 100644 server/src/main/java/dev/plex/command/annotation/CommandParameters.java delete mode 100644 server/src/main/java/dev/plex/command/annotation/CommandPermissions.java delete mode 100644 server/src/main/java/dev/plex/command/exception/CommandFailException.java rename server/src/main/java/dev/plex/listener/{PlexListener.java => ServerListenerBase.java} (66%) delete mode 100644 server/src/main/java/dev/plex/module/PlexModule.java delete mode 100644 server/src/main/java/dev/plex/module/PlexModuleFile.java diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 0000000..713dc0f --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + java + `maven-publish` +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:26.1.2.build.+") + compileOnly("org.apache.logging.log4j:log4j-api:2.26.0") + compileOnly("org.jetbrains:annotations:26.1.0") +} + +group = rootProject.group +version = rootProject.version +description = "Plex-API" + + +publishing { + publications { + create("maven") { + from(components["java"]) + } + } +} \ No newline at end of file diff --git a/api/src/main/java/dev/plex/api/ApiCompatibility.java b/api/src/main/java/dev/plex/api/ApiCompatibility.java new file mode 100644 index 0000000..9b487b7 --- /dev/null +++ b/api/src/main/java/dev/plex/api/ApiCompatibility.java @@ -0,0 +1,12 @@ +package dev.plex.api; + +/** + * Describes the module API compatibility level provided by this Plex build. + */ +public interface ApiCompatibility +{ + /** + * @return the provided module API compatibility version + */ + int version(); +} diff --git a/api/src/main/java/dev/plex/api/PlexApi.java b/api/src/main/java/dev/plex/api/PlexApi.java new file mode 100644 index 0000000..377e552 --- /dev/null +++ b/api/src/main/java/dev/plex/api/PlexApi.java @@ -0,0 +1,55 @@ +package dev.plex.api; + +import dev.plex.api.command.CommandApi; +import dev.plex.api.config.ConfigurationApi; +import dev.plex.api.config.ModuleConfigApi; +import dev.plex.api.listener.ListenerApi; +import dev.plex.api.logging.LoggingApi; +import dev.plex.api.message.MessageApi; +import dev.plex.api.module.ModulesApi; +import dev.plex.api.player.PlayersApi; +import dev.plex.api.punishment.PunishmentsApi; +import dev.plex.api.scheduler.SchedulerApi; +import dev.plex.api.storage.StorageApi; + +/** + * Public API facade exposed to Plex modules. + * + *

Keep this interface small and deliberate; adding a method here makes it + * part of the supported module API contract.

+ */ +public interface PlexApi +{ + /** + * @return module API compatibility information for this Plex build + */ + ApiCompatibility compatibility(); + + /** + * @return safe access to shared Plex configuration files + */ + ConfigurationApi configuration(); + + /** + * @return safe access to module metadata and module-related operations + */ + ModulesApi modules(); + + CommandApi commands(); + + ListenerApi listeners(); + + ModuleConfigApi moduleConfigs(); + + LoggingApi logging(); + + MessageApi messages(); + + PlayersApi players(); + + PunishmentsApi punishments(); + + SchedulerApi scheduler(); + + StorageApi storage(); +} diff --git a/api/src/main/java/dev/plex/api/command/CommandApi.java b/api/src/main/java/dev/plex/api/command/CommandApi.java new file mode 100644 index 0000000..12bc3a5 --- /dev/null +++ b/api/src/main/java/dev/plex/api/command/CommandApi.java @@ -0,0 +1,10 @@ +package dev.plex.api.command; + +import org.bukkit.command.Command; + +public interface CommandApi +{ + void register(Command command); + + void unregister(Command command); +} diff --git a/api/src/main/java/dev/plex/api/config/ConfigurationApi.java b/api/src/main/java/dev/plex/api/config/ConfigurationApi.java new file mode 100644 index 0000000..ff87731 --- /dev/null +++ b/api/src/main/java/dev/plex/api/config/ConfigurationApi.java @@ -0,0 +1,15 @@ +package dev.plex.api.config; + +/** + * Public configuration access exposed to modules. + */ +public interface ConfigurationApi +{ + PlexConfiguration mainConfig(); + + PlexConfiguration messages(); + + PlexConfiguration indefiniteBans(); + + PlexConfiguration toggles(); +} diff --git a/api/src/main/java/dev/plex/api/config/ModuleConfigApi.java b/api/src/main/java/dev/plex/api/config/ModuleConfigApi.java new file mode 100644 index 0000000..42024a7 --- /dev/null +++ b/api/src/main/java/dev/plex/api/config/ModuleConfigApi.java @@ -0,0 +1,8 @@ +package dev.plex.api.config; + +import dev.plex.module.PlexModule; + +public interface ModuleConfigApi +{ + ModuleConfiguration create(PlexModule module, String from, String to); +} diff --git a/api/src/main/java/dev/plex/api/config/ModuleConfiguration.java b/api/src/main/java/dev/plex/api/config/ModuleConfiguration.java new file mode 100644 index 0000000..6135c95 --- /dev/null +++ b/api/src/main/java/dev/plex/api/config/ModuleConfiguration.java @@ -0,0 +1,9 @@ +package dev.plex.api.config; + +import org.bukkit.configuration.file.YamlConfiguration; + +public abstract class ModuleConfiguration extends YamlConfiguration +{ + public abstract void load(); + public abstract void save(); +} diff --git a/api/src/main/java/dev/plex/api/config/PlexConfiguration.java b/api/src/main/java/dev/plex/api/config/PlexConfiguration.java new file mode 100644 index 0000000..da9736c --- /dev/null +++ b/api/src/main/java/dev/plex/api/config/PlexConfiguration.java @@ -0,0 +1,23 @@ +package dev.plex.api.config; + +import java.util.List; + +/** + * Stable configuration wrapper exposed through the Plex module API. + */ +public interface PlexConfiguration +{ + String getString(String path); + + boolean getBoolean(String path); + + int getInt(String path); + + List getStringList(String path); + + void set(String path, Object value); + + void setComments(String path, List comments); + + void save(); +} diff --git a/api/src/main/java/dev/plex/api/listener/ListenerApi.java b/api/src/main/java/dev/plex/api/listener/ListenerApi.java new file mode 100644 index 0000000..e61e7c4 --- /dev/null +++ b/api/src/main/java/dev/plex/api/listener/ListenerApi.java @@ -0,0 +1,10 @@ +package dev.plex.api.listener; + +import org.bukkit.event.Listener; + +public interface ListenerApi +{ + void register(Listener listener); + + void unregister(Listener listener); +} diff --git a/api/src/main/java/dev/plex/api/logging/LoggingApi.java b/api/src/main/java/dev/plex/api/logging/LoggingApi.java new file mode 100644 index 0000000..e9f9a2e --- /dev/null +++ b/api/src/main/java/dev/plex/api/logging/LoggingApi.java @@ -0,0 +1,9 @@ +package dev.plex.api.logging; + +public interface LoggingApi +{ + void info(String message, Object... args); + void debug(String message, Object... args); + void warn(String message, Object... args); + void error(String message, Object... args); +} diff --git a/api/src/main/java/dev/plex/api/message/MessageApi.java b/api/src/main/java/dev/plex/api/message/MessageApi.java new file mode 100644 index 0000000..61cc302 --- /dev/null +++ b/api/src/main/java/dev/plex/api/message/MessageApi.java @@ -0,0 +1,15 @@ +package dev.plex.api.message; + +import java.util.List; +import net.kyori.adventure.text.Component; + +public interface MessageApi +{ + Component messageComponent(String entry, Object... objects); + Component messageComponent(String entry, Component... objects); + String messageString(String entry, Object... objects); + Component miniMessage(String input); + void broadcast(String miniMessage); + void broadcast(Component component); + List onlinePlayerNames(); +} diff --git a/api/src/main/java/dev/plex/api/module/ModulesApi.java b/api/src/main/java/dev/plex/api/module/ModulesApi.java new file mode 100644 index 0000000..21fff44 --- /dev/null +++ b/api/src/main/java/dev/plex/api/module/ModulesApi.java @@ -0,0 +1,25 @@ +package dev.plex.api.module; + +import dev.plex.module.PlexModuleFile; + +import java.util.Collection; +import java.util.Optional; + +/** + * Public module metadata access exposed to modules. + */ +public interface ModulesApi +{ + /** + * @return immutable metadata for all currently discovered modules + */ + Collection loadedModules(); + + /** + * Looks up a module by name. + * + * @param name module name from module.yml + * @return module metadata, if a module with this name is loaded + */ + Optional module(String name); +} diff --git a/api/src/main/java/dev/plex/api/player/PlayersApi.java b/api/src/main/java/dev/plex/api/player/PlayersApi.java new file mode 100644 index 0000000..3455838 --- /dev/null +++ b/api/src/main/java/dev/plex/api/player/PlayersApi.java @@ -0,0 +1,12 @@ +package dev.plex.api.player; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface PlayersApi +{ + Optional byUuid(UUID uuid); + Optional byName(String name); + List onlineNames(); +} diff --git a/api/src/main/java/dev/plex/api/player/PlexPlayerView.java b/api/src/main/java/dev/plex/api/player/PlexPlayerView.java new file mode 100644 index 0000000..b833e68 --- /dev/null +++ b/api/src/main/java/dev/plex/api/player/PlexPlayerView.java @@ -0,0 +1,18 @@ +package dev.plex.api.player; + +import java.util.List; +import java.util.UUID; +import dev.plex.api.punishment.PunishmentView; +import org.bukkit.entity.Player; + +public interface PlexPlayerView +{ + UUID uuid(); + String name(); + List ips(); + List punishments(); + boolean frozen(); + boolean muted(); + boolean lockedUp(); + Player bukkitPlayer(); +} diff --git a/api/src/main/java/dev/plex/api/punishment/IndefiniteBanView.java b/api/src/main/java/dev/plex/api/punishment/IndefiniteBanView.java new file mode 100644 index 0000000..b2f7ac1 --- /dev/null +++ b/api/src/main/java/dev/plex/api/punishment/IndefiniteBanView.java @@ -0,0 +1,12 @@ +package dev.plex.api.punishment; + +import java.util.List; +import java.util.UUID; + +public interface IndefiniteBanView +{ + List usernames(); + List uuids(); + List ips(); + String reason(); +} diff --git a/api/src/main/java/dev/plex/api/punishment/PunishmentRequest.java b/api/src/main/java/dev/plex/api/punishment/PunishmentRequest.java new file mode 100644 index 0000000..4f2f3a4 --- /dev/null +++ b/api/src/main/java/dev/plex/api/punishment/PunishmentRequest.java @@ -0,0 +1,10 @@ +package dev.plex.api.punishment; + +import java.time.ZonedDateTime; +import java.util.UUID; + +public record PunishmentRequest(UUID punished, UUID punisher, String punisherName, String ip, + String punishedUsername, PunishmentType type, String reason, + boolean customTime, boolean active, ZonedDateTime endDate) +{ +} diff --git a/api/src/main/java/dev/plex/api/punishment/PunishmentType.java b/api/src/main/java/dev/plex/api/punishment/PunishmentType.java new file mode 100644 index 0000000..3efcac8 --- /dev/null +++ b/api/src/main/java/dev/plex/api/punishment/PunishmentType.java @@ -0,0 +1,11 @@ +package dev.plex.api.punishment; + +public enum PunishmentType +{ + MUTE, + FREEZE, + BAN, + TEMPBAN, + KICK, + SMITE +} diff --git a/api/src/main/java/dev/plex/api/punishment/PunishmentView.java b/api/src/main/java/dev/plex/api/punishment/PunishmentView.java new file mode 100644 index 0000000..5089d52 --- /dev/null +++ b/api/src/main/java/dev/plex/api/punishment/PunishmentView.java @@ -0,0 +1,19 @@ +package dev.plex.api.punishment; + +import java.time.ZonedDateTime; +import java.util.UUID; + +public interface PunishmentView +{ + UUID punished(); + UUID punisher(); + String punisherName(); + String ip(); + String punishedUsername(); + PunishmentType type(); + String reason(); + boolean customTime(); + boolean active(); + ZonedDateTime issueDate(); + ZonedDateTime endDate(); +} diff --git a/api/src/main/java/dev/plex/api/punishment/PunishmentsApi.java b/api/src/main/java/dev/plex/api/punishment/PunishmentsApi.java new file mode 100644 index 0000000..7435b9a --- /dev/null +++ b/api/src/main/java/dev/plex/api/punishment/PunishmentsApi.java @@ -0,0 +1,13 @@ +package dev.plex.api.punishment; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import dev.plex.api.player.PlexPlayerView; + +public interface PunishmentsApi +{ + List indefiniteBans(); + Optional indefiniteBanByUuid(UUID uuid); + void punish(PlexPlayerView player, PunishmentRequest punishment); +} diff --git a/api/src/main/java/dev/plex/api/scheduler/SchedulerApi.java b/api/src/main/java/dev/plex/api/scheduler/SchedulerApi.java new file mode 100644 index 0000000..c23ea96 --- /dev/null +++ b/api/src/main/java/dev/plex/api/scheduler/SchedulerApi.java @@ -0,0 +1,8 @@ +package dev.plex.api.scheduler; + +public interface SchedulerApi +{ + Object runSync(Runnable task); + Object runLater(Runnable task, long delayTicks); + Object runTimer(Runnable task, long delayTicks, long periodTicks); +} diff --git a/api/src/main/java/dev/plex/api/storage/StorageApi.java b/api/src/main/java/dev/plex/api/storage/StorageApi.java new file mode 100644 index 0000000..083585f --- /dev/null +++ b/api/src/main/java/dev/plex/api/storage/StorageApi.java @@ -0,0 +1,15 @@ +package dev.plex.api.storage; + +import java.sql.Connection; +import java.sql.SQLException; + +public interface StorageApi +{ + T withConnection(SqlFunction function) throws SQLException; + + @FunctionalInterface + interface SqlFunction + { + T apply(Connection connection) throws SQLException; + } +} diff --git a/api/src/main/java/dev/plex/command/PlexCommand.java b/api/src/main/java/dev/plex/command/PlexCommand.java new file mode 100644 index 0000000..6260f42 --- /dev/null +++ b/api/src/main/java/dev/plex/command/PlexCommand.java @@ -0,0 +1,262 @@ +package dev.plex.command; + +import java.util.ArrayList; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.exception.CommandFailException; +import dev.plex.command.exception.ConsoleMustDefinePlayerException; +import dev.plex.command.exception.ConsoleOnlyException; +import dev.plex.command.exception.PlayerNotBannedException; +import dev.plex.command.exception.PlayerNotFoundException; +import dev.plex.command.source.RequiredCommandSource; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** Public base class for module commands. */ +public abstract class PlexCommand extends Command +{ + private static Runtime runtime; + private final CommandParameters params; + private final CommandPermissions perms; + private final RequiredCommandSource commandSource; + + public static void setRuntime(Runtime runtime) + { + PlexCommand.runtime = runtime; + } + + public PlexCommand(boolean register) + { + super(""); + this.params = getClass().getAnnotation(CommandParameters.class); + this.perms = getClass().getAnnotation(CommandPermissions.class); + if (params == null || perms == null) + { + throw new IllegalStateException("PlexCommand requires CommandParameters and CommandPermissions annotations"); + } + setName(params.name()); + setLabel(params.name()); + setDescription(params.description()); + setPermission(perms.permission()); + setUsage(params.usage().replace("", params.name())); + if (!params.aliases().isEmpty()) + { + setAliases(Arrays.asList(params.aliases().split(","))); + } + this.commandSource = perms.source(); + if (register) + { + requireRuntime().register(this); + } + } + + public PlexCommand() + { + this(true); + } + + protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args); + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args) + { + if (!matches(label)) + { + return false; + } + if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player) + { + send(sender, messageComponent("noPermissionInGame")); + return true; + } + if (commandSource == RequiredCommandSource.IN_GAME && sender instanceof ConsoleCommandSender) + { + send(sender, messageComponent("noPermissionConsole")); + return true; + } + if (!perms.permission().isEmpty() && sender instanceof Player player && !player.hasPermission(perms.permission())) + { + send(sender, messageComponent("noPermissionNode", perms.permission())); + return true; + } + try + { + Component component = execute(sender, isConsole(sender) ? null : (Player)sender, args); + if (component != null) + { + send(sender, component); + } + } + catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException | + ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex) + { + send(sender, mmString(ex.getMessage())); + } + return true; + } + + @NotNull + public abstract List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException; + + @NotNull + @Override + public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return StringUtil.copyPartialMatches(args[args.length - 1], smartTabComplete(sender, alias, args), new ArrayList<>()); + } + + private boolean matches(String label) + { + return getName().equalsIgnoreCase(label) || getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(label)); + } + + protected void send(Audience audience, String s) + { + audience.sendMessage(componentFromString(s)); + } + + protected void send(Audience audience, Component component) + { + audience.sendMessage(component); + } + + protected boolean checkPermission(CommandSender sender, String permission) + { + return isConsole(sender) || checkPermission((Player)sender, permission); + } + + protected boolean silentCheckPermission(CommandSender sender, String permission) + { + return isConsole(sender) || silentCheckPermission((Player)sender, permission); + } + + protected boolean checkPermission(Player player, String permission) + { + if (!permission.isEmpty() && !player.hasPermission(permission)) + { + throw new CommandFailException(messageString("noPermissionNode", permission)); + } + return true; + } + + protected boolean silentCheckPermission(Player player, String permission) + { + return permission.isEmpty() || player.hasPermission(permission); + } + + protected UUID getUUID(CommandSender sender) + { + return sender instanceof Player player ? player.getUniqueId() : null; + } + + protected boolean isConsole(CommandSender sender) + { + return !(sender instanceof Player); + } + + protected Component messageComponent(String s, Object... objects) + { + return requireRuntime().messageComponent(s, objects); + } + + protected Component messageComponent(String s, Component... objects) + { + return requireRuntime().messageComponent(s, objects); + } + + protected String messageString(String s, Object... objects) + { + return requireRuntime().messageString(s, objects); + } + + protected Component usage() + { + return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(getUsage()).color(NamedTextColor.GRAY)); + } + + protected Component usage(String s) + { + return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(s).color(NamedTextColor.GRAY)); + } + + protected Player getNonNullPlayer(String name) + { + Player player; + try + { + player = Bukkit.getPlayer(UUID.fromString(name)); + } + catch (IllegalArgumentException ignored) + { + player = Bukkit.getPlayer(name); + } + if (player == null) + { + throw new PlayerNotFoundException(); + } + return player; + } + + protected World getNonNullWorld(String name) + { + World world = Bukkit.getWorld(name); + if (world == null) + { + throw new CommandFailException(messageString("worldNotFound")); + } + return world; + } + + protected Component componentFromString(String s) + { + return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY); + } + + protected Component noColorComponentFromString(String s) + { + return LegacyComponentSerializer.legacyAmpersand().deserialize(s); + } + + protected Component mmString(String s) + { + return requireRuntime().miniMessage(s); + } + + public CommandMap getMap() + { + return Bukkit.getCommandMap(); + } + + private static Runtime requireRuntime() + { + if (runtime == null) + { + throw new IllegalStateException("PlexCommand runtime has not been installed by Plex"); + } + return runtime; + } + + public interface Runtime + { + void register(Command command); + Component messageComponent(String entry, Object... objects); + Component messageComponent(String entry, Component... objects); + String messageString(String entry, Object... objects); + Component miniMessage(String input); + } +} diff --git a/api/src/main/java/dev/plex/command/annotation/CommandParameters.java b/api/src/main/java/dev/plex/command/annotation/CommandParameters.java new file mode 100644 index 0000000..aa33bb3 --- /dev/null +++ b/api/src/main/java/dev/plex/command/annotation/CommandParameters.java @@ -0,0 +1,13 @@ +package dev.plex.command.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandParameters +{ + String name(); + String description() default ""; + String usage() default "/"; + String aliases() default ""; +} diff --git a/api/src/main/java/dev/plex/command/annotation/CommandPermissions.java b/api/src/main/java/dev/plex/command/annotation/CommandPermissions.java new file mode 100644 index 0000000..f51e354 --- /dev/null +++ b/api/src/main/java/dev/plex/command/annotation/CommandPermissions.java @@ -0,0 +1,12 @@ +package dev.plex.command.annotation; + +import dev.plex.command.source.RequiredCommandSource; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandPermissions +{ + String permission() default ""; + RequiredCommandSource source() default RequiredCommandSource.ANY; +} diff --git a/api/src/main/java/dev/plex/command/exception/CommandFailException.java b/api/src/main/java/dev/plex/command/exception/CommandFailException.java new file mode 100644 index 0000000..cc71d47 --- /dev/null +++ b/api/src/main/java/dev/plex/command/exception/CommandFailException.java @@ -0,0 +1,14 @@ +package dev.plex.command.exception; + +public class CommandFailException extends RuntimeException +{ + public CommandFailException() + { + super("CommandFailException"); + } + + public CommandFailException(String message) + { + super(message); + } +} diff --git a/server/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java b/api/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java similarity index 53% rename from server/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java rename to api/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java index 32ca55a..4279542 100644 --- a/server/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java +++ b/api/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java @@ -1,11 +1,14 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.messageString; - public class ConsoleMustDefinePlayerException extends RuntimeException { public ConsoleMustDefinePlayerException() { - super(messageString("consoleMustDefinePlayer")); + super("ConsoleMustDefinePlayerException"); } -} \ No newline at end of file + + public ConsoleMustDefinePlayerException(String message) + { + super(message); + } +} diff --git a/server/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java b/api/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java similarity index 53% rename from server/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java rename to api/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java index 09a5439..1a61971 100644 --- a/server/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java +++ b/api/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java @@ -1,11 +1,14 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.messageString; - public class ConsoleOnlyException extends RuntimeException { public ConsoleOnlyException() { - super(messageString("consoleOnly")); + super("ConsoleOnlyException"); } -} \ No newline at end of file + + public ConsoleOnlyException(String message) + { + super(message); + } +} diff --git a/server/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java b/api/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java similarity index 53% rename from server/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java rename to api/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java index 0558baa..9c0749b 100644 --- a/server/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java +++ b/api/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java @@ -1,11 +1,14 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.messageString; - public class PlayerNotBannedException extends RuntimeException { public PlayerNotBannedException() { - super(messageString("playerNotBanned")); + super("PlayerNotBannedException"); } -} \ No newline at end of file + + public PlayerNotBannedException(String message) + { + super(message); + } +} diff --git a/server/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java b/api/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java similarity index 53% rename from server/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java rename to api/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java index efb8f91..323704d 100644 --- a/server/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java +++ b/api/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java @@ -1,11 +1,14 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.messageString; - public class PlayerNotFoundException extends RuntimeException { public PlayerNotFoundException() { - super(messageString("playerNotFound")); + super("PlayerNotFoundException"); } -} \ No newline at end of file + + public PlayerNotFoundException(String message) + { + super(message); + } +} diff --git a/server/src/main/java/dev/plex/command/source/RequiredCommandSource.java b/api/src/main/java/dev/plex/command/source/RequiredCommandSource.java similarity index 78% rename from server/src/main/java/dev/plex/command/source/RequiredCommandSource.java rename to api/src/main/java/dev/plex/command/source/RequiredCommandSource.java index 2f8ee08..a3d40e8 100644 --- a/server/src/main/java/dev/plex/command/source/RequiredCommandSource.java +++ b/api/src/main/java/dev/plex/command/source/RequiredCommandSource.java @@ -2,7 +2,7 @@ package dev.plex.command.source; public enum RequiredCommandSource { + ANY, IN_GAME, - CONSOLE, - ANY -} \ No newline at end of file + CONSOLE +} diff --git a/api/src/main/java/dev/plex/config/ModuleConfig.java b/api/src/main/java/dev/plex/config/ModuleConfig.java new file mode 100644 index 0000000..d8f4754 --- /dev/null +++ b/api/src/main/java/dev/plex/config/ModuleConfig.java @@ -0,0 +1,87 @@ +package dev.plex.config; + +import dev.plex.api.config.ModuleConfiguration; +import dev.plex.module.PlexModule; + +/** + * Public module config entry point. The platform installs a factory at runtime. + */ +public class ModuleConfig extends ModuleConfiguration +{ + private static Factory factory; + private final ModuleConfiguration delegate; + + public static void setFactory(Factory factory) + { + ModuleConfig.factory = factory; + } + + public ModuleConfig(PlexModule module, String from, String to) + { + if (factory == null) + { + throw new IllegalStateException("ModuleConfig factory has not been installed by Plex"); + } + this.delegate = factory.create(module, from, to); + } + + @Override + public void load() + { + delegate.load(); + } + + @Override + public void save() + { + delegate.save(); + } + + @Override + public Object get(String path) + { + return delegate.get(path); + } + + @Override + public String getString(String path) + { + return delegate.getString(path); + } + + @Override + public String getString(String path, String def) + { + return delegate.getString(path, def); + } + + @Override + public int getInt(String path) + { + return delegate.getInt(path); + } + + @Override + public int getInt(String path, int def) + { + return delegate.getInt(path, def); + } + + @Override + public boolean getBoolean(String path) + { + return delegate.getBoolean(path); + } + + @Override + public void set(String path, Object value) + { + delegate.set(path, value); + } + + @FunctionalInterface + public interface Factory + { + ModuleConfiguration create(PlexModule module, String from, String to); + } +} diff --git a/api/src/main/java/dev/plex/listener/PlexListener.java b/api/src/main/java/dev/plex/listener/PlexListener.java new file mode 100644 index 0000000..64b182b --- /dev/null +++ b/api/src/main/java/dev/plex/listener/PlexListener.java @@ -0,0 +1,10 @@ +package dev.plex.listener; + +import org.bukkit.event.Listener; + +public abstract class PlexListener implements Listener +{ + protected PlexListener() + { + } +} diff --git a/api/src/main/java/dev/plex/module/PlexModule.java b/api/src/main/java/dev/plex/module/PlexModule.java new file mode 100644 index 0000000..803c862 --- /dev/null +++ b/api/src/main/java/dev/plex/module/PlexModule.java @@ -0,0 +1,172 @@ +package dev.plex.module; + +import dev.plex.api.PlexApi; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import org.apache.logging.log4j.Logger; +import org.bukkit.command.Command; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Base class for Plex modules. + * + *

This class is part of the public module API. Modules use {@link #api()} for + * supported integration points.

+ */ +public abstract class PlexModule +{ + private final List commands = new ArrayList<>(); + private final List listeners = new ArrayList<>(); + + private PlexApi api; + private PlexModuleFile plexModuleFile; + private File dataFolder; + private Logger logger; + + public PlexApi api() + { + return api; + } + + public void load() + { + } + + public void enable() + { + } + + public void disable() + { + } + + public void registerListener(Listener listener) + { + listeners.add(listener); + } + + public void unregisterListener(Listener listener) + { + listeners.remove(listener); + HandlerList.unregisterAll(listener); + } + + public void registerCommand(Command command) + { + commands.add(command); + } + + public void unregisterCommand(Command command) + { + commands.remove(command); + } + + @Nullable + public Command getCommand(String name) + { + return commands.stream() + .filter(command -> command.getName().equalsIgnoreCase(name) || command.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT))) + .findFirst() + .orElse(null); + } + + public void addDefaultMessage(String message, Object initValue) + { + if (api.configuration().messages().getString(message) == null) + { + api.configuration().messages().set(message, initValue); + api.configuration().messages().save(); + logger.debug("'{}' message added from {}", message, plexModuleFile.getName()); + } + } + + public void addDefaultMessage(String message, Object initValue, String... comments) + { + if (api.configuration().messages().getString(message) == null) + { + api.configuration().messages().set(message, initValue); + api.configuration().messages().save(); + api.configuration().messages().setComments(message, Arrays.asList(comments)); + api.configuration().messages().save(); + logger.debug("'{}' message added from {}", message, plexModuleFile.getName()); + } + } + + @Nullable + public InputStream getResource(@NotNull String filename) + { + try + { + URL url = this.getClass().getClassLoader().getResource(filename); + if (url == null) + { + return null; + } + + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + return connection.getInputStream(); + } + catch (IOException ex) + { + return null; + } + } + + public List getCommands() + { + return commands; + } + + public List getListeners() + { + return listeners; + } + + public PlexModuleFile getPlexModuleFile() + { + return plexModuleFile; + } + + public File getDataFolder() + { + return dataFolder; + } + + public Logger getLogger() + { + return logger; + } + + public void setApi(PlexApi api) + { + this.api = api; + } + + public void setPlexModuleFile(PlexModuleFile plexModuleFile) + { + this.plexModuleFile = plexModuleFile; + } + + public void setDataFolder(File dataFolder) + { + this.dataFolder = dataFolder; + } + + public void setLogger(Logger logger) + { + this.logger = logger; + } +} diff --git a/api/src/main/java/dev/plex/module/PlexModuleFile.java b/api/src/main/java/dev/plex/module/PlexModuleFile.java new file mode 100644 index 0000000..fdaae7b --- /dev/null +++ b/api/src/main/java/dev/plex/module/PlexModuleFile.java @@ -0,0 +1,60 @@ +package dev.plex.module; + +import java.util.List; + +/** + * Metadata read from a module's module.yml file. + */ +public final class PlexModuleFile +{ + private final String name; + private final String main; + private final String description; + private final String version; + private final int apiCompatibility; + private List libraries = List.of(); + + public PlexModuleFile(String name, String main, String description, String version, int apiCompatibility) + { + this.name = name; + this.main = main; + this.description = description; + this.version = version; + this.apiCompatibility = apiCompatibility; + } + + public String getName() + { + return name; + } + + public String getMain() + { + return main; + } + + public String getDescription() + { + return description; + } + + public String getVersion() + { + return version; + } + + public int getApiCompatibility() + { + return apiCompatibility; + } + + public List getLibraries() + { + return libraries; + } + + public void setLibraries(List libraries) + { + this.libraries = List.copyOf(libraries); + } +} diff --git a/proxy/build.gradle.kts b/proxy/build.gradle.kts index 7962f7c..f79b112 100644 --- a/proxy/build.gradle.kts +++ b/proxy/build.gradle.kts @@ -47,6 +47,7 @@ publishing { } dependencies { + implementation(project(":api")) compileOnly("org.projectlombok:lombok:1.18.46") annotationProcessor("org.projectlombok:lombok:1.18.46") compileOnly("org.json:json:20251224") diff --git a/proxy/src/main/java/dev/plex/Plex.java b/proxy/src/main/java/dev/plex/Plex.java index e11f520..fd84f87 100644 --- a/proxy/src/main/java/dev/plex/Plex.java +++ b/proxy/src/main/java/dev/plex/Plex.java @@ -6,6 +6,8 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; +import dev.plex.api.PlexApi; +import dev.plex.api.impl.DefaultPlexApi; import dev.plex.config.TomlConfig; import dev.plex.handlers.ListenerHandler; import dev.plex.settings.ServerSettings; @@ -35,6 +37,7 @@ import lombok.Getter; @Getter public class Plex { + public static final int MODULE_API_COMPATIBILITY_VERSION = 1; private static Plex plugin; public final ProxyServer server; @@ -42,6 +45,7 @@ public class Plex private final File dataFolder; private TomlConfig config; + private PlexApi api; @Inject public Plex(ProxyServer server, Logger logger, @DataDirectory Path folder) @@ -71,6 +75,7 @@ public class Plex }); this.config.create(true); this.config.write(new ServerSettings()); + this.api = new DefaultPlexApi(this, MODULE_API_COMPATIBILITY_VERSION); new ListenerHandler(); } diff --git a/proxy/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java b/proxy/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java new file mode 100644 index 0000000..8a63512 --- /dev/null +++ b/proxy/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java @@ -0,0 +1,19 @@ +package dev.plex.api.impl; + +import dev.plex.api.ApiCompatibility; + +final class DefaultApiCompatibility implements ApiCompatibility +{ + private final int version; + + DefaultApiCompatibility(int version) + { + this.version = version; + } + + @Override + public int version() + { + return version; + } +} diff --git a/proxy/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java b/proxy/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java new file mode 100644 index 0000000..ff7b93c --- /dev/null +++ b/proxy/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java @@ -0,0 +1,39 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.config.ConfigurationApi; +import dev.plex.api.config.PlexConfiguration; + +final class DefaultConfigurationApi implements ConfigurationApi +{ + private final Plex plugin; + + DefaultConfigurationApi(Plex plugin) + { + this.plugin = plugin; + } + + @Override + public PlexConfiguration mainConfig() + { + return new DefaultPlexConfiguration(plugin.getConfig()); + } + + @Override + public PlexConfiguration messages() + { + throw new UnsupportedOperationException("Proxy does not provide messages configuration"); + } + + @Override + public PlexConfiguration indefiniteBans() + { + throw new UnsupportedOperationException("Proxy does not provide indefinite bans configuration"); + } + + @Override + public PlexConfiguration toggles() + { + throw new UnsupportedOperationException("Proxy does not provide toggles configuration"); + } +} diff --git a/proxy/src/main/java/dev/plex/api/impl/DefaultModulesApi.java b/proxy/src/main/java/dev/plex/api/impl/DefaultModulesApi.java new file mode 100644 index 0000000..8ea79cd --- /dev/null +++ b/proxy/src/main/java/dev/plex/api/impl/DefaultModulesApi.java @@ -0,0 +1,23 @@ +package dev.plex.api.impl; + +import dev.plex.api.module.ModulesApi; +import dev.plex.module.PlexModuleFile; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +final class DefaultModulesApi implements ModulesApi +{ + @Override + public Collection loadedModules() + { + return List.of(); + } + + @Override + public Optional module(String name) + { + return Optional.empty(); + } +} diff --git a/proxy/src/main/java/dev/plex/api/impl/DefaultPlexApi.java b/proxy/src/main/java/dev/plex/api/impl/DefaultPlexApi.java new file mode 100644 index 0000000..b4671c8 --- /dev/null +++ b/proxy/src/main/java/dev/plex/api/impl/DefaultPlexApi.java @@ -0,0 +1,48 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.ApiCompatibility; +import dev.plex.api.PlexApi; +import dev.plex.api.command.CommandApi; +import dev.plex.api.config.ConfigurationApi; +import dev.plex.api.config.ModuleConfigApi; +import dev.plex.api.listener.ListenerApi; +import dev.plex.api.logging.LoggingApi; +import dev.plex.api.message.MessageApi; +import dev.plex.api.module.ModulesApi; +import dev.plex.api.player.PlayersApi; +import dev.plex.api.punishment.PunishmentsApi; +import dev.plex.api.scheduler.SchedulerApi; +import dev.plex.api.storage.StorageApi; + +public final class DefaultPlexApi implements PlexApi +{ + private final ApiCompatibility compatibility; + private final ConfigurationApi configuration; + private final ModulesApi modules; + + public DefaultPlexApi(Plex plugin, int apiCompatibilityVersion) + { + this.compatibility = new DefaultApiCompatibility(apiCompatibilityVersion); + this.configuration = new DefaultConfigurationApi(plugin); + this.modules = new DefaultModulesApi(); + } + + @Override public ApiCompatibility compatibility() { return compatibility; } + @Override public ConfigurationApi configuration() { return configuration; } + @Override public ModulesApi modules() { return modules; } + @Override public CommandApi commands() { throw unsupported(); } + @Override public ListenerApi listeners() { throw unsupported(); } + @Override public ModuleConfigApi moduleConfigs() { throw unsupported(); } + @Override public LoggingApi logging() { throw unsupported(); } + @Override public MessageApi messages() { throw unsupported(); } + @Override public PlayersApi players() { throw unsupported(); } + @Override public PunishmentsApi punishments() { throw unsupported(); } + @Override public SchedulerApi scheduler() { throw unsupported(); } + @Override public StorageApi storage() { throw unsupported(); } + + private static UnsupportedOperationException unsupported() + { + return new UnsupportedOperationException("This Plex API service is only available on the server platform"); + } +} diff --git a/proxy/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java b/proxy/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java new file mode 100644 index 0000000..bfbbf19 --- /dev/null +++ b/proxy/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java @@ -0,0 +1,59 @@ +package dev.plex.api.impl; + +import dev.plex.api.config.PlexConfiguration; +import dev.plex.config.TomlConfig; + +import java.util.List; + +final class DefaultPlexConfiguration implements PlexConfiguration +{ + private final TomlConfig config; + + DefaultPlexConfiguration(TomlConfig config) + { + this.config = config; + } + + @Override + public String getString(String path) + { + return config.getToml().getString(path); + } + + @Override + public boolean getBoolean(String path) + { + return config.getToml().getBoolean(path, false); + } + + @Override + public int getInt(String path) + { + Long value = config.getToml().getLong(path, 0L); + return value.intValue(); + } + + @Override + public List getStringList(String path) + { + return config.getToml().getList(path, List.of()); + } + + @Override + public void set(String path, Object value) + { + throw new UnsupportedOperationException("Proxy TOML configuration writes are not supported through PlexConfiguration"); + } + + @Override + public void setComments(String path, List comments) + { + throw new UnsupportedOperationException("Proxy TOML configuration comments are not supported through PlexConfiguration"); + } + + @Override + public void save() + { + throw new UnsupportedOperationException("Proxy TOML configuration saves are not supported through PlexConfiguration"); + } +} diff --git a/proxy/src/main/java/dev/plex/command/PlexCommand.java b/proxy/src/main/java/dev/plex/command/ProxyCommand.java similarity index 89% rename from proxy/src/main/java/dev/plex/command/PlexCommand.java rename to proxy/src/main/java/dev/plex/command/ProxyCommand.java index b048516..41f6180 100644 --- a/proxy/src/main/java/dev/plex/command/PlexCommand.java +++ b/proxy/src/main/java/dev/plex/command/ProxyCommand.java @@ -9,13 +9,12 @@ import dev.plex.Plex; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import java.util.Arrays; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class PlexCommand implements SimpleCommand +public abstract class ProxyCommand implements SimpleCommand { /** * Returns the instance of the plugin @@ -36,14 +35,17 @@ public abstract class PlexCommand implements SimpleCommand */ private final RequiredCommandSource commandSource; - public PlexCommand() + public ProxyCommand() { this.params = getClass().getAnnotation(CommandParameters.class); this.perms = getClass().getAnnotation(CommandPermissions.class); this.commandSource = this.perms.source(); CommandMeta.Builder meta = plugin.getServer().getCommandManager().metaBuilder(this.params.name()); - meta.aliases(this.params.aliases()); + if (!this.params.aliases().isEmpty()) + { + meta.aliases(this.params.aliases().split(",")); + } meta.plugin(Plex.get()); plugin.getServer().getCommandManager().register(meta.build(), this); } @@ -92,7 +94,7 @@ public abstract class PlexCommand implements SimpleCommand { return true; } - return Arrays.stream(params.aliases()).anyMatch(s -> s.equalsIgnoreCase(label)); + return !params.aliases().isEmpty() && java.util.Arrays.stream(params.aliases().split(",")).anyMatch(s -> s.equalsIgnoreCase(label)); } protected void send(Audience audience, Component component) diff --git a/proxy/src/main/java/dev/plex/command/annotation/CommandParameters.java b/proxy/src/main/java/dev/plex/command/annotation/CommandParameters.java deleted file mode 100644 index 687b491..0000000 --- a/proxy/src/main/java/dev/plex/command/annotation/CommandParameters.java +++ /dev/null @@ -1,39 +0,0 @@ -package dev.plex.command.annotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Storage for a command's parameters - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface CommandParameters -{ - /** - * The name - * - * @return Name of the command - */ - String name(); - - /** - * The description - * - * @return Description of the command - */ - String description() default ""; - - /** - * The usage (optional) - * - * @return The usage of the command - */ - String usage() default "/"; - - /** - * The aliases (optional) - * - * @return The aliases of the command - */ - String[] aliases() default {}; -} \ No newline at end of file diff --git a/proxy/src/main/java/dev/plex/command/annotation/CommandPermissions.java b/proxy/src/main/java/dev/plex/command/annotation/CommandPermissions.java deleted file mode 100644 index 0c67abe..0000000 --- a/proxy/src/main/java/dev/plex/command/annotation/CommandPermissions.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.plex.command.annotation; - -import dev.plex.command.source.RequiredCommandSource; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Storage for the command's permissions - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface CommandPermissions -{ - /** - * Required command source - * - * @return The required command source of the command - * @see RequiredCommandSource - */ - RequiredCommandSource source() default RequiredCommandSource.ANY; - - /** - * The permission - * - * @return Permission of the command - */ - String permission() default ""; // No idea what to put here -} \ No newline at end of file diff --git a/proxy/src/main/java/dev/plex/command/source/RequiredCommandSource.java b/proxy/src/main/java/dev/plex/command/source/RequiredCommandSource.java deleted file mode 100644 index 2f8ee08..0000000 --- a/proxy/src/main/java/dev/plex/command/source/RequiredCommandSource.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.plex.command.source; - -public enum RequiredCommandSource -{ - IN_GAME, - CONSOLE, - ANY -} \ No newline at end of file diff --git a/proxy/src/main/java/dev/plex/handlers/ListenerHandler.java b/proxy/src/main/java/dev/plex/handlers/ListenerHandler.java index c800324..dc1d9c0 100644 --- a/proxy/src/main/java/dev/plex/handlers/ListenerHandler.java +++ b/proxy/src/main/java/dev/plex/handlers/ListenerHandler.java @@ -1,7 +1,7 @@ package dev.plex.handlers; import com.google.common.collect.Lists; -import dev.plex.listener.PlexListener; +import dev.plex.listener.ProxyListener; import dev.plex.util.PlexLog; import dev.plex.util.ReflectionsUtil; import java.lang.reflect.InvocationTargetException; @@ -12,8 +12,8 @@ public class ListenerHandler { public ListenerHandler() { - Set> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", PlexListener.class); - List listeners = Lists.newArrayList(); + Set> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl", ProxyListener.class); + List listeners = Lists.newArrayList(); listenerSet.forEach(clazz -> { diff --git a/proxy/src/main/java/dev/plex/listener/PlexListener.java b/proxy/src/main/java/dev/plex/listener/ProxyListener.java similarity index 77% rename from proxy/src/main/java/dev/plex/listener/PlexListener.java rename to proxy/src/main/java/dev/plex/listener/ProxyListener.java index 5249aed..6b47d1d 100644 --- a/proxy/src/main/java/dev/plex/listener/PlexListener.java +++ b/proxy/src/main/java/dev/plex/listener/ProxyListener.java @@ -2,11 +2,11 @@ package dev.plex.listener; import dev.plex.Plex; -public class PlexListener +public class ProxyListener { protected final Plex plugin = Plex.get(); - public PlexListener() + public ProxyListener() { Plex.get().getServer().getEventManager().register(Plex.get(), this); } diff --git a/proxy/src/main/java/dev/plex/listener/impl/ConnectionListener.java b/proxy/src/main/java/dev/plex/listener/impl/ConnectionListener.java index e7a71aa..9d0edce 100644 --- a/proxy/src/main/java/dev/plex/listener/impl/ConnectionListener.java +++ b/proxy/src/main/java/dev/plex/listener/impl/ConnectionListener.java @@ -5,11 +5,11 @@ import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import dev.plex.Plex; -import dev.plex.listener.PlexListener; +import dev.plex.listener.ProxyListener; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; -public class ConnectionListener extends PlexListener +public class ConnectionListener extends ProxyListener { @Subscribe(order = PostOrder.FIRST) public void onPlayerJoin(ServerConnectedEvent event) diff --git a/proxy/src/main/java/dev/plex/listener/impl/ServerListener.java b/proxy/src/main/java/dev/plex/listener/impl/ServerListener.java index 7e9de8f..963c015 100644 --- a/proxy/src/main/java/dev/plex/listener/impl/ServerListener.java +++ b/proxy/src/main/java/dev/plex/listener/impl/ServerListener.java @@ -4,7 +4,7 @@ import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyPingEvent; import com.velocitypowered.api.proxy.server.ServerPing; -import dev.plex.listener.PlexListener; +import dev.plex.listener.ProxyListener; import dev.plex.settings.ServerSettings; import dev.plex.util.RandomUtil; import java.util.UUID; @@ -15,7 +15,7 @@ import java.util.regex.Pattern; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; -public class ServerListener extends PlexListener +public class ServerListener extends ProxyListener { @Subscribe(order = PostOrder.FIRST) public void onPing(ProxyPingEvent event) diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 19078fd..b7d51c1 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -19,6 +19,7 @@ repositories { } dependencies { + implementation(project(":api")) library("org.projectlombok:lombok:1.18.46") library("commons-io:commons-io:2.22.0") library("redis.clients:jedis:7.5.0") diff --git a/server/src/main/java/dev/plex/Plex.java b/server/src/main/java/dev/plex/Plex.java index 909b25e..1020501 100644 --- a/server/src/main/java/dev/plex/Plex.java +++ b/server/src/main/java/dev/plex/Plex.java @@ -1,7 +1,12 @@ package dev.plex; +import dev.plex.api.PlexApi; +import dev.plex.api.impl.DefaultPlexApi; import dev.plex.cache.PlayerCache; +import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.config.Config; +import dev.plex.config.ModuleConfig; import dev.plex.handlers.CommandHandler; import dev.plex.handlers.ListenerHandler; import dev.plex.hook.CoreProtectHook; @@ -45,6 +50,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Plex extends JavaPlugin { public static final BuildInfo build = new BuildInfo(); + public static final int MODULE_API_COMPATIBILITY_VERSION = 1; private static Plex plugin; public Config config; public Config messages; @@ -66,6 +72,7 @@ public class Plex extends JavaPlugin private ServiceManager serviceManager; private PunishmentManager punishmentManager; private UpdateChecker updateChecker; + private PlexApi api; private Permission permissions; private Chat chat; @@ -88,6 +95,8 @@ public class Plex extends JavaPlugin indefBans = new Config(this, "indefbans.yml"); toggles = new Config(this, "toggles.yml"); build.load(this); + api = new DefaultPlexApi(this, MODULE_API_COMPATIBILITY_VERSION); + installModuleApiRuntimes(); modulesFolder = new File(this.getDataFolder() + File.separator + "modules"); if (!modulesFolder.exists()) @@ -102,6 +111,57 @@ public class Plex extends JavaPlugin //this.setChatHandler(new ChatListener.ChatHandlerImpl()); } + private void installModuleApiRuntimes() + { + ServerCommand.setRuntime(new ServerCommand.Runtime() + { + @Override + public Plex plugin() + { + return Plex.this; + } + + @Override + public void register(org.bukkit.command.Command command) + { + api.commands().register(command); + } + }); + PlexCommand.setRuntime(new PlexCommand.Runtime() + { + @Override + public void register(org.bukkit.command.Command command) + { + api.commands().register(command); + } + + @Override + public net.kyori.adventure.text.Component messageComponent(String entry, Object... objects) + { + return api.messages().messageComponent(entry, objects); + } + + @Override + public net.kyori.adventure.text.Component messageComponent(String entry, net.kyori.adventure.text.Component... objects) + { + return api.messages().messageComponent(entry, objects); + } + + @Override + public String messageString(String entry, Object... objects) + { + return api.messages().messageString(entry, objects); + } + + @Override + public net.kyori.adventure.text.Component miniMessage(String input) + { + return api.messages().miniMessage(input); + } + }); + ModuleConfig.setFactory((module, from, to) -> api.moduleConfigs().create(module, from, to)); + } + @Override public void onEnable() { diff --git a/server/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java b/server/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java new file mode 100644 index 0000000..8a63512 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultApiCompatibility.java @@ -0,0 +1,19 @@ +package dev.plex.api.impl; + +import dev.plex.api.ApiCompatibility; + +final class DefaultApiCompatibility implements ApiCompatibility +{ + private final int version; + + DefaultApiCompatibility(int version) + { + this.version = version; + } + + @Override + public int version() + { + return version; + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultCommandApi.java b/server/src/main/java/dev/plex/api/impl/DefaultCommandApi.java new file mode 100644 index 0000000..bb665b7 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultCommandApi.java @@ -0,0 +1,28 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.command.CommandApi; +import org.bukkit.command.Command; + +final class DefaultCommandApi implements CommandApi +{ + private final Plex plugin; + + DefaultCommandApi(Plex plugin) { this.plugin = plugin; } + + @Override + public void register(Command command) + { + plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase()); + command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase())); + plugin.getServer().getCommandMap().register("plex", command); + } + + @Override + public void unregister(Command command) + { + plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName()); + command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias)); + command.unregister(plugin.getServer().getCommandMap()); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java b/server/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java new file mode 100644 index 0000000..02fb935 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultConfigurationApi.java @@ -0,0 +1,39 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.config.ConfigurationApi; +import dev.plex.api.config.PlexConfiguration; + +final class DefaultConfigurationApi implements ConfigurationApi +{ + private final Plex plugin; + + DefaultConfigurationApi(Plex plugin) + { + this.plugin = plugin; + } + + @Override + public PlexConfiguration mainConfig() + { + return new DefaultPlexConfiguration(plugin.config); + } + + @Override + public PlexConfiguration messages() + { + return new DefaultPlexConfiguration(plugin.messages); + } + + @Override + public PlexConfiguration indefiniteBans() + { + return new DefaultPlexConfiguration(plugin.indefBans); + } + + @Override + public PlexConfiguration toggles() + { + return new DefaultPlexConfiguration(plugin.toggles); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultIndefiniteBanView.java b/server/src/main/java/dev/plex/api/impl/DefaultIndefiniteBanView.java new file mode 100644 index 0000000..3d922ed --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultIndefiniteBanView.java @@ -0,0 +1,14 @@ +package dev.plex.api.impl; + +import dev.plex.api.punishment.IndefiniteBanView; +import dev.plex.punishment.PunishmentManager; +import java.util.List; +import java.util.UUID; + +record DefaultIndefiniteBanView(PunishmentManager.IndefiniteBan ban) implements IndefiniteBanView +{ + @Override public List usernames() { return List.copyOf(ban.getUsernames()); } + @Override public List uuids() { return List.copyOf(ban.getUuids()); } + @Override public List ips() { return List.copyOf(ban.getIps()); } + @Override public String reason() { return ban.getReason(); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultListenerApi.java b/server/src/main/java/dev/plex/api/impl/DefaultListenerApi.java new file mode 100644 index 0000000..e28d5b2 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultListenerApi.java @@ -0,0 +1,19 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.listener.ListenerApi; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + +final class DefaultListenerApi implements ListenerApi +{ + private final Plex plugin; + + DefaultListenerApi(Plex plugin) { this.plugin = plugin; } + + @Override + public void register(Listener listener) { plugin.getServer().getPluginManager().registerEvents(listener, plugin); } + + @Override + public void unregister(Listener listener) { HandlerList.unregisterAll(listener); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultLoggingApi.java b/server/src/main/java/dev/plex/api/impl/DefaultLoggingApi.java new file mode 100644 index 0000000..3e42c10 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultLoggingApi.java @@ -0,0 +1,12 @@ +package dev.plex.api.impl; + +import dev.plex.api.logging.LoggingApi; +import dev.plex.util.PlexLog; + +final class DefaultLoggingApi implements LoggingApi +{ + @Override public void info(String message, Object... args) { PlexLog.log(message, args); } + @Override public void debug(String message, Object... args) { PlexLog.debug(message, args); } + @Override public void warn(String message, Object... args) { PlexLog.warn(message, args); } + @Override public void error(String message, Object... args) { PlexLog.error(message, args); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultMessageApi.java b/server/src/main/java/dev/plex/api/impl/DefaultMessageApi.java new file mode 100644 index 0000000..619a4d4 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultMessageApi.java @@ -0,0 +1,17 @@ +package dev.plex.api.impl; + +import dev.plex.api.message.MessageApi; +import dev.plex.util.PlexUtils; +import java.util.List; +import net.kyori.adventure.text.Component; + +final class DefaultMessageApi implements MessageApi +{ + @Override public Component messageComponent(String entry, Object... objects) { return PlexUtils.messageComponent(entry, objects); } + @Override public Component messageComponent(String entry, Component... objects) { return PlexUtils.messageComponent(entry, objects); } + @Override public String messageString(String entry, Object... objects) { return PlexUtils.messageString(entry, objects); } + @Override public Component miniMessage(String input) { return PlexUtils.mmDeserialize(input); } + @Override public void broadcast(String miniMessage) { PlexUtils.broadcast(miniMessage); } + @Override public void broadcast(Component component) { PlexUtils.broadcast(component); } + @Override public List onlinePlayerNames() { return PlexUtils.getPlayerNameList(); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultModuleConfigApi.java b/server/src/main/java/dev/plex/api/impl/DefaultModuleConfigApi.java new file mode 100644 index 0000000..ca75d0d --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultModuleConfigApi.java @@ -0,0 +1,14 @@ +package dev.plex.api.impl; + +import dev.plex.api.config.ModuleConfigApi; +import dev.plex.api.config.ModuleConfiguration; +import dev.plex.module.PlexModule; + +final class DefaultModuleConfigApi implements ModuleConfigApi +{ + @Override + public ModuleConfiguration create(PlexModule module, String from, String to) + { + return new ServerModuleConfiguration(module, from, to); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultModulesApi.java b/server/src/main/java/dev/plex/api/impl/DefaultModulesApi.java new file mode 100644 index 0000000..321dade --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultModulesApi.java @@ -0,0 +1,36 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.module.ModulesApi; +import dev.plex.module.PlexModuleFile; + +import java.util.Collection; +import java.util.Locale; +import java.util.Optional; + +final class DefaultModulesApi implements ModulesApi +{ + private final Plex plugin; + + DefaultModulesApi(Plex plugin) + { + this.plugin = plugin; + } + + @Override + public Collection loadedModules() + { + return plugin.getModuleManager().getModules().stream() + .map(module -> module.getPlexModuleFile()) + .toList(); + } + + @Override + public Optional module(String name) + { + String normalizedName = name.toLowerCase(Locale.ROOT); + return loadedModules().stream() + .filter(module -> module.getName().toLowerCase(Locale.ROOT).equals(normalizedName)) + .findFirst(); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPlayersApi.java b/server/src/main/java/dev/plex/api/impl/DefaultPlayersApi.java new file mode 100644 index 0000000..49c3ab3 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPlayersApi.java @@ -0,0 +1,27 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.player.PlayersApi; +import dev.plex.api.player.PlexPlayerView; +import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexUtils; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +final class DefaultPlayersApi implements PlayersApi +{ + private final Plex plugin; + + DefaultPlayersApi(Plex plugin) { this.plugin = plugin; } + + @Override public Optional byUuid(UUID uuid) { return Optional.ofNullable(plugin.getPlayerService().getPlayer(uuid)).map(DefaultPlexPlayerView::new); } + @Override public Optional byName(String name) { return Optional.ofNullable(plugin.getPlayerService().getPlayer(name)).map(DefaultPlexPlayerView::new); } + @Override public List onlineNames() { return PlexUtils.getPlayerNameList(); } + + static PlexPlayer unwrap(PlexPlayerView view) + { + if (view instanceof DefaultPlexPlayerView wrapped) return wrapped.player(); + return null; + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPlexApi.java b/server/src/main/java/dev/plex/api/impl/DefaultPlexApi.java new file mode 100644 index 0000000..33e3555 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPlexApi.java @@ -0,0 +1,61 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.ApiCompatibility; +import dev.plex.api.PlexApi; +import dev.plex.api.command.CommandApi; +import dev.plex.api.config.ConfigurationApi; +import dev.plex.api.config.ModuleConfigApi; +import dev.plex.api.listener.ListenerApi; +import dev.plex.api.logging.LoggingApi; +import dev.plex.api.message.MessageApi; +import dev.plex.api.module.ModulesApi; +import dev.plex.api.player.PlayersApi; +import dev.plex.api.punishment.PunishmentsApi; +import dev.plex.api.scheduler.SchedulerApi; +import dev.plex.api.storage.StorageApi; + +public final class DefaultPlexApi implements PlexApi +{ + private final ApiCompatibility compatibility; + private final ConfigurationApi configuration; + private final ModulesApi modules; + private final CommandApi commands; + private final ListenerApi listeners; + private final ModuleConfigApi moduleConfigs; + private final LoggingApi logging; + private final MessageApi messages; + private final PlayersApi players; + private final PunishmentsApi punishments; + private final SchedulerApi scheduler; + private final StorageApi storage; + + public DefaultPlexApi(Plex plugin, int apiCompatibilityVersion) + { + this.compatibility = new DefaultApiCompatibility(apiCompatibilityVersion); + this.configuration = new DefaultConfigurationApi(plugin); + this.modules = new DefaultModulesApi(plugin); + this.commands = new DefaultCommandApi(plugin); + this.listeners = new DefaultListenerApi(plugin); + this.moduleConfigs = new DefaultModuleConfigApi(); + this.logging = new DefaultLoggingApi(); + this.messages = new DefaultMessageApi(); + this.players = new DefaultPlayersApi(plugin); + this.punishments = new DefaultPunishmentsApi(plugin); + this.scheduler = new DefaultSchedulerApi(plugin); + this.storage = new DefaultStorageApi(plugin); + } + + @Override public ApiCompatibility compatibility() { return compatibility; } + @Override public ConfigurationApi configuration() { return configuration; } + @Override public ModulesApi modules() { return modules; } + @Override public CommandApi commands() { return commands; } + @Override public ListenerApi listeners() { return listeners; } + @Override public ModuleConfigApi moduleConfigs() { return moduleConfigs; } + @Override public LoggingApi logging() { return logging; } + @Override public MessageApi messages() { return messages; } + @Override public PlayersApi players() { return players; } + @Override public PunishmentsApi punishments() { return punishments; } + @Override public SchedulerApi scheduler() { return scheduler; } + @Override public StorageApi storage() { return storage; } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java b/server/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java new file mode 100644 index 0000000..e9bb6ff --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPlexConfiguration.java @@ -0,0 +1,58 @@ +package dev.plex.api.impl; + +import dev.plex.api.config.PlexConfiguration; +import dev.plex.config.Config; + +import java.util.List; + +final class DefaultPlexConfiguration implements PlexConfiguration +{ + private final Config config; + + DefaultPlexConfiguration(Config config) + { + this.config = config; + } + + @Override + public String getString(String path) + { + return config.getString(path); + } + + @Override + public boolean getBoolean(String path) + { + return config.getBoolean(path); + } + + @Override + public int getInt(String path) + { + return config.getInt(path); + } + + @Override + public List getStringList(String path) + { + return config.getStringList(path); + } + + @Override + public void set(String path, Object value) + { + config.set(path, value); + } + + @Override + public void setComments(String path, List comments) + { + config.setComments(path, comments); + } + + @Override + public void save() + { + config.save(); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPlexPlayerView.java b/server/src/main/java/dev/plex/api/impl/DefaultPlexPlayerView.java new file mode 100644 index 0000000..3760d03 --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPlexPlayerView.java @@ -0,0 +1,20 @@ +package dev.plex.api.impl; + +import dev.plex.api.player.PlexPlayerView; +import dev.plex.api.punishment.PunishmentView; +import dev.plex.player.PlexPlayer; +import java.util.List; +import java.util.UUID; +import org.bukkit.entity.Player; + +record DefaultPlexPlayerView(PlexPlayer player) implements PlexPlayerView +{ + @Override public UUID uuid() { return player.getUuid(); } + @Override public String name() { return player.getName(); } + @Override public List ips() { return List.copyOf(player.getIps()); } + @Override public List punishments() { return player.getPunishments().stream().map(DefaultPunishmentView::new).toList(); } + @Override public boolean frozen() { return player.isFrozen(); } + @Override public boolean muted() { return player.isMuted(); } + @Override public boolean lockedUp() { return player.isLockedUp(); } + @Override public Player bukkitPlayer() { return player.getPlayer(); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPunishmentView.java b/server/src/main/java/dev/plex/api/impl/DefaultPunishmentView.java new file mode 100644 index 0000000..d94fddd --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPunishmentView.java @@ -0,0 +1,22 @@ +package dev.plex.api.impl; + +import dev.plex.api.punishment.PunishmentType; +import dev.plex.api.punishment.PunishmentView; +import dev.plex.punishment.Punishment; +import java.time.ZonedDateTime; +import java.util.UUID; + +record DefaultPunishmentView(Punishment punishment) implements PunishmentView +{ + @Override public UUID punished() { return punishment.getPunished(); } + @Override public UUID punisher() { return punishment.getPunisher(); } + @Override public String punisherName() { return punishment.getPunisherName(); } + @Override public String ip() { return punishment.getIp(); } + @Override public String punishedUsername() { return punishment.getPunishedUsername(); } + @Override public PunishmentType type() { return PunishmentType.valueOf(punishment.getType().name()); } + @Override public String reason() { return punishment.getReason(); } + @Override public boolean customTime() { return punishment.isCustomTime(); } + @Override public boolean active() { return punishment.isActive(); } + @Override public ZonedDateTime issueDate() { return punishment.getIssueDate(); } + @Override public ZonedDateTime endDate() { return punishment.getEndDate(); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultPunishmentsApi.java b/server/src/main/java/dev/plex/api/impl/DefaultPunishmentsApi.java new file mode 100644 index 0000000..fd2f84f --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultPunishmentsApi.java @@ -0,0 +1,40 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.player.PlexPlayerView; +import dev.plex.api.punishment.IndefiniteBanView; +import dev.plex.api.punishment.PunishmentRequest; +import dev.plex.api.punishment.PunishmentsApi; +import dev.plex.player.PlexPlayer; +import dev.plex.punishment.Punishment; +import dev.plex.punishment.PunishmentType; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +final class DefaultPunishmentsApi implements PunishmentsApi +{ + private final Plex plugin; + + DefaultPunishmentsApi(Plex plugin) { this.plugin = plugin; } + + @Override public List indefiniteBans() { return plugin.getPunishmentManager().getIndefiniteBans().stream().map(DefaultIndefiniteBanView::new).toList(); } + @Override public Optional indefiniteBanByUuid(UUID uuid) { return Optional.ofNullable(plugin.getPunishmentManager().getIndefiniteBanByUUID(uuid)).map(DefaultIndefiniteBanView::new); } + + @Override + public void punish(PlexPlayerView playerView, PunishmentRequest request) + { + PlexPlayer player = DefaultPlayersApi.unwrap(playerView); + if (player == null) player = plugin.getPlayerService().getPlayer(playerView.uuid()); + Punishment punishment = new Punishment(request.punished(), request.punisher()); + punishment.setPunisherName(request.punisherName()); + punishment.setIp(request.ip()); + punishment.setPunishedUsername(request.punishedUsername()); + punishment.setType(PunishmentType.valueOf(request.type().name())); + punishment.setReason(request.reason()); + punishment.setCustomTime(request.customTime()); + punishment.setActive(request.active()); + punishment.setEndDate(request.endDate()); + plugin.getPunishmentManager().punish(player, punishment); + } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultSchedulerApi.java b/server/src/main/java/dev/plex/api/impl/DefaultSchedulerApi.java new file mode 100644 index 0000000..fe7d53f --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultSchedulerApi.java @@ -0,0 +1,15 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.scheduler.SchedulerApi; + +final class DefaultSchedulerApi implements SchedulerApi +{ + private final Plex plugin; + + DefaultSchedulerApi(Plex plugin) { this.plugin = plugin; } + + @Override public Object runSync(Runnable task) { return plugin.getServer().getScheduler().runTask(plugin, task); } + @Override public Object runLater(Runnable task, long delayTicks) { return plugin.getServer().getScheduler().runTaskLater(plugin, task, delayTicks); } + @Override public Object runTimer(Runnable task, long delayTicks, long periodTicks) { return plugin.getServer().getScheduler().runTaskTimer(plugin, task, delayTicks, periodTicks); } +} diff --git a/server/src/main/java/dev/plex/api/impl/DefaultStorageApi.java b/server/src/main/java/dev/plex/api/impl/DefaultStorageApi.java new file mode 100644 index 0000000..1de916a --- /dev/null +++ b/server/src/main/java/dev/plex/api/impl/DefaultStorageApi.java @@ -0,0 +1,22 @@ +package dev.plex.api.impl; + +import dev.plex.Plex; +import dev.plex.api.storage.StorageApi; +import java.sql.Connection; +import java.sql.SQLException; + +final class DefaultStorageApi implements StorageApi +{ + private final Plex plugin; + + DefaultStorageApi(Plex plugin) { this.plugin = plugin; } + + @Override + public T withConnection(SqlFunction function) throws SQLException + { + try (Connection connection = plugin.getSqlConnection().getCon()) + { + return function.apply(connection); + } + } +} diff --git a/server/src/main/java/dev/plex/config/ModuleConfig.java b/server/src/main/java/dev/plex/api/impl/ServerModuleConfiguration.java similarity index 56% rename from server/src/main/java/dev/plex/config/ModuleConfig.java rename to server/src/main/java/dev/plex/api/impl/ServerModuleConfiguration.java index 8993477..64eee25 100644 --- a/server/src/main/java/dev/plex/config/ModuleConfig.java +++ b/server/src/main/java/dev/plex/api/impl/ServerModuleConfiguration.java @@ -1,60 +1,32 @@ -package dev.plex.config; +package dev.plex.api.impl; +import dev.plex.api.config.ModuleConfiguration; +import dev.plex.config.ConfigDefaultsMerger; import dev.plex.module.PlexModule; import dev.plex.util.PlexLog; - import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; - import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -/** - * Creates a custom Config object - */ -public class ModuleConfig extends YamlConfiguration +final class ServerModuleConfiguration extends ModuleConfiguration { - /** - * The plugin instance - */ private final PlexModule module; - - /** - * The File instance - */ private final File file; - - /** - * Where the file is in the module JAR - */ private final String from; - - /** - * Where it should be copied to in the module folder - */ private final String to; - /** - * Creates a config object - * - * @param module The module instance - * @param to The file name - */ - public ModuleConfig(PlexModule module, String from, String to) + ServerModuleConfiguration(PlexModule module, String from, String to) { this.module = module; this.file = new File(module.getDataFolder(), to); - this.to = to; this.from = from; - - if (!file.exists()) - { - saveDefault(); - } + this.to = to; + if (!file.exists()) saveDefault(); } + @Override public void load() { try @@ -64,8 +36,7 @@ public class ModuleConfig extends YamlConfiguration { PlexLog.log("Merged default key(s) into " + to + ": " + String.join(", ", result.addedKeys())); } - - this.options().parseComments(true); + options().parseComments(true); super.load(file); } catch (IOException | InvalidConfigurationException ex) @@ -74,33 +45,18 @@ public class ModuleConfig extends YamlConfiguration } } - /** - * Saves the configuration file - */ + @Override public void save() { - try - { - super.save(file); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + try { super.save(file); } catch (IOException ex) { ex.printStackTrace(); } } - /** - * Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/) - */ private void saveDefault() { try { File parent = file.getParentFile(); - if (parent != null) - { - parent.mkdirs(); - } + if (parent != null) parent.mkdirs(); try (InputStream stream = module.getClass().getResourceAsStream("/" + from)) { if (stream == null) @@ -108,12 +64,12 @@ public class ModuleConfig extends YamlConfiguration PlexLog.warn("Unable to save default module config " + to + ": missing resource " + from); return; } - Files.copy(stream, this.file.toPath()); + Files.copy(stream, file.toPath()); } } - catch (IOException e) + catch (IOException ex) { - e.printStackTrace(); + ex.printStackTrace(); } } } diff --git a/server/src/main/java/dev/plex/command/PlexCommand.java b/server/src/main/java/dev/plex/command/ServerCommand.java similarity index 90% rename from server/src/main/java/dev/plex/command/PlexCommand.java rename to server/src/main/java/dev/plex/command/ServerCommand.java index 96aea01..02f82d6 100644 --- a/server/src/main/java/dev/plex/command/PlexCommand.java +++ b/server/src/main/java/dev/plex/command/ServerCommand.java @@ -35,10 +35,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * Superclass for all commands + * Superclass for all server commands. */ -public abstract class PlexCommand extends Command implements PluginIdentifiableCommand +public abstract class ServerCommand extends Command implements PluginIdentifiableCommand { + private static Runtime runtime; + /** * Returns the instance of the plugin */ @@ -59,13 +61,18 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC */ private final RequiredCommandSource commandSource; + public static void setRuntime(Runtime runtime) + { + ServerCommand.runtime = runtime; + } + /** * Creates an instance of the command */ - public PlexCommand(boolean register) + public ServerCommand(boolean register) { super(""); - this.plugin = Plex.get(); + this.plugin = requireRuntime().plugin(); this.params = getClass().getAnnotation(CommandParameters.class); this.perms = getClass().getAnnotation(CommandPermissions.class); @@ -82,16 +89,11 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC if (register) { - getMap().getKnownCommands().remove(this.getName().toLowerCase()); - this.getAliases().forEach(s -> - { - getMap().getKnownCommands().remove(s.toLowerCase()); - }); - getMap().register("plex", this); + requireRuntime().register(this); } } - public PlexCommand() + public ServerCommand() { this(true); } @@ -480,4 +482,40 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { return plugin.getServer().getCommandMap(); } + + private static Runtime requireRuntime() + { + if (runtime == null) + { + Plex plex = Plex.get(); + if (plex == null) + { + throw new IllegalStateException("ServerCommand runtime has not been installed by Plex"); + } + return new Runtime() + { + @Override + public Plex plugin() + { + return plex; + } + + @Override + public void register(Command command) + { + plex.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase()); + command.getAliases().forEach(alias -> plex.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase())); + plex.getServer().getCommandMap().register("plex", command); + } + }; + } + return runtime; + } + + public interface Runtime + { + Plex plugin(); + + void register(Command command); + } } diff --git a/server/src/main/java/dev/plex/command/annotation/CommandParameters.java b/server/src/main/java/dev/plex/command/annotation/CommandParameters.java deleted file mode 100644 index fa5d6a2..0000000 --- a/server/src/main/java/dev/plex/command/annotation/CommandParameters.java +++ /dev/null @@ -1,39 +0,0 @@ -package dev.plex.command.annotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Storage for a command's parameters - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface CommandParameters -{ - /** - * The name - * - * @return Name of the command - */ - String name(); - - /** - * The description - * - * @return Description of the command - */ - String description() default ""; - - /** - * The usage (optional) - * - * @return The usage of the command - */ - String usage() default "/"; - - /** - * The aliases (optional) - * - * @return The aliases of the command - */ - String aliases() default ""; -} \ No newline at end of file diff --git a/server/src/main/java/dev/plex/command/annotation/CommandPermissions.java b/server/src/main/java/dev/plex/command/annotation/CommandPermissions.java deleted file mode 100644 index 1738d6f..0000000 --- a/server/src/main/java/dev/plex/command/annotation/CommandPermissions.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.plex.command.annotation; - -import dev.plex.command.source.RequiredCommandSource; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Storage for the command's permissions - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface CommandPermissions -{ - /** - * Required command source - * - * @return The required command source of the command - * @see RequiredCommandSource - */ - RequiredCommandSource source() default RequiredCommandSource.ANY; - - /** - * The permission - * - * @return Permission of the command - */ - String permission() default ""; // No idea what to put here -} \ No newline at end of file diff --git a/server/src/main/java/dev/plex/command/exception/CommandFailException.java b/server/src/main/java/dev/plex/command/exception/CommandFailException.java deleted file mode 100644 index 5c3c65c..0000000 --- a/server/src/main/java/dev/plex/command/exception/CommandFailException.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.plex.command.exception; - -public class CommandFailException extends RuntimeException // this is literally just a runtime exception lol -{ - public CommandFailException(String s) - { - super(s); - } -} \ No newline at end of file diff --git a/server/src/main/java/dev/plex/command/impl/AdminChatCMD.java b/server/src/main/java/dev/plex/command/impl/AdminChatCMD.java index 19790e2..e0667f0 100644 --- a/server/src/main/java/dev/plex/command/impl/AdminChatCMD.java +++ b/server/src/main/java/dev/plex/command/impl/AdminChatCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY) @CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/ ", aliases = "o,ac,sc,staffchat") -public class AdminChatCMD extends PlexCommand +public class AdminChatCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/AdminworldCMD.java b/server/src/main/java/dev/plex/command/impl/AdminworldCMD.java index b696b8d..10b46a6 100644 --- a/server/src/main/java/dev/plex/command/impl/AdminworldCMD.java +++ b/server/src/main/java/dev/plex/command/impl/AdminworldCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME) @CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld") -public class AdminworldCMD extends PlexCommand +public class AdminworldCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/AdventureCMD.java b/server/src/main/java/dev/plex/command/impl/AdventureCMD.java index 42143af..6c38216 100644 --- a/server/src/main/java/dev/plex/command/impl/AdventureCMD.java +++ b/server/src/main/java/dev/plex/command/impl/AdventureCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY) @CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode") -public class AdventureCMD extends PlexCommand +public class AdventureCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/BanCMD.java b/server/src/main/java/dev/plex/command/impl/BanCMD.java index 7b5b933..0af1099 100644 --- a/server/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/server/src/main/java/dev/plex/command/impl/BanCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; @@ -35,7 +35,7 @@ import org.prism_mc.prism.paper.api.activities.PaperActivityQuery; @CommandParameters(name = "ban", usage = "/ [reason] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online") @CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY) -public class BanCMD extends PlexCommand +public class BanCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/BanListCommand.java b/server/src/main/java/dev/plex/command/impl/BanListCommand.java index e8a0078..011859d 100755 --- a/server/src/main/java/dev/plex/command/impl/BanListCommand.java +++ b/server/src/main/java/dev/plex/command/impl/BanListCommand.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.punishment.Punishment; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/ [purge]") @CommandPermissions(permission = "plex.banlist") -public class BanListCommand extends PlexCommand +public class BanListCommand extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/BcastLoginMessageCMD.java b/server/src/main/java/dev/plex/command/impl/BcastLoginMessageCMD.java index 75ca011..c23a80a 100644 --- a/server/src/main/java/dev/plex/command/impl/BcastLoginMessageCMD.java +++ b/server/src/main/java/dev/plex/command/impl/BcastLoginMessageCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.broadcastloginmessage", source = RequiredCommandSource.ANY) @CommandParameters(name = "bcastloginmessage", usage = "/ ", description = "Broadcast your login message (for vanish support)", aliases = "bcastlm") -public class BcastLoginMessageCMD extends PlexCommand +public class BcastLoginMessageCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/BlockEditCMD.java b/server/src/main/java/dev/plex/command/impl/BlockEditCMD.java index 4b922e8..13debcd 100644 --- a/server/src/main/java/dev/plex/command/impl/BlockEditCMD.java +++ b/server/src/main/java/dev/plex/command/impl/BlockEditCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.listener.impl.BlockListener; @@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.blockedit") @CommandParameters(name = "blockedit", usage = "/ [list | purge | all | ]", aliases = "bedit", description = "Prevent players from modifying blocks") -public class BlockEditCMD extends PlexCommand +public class BlockEditCMD extends ServerCommand { private final BlockListener bl = new BlockListener(); diff --git a/server/src/main/java/dev/plex/command/impl/CommandSpyCMD.java b/server/src/main/java/dev/plex/command/impl/CommandSpyCMD.java index 849aae5..874a96a 100644 --- a/server/src/main/java/dev/plex/command/impl/CommandSpyCMD.java +++ b/server/src/main/java/dev/plex/command/impl/CommandSpyCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME) @CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands") -public class CommandSpyCMD extends PlexCommand +public class CommandSpyCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/ConsoleSayCMD.java b/server/src/main/java/dev/plex/command/impl/ConsoleSayCMD.java index de818d4..7b4235d 100644 --- a/server/src/main/java/dev/plex/command/impl/ConsoleSayCMD.java +++ b/server/src/main/java/dev/plex/command/impl/ConsoleSayCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE) @CommandParameters(name = "consolesay", usage = "/ ", description = "Displays a message to everyone", aliases = "csay") -public class ConsoleSayCMD extends PlexCommand +public class ConsoleSayCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/CreativeCMD.java b/server/src/main/java/dev/plex/command/impl/CreativeCMD.java index 64ef428..db1b3ff 100644 --- a/server/src/main/java/dev/plex/command/impl/CreativeCMD.java +++ b/server/src/main/java/dev/plex/command/impl/CreativeCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY) @CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode") -public class CreativeCMD extends PlexCommand +public class CreativeCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/DebugCMD.java b/server/src/main/java/dev/plex/command/impl/DebugCMD.java index 6683a65..52b6ff5 100644 --- a/server/src/main/java/dev/plex/command/impl/DebugCMD.java +++ b/server/src/main/java/dev/plex/command/impl/DebugCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.menu.impl.MaterialMenu; @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/ | redis-reset | gamerules>") @CommandPermissions(permission = "plex.debug") -public class DebugCMD extends PlexCommand +public class DebugCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index 40a1b5b..85a5c28 100644 --- a/server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/server/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY) @CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/ [entity] [radius]", aliases = "ew,rd") -public class EntityWipeCMD extends PlexCommand +public class EntityWipeCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java b/server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java index bc6b737..2a9c2ce 100644 --- a/server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java +++ b/server/src/main/java/dev/plex/command/impl/FlatlandsCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME) @CommandParameters(name = "flatlands", description = "Teleport to the flatlands") -public class FlatlandsCMD extends PlexCommand +public class FlatlandsCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/FreezeCMD.java b/server/src/main/java/dev/plex/command/impl/FreezeCMD.java index 11d9e95..3b07eb1 100644 --- a/server/src/main/java/dev/plex/command/impl/FreezeCMD.java +++ b/server/src/main/java/dev/plex/command/impl/FreezeCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.player.PlexPlayer; @@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/ ", aliases = "fr") @CommandPermissions(permission = "plex.freeze") -public class FreezeCMD extends PlexCommand +public class FreezeCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/GamemodeCMD.java b/server/src/main/java/dev/plex/command/impl/GamemodeCMD.java index 38e245e..47e286d 100644 --- a/server/src/main/java/dev/plex/command/impl/GamemodeCMD.java +++ b/server/src/main/java/dev/plex/command/impl/GamemodeCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "gamemode", usage = "/ [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt") @CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY) -public class GamemodeCMD extends PlexCommand +public class GamemodeCMD extends ServerCommand { private GameMode gamemode; diff --git a/server/src/main/java/dev/plex/command/impl/KickCMD.java b/server/src/main/java/dev/plex/command/impl/KickCMD.java index 2842bd0..280f749 100644 --- a/server/src/main/java/dev/plex/command/impl/KickCMD.java +++ b/server/src/main/java/dev/plex/command/impl/KickCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "kick", description = "Kicks a player", usage = "/ ") @CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY) -public class KickCMD extends PlexCommand +public class KickCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/ListCMD.java b/server/src/main/java/dev/plex/command/impl/ListCMD.java index f270ac0..9a7eaf8 100644 --- a/server/src/main/java/dev/plex/command/impl/ListCMD.java +++ b/server/src/main/java/dev/plex/command/impl/ListCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.Lists; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.hook.VaultHook; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "list", description = "Show a list of all online players", usage = "/ [-d | -v]", aliases = "lsit,who,playerlist,online") @CommandPermissions(permission = "plex.list") -public class ListCMD extends PlexCommand +public class ListCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java b/server/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java index 4c06737..1e74fbc 100644 --- a/server/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java +++ b/server/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in") @CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME) -public class LocalSpawnCMD extends PlexCommand +public class LocalSpawnCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/LockupCMD.java b/server/src/main/java/dev/plex/command/impl/LockupCMD.java index 9d532d4..185ae37 100644 --- a/server/src/main/java/dev/plex/command/impl/LockupCMD.java +++ b/server/src/main/java/dev/plex/command/impl/LockupCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.player.PlexPlayer; @@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/ ") @CommandPermissions(permission = "plex.lockup") -public class LockupCMD extends PlexCommand +public class LockupCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java b/server/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java index 41d4fe2..69acee1 100644 --- a/server/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java +++ b/server/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME) @CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world") -public class MasterbuilderworldCMD extends PlexCommand +public class MasterbuilderworldCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/MobLimitCMD.java b/server/src/main/java/dev/plex/command/impl/MobLimitCMD.java index 019e432..5ba149e 100644 --- a/server/src/main/java/dev/plex/command/impl/MobLimitCMD.java +++ b/server/src/main/java/dev/plex/command/impl/MobLimitCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "moblimit", usage = "/ [on | off | setmax ]", aliases = "entitylimit", description = "Manages the mob limit per chunk.") @CommandPermissions(permission = "plex.moblimit", source = RequiredCommandSource.ANY) -public class MobLimitCMD extends PlexCommand +public class MobLimitCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java b/server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java index 77726b6..7fc7c94 100644 --- a/server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java +++ b/server/src/main/java/dev/plex/command/impl/MobPurgeCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY) @CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/ [mob]", aliases = "mp") -public class MobPurgeCMD extends PlexCommand +public class MobPurgeCMD extends ServerCommand { private final List MOB_TYPES = new ArrayList<>(); diff --git a/server/src/main/java/dev/plex/command/impl/MuteCMD.java b/server/src/main/java/dev/plex/command/impl/MuteCMD.java index 23e6e17..75ce43b 100644 --- a/server/src/main/java/dev/plex/command/impl/MuteCMD.java +++ b/server/src/main/java/dev/plex/command/impl/MuteCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.player.PlexPlayer; @@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/ ", aliases = "stfu") @CommandPermissions(permission = "plex.mute") -public class MuteCMD extends PlexCommand +public class MuteCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/NotesCMD.java b/server/src/main/java/dev/plex/command/impl/NotesCMD.java index eed498d..b5dcbcd 100644 --- a/server/src/main/java/dev/plex/command/impl/NotesCMD.java +++ b/server/src/main/java/dev/plex/command/impl/NotesCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.player.PlexPlayer; @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/ | remove | clear>") @CommandPermissions(permission = "plex.notes") -public class NotesCMD extends PlexCommand +public class NotesCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/PlexCMD.java b/server/src/main/java/dev/plex/command/impl/PlexCMD.java index 95b69b5..4c0d057 100644 --- a/server/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/server/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(source = RequiredCommandSource.ANY) @CommandParameters(name = "plex", usage = "/ [reload | redis | modules [reload]]", description = "Show information about Plex or reload it") -public class PlexCMD extends PlexCommand +public class PlexCMD extends ServerCommand { // Don't modify this command @Override diff --git a/server/src/main/java/dev/plex/command/impl/PunishmentsCMD.java b/server/src/main/java/dev/plex/command/impl/PunishmentsCMD.java index 62d074e..d98276c 100644 --- a/server/src/main/java/dev/plex/command/impl/PunishmentsCMD.java +++ b/server/src/main/java/dev/plex/command/impl/PunishmentsCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "punishments", usage = "/ [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes") @CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME) -public class PunishmentsCMD extends PlexCommand +public class PunishmentsCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/RawSayCMD.java b/server/src/main/java/dev/plex/command/impl/RawSayCMD.java index 90a7723..68ecbbd 100644 --- a/server/src/main/java/dev/plex/command/impl/RawSayCMD.java +++ b/server/src/main/java/dev/plex/command/impl/RawSayCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY) @CommandParameters(name = "rawsay", usage = "/ ", description = "Displays a raw message to everyone") -public class RawSayCMD extends PlexCommand +public class RawSayCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/RemoveLoginMessageCMD.java b/server/src/main/java/dev/plex/command/impl/RemoveLoginMessageCMD.java index 91afc0f..9fc34f6 100644 --- a/server/src/main/java/dev/plex/command/impl/RemoveLoginMessageCMD.java +++ b/server/src/main/java/dev/plex/command/impl/RemoveLoginMessageCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY) @CommandParameters(name = "removeloginmessage", usage = "/ [-o ]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg") -public class RemoveLoginMessageCMD extends PlexCommand +public class RemoveLoginMessageCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/SayCMD.java b/server/src/main/java/dev/plex/command/impl/SayCMD.java index 5e4a73a..f341d18 100644 --- a/server/src/main/java/dev/plex/command/impl/SayCMD.java +++ b/server/src/main/java/dev/plex/command/impl/SayCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY) @CommandParameters(name = "say", usage = "/ ", description = "Displays a message to everyone") -public class SayCMD extends PlexCommand +public class SayCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/SetLoginMessageCMD.java b/server/src/main/java/dev/plex/command/impl/SetLoginMessageCMD.java index fffecad..e0afcc4 100644 --- a/server/src/main/java/dev/plex/command/impl/SetLoginMessageCMD.java +++ b/server/src/main/java/dev/plex/command/impl/SetLoginMessageCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY) @CommandParameters(name = "setloginmessage", usage = "/ [-o ] ", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg") -public class SetLoginMessageCMD extends PlexCommand +public class SetLoginMessageCMD extends ServerCommand { private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name"); diff --git a/server/src/main/java/dev/plex/command/impl/SmiteCMD.java b/server/src/main/java/dev/plex/command/impl/SmiteCMD.java index 6db6a46..bb4e620 100644 --- a/server/src/main/java/dev/plex/command/impl/SmiteCMD.java +++ b/server/src/main/java/dev/plex/command/impl/SmiteCMD.java @@ -1,6 +1,6 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY) @CommandParameters(name = "smite", usage = "/ [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...") -public class SmiteCMD extends PlexCommand +public class SmiteCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/SpectatorCMD.java b/server/src/main/java/dev/plex/command/impl/SpectatorCMD.java index 708ae6f..6f82f74 100644 --- a/server/src/main/java/dev/plex/command/impl/SpectatorCMD.java +++ b/server/src/main/java/dev/plex/command/impl/SpectatorCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY) @CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode") -public class SpectatorCMD extends PlexCommand +public class SpectatorCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/SurvivalCMD.java b/server/src/main/java/dev/plex/command/impl/SurvivalCMD.java index 47435e4..0c05390 100644 --- a/server/src/main/java/dev/plex/command/impl/SurvivalCMD.java +++ b/server/src/main/java/dev/plex/command/impl/SurvivalCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.CommandFailException; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY) @CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode") -public class SurvivalCMD extends PlexCommand +public class SurvivalCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/TagCMD.java b/server/src/main/java/dev/plex/command/impl/TagCMD.java index 7a96bb2..d81b880 100644 --- a/server/src/main/java/dev/plex/command/impl/TagCMD.java +++ b/server/src/main/java/dev/plex/command/impl/TagCMD.java @@ -1,7 +1,7 @@ package dev.plex.command.impl; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; @CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY) @CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/ | clear >") -public class TagCMD extends PlexCommand +public class TagCMD extends ServerCommand { @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) diff --git a/server/src/main/java/dev/plex/command/impl/TempbanCMD.java b/server/src/main/java/dev/plex/command/impl/TempbanCMD.java index 010b9f4..b8baadf 100644 --- a/server/src/main/java/dev/plex/command/impl/TempbanCMD.java +++ b/server/src/main/java/dev/plex/command/impl/TempbanCMD.java @@ -2,7 +2,7 @@ package dev.plex.command.impl; import com.google.common.collect.ImmutableList; -import dev.plex.command.PlexCommand; +import dev.plex.command.ServerCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; @@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "tempban", usage = "/