#411 Create tests for command migration and manager, minor tweaks
This commit is contained in:
@@ -42,4 +42,9 @@ public class Command {
|
||||
public void setExecutor(Executor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return command + " (" + executor + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -10,9 +10,9 @@ import java.util.Map;
|
||||
*/
|
||||
public class CommandConfig {
|
||||
|
||||
private Map<String, Command> onJoin = new HashMap<>();
|
||||
private Map<String, Command> onLogin = new HashMap<>();
|
||||
private Map<String, Command> onRegister = new HashMap<>();
|
||||
private Map<String, Command> onJoin = new LinkedHashMap<>();
|
||||
private Map<String, Command> onLogin = new LinkedHashMap<>();
|
||||
private Map<String, Command> onRegister = new LinkedHashMap<>();
|
||||
|
||||
public Map<String, Command> getOnJoin() {
|
||||
return onJoin;
|
||||
|
||||
@@ -10,7 +10,6 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
@@ -20,23 +19,21 @@ import java.util.Map;
|
||||
*/
|
||||
public class CommandManager implements Reloadable {
|
||||
|
||||
private final File dataFolder;
|
||||
private final BukkitService bukkitService;
|
||||
private final CommandsMigrater commandsMigrater;
|
||||
private final Settings settings;
|
||||
|
||||
private CommandConfig commandConfig;
|
||||
|
||||
@Inject
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private CommandsMigrater commandsMigrater;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
|
||||
CommandManager() {
|
||||
CommandManager(@DataFolder File dataFolder, BukkitService bukkitService,
|
||||
CommandsMigrater commandsMigrater, Settings settings) {
|
||||
this.dataFolder = dataFolder;
|
||||
this.bukkitService = bukkitService;
|
||||
this.commandsMigrater = commandsMigrater;
|
||||
this.settings = settings;
|
||||
reload();
|
||||
}
|
||||
|
||||
public void runCommandsOnJoin(Player player) {
|
||||
@@ -62,7 +59,6 @@ public class CommandManager implements Reloadable {
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@Override
|
||||
public void reload() {
|
||||
File file = new File(dataFolder, "commands.yml");
|
||||
|
||||
@@ -21,6 +21,12 @@ class CommandsMigrater {
|
||||
CommandsMigrater() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds command settings from their old location (in config.yml) to the given command configuration object.
|
||||
*
|
||||
* @param commandConfig the command config object to move old commands to
|
||||
* @return true if commands have been moved, false if no migration was necessary
|
||||
*/
|
||||
boolean transformOldCommands(CommandConfig commandConfig) {
|
||||
boolean didMoveCommands = false;
|
||||
for (MigratableCommandSection section : MigratableCommandSection.values()) {
|
||||
@@ -37,12 +43,12 @@ class CommandsMigrater {
|
||||
ON_JOIN(
|
||||
SettingsMigrationService::getOnLoginCommands,
|
||||
Executor.PLAYER,
|
||||
CommandConfig::getOnJoin),
|
||||
CommandConfig::getOnLogin),
|
||||
|
||||
ON_JOIN_CONSOLE(
|
||||
SettingsMigrationService::getOnLoginConsoleCommands,
|
||||
Executor.CONSOLE,
|
||||
CommandConfig::getOnJoin),
|
||||
CommandConfig::getOnLogin),
|
||||
|
||||
ON_REGISTER(
|
||||
SettingsMigrationService::getOnRegisterCommands,
|
||||
@@ -91,7 +97,7 @@ class CommandsMigrater {
|
||||
}
|
||||
Map<String, Command> commandMap = commandMapGetter.apply(commandConfig);
|
||||
commands.forEach(cmd -> commandMap.put(RandomStringUtils.generate(10), cmd));
|
||||
ConsoleLogger.info("Migrated " + commands.size() + " of type " + this);
|
||||
ConsoleLogger.info("Migrated " + commands.size() + " commands of type " + this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user