Skip to content

Commit

Permalink
1.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ancap-kun committed Feb 17, 2023
1 parent 25d6b8c commit ac6f226
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -146,19 +145,18 @@ private void loadPluginSettings() {
this.settings = new AncapPluginSettings(this.newResourceSource(FileConfigurationPreparator.internal()).getResource("ancapplugin.yml"));
}

private final Cache<FileConfiguration> configCache = new Cache<>(1_000_000_000);

protected ConfigurationSection getConfiguration() {
return this.getConfiguration("configuration.yml");
}

private final Cache<FileConfiguration> 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));
}

Expand Down
2 changes: 1 addition & 1 deletion Artifex/configuration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# не менять, отвечает за обновление конфига и автоперенос значений
config-version: 1
configuration-version: 1

default-language: ru

Expand Down
2 changes: 1 addition & 1 deletion Artifex/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>Artifex</artifactId>
<name>Artifex</name>
<version>1.6.1</version>
<version>1.6.3</version>
<description>AncapAPI runtime part</description>
<build>
<finalName>artifex-v${version}</finalName>
Expand Down
2 changes: 1 addition & 1 deletion Artifex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<packaging>jar</packaging>

<artifactId>Artifex</artifactId>
<version>1.6.1</version>
<version>1.6.3</version>

<name>Artifex</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,27 +56,25 @@ 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
))
);
}

@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
)
)
);
}

Expand All @@ -86,10 +85,10 @@ private void operate(LeveledCommand command, Consumer<CommandForm> commandFormCo
new Thread(() -> {
CommandOperator rule = this.executeRules.get(key);
commandFormConsumer.accept(
new CommandForm(
finalCommand,
rule
)
new CommandForm(
finalCommand,
rule
)
);
}).start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
)
)
));
}

Expand Down
2 changes: 1 addition & 1 deletion Artifex/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# не менять, отвечает за обновление конфига и автоперенос значений
config-version: 1
configuration-version: 1

default-language: ru

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,8 +37,8 @@ public class Arguments implements CommandOperator {
private final int requiredLiterals;
private final Consumer<ArgumentCommandDispatch> dispatchConsumer;

public Arguments(BiConsumer<CommandSender, Integer> onNotEnough, List<Argument> arguments, Consumer<ArgumentCommandDispatch> dispatchConsumer) {
this(onNotEnough, Arguments.bindingsFor(arguments), arguments, Arguments.requiredLiteralsAmountFor(arguments), dispatchConsumer);
public Arguments(BiConsumer<CommandSender, Integer> onNotEnough, Accept accept, Consumer<ArgumentCommandDispatch> dispatchConsumer) {
this(onNotEnough, Arguments.bindingsFor(accept), accept, Arguments.requiredLiteralsAmountFor(accept), dispatchConsumer);
}

public Arguments(Accept accept, Consumer<ArgumentCommandDispatch> dispatchConsumer) {
Expand All @@ -51,6 +54,7 @@ private static Map<Integer, ArgumentsShard> bindingsFor(List<Argument> 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;
}
Expand Down Expand Up @@ -152,6 +156,8 @@ public String closing() {
}

@AllArgsConstructor
@ToString
@EqualsAndHashCode
private static class ArgumentsShard {

private final int firstLiteralIndex;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +15,8 @@
import java.util.function.Function;

@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
public abstract class PrimitiveExtractor<T> implements ArgumentExtractor<T> {

private final Class<T> type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,7 @@
public class FileConfigurationPreparator implements ResourcePreparator<FileConfiguration> {

private final Function<Integer, TransferMap> versionToMap;
private final String versionFieldName;
private String versionFieldName;
private final boolean saveFiles;

public static Builder builder() {
Expand Down Expand Up @@ -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<ConfigurationSection, Integer> versionExtractor = new VersionExtractor(this.versionFieldName);
if (versionExtractor.apply(userData) == versionExtractor.apply(softwareData)) {
finalConfig = userData;
Expand Down

0 comments on commit ac6f226

Please sign in to comment.