mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 03:49:15 +00:00
实验性报错格式
This commit is contained in:
@@ -63,6 +63,7 @@ command.upload.failure.not_supported: "<red>Current hosting method '<arg:0>' doe
|
||||
command.upload.on_progress: "<white>Started uploading progress. Check the console for more information.</white>"
|
||||
command.send_resource_pack.success.single: "<white>Sent resource pack to <arg:0>.</white>"
|
||||
command.send_resource_pack.success.multiple: "<white>Send resource packs to <arg:0> players.</white>"
|
||||
warning.config.not_a_section: "<yellow>Issue found in file <arg:0> - '<arg:1>.<arg:2>' is expected to be a config section while it's actually a(n) '<arg:3>'.</yellow>"
|
||||
warning.config.image.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'.</yellow>"
|
||||
warning.config.image.lack_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
|
||||
warning.config.image.height_smaller_than_ascent: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' violates the bitmap image rule: 'height' should be no lower than 'ascent'.</yellow>"
|
||||
@@ -83,6 +84,7 @@ warning.config.jukebox_song.duplicated: "<yellow>Issue found in file <arg:0> - D
|
||||
warning.config.furniture.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated furniture '<arg:1>'.</yellow>"
|
||||
warning.config.furniture.lack_placement: "<yellow>Issue found in file <arg:0> - The furniture '<arg:1>' is missing the required 'placement' argument.</yellow>"
|
||||
warning.config.furniture.element.lack_item: "<yellow>Issue found in file <arg:0> - The furniture '<arg:1>' is missing the required 'item' argument for one of its elements.</yellow>"
|
||||
warning.config.furniture.settings.unknown: "<yellow>Issue found in file <arg:0> - The furniture '<arg:1>' is using an unknown setting type '<arg:2>'.</yellow>"
|
||||
warning.config.item.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated item '<arg:1>'.</yellow>"
|
||||
warning.config.item.lack_material: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'material' argument.</yellow>"
|
||||
warning.config.item.invalid_material: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid material type '<arg:2>'.</yellow>"
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.momirealms.craftengine.core.advancement.AbstractAdvancementManager;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -51,8 +52,7 @@ public class BukkitAdvancementManager extends AbstractAdvancementManager {
|
||||
@Override
|
||||
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
|
||||
if (advancements.containsKey(id)) {
|
||||
TranslationManager.instance().log("warning.config.advancement.duplicated", path.toString(), id.toString());
|
||||
return;
|
||||
throw new LocalizedException("warning.config.advancement.duplicated", path.toString(), id.toString());
|
||||
}
|
||||
JsonElement jsonTree = GsonHelper.get().toJsonTree(section);
|
||||
FastNMS.INSTANCE.registerAdvancement(id.decompose(), jsonTree);
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -106,19 +107,18 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
@Override
|
||||
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
|
||||
if (byId.containsKey(id)) {
|
||||
TranslationManager.instance().log("warning.config.furniture.duplicated", path.toString(), id.toString());
|
||||
return;
|
||||
throw new LocalizedException("warning.config.furniture.duplicated", path.toString(), id.toString());
|
||||
}
|
||||
|
||||
Map<String, Object> lootMap = MiscUtils.castToMap(section.get("loot"), true);
|
||||
Map<String, Object> settingsMap = MiscUtils.castToMap(section.get("settings"), true);
|
||||
Map<String, Object> placementMap = MiscUtils.castToMap(section.get("placement"), true);
|
||||
EnumMap<AnchorType, CustomFurniture.Placement> placements = new EnumMap<>(AnchorType.class);
|
||||
if (placementMap == null) {
|
||||
TranslationManager.instance().log("warning.config.furniture.lack_placement", path.toString(), id.toString());
|
||||
return;
|
||||
throw new LocalizedException("warning.config.furniture.lack_placement", path.toString(), id.toString());
|
||||
}
|
||||
|
||||
EnumMap<AnchorType, CustomFurniture.Placement> placements = new EnumMap<>(AnchorType.class);
|
||||
|
||||
for (Map.Entry<String, Object> entry : placementMap.entrySet()) {
|
||||
// anchor type
|
||||
AnchorType anchorType = AnchorType.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH));
|
||||
@@ -130,8 +130,7 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
for (Map<String, Object> element : elementConfigs) {
|
||||
String key = (String) element.get("item");
|
||||
if (key == null) {
|
||||
TranslationManager.instance().log("warning.config.furniture.element.lack_item", path.toString(), id.toString());
|
||||
return;
|
||||
throw new LocalizedException("warning.config.furniture.element.lack_item", path.toString(), id.toString());
|
||||
}
|
||||
ItemDisplayContext transform = ItemDisplayContext.valueOf(element.getOrDefault("transform", "NONE").toString().toUpperCase(Locale.ENGLISH));
|
||||
Billboard billboard = Billboard.valueOf(element.getOrDefault("billboard", "FIXED").toString().toUpperCase(Locale.ENGLISH));
|
||||
@@ -192,13 +191,16 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
}
|
||||
}
|
||||
|
||||
CustomFurniture furniture = new CustomFurniture(
|
||||
id,
|
||||
FurnitureSettings.fromMap(settingsMap),
|
||||
placements,
|
||||
lootMap == null ? null : LootTable.fromMap(lootMap)
|
||||
);
|
||||
|
||||
// get furniture settings
|
||||
FurnitureSettings settings;
|
||||
try {
|
||||
settings = FurnitureSettings.fromMap(settingsMap);
|
||||
} catch (LocalizedException e) {
|
||||
e.setArgument(0, path.toString());
|
||||
e.setArgument(1, id.toString());
|
||||
throw e;
|
||||
}
|
||||
CustomFurniture furniture = new CustomFurniture(id, settings, placements, lootMap == null ? null : LootTable.fromMap(lootMap));
|
||||
byId.put(id, furniture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -38,7 +39,7 @@ public class FurnitureSettings {
|
||||
if (factory != null) {
|
||||
factory.createModifier(entry.getValue()).apply(settings);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown item settings key: " + entry.getKey());
|
||||
throw new LocalizedException("warning.config.furniture.settings.unknown", new RuntimeException("Unknown furniture settings: " + entry.getKey()), "null", "null", entry.getKey());
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
|
||||
@@ -454,11 +454,13 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
|
||||
}
|
||||
} else {
|
||||
this.plugin.logger().warn(cached.filePath(), "Configuration section is required for " + parser.sectionId()[0] + "." + configEntry.getKey() + " - ");
|
||||
TranslationManager.instance().log("warning.config.not_a_section", cached.filePath().toString(), parser.sectionId()[0], configEntry.getKey(), configEntry.getValue().getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
} catch (LocalizedException e) {
|
||||
TranslationManager.instance().log(e.node(), e.arguments());
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn(cached.filePath(), "Error loading " + parser.sectionId()[0] + "." + key, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.core.plugin.config;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -11,7 +12,7 @@ public interface ConfigSectionParser extends Comparable<ConfigSectionParser> {
|
||||
|
||||
String[] sectionId();
|
||||
|
||||
void parseSection(Pack pack, Path path, Key id, Map<String, Object> section);
|
||||
void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) throws LocalizedException;
|
||||
|
||||
int loadingSequence();
|
||||
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
package net.momirealms.craftengine.core.plugin.locale;
|
||||
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.ArrayUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LocalizedException extends RuntimeException {
|
||||
private final String node;
|
||||
private final String[] arguments;
|
||||
private final Exception originalException;
|
||||
private String[] arguments;
|
||||
|
||||
public LocalizedException(String node, String... arguments) {
|
||||
public LocalizedException(String node, Exception originalException, String... arguments) {
|
||||
super(node);
|
||||
this.node = node;
|
||||
this.arguments = arguments;
|
||||
this.originalException = originalException;
|
||||
}
|
||||
|
||||
public LocalizedException(String node, String... arguments) {
|
||||
this(node, (Exception) null, arguments);
|
||||
}
|
||||
|
||||
public LocalizedException(String node, String[] arguments1, String... arguments2) {
|
||||
this(node, (Exception) null, ArrayUtils.merge(arguments1, arguments2));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Exception originalException() {
|
||||
return originalException;
|
||||
}
|
||||
|
||||
public String[] arguments() {
|
||||
@@ -17,4 +36,32 @@ public class LocalizedException extends RuntimeException {
|
||||
public String node() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setArgument(int index, String argument) {
|
||||
this.arguments[index] = argument;
|
||||
}
|
||||
|
||||
public void appendHeadArgument(String argument) {
|
||||
this.arguments = ArrayUtils.appendElementToArrayHead(this.arguments, argument);
|
||||
}
|
||||
|
||||
public void appendTailArgument(String argument) {
|
||||
this.arguments = ArrayUtils.appendElementToArrayTail(this.arguments, argument);
|
||||
}
|
||||
|
||||
// we should not call this method directly, as it's inaccurate
|
||||
@Override
|
||||
public String getMessage() {
|
||||
if (originalException != null) {
|
||||
return originalException.getMessage();
|
||||
}
|
||||
String text = AdventureHelper.miniMessage().stripTags(TranslationManager.instance().miniMessageTranslation(this.node));
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
text = text.replace("<arg:" + i + ">", arguments[i]);
|
||||
}
|
||||
return text;
|
||||
// return "\n" + "Node: '" + this.node + "'" +
|
||||
// "\n" + "Translation: '" + AdventureHelper.miniMessage().stripTags(TranslationManager.instance().miniMessageTranslation(this.node)) + "'" +
|
||||
// "\n" + "Arguments: " + Arrays.toString(this.arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,26 @@ public class ArrayUtils {
|
||||
return subArray;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] merge(T[] array1, T[] array2) {
|
||||
if (array1 == null && array2 == null) {
|
||||
return null;
|
||||
}
|
||||
if (array1 == null) {
|
||||
return Arrays.copyOf(array2, array2.length);
|
||||
}
|
||||
if (array2 == null) {
|
||||
return Arrays.copyOf(array1, array1.length);
|
||||
}
|
||||
T[] mergedArray = (T[]) Array.newInstance(
|
||||
array1.getClass().getComponentType(),
|
||||
array1.length + array2.length
|
||||
);
|
||||
System.arraycopy(array1, 0, mergedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, mergedArray, array1.length, array2.length);
|
||||
return mergedArray;
|
||||
}
|
||||
|
||||
public static <T> List<T[]> splitArray(T[] array, int chunkSize) {
|
||||
List<T[]> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length; i += chunkSize) {
|
||||
|
||||
@@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.51
|
||||
config_version=30
|
||||
lang_version=7
|
||||
lang_version=8
|
||||
project_group=net.momirealms
|
||||
latest_supported_version=1.21.5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user