mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 02:49:15 +00:00
向外
This commit is contained in:
@@ -159,14 +159,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
if (AbstractRecipeManager.this.byId.containsKey(id)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.recipe.duplicated", path, id);
|
||||
}
|
||||
Recipe<T> recipe;
|
||||
try {
|
||||
recipe = RecipeTypes.fromMap(id, section);
|
||||
} catch (LocalizedResourceConfigException e) {
|
||||
e.setPath(path);
|
||||
e.setId(id);
|
||||
throw e;
|
||||
}
|
||||
Recipe<T> recipe = RecipeTypes.fromMap(id, section);
|
||||
try {
|
||||
markAsCustomRecipe(id);
|
||||
registerInternalRecipe(id, recipe);
|
||||
|
||||
@@ -450,20 +450,27 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
String key = configEntry.getKey();
|
||||
try {
|
||||
Key id = Key.withDefaultNamespace(key, cached.pack().namespace());
|
||||
if (parser.isTemplate()) {
|
||||
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
|
||||
} else if (predicate.test(parser)) {
|
||||
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
|
||||
Map<String, Object> configSection1 = castToMap(configSection0, false);
|
||||
if ((boolean) configSection1.getOrDefault("enable", true)) {
|
||||
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
|
||||
try {
|
||||
if (parser.isTemplate()) {
|
||||
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
|
||||
} else if (predicate.test(parser)) {
|
||||
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
|
||||
Map<String, Object> configSection1 = castToMap(configSection0, false);
|
||||
if ((boolean) configSection1.getOrDefault("enable", true)) {
|
||||
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
|
||||
}
|
||||
} else {
|
||||
TranslationManager.instance().log("warning.config.not_a_section", cached.filePath().toString(), parser.sectionId()[0], configEntry.getKey(), configEntry.getValue().getClass().getSimpleName());
|
||||
}
|
||||
} else {
|
||||
TranslationManager.instance().log("warning.config.not_a_section", cached.filePath().toString(), parser.sectionId()[0], configEntry.getKey(), configEntry.getValue().getClass().getSimpleName());
|
||||
}
|
||||
} catch (LocalizedException e) {
|
||||
if (e instanceof LocalizedResourceConfigException exception) {
|
||||
exception.setPath(cached.filePath());
|
||||
exception.setId(cached.prefix() + "." + key);
|
||||
}
|
||||
TranslationManager.instance().log(e.node(), e.arguments());
|
||||
this.plugin.debug(e::node);
|
||||
}
|
||||
} catch (LocalizedException e) {
|
||||
TranslationManager.instance().log(e.node(), e.arguments());
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("Unexpected error loading file " + cached.filePath() + " - '" + parser.sectionId()[0] + "." + key + "'. Please find the cause according to the stacktrace or seek developer help.", e);
|
||||
}
|
||||
@@ -482,7 +489,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
String configType = hashIndex != -1 ? key.substring(0, hashIndex) : key;
|
||||
Optional.ofNullable(this.sectionParsers.get(configType))
|
||||
.ifPresent(parser -> this.cachedConfigs.computeIfAbsent(parser, k -> new ArrayList<>())
|
||||
.add(new CachedConfig(castToMap(typeSections0, false), path, pack)));
|
||||
.add(new CachedConfig(key, castToMap(typeSections0, false), path, pack)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ import java.util.Map;
|
||||
public class CachedConfig {
|
||||
private final Pack pack;
|
||||
private final Path filePath;
|
||||
private final String prefix;
|
||||
private final Map<String, Object> config;
|
||||
|
||||
public CachedConfig(Map<String, Object> config, Path filePath, Pack pack) {
|
||||
public CachedConfig(String prefix, Map<String, Object> config, Path filePath, Pack pack) {
|
||||
this.config = config;
|
||||
this.filePath = filePath;
|
||||
this.pack = pack;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public Map<String, Object> config() {
|
||||
@@ -25,4 +27,8 @@ public class CachedConfig {
|
||||
public Pack pack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class LocalizedResourceConfigException extends LocalizedException {
|
||||
super.setArgument(0, path.toString());
|
||||
}
|
||||
|
||||
public void setId(Key id) {
|
||||
super.setArgument(1, id.toString());
|
||||
public void setId(String id) {
|
||||
super.setArgument(1, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class CharacterUtils {
|
||||
chars[i] = (char) codePoint;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new LocalizedResourceConfigException("");
|
||||
throw new LocalizedResourceConfigException("warning.config.image.invalid_hex", e, hex);
|
||||
}
|
||||
}
|
||||
return chars;
|
||||
|
||||
Reference in New Issue
Block a user