diff --git a/AncapPluginAPI/src/main/java/ru/ancap/framework/plugin/api/AncapPlugin.java b/AncapPluginAPI/src/main/java/ru/ancap/framework/plugin/api/AncapPlugin.java index 68857be3..9df484d1 100644 --- a/AncapPluginAPI/src/main/java/ru/ancap/framework/plugin/api/AncapPlugin.java +++ b/AncapPluginAPI/src/main/java/ru/ancap/framework/plugin/api/AncapPlugin.java @@ -109,14 +109,13 @@ protected void registerCommandExecutors() { } protected void loadLocales() { - VersionExtractor versionExtractor = new VersionExtractor("version"); new LocaleLoader( this.getLogger(), this.newResourceSource(FileConfigurationPreparator.resolveConflicts( (version) -> this.valueTransferMap() != null ? BuiltTransferMap.makeFor(this.valueTransferMap().getConfigurationSection("custom.LanguageAPI"), version) : BuiltTransferMap.EMPTY, - versionExtractor.versionFieldName() + "version" )) ).run(); } @@ -146,19 +145,18 @@ private void loadPluginSettings() { this.settings = new AncapPluginSettings(this.newResourceSource(FileConfigurationPreparator.internal()).getResource("ancapplugin.yml")); } - private final Cache configCache = new Cache<>(1_000_000_000); - protected ConfigurationSection getConfiguration() { return this.getConfiguration("configuration.yml"); } + + private final Cache configCache = new Cache<>(1_000_000_000); protected ConfigurationSection getConfiguration(String fileName) { - VersionExtractor versionExtractor = new VersionExtractor("config-version"); return this.configCache.get(() -> this.newResourceSource(FileConfigurationPreparator.resolveConflicts( (version) -> this.valueTransferMap() != null ? BuiltTransferMap.makeFor(this.valueTransferMap().getConfigurationSection("main-domain."+fileName), version) : BuiltTransferMap.EMPTY, - versionExtractor.versionFieldName() + "configuration-version" )).getResource(fileName)); } diff --git a/Artifex/configuration.yml b/Artifex/configuration.yml index 38b4890c..5ed10344 100644 --- a/Artifex/configuration.yml +++ b/Artifex/configuration.yml @@ -1,5 +1,5 @@ # не менять, отвечает за обновление конфига и автоперенос значений -config-version: 1 +configuration-version: 1 default-language: ru diff --git a/Artifex/dependency-reduced-pom.xml b/Artifex/dependency-reduced-pom.xml index 18d5a70b..e6f36567 100644 --- a/Artifex/dependency-reduced-pom.xml +++ b/Artifex/dependency-reduced-pom.xml @@ -8,7 +8,7 @@ 4.0.0 Artifex Artifex - 1.6.1 + 1.6.3 AncapAPI runtime part artifex-v${version} diff --git a/Artifex/pom.xml b/Artifex/pom.xml index 98ebde71..dceaf9b2 100644 --- a/Artifex/pom.xml +++ b/Artifex/pom.xml @@ -13,7 +13,7 @@ jar Artifex - 1.6.1 + 1.6.3 Artifex diff --git a/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/command/center/AsyncCommandCenter.java b/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/command/center/AsyncCommandCenter.java index 624d341f..0d941538 100644 --- a/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/command/center/AsyncCommandCenter.java +++ b/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/command/center/AsyncCommandCenter.java @@ -44,7 +44,8 @@ public void initialize(AncapPlugin plugin) { public void setExecutor(String commandName, CommandOperator executor) throws CommandNotRegisteredException { CommandOperator previous = this.executeRules.get(commandName); if (previous == null) { - throw new CommandNotRegisteredException("Command "+commandName+" must be registered in ancapplugin.yml to set its executor!"); + throw new CommandNotRegisteredException( + "Command " + commandName + " must be registered in ancapplugin.yml to set its executor!"); } for (String alias : this.aliasesMap.get(commandName)) { this.executeRules.put(alias, executor); @@ -55,11 +56,11 @@ public void setExecutor(String commandName, CommandOperator executor) throws Com @Override public void on(CommandDispatch dispatch) { this.operate( - dispatch.command(), - commandForm -> commandForm.commandOperator.on( - new CommandDispatch( - dispatch.source(), - commandForm.command + dispatch.command(), + commandForm -> commandForm.commandOperator.on( + new CommandDispatch( + dispatch.source(), + commandForm.command )) ); } @@ -67,15 +68,13 @@ public void on(CommandDispatch dispatch) { @Override public void on(CommandWrite write) { this.operate( - write.line(), - commandForm -> { - commandForm.commandOperator.on( - new CommandWrite( - write.speaker(), - commandForm.command - ) - ); - } + write.line(), + commandForm -> commandForm.commandOperator.on( + new CommandWrite( + write.speaker(), + commandForm.command + ) + ) ); } @@ -86,10 +85,10 @@ private void operate(LeveledCommand command, Consumer commandFormCo new Thread(() -> { CommandOperator rule = this.executeRules.get(key); commandFormConsumer.accept( - new CommandForm( - finalCommand, - rule - ) + new CommandForm( + finalCommand, + rule + ) ); }).start(); diff --git a/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/language/input/LanguageChangeInput.java b/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/language/input/LanguageChangeInput.java index 649d788d..0eae7b13 100644 --- a/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/language/input/LanguageChangeInput.java +++ b/Artifex/src/main/java/ru/ancap/framework/artifex/implementation/language/input/LanguageChangeInput.java @@ -13,27 +13,26 @@ import ru.ancap.framework.command.api.commands.operator.delegate.subcommand.Raw; import ru.ancap.framework.command.api.commands.operator.delegate.subcommand.SubCommand; import ru.ancap.framework.command.api.commands.operator.delegate.subcommand.rule.delegate.StringDelegatePattern; +import ru.ancap.framework.communicate.Communicator; +import ru.ancap.framework.language.LAPI; import ru.ancap.framework.language.additional.LAPIMessage; +import ru.ancap.framework.language.language.Language; public class LanguageChangeInput extends CommandTarget { public LanguageChangeInput() { super(new Delegate( - new Raw( - new Advice(new LAPIMessage(Artifex.class, "command.language.enter-language")) - ), - new SubCommand( - new StringDelegatePattern("set"), - new Arguments( - new Accept( - new Argument("language", new Self()) - ), - dispatch -> Bukkit.getPluginManager().callEvent(new LanguageChangeEvent( - dispatch.source().sender(), - dispatch.arguments().get("language", String.class) - )) - ) + new Raw(new Advice(new LAPIMessage(Artifex.class, "command.language.enter-language"))), + new SubCommand( + new StringDelegatePattern("set"), + new Arguments( + new Accept(new Argument("language", new Self())), + dispatch -> { + LAPI.setupLanguage(dispatch.source().sender().getName(), Language.of(dispatch.arguments().get("language", String.class))); + new Communicator(dispatch.source().sender()).send(new LAPIMessage(Artifex.class, "command.language.setup")); + } ) + ) )); } diff --git a/Artifex/src/main/resources/configuration.yml b/Artifex/src/main/resources/configuration.yml index 38b4890c..5ed10344 100644 --- a/Artifex/src/main/resources/configuration.yml +++ b/Artifex/src/main/resources/configuration.yml @@ -1,5 +1,5 @@ # не менять, отвечает за обновление конфига и автоперенос значений -config-version: 1 +configuration-version: 1 default-language: ru diff --git a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Argument.java b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Argument.java index bcbc24d9..aeb2f17f 100644 --- a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Argument.java +++ b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Argument.java @@ -1,9 +1,13 @@ package ru.ancap.framework.command.api.commands.operator.arguments; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.ToString; import ru.ancap.framework.command.api.commands.operator.arguments.extractor.ArgumentExtractor; @AllArgsConstructor +@ToString +@EqualsAndHashCode public class Argument { private final String argumentName; diff --git a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Arguments.java b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Arguments.java index d82dd2fc..6187db0e 100644 --- a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Arguments.java +++ b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/Arguments.java @@ -1,9 +1,12 @@ package ru.ancap.framework.command.api.commands.operator.arguments; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import ru.ancap.commons.AncapDebug; import ru.ancap.framework.command.api.commands.object.dispatched.LeveledCommand; import ru.ancap.framework.command.api.commands.object.dispatched.exception.NoNextArgumentException; import ru.ancap.framework.command.api.commands.object.event.CommandDispatch; @@ -34,8 +37,8 @@ public class Arguments implements CommandOperator { private final int requiredLiterals; private final Consumer dispatchConsumer; - public Arguments(BiConsumer onNotEnough, List arguments, Consumer dispatchConsumer) { - this(onNotEnough, Arguments.bindingsFor(arguments), arguments, Arguments.requiredLiteralsAmountFor(arguments), dispatchConsumer); + public Arguments(BiConsumer onNotEnough, Accept accept, Consumer dispatchConsumer) { + this(onNotEnough, Arguments.bindingsFor(accept), accept, Arguments.requiredLiteralsAmountFor(accept), dispatchConsumer); } public Arguments(Accept accept, Consumer dispatchConsumer) { @@ -51,6 +54,7 @@ private static Map bindingsFor(List arguments int endIndex = lastStartIndex + size; ArgumentsShard shard = new ArgumentsShard(lastStartIndex, endIndex, argument); for (int cursor = lastStartIndex; cursor < endIndex; cursor++) map.put(cursor, shard); + lastStartIndex = endIndex + 1; } return map; } @@ -152,6 +156,8 @@ public String closing() { } @AllArgsConstructor + @ToString + @EqualsAndHashCode private static class ArgumentsShard { private final int firstLiteralIndex; diff --git a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/extractor/basic/PrimitiveExtractor.java b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/extractor/basic/PrimitiveExtractor.java index 8a5c2e61..c35f0ccf 100644 --- a/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/extractor/basic/PrimitiveExtractor.java +++ b/CommandAPI/src/main/java/ru/ancap/framework/command/api/commands/operator/arguments/extractor/basic/PrimitiveExtractor.java @@ -1,6 +1,8 @@ package ru.ancap.framework.command.api.commands.operator.arguments.extractor.basic; +import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.bukkit.command.CommandSender; import ru.ancap.framework.command.api.commands.object.dispatched.LeveledCommand; import ru.ancap.framework.command.api.commands.object.tab.Tab; @@ -13,6 +15,8 @@ import java.util.function.Function; @RequiredArgsConstructor +@ToString +@EqualsAndHashCode public abstract class PrimitiveExtractor implements ArgumentExtractor { private final Class type; diff --git a/ResourceAPI/src/main/java/ru/ancap/framework/resource/config/FileConfigurationPreparator.java b/ResourceAPI/src/main/java/ru/ancap/framework/resource/config/FileConfigurationPreparator.java index 649c035d..6403c931 100644 --- a/ResourceAPI/src/main/java/ru/ancap/framework/resource/config/FileConfigurationPreparator.java +++ b/ResourceAPI/src/main/java/ru/ancap/framework/resource/config/FileConfigurationPreparator.java @@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; +import ru.ancap.commons.AncapDebug; import ru.ancap.framework.resource.ResourcePreparator; import java.io.File; @@ -21,7 +22,7 @@ public class FileConfigurationPreparator implements ResourcePreparator { private final Function versionToMap; - private final String versionFieldName; + private String versionFieldName; private final boolean saveFiles; public static Builder builder() { @@ -77,6 +78,7 @@ public FileConfiguration prepare(InputStream base, @NotNull File target) { case CONFLICT: FileConfiguration userData = this.extract(new FileInputStream(target)); FileConfiguration softwareData = this.extract(base); + if (this.versionFieldName == null) this.versionFieldName = "dummy"; Function versionExtractor = new VersionExtractor(this.versionFieldName); if (versionExtractor.apply(userData) == versionExtractor.apply(softwareData)) { finalConfig = userData;