9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 19:09:08 +00:00

修复map类型参数,增加debug功能

This commit is contained in:
XiaoMoMi
2025-06-18 17:57:54 +08:00
parent 89c35d2d41
commit 730ce99fe4
10 changed files with 31 additions and 76 deletions

View File

@@ -424,6 +424,9 @@ public abstract class AbstractPackManager implements PackManager {
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/stripped_palm_log.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/stripped_palm_log_top.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_leaves.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_trapdoor.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_door_top.png");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/palm_door_bottom.png");
// plants
plugin.saveResource("resources/default/configuration/plants.yml");
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/fairy_flower_1.png");
@@ -529,6 +532,9 @@ public abstract class AbstractPackManager implements PackManager {
} else {
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
Map<String, Object> config = castToMap(configSection0, false);
if (Config.debug() && (boolean) config.getOrDefault("debug", false)) {
this.plugin.logger().info(GsonHelper.get().toJson(this.plugin.templateManager().applyTemplates(id, config)));
}
if ((boolean) config.getOrDefault("enable", true)) {
parser.parseSection(cached.pack(), cached.filePath(), id, MiscUtils.castToMap(this.plugin.templateManager().applyTemplates(id, config), false));
}

View File

@@ -1,64 +0,0 @@
package net.momirealms.craftengine.core.plugin.command.parser;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCaptionKeys;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.caption.CaptionVariable;
import org.incendo.cloud.component.CommandComponent;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.context.CommandInput;
import org.incendo.cloud.exception.parsing.ParserException;
import org.incendo.cloud.parser.ArgumentParseResult;
import org.incendo.cloud.parser.ArgumentParser;
import org.incendo.cloud.parser.ParserDescriptor;
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
import org.incendo.cloud.suggestion.Suggestion;
public class BlockStateParser<C> implements ArgumentParser<C, ImmutableBlockState>, BlockingSuggestionProvider.Strings<C> {
public static <C> @NonNull ParserDescriptor<C, ImmutableBlockState> blockStateParser() {
return ParserDescriptor.of(new BlockStateParser<>(), ImmutableBlockState.class);
}
public static <C> CommandComponent.@NonNull Builder<C, ImmutableBlockState> blockStateComponent() {
return CommandComponent.<C, ImmutableBlockState>builder().parser(blockStateParser());
}
@Override
public @NonNull ArgumentParseResult<@NonNull ImmutableBlockState> parse(@NonNull CommandContext<@NonNull C> commandContext, @NonNull CommandInput commandInput) {
String input = commandInput.readString();
ImmutableBlockState state = net.momirealms.craftengine.core.block.BlockStateParser.deserialize(input);
if (state == null) {
return ArgumentParseResult.failure(new BlockStateParseException(input, commandContext));
}
return ArgumentParseResult.success(state);
}
@Override
public @NonNull Iterable<@NonNull String> stringSuggestions(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) {
return CraftEngine.instance().blockManager().cachedSuggestions().stream().map(Suggestion::suggestion).toList();
}
public static final class BlockStateParseException extends ParserException {
private final String input;
public BlockStateParseException(
final @NonNull String input,
final @NonNull CommandContext<?> context
) {
super(
BlockStateParser.class,
context,
CraftEngineCaptionKeys.ARGUMENT_PARSE_FAILURE_BLOCK_STATE,
CaptionVariable.of("input", input)
);
this.input = input;
}
public @NonNull String input() {
return this.input;
}
}
}

View File

@@ -36,7 +36,7 @@ public class TemplateArguments {
public static TemplateArgument fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
return MapTemplateArgument.FACTORY.create(map);
return new MapTemplateArgument(map);
} else {
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key);

View File

@@ -71,7 +71,7 @@ public interface TemplateManager extends Manageable {
int separatorIndex = placeholderContent.indexOf(":-");
if (separatorIndex == -1) {
this.placeholder = placeholderContent;
this.defaultValue = this.rawText;
this.defaultValue = null;
} else {
this.placeholder = placeholderContent.substring(0, separatorIndex);
String defaultValueString = placeholderContent.substring(separatorIndex + 2);