Skip to content

Commit

Permalink
Add reload configuration command (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK authored May 25, 2024
1 parent d62328c commit 9c66766
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.github.imdmk.doublejump.command.handler.NotificationHandler;
import com.github.imdmk.doublejump.command.handler.PermissionHandler;
import com.github.imdmk.doublejump.command.handler.UsageHandler;
import com.github.imdmk.doublejump.configuration.ConfigurationFactory;
import com.github.imdmk.doublejump.configuration.ConfigurationService;
import com.github.imdmk.doublejump.configuration.implementation.PluginConfiguration;
import com.github.imdmk.doublejump.jump.JumpPlayerManager;
import com.github.imdmk.doublejump.jump.JumpPlayerService;
import com.github.imdmk.doublejump.jump.command.DoubleJumpCommand;
import com.github.imdmk.doublejump.jump.command.DoubleJumpForCommand;
import com.github.imdmk.doublejump.jump.command.DoubleJumpReloadCommand;
import com.github.imdmk.doublejump.jump.item.JumpItemService;
import com.github.imdmk.doublejump.jump.item.command.DoubleJumpItemCommand;
import com.github.imdmk.doublejump.jump.item.listener.JumpItemActionBlockListener;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class DoubleJump implements DoubleJumpApi {

private final JumpPlayerManager jumpPlayerManager;

private final ConfigurationService configurationService;
private final JumpPlayerService jumpPlayerService;
private final JumpRestrictionService jumpRestrictionService;

Expand All @@ -99,8 +101,8 @@ public DoubleJump(Plugin plugin) {

/* Configuration */
File dataFolder = plugin.getDataFolder();

this.pluginConfiguration = ConfigurationFactory.create(PluginConfiguration.class, new File(dataFolder, "configuration.yml"));
this.configurationService = new ConfigurationService();
this.pluginConfiguration = this.configurationService.create(PluginConfiguration.class, new File(dataFolder, "configuration.yml"));

/* Adventure */
this.bukkitAudiences = BukkitAudiences.create(plugin);
Expand Down Expand Up @@ -199,6 +201,7 @@ private LiteCommands<CommandSender> registerLiteCommands() {

.commands(
new DoubleJumpCommand(this.pluginConfiguration.jumpSettings, this.notificationSender, this.jumpPlayerManager, this.jumpPlayerService, this.jumpRestrictionService),
new DoubleJumpReloadCommand(this.pluginConfiguration.notificationSettings, this.notificationSender, this.configurationService),
new DoubleJumpForCommand(this.pluginConfiguration.jumpSettings, this.notificationSender, this.jumpPlayerService),
new DoubleJumpItemCommand(this.pluginConfiguration.jumpSettings.itemSettings, this.notificationSender)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.imdmk.doublejump.configuration;

import eu.okaeri.configs.OkaeriConfig;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public class ConfigurationService {

private final Set<OkaeriConfig> configs = new HashSet<>();

public <T extends OkaeriConfig> T create(Class<T> config, File file) {
T configFile = ConfigurationFactory.create(config, file);

this.configs.add(configFile);
return configFile;
}

public void reload() {
for (OkaeriConfig config : this.configs) {
config.load();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.imdmk.doublejump.jump.command;

import com.github.imdmk.doublejump.configuration.ConfigurationService;
import com.github.imdmk.doublejump.notification.NotificationSender;
import com.github.imdmk.doublejump.notification.configuration.NotificationSettings;
import dev.rollczi.litecommands.annotations.async.Async;
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;

@Command(name = "doublejump reload")
@Permission("command.doublejump.reload")
public class DoubleJumpReloadCommand {

private final NotificationSettings notificationSettings;
private final NotificationSender notificationSender;
private final ConfigurationService configurationService;

public DoubleJumpReloadCommand(NotificationSettings notificationSettings, NotificationSender notificationSender, ConfigurationService configurationService) {
this.notificationSettings = notificationSettings;
this.notificationSender = notificationSender;
this.configurationService = configurationService;
}

@Async
@Execute
void execute(@Context CommandSender sender) {
this.configurationService.reload();
this.notificationSender.send(sender, this.notificationSettings.configurationReloaded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class NotificationSettings extends OkaeriConfig {

public Notification configurationReloaded = new Notification(NotificationType.CHAT, "<green>The plugin configuration has been reloaded.");
public Notification playerNotFound = new Notification(NotificationType.CHAT, "<red>No player found with the given name");

@Comment("# {PERMISSIONS} - Required permissions to use the command")
Expand Down

0 comments on commit 9c66766

Please sign in to comment.