-
-
Notifications
You must be signed in to change notification settings - Fork 1
GH-87 Complete project overhaul — Architecture, Performance, Scheduling, Messaging, Configuration #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
GH-87 Complete project overhaul — Architecture, Performance, Scheduling, Messaging, Configuration #87
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b365dcb
refactor: complete system overhaul (architecture, performance, messag…
imDMK 18a37b3
Update gradle.yml to use JDK 21 version.
imDMK 9740381
Correct gradlew file.
imDMK a36fb28
Update automessage-core/src/main/java/com/github/imdmk/automessage/sc…
imDMK d0b8acd
Update automessage-core/src/main/java/com/github/imdmk/automessage/sc…
imDMK 2b26171
Update automessage-core/src/main/java/com/github/imdmk/automessage/co…
imDMK a462728
Update automessage-core/src/main/java/com/github/imdmk/automessage/pl…
imDMK 1053cf1
Update automessage-core/src/main/java/com/github/imdmk/automessage/pl…
imDMK 233cbf4
Update automessage-core/src/main/java/com/github/imdmk/automessage/co…
imDMK b884d09
Improve ReloadCommand nad DispatcherCommands.
imDMK 1ac962a
Add Config tests, improve ConfigManager, add Javadocs.
imDMK 14e2a5c
Improve config documentation.
imDMK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| dependencies { | ||
| compileOnlyApi("org.spigotmc:spigot-api:1.21.10-R0.1-SNAPSHOT") | ||
|
|
||
| implementation("net.kyori:adventure-platform-bukkit:4.4.1") | ||
| implementation("net.kyori:adventure-text-minimessage:4.21.0") | ||
|
|
||
| implementation("com.eternalcode:multification-bukkit:1.2.2") | ||
| implementation("com.eternalcode:multification-okaeri:1.2.2") | ||
|
|
||
| api("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.9") | ||
| implementation("eu.okaeri:okaeri-configs-serdes-commons:5.0.5") | ||
|
|
||
| implementation("org.bstats:bstats-bukkit:3.1.0") | ||
| implementation("dev.rollczi:litecommands-bukkit:3.10.6") | ||
| implementation("dev.rollczi:litecommands-annotations:3.10.6") | ||
|
|
||
| testImplementation("org.junit.jupiter:junit-jupiter:6.0.1") | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| testImplementation("org.assertj:assertj-core:3.25.2") | ||
| testImplementation("org.mockito:mockito-core:5.8.0") | ||
| testImplementation("org.mockito:mockito-junit-jupiter:5.8.0") | ||
| testImplementation("org.mockito:mockito-inline:5.2.0") | ||
| testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
| } | ||
121 changes: 121 additions & 0 deletions
121
automessage-core/src/main/java/com/github/imdmk/automessage/AutoMessagePlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package com.github.imdmk.automessage; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import com.github.imdmk.automessage.command.dispatcher.DisableCommand; | ||
| import com.github.imdmk.automessage.command.dispatcher.EnableCommand; | ||
| import com.github.imdmk.automessage.command.reload.ReloadCommand; | ||
| import com.github.imdmk.automessage.config.ConfigManager; | ||
| import com.github.imdmk.automessage.platform.litecommands.handler.InvalidUsageHandlerImpl; | ||
| import com.github.imdmk.automessage.platform.litecommands.handler.MissingPermissionsHandlerImpl; | ||
| import com.github.imdmk.automessage.platform.litecommands.handler.NoticeResultHandlerImpl; | ||
| import com.github.imdmk.automessage.platform.logger.BukkitPluginLogger; | ||
| import com.github.imdmk.automessage.platform.logger.PluginLogger; | ||
| import com.github.imdmk.automessage.platform.scheduler.BukkitTaskScheduler; | ||
| import com.github.imdmk.automessage.platform.scheduler.TaskScheduler; | ||
| import com.github.imdmk.automessage.scheduled.ScheduledMessagesConfig; | ||
| import com.github.imdmk.automessage.scheduled.audience.filter.AudienceFilter; | ||
| import com.github.imdmk.automessage.scheduled.dispatcher.MessageDispatcher; | ||
| import com.github.imdmk.automessage.scheduled.dispatcher.MessageDispatcherConfig; | ||
| import com.github.imdmk.automessage.scheduled.dispatcher.MessageDispatcherTask; | ||
| import com.github.imdmk.automessage.scheduled.selector.MessageSelector; | ||
| import com.github.imdmk.automessage.scheduled.selector.MessageSelectorFactory; | ||
| import com.github.imdmk.automessage.shared.message.MessageConfig; | ||
| import com.github.imdmk.automessage.shared.message.MessageService; | ||
| import com.github.imdmk.automessage.shared.validate.Validator; | ||
| import dev.rollczi.litecommands.LiteCommands; | ||
| import dev.rollczi.litecommands.bukkit.LiteBukkitFactory; | ||
| import net.kyori.adventure.platform.bukkit.BukkitAudiences; | ||
| import org.bstats.bukkit.Metrics; | ||
| import org.bukkit.Server; | ||
| import org.bukkit.plugin.Plugin; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| final class AutoMessagePlugin { | ||
|
|
||
| private static final String PLUGIN_PREFIX = "AutoMessage"; | ||
| private static final int PLUGIN_METRICS_ID = 19487; | ||
|
|
||
| private final Plugin plugin; | ||
| private final Server server; | ||
| private final PluginLogger logger; | ||
|
|
||
| private ConfigManager configManager; | ||
|
|
||
| private BukkitAudiences bukkitAudiences; | ||
| private MessageService messageService; | ||
| private TaskScheduler taskScheduler; | ||
|
|
||
| private LiteCommands<?> liteCommands; | ||
| private Metrics metrics; | ||
|
|
||
| public AutoMessagePlugin( | ||
| @NotNull final Plugin plugin, | ||
| @NotNull final Server server, | ||
| @NotNull final PluginLogger logger | ||
| ) { | ||
| this.plugin = Validator.notNull(plugin, "plugin"); | ||
| this.server = Validator.notNull(server, "server"); | ||
| this.logger = Validator.notNull(logger, "logger"); | ||
| } | ||
|
|
||
| AutoMessagePlugin(@NotNull final Plugin plugin) { | ||
| this(plugin, plugin.getServer(), new BukkitPluginLogger(plugin)); | ||
| } | ||
|
|
||
| void enable(@NotNull PluginSettings settings) { | ||
| Validator.notNull(settings, "settings"); | ||
|
|
||
| configManager = new ConfigManager(logger, plugin.getDataFolder()); | ||
| configManager.createAll(settings.configs()); | ||
|
|
||
| bukkitAudiences = BukkitAudiences.create(plugin); | ||
| messageService = new MessageService(configManager.require(MessageConfig.class), bukkitAudiences); | ||
| taskScheduler = new BukkitTaskScheduler(plugin, server.getScheduler()); | ||
|
|
||
| final MessageDispatcherConfig messageDispatcherConfig = configManager.require(MessageDispatcherConfig.class); | ||
| final ScheduledMessagesConfig scheduledMessagesConfig = configManager.require(ScheduledMessagesConfig.class); | ||
|
|
||
| final AudienceFilter audienceFilter = AudienceFilter.createDefault(); | ||
| final MessageSelector messageSelector = MessageSelectorFactory.create(messageDispatcherConfig.selector); | ||
|
|
||
| final MessageDispatcher messageDispatcher = new MessageDispatcher( | ||
| messageService, | ||
| messageSelector, | ||
| audienceFilter, | ||
| () -> scheduledMessagesConfig.messages | ||
| ); | ||
|
|
||
| MessageDispatcherTask messageDispatcherTask = new MessageDispatcherTask(server, messageDispatcherConfig, messageDispatcher); | ||
| taskScheduler.runTimerAsync(messageDispatcherTask); | ||
|
|
||
| liteCommands = LiteBukkitFactory.builder(PLUGIN_PREFIX, plugin, server) | ||
| .invalidUsage(new InvalidUsageHandlerImpl(messageService)) | ||
| .missingPermission(new MissingPermissionsHandlerImpl(messageService)) | ||
| .result(Notice.class, new NoticeResultHandlerImpl(messageService)) | ||
|
|
||
| .commands( | ||
| new DisableCommand(messageDispatcherConfig, messageService), | ||
| new EnableCommand(messageDispatcherConfig, messageService), | ||
| new ReloadCommand(logger, configManager, taskScheduler, messageService) | ||
| ) | ||
|
|
||
| .build(); | ||
|
|
||
| metrics = new Metrics(plugin, PLUGIN_METRICS_ID); | ||
|
|
||
| logger.info("%s plugin enabled.", PLUGIN_PREFIX); | ||
| } | ||
|
|
||
| void disable() { | ||
| // Validator.ifNotNull(configManager, manager -> { | ||
| // manager.saveAll(); | ||
| // manager.clearAll(); | ||
| // }); | ||
| Validator.ifNotNull(bukkitAudiences, BukkitAudiences::close); | ||
| Validator.ifNotNull(taskScheduler, TaskScheduler::shutdown); | ||
| Validator.ifNotNull(liteCommands, LiteCommands::unregister); | ||
| Validator.ifNotNull(metrics, Metrics::shutdown); | ||
|
|
||
| logger.info("%s plugin disabled successfully.", PLUGIN_PREFIX); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
automessage-core/src/main/java/com/github/imdmk/automessage/PluginSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.github.imdmk.automessage; | ||
|
|
||
| import com.github.imdmk.automessage.config.ConfigSection; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface PluginSettings { | ||
|
|
||
| List<Class<? extends ConfigSection>> configs(); | ||
|
|
||
| } |
40 changes: 40 additions & 0 deletions
40
...ge-core/src/main/java/com/github/imdmk/automessage/command/dispatcher/DisableCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.github.imdmk.automessage.command.dispatcher; | ||
|
|
||
| import com.github.imdmk.automessage.scheduled.dispatcher.MessageDispatcherConfig; | ||
| import com.github.imdmk.automessage.shared.message.MessageService; | ||
| import com.github.imdmk.automessage.shared.validate.Validator; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Context; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Command(name = "automessage disable") | ||
| @Permission("command.automessage.disable") | ||
| public final class DisableCommand { | ||
|
|
||
| private final MessageDispatcherConfig dispatcherConfig; | ||
| private final MessageService messageService; | ||
|
|
||
| public DisableCommand( | ||
| @NotNull MessageDispatcherConfig dispatcherConfig, | ||
| @NotNull MessageService messageService | ||
| ) { | ||
| this.dispatcherConfig = Validator.notNull(dispatcherConfig, "dispatcherConfig"); | ||
| this.messageService = Validator.notNull(messageService, "messageService"); | ||
| } | ||
|
|
||
| @Execute | ||
| void disable(@Context CommandSender sender) { | ||
| if (!dispatcherConfig.isEnabled()) { | ||
| messageService.send(sender, n -> n.dispatcherMessages.dispatcherAlreadyDisabled()); | ||
| return; | ||
| } | ||
|
|
||
| dispatcherConfig.setEnabled(false); | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dispatcherConfig.save(); | ||
|
|
||
| messageService.send(sender, n -> n.dispatcherMessages.dispatcherDisabled()); | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
...age-core/src/main/java/com/github/imdmk/automessage/command/dispatcher/EnableCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.github.imdmk.automessage.command.dispatcher; | ||
|
|
||
| import com.github.imdmk.automessage.scheduled.dispatcher.MessageDispatcherConfig; | ||
| import com.github.imdmk.automessage.shared.message.MessageService; | ||
| import com.github.imdmk.automessage.shared.validate.Validator; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Context; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Command(name = "automessage enable") | ||
| @Permission("command.automessage.enable") | ||
| public final class EnableCommand { | ||
|
|
||
| private final MessageDispatcherConfig dispatcherConfig; | ||
| private final MessageService messageService; | ||
|
|
||
| public EnableCommand( | ||
| @NotNull MessageDispatcherConfig dispatcherConfig, | ||
| @NotNull MessageService messageService | ||
| ) { | ||
| this.dispatcherConfig = Validator.notNull(dispatcherConfig, "dispatcherConfig"); | ||
| this.messageService = Validator.notNull(messageService, "messageService"); | ||
| } | ||
|
|
||
| @Execute | ||
| void enable(@Context CommandSender sender) { | ||
| if (dispatcherConfig.isEnabled()) { | ||
| messageService.send(sender, n -> n.dispatcherMessages.dispatcherAlreadyEnabled()); | ||
| return; | ||
| } | ||
|
|
||
| dispatcherConfig.setEnabled(true); | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dispatcherConfig.save(); | ||
|
|
||
| messageService.send(sender, n -> n.dispatcherMessages.dispatcherEnabled()); | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
...ain/java/com/github/imdmk/automessage/command/dispatcher/messages/DispatcherMessages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.github.imdmk.automessage.command.dispatcher.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
|
|
||
| public interface DispatcherMessages { | ||
|
|
||
| Notice dispatcherEnabled(); | ||
|
|
||
| Notice dispatcherAlreadyEnabled(); | ||
|
|
||
| Notice dispatcherDisabled(); | ||
|
|
||
| Notice dispatcherAlreadyDisabled(); | ||
| } |
50 changes: 50 additions & 0 deletions
50
...java/com/github/imdmk/automessage/command/dispatcher/messages/DispatcherMessagesImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.github.imdmk.automessage.command.dispatcher.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
| import eu.okaeri.configs.OkaeriConfig; | ||
| import eu.okaeri.configs.annotation.Comment; | ||
|
|
||
| public final class DispatcherMessagesImpl | ||
| extends OkaeriConfig | ||
| implements DispatcherMessages { | ||
|
|
||
| @Comment({"#", "# Sent when automatic message dispatching is successfully enabled.", "#"}) | ||
| Notice dispatcherEnabled = Notice.chat( | ||
| "<dark_gray>• <green>Automatic messages have been <bold>enabled</bold>.<dark_gray>" | ||
| ); | ||
|
|
||
| @Comment({"#", "# Sent when a user attempts to enable dispatching, but it is already active.", "#"}) | ||
| Notice dispatcherAlreadyEnabled = Notice.chat( | ||
| "<dark_gray>• <yellow>Automatic messages are already enabled.<dark_gray>" | ||
| ); | ||
|
|
||
| @Comment({"#", "# Sent when automatic message dispatching is successfully disabled.", "#"}) | ||
| Notice dispatcherDisabled = Notice.chat( | ||
| "<dark_gray>• <red>Automatic messages have been <bold>disabled</bold>.<dark_gray>" | ||
| ); | ||
|
|
||
| @Comment({"#", "# Sent when a user attempts to disable dispatching, but it is already inactive.", "#"}) | ||
| Notice dispatcherAlreadyDisabled = Notice.chat( | ||
| "<dark_gray>• <yellow>Automatic messages are already disabled.<dark_gray>" | ||
| ); | ||
|
|
||
| @Override | ||
| public Notice dispatcherEnabled() { | ||
| return dispatcherEnabled; | ||
| } | ||
|
|
||
| @Override | ||
| public Notice dispatcherAlreadyEnabled() { | ||
| return dispatcherAlreadyEnabled; | ||
| } | ||
|
|
||
| @Override | ||
| public Notice dispatcherDisabled() { | ||
| return dispatcherDisabled; | ||
| } | ||
|
|
||
| @Override | ||
| public Notice dispatcherAlreadyDisabled() { | ||
| return dispatcherAlreadyDisabled; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...message-core/src/main/java/com/github/imdmk/automessage/command/reload/ReloadCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.github.imdmk.automessage.command.reload; | ||
|
|
||
| import com.github.imdmk.automessage.config.ConfigManager; | ||
| import com.github.imdmk.automessage.platform.logger.PluginLogger; | ||
| import com.github.imdmk.automessage.platform.scheduler.TaskScheduler; | ||
| import com.github.imdmk.automessage.shared.message.MessageService; | ||
| import com.github.imdmk.automessage.shared.validate.Validator; | ||
| import dev.rollczi.litecommands.annotations.command.Command; | ||
| import dev.rollczi.litecommands.annotations.context.Context; | ||
| import dev.rollczi.litecommands.annotations.execute.Execute; | ||
| import dev.rollczi.litecommands.annotations.permission.Permission; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Command(name = "automessage reload") | ||
| @Permission("command.automessage.reload") | ||
| public final class ReloadCommand { | ||
|
|
||
| private final PluginLogger logger; | ||
| private final ConfigManager configManager; | ||
| private final TaskScheduler taskScheduler; | ||
| private final MessageService messageService; | ||
|
|
||
| public ReloadCommand( | ||
| @NotNull PluginLogger logger, | ||
| @NotNull ConfigManager configManager, | ||
| @NotNull TaskScheduler taskScheduler, | ||
| @NotNull MessageService messageService | ||
| ) { | ||
| this.logger = Validator.notNull(logger, "logger"); | ||
| this.configManager = Validator.notNull(configManager, "configManager"); | ||
| this.taskScheduler = Validator.notNull(taskScheduler, "taskScheduler"); | ||
| this.messageService = Validator.notNull(messageService, "messageService"); | ||
| } | ||
|
|
||
| @Execute | ||
| void reload(@Context CommandSender sender) { | ||
| taskScheduler.runAsync(() -> { | ||
| try { | ||
| configManager.loadAll(); | ||
| messageService.send(sender, n -> n.reloadMessages.configReloadedSuccess()); | ||
| } catch (Exception e) { | ||
| logger.error(e, "Failed to reload plugin config"); | ||
| messageService.send(sender, n -> n.reloadMessages.configReloadFailed()); | ||
| } | ||
| }); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...re/src/main/java/com/github/imdmk/automessage/command/reload/messages/ReloadMessages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.github.imdmk.automessage.command.reload.messages; | ||
|
|
||
| import com.eternalcode.multification.notice.Notice; | ||
|
|
||
| public interface ReloadMessages { | ||
|
|
||
| Notice configReloadedSuccess(); | ||
|
|
||
| Notice configReloadFailed(); | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.