diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 6b387bd4d..6b918c595 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -66,7 +66,7 @@ command.send_resource_pack.success.multiple: "Send resource packs to Issue found in file - '.' is expected to be a config section while it's actually a(n) ''." warning.config.image.duplicated: "Issue found in file - Duplicated image ''." warning.config.image.lack_height: "Issue found in file - The image '' is missing the required 'height' argument." -warning.config.image.height_smaller_than_ascent: "Issue found in file - The image '' violates the bitmap image rule: 'height' should be no lower than 'ascent'." +warning.config.image.height_smaller_than_ascent: "Issue found in file - The image '' violates the bitmap image rule: 'height'[] should be no lower than 'ascent'[]." warning.config.image.lack_file: "Issue found in file - The image '' is missing the required 'file' argument." warning.config.image.invalid_resource_location: "Issue found in file - The image '' has a 'file' argument [] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters" warning.config.image.invalid_font_name: "Issue found in file - The image '' has a 'font' argument [] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters" @@ -74,6 +74,7 @@ warning.config.image.lack_char: "Issue found in file - The image warning.config.image.codepoint_in_use: "Issue found in file - The image '' is using a character[()] in font that has been used by another image ''." warning.config.image.invalid_codepoint_grid: "Issue found in file - Image '' has an invalid 'chars' codepoint grind." warning.config.image.file_not_exist: "Issue found in file - PNG file '' not found for image ''." +warning.config.image.invalid_hex: "Issue found in file - The image '' is using an unicode character '' that is not a valid hexadecimal (radix 16) value." warning.config.recipe.duplicated: "Issue found in file - Duplicated recipe ''." warning.config.recipe.lack_type: "Issue found in file - The recipe '' is missing the required argument 'type'." warning.config.recipe.invalid_type: "Issue found in file - The recipe '' is using an invalid recipe type ''." @@ -81,6 +82,8 @@ warning.config.recipe.invalid_item: "Issue found in file - The r warning.config.recipe.lack_ingredient: "Issue found in file - The cooking recipe '' is missing the required 'ingredient' argument." warning.config.recipe.lack_result: "Issue found in file - The recipe '' is missing the required argument 'result'." warning.config.recipe.result.lack_id: "Issue found in file - The recipe '' is missing the required argument 'id' for recipe result." +warning.config.recipe.crafting.invalid_category: "Issue found in file - The crafting recipe '' is using an invalid category ''. Allowed categories: [BUILDING, REDSTONE, EQUIPMENT, MISC]" +warning.config.recipe.cooking.invalid_category: "Issue found in file - The cooking recipe '' is using an invalid category ''. Allowed categories: [FOOD, BLOCKS, MISC]" warning.config.recipe.shaped.lack_pattern: "Issue found in file - The shaped recipe '' is missing the required argument 'pattern'." warning.config.recipe.shaped.invalid_pattern: "Issue found in file - The shaped recipe '' is using an invalid pattern ''." warning.config.recipe.shaped.invalid_symbol: "Issue found in file - The shaped recipe '' is using an invalid symbol '' in pattern." diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index 65dbaa320..e4e3185bc 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -65,8 +65,8 @@ command.send_resource_pack.success.single: "发送资源包给 发送资源包给 个玩家" warning.config.image.duplicated: "在文件 中发现问题 - 图片 '' 重复定义" warning.config.image.lack_height: "在文件 中发现问题 - 图片 '' 缺少必要的 'height' 高度参数" -warning.config.image.height_smaller_than_ascent: "在文件 中发现问题 - 图片 '' 违反位图规则:'height' 高度值不应小于 'ascent' 基准线高度" -warning.config.image.no_file: "在文件 中发现问题 - 图片 '' 缺少必要的 'file' 文件参数" +warning.config.image.height_smaller_than_ascent: "在文件 中发现问题 - 图片 '' 违反位图规则:'height' 高度值[]不应小于 'ascent' 基准线高度[]" +warning.config.image.lack_file: "在文件 中发现问题 - 图片 '' 缺少必要的 'file' 文件参数" warning.config.image.invalid_resource_location: "在文件 中发现问题 - 图片 '' 的 'file' 参数 [] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6" warning.config.image.invalid_font_name: "在文件 中发现问题 - 图片 '' 的 'font' 字体参数 [] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6" warning.config.image.lack_char: "在文件 中发现问题 - 图片 '' 缺少必要的 'char' 字符参数" @@ -74,7 +74,7 @@ warning.config.image.codepoint_in_use: "在文件 中发现问 warning.config.image.invalid_codepoint_grid: "在文件 中发现问题 - 图片 '' 的 'chars' 码位网格配置无效" warning.config.image.file_not_exist: "在文件 中发现问题 - 图片 '' 对应的PNG文件 不存在" warning.config.recipe.duplicated: "在文件 中发现问题 - 配方 '' 重复定义" -warning.config.i18n.unknown_locale: "在文件 中发现问题 - 未知的语言区域 ''" +warning.config.i18n.unknown_locale: "在文件 中发现问题 - 未知的语言 ''" warning.config.template.duplicated: "在文件 中发现问题 - 模板 '' 重复定义" warning.config.vanilla_loot.type_not_exist: "在文件 中发现问题 - 原版战利品 '' 未设置 'type' 类型参数" warning.config.vanilla_loot.block.invalid_target: "在文件 中发现问题 - 原版战利品 '' 中的方块目标 [] 无效" diff --git a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java index bc7426351..c2d829228 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java @@ -518,7 +518,7 @@ public abstract class AbstractFontManager implements FontManager { int height = MiscUtils.getAsInt(heightObj); int ascent = MiscUtils.getAsInt(section.getOrDefault("ascent", height - 1)); if (height < ascent) { - throw new LocalizedResourceConfigException("warning.config.image.height_smaller_than_ascent", path, id); + throw new LocalizedResourceConfigException("warning.config.image.height_smaller_than_ascent", path, id, String.valueOf(height), String.valueOf(ascent)); } BitmapImage bitmapImage = new BitmapImage(id, fontKey, height, ascent, resourceLocation, codepointGrid); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeFactory.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeFactory.java index bfb72ec03..f19b239d9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeFactory.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeFactory.java @@ -7,10 +7,7 @@ import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public abstract class AbstractRecipeFactory implements RecipeFactory { @@ -45,4 +42,24 @@ public abstract class AbstractRecipeFactory implements RecipeFactory { } return ingredient; } + + protected CookingRecipeCategory cookingRecipeCategory(Map arguments) { + CookingRecipeCategory recipeCategory; + try { + recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; + } catch (IllegalArgumentException e) { + throw new LocalizedResourceConfigException("warning.config.recipe.cooking.invalid_category", e, arguments.get("category").toString()); + } + return recipeCategory; + } + + protected CraftingRecipeCategory craftingRecipeCategory(Map arguments) { + CraftingRecipeCategory recipeCategory; + try { + recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; + } catch (IllegalArgumentException e) { + throw new LocalizedResourceConfigException("warning.config.recipe.crafting.invalid_category", e, arguments.get("category").toString()); + } + return recipeCategory; + } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java index c5d68e2c1..2ec2dc0ae 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java @@ -26,12 +26,11 @@ public class CustomBlastingRecipe extends CustomCookingRecipe { @SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"}) @Override public Recipe create(Key id, Map arguments) { - CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80)); float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f)); Set> holders = ingredientHolders(arguments); - return new CustomBlastingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); + return new CustomBlastingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java index 96a983fec..0a60194cd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java @@ -26,12 +26,11 @@ public class CustomCampfireRecipe extends CustomCookingRecipe { @SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"}) @Override public Recipe create(Key id, Map arguments) { - CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80)); float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f)); Set> holders = ingredientHolders(arguments); - return new CustomCampfireRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); + return new CustomCampfireRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java index 4000cde6c..30cfccd46 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java @@ -147,7 +147,6 @@ public class CustomShapedRecipe extends CustomCraftingTableRecipe { throw new LocalizedResourceConfigException("warning.config.recipe.shaped.invalid_pattern", new IllegalArgumentException("Invalid pattern: " + pattern), pattern.toString()); } Object ingredientObj = getIngredientOrThrow(arguments); - CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; Map> ingredients = new HashMap<>(); for (Map.Entry entry : MiscUtils.castToMap(ingredientObj, false).entrySet()) { @@ -168,13 +167,7 @@ public class CustomShapedRecipe extends CustomCraftingTableRecipe { } ingredients.put(ch, Ingredient.of(holders)); } - return new CustomShapedRecipe( - id, - recipeCategory, - group, - new Pattern<>(pattern.toArray(new String[0]), ingredients), - parseResult(arguments) - ); + return new CustomShapedRecipe(id, craftingRecipeCategory(arguments), group, new Pattern<>(pattern.toArray(new String[0]), ingredients), parseResult(arguments)); } private boolean validatePattern(List pattern) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java index 7668a13bc..152199a8a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java @@ -58,7 +58,6 @@ public class CustomShapelessRecipe extends CustomCraftingTableRecipe { @SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"}) @Override public Recipe create(Key id, Map arguments) { - CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; List> ingredients = new ArrayList<>(); Object ingredientsObject = getIngredientOrThrow(arguments); @@ -112,7 +111,7 @@ public class CustomShapelessRecipe extends CustomCraftingTableRecipe { } ingredients.add(Ingredient.of(holders)); } - return new CustomShapelessRecipe(id, recipeCategory, group, ingredients, parseResult(arguments)); + return new CustomShapelessRecipe(id, craftingRecipeCategory(arguments), group, ingredients, parseResult(arguments)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java index b08089f7b..b85c1a137 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.item.recipe; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; @@ -26,12 +27,11 @@ public class CustomSmeltingRecipe extends CustomCookingRecipe { @SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"}) @Override public Recipe create(Key id, Map arguments) { - CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80)); float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f)); Set> holders = ingredientHolders(arguments); - return new CustomSmeltingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); + return new CustomSmeltingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java index df5e02007..308fed3a4 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.item.recipe; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; @@ -26,12 +27,11 @@ public class CustomSmokingRecipe extends CustomCookingRecipe { @SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"}) @Override public Recipe create(Key id, Map arguments) { - CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null; String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80)); float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f)); Set> holders = ingredientHolders(arguments); - return new CustomSmokingRecipe(id, recipeCategory, group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); + return new CustomSmokingRecipe(id, cookingRecipeCategory(arguments), group, Ingredient.of(holders), cookingTime, experience, parseResult(arguments)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/RecipeTypes.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/RecipeTypes.java index 12918f6bf..4061a266f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/RecipeTypes.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/RecipeTypes.java @@ -42,7 +42,7 @@ public class RecipeTypes { public static Recipe fromMap(Key id, Map map) { String type = (String) map.get("type"); if (type == null) { - throw new LocalizedResourceConfigException("warning.config.recipe.lack_type", new NullPointerException("recipe type cannot be null")); + throw new LocalizedResourceConfigException("warning.config.recipe.lack_type", new NullPointerException("'type' cannot be null for recipe")); } Key key = Key.withDefaultNamespace(type, "minecraft"); RecipeFactory factory = (RecipeFactory) BuiltInRegistries.RECIPE_FACTORY.getValue(key); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/CharacterUtils.java b/core/src/main/java/net/momirealms/craftengine/core/util/CharacterUtils.java index fe8c26071..5d00bb55e 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/CharacterUtils.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/CharacterUtils.java @@ -1,5 +1,7 @@ package net.momirealms.craftengine.core.util; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; + import java.util.stream.IntStream; public class CharacterUtils { @@ -11,12 +13,17 @@ public class CharacterUtils { int length = processedString.length() / 4; char[] chars = new char[length]; for (int i = 0; i < length; i++) { - int codePoint = Integer.parseInt(processedString.substring(i * 4, i * 4 + 4), 16); - if (Character.isSupplementaryCodePoint(codePoint)) { - chars[i] = Character.highSurrogate(codePoint); - chars[++i] = Character.lowSurrogate(codePoint); - } else { - chars[i] = (char) codePoint; + String hex = processedString.substring(i * 4, i * 4 + 4); + try { + int codePoint = Integer.parseInt(hex, 16); + if (Character.isSupplementaryCodePoint(codePoint)) { + chars[i] = Character.highSurrogate(codePoint); + chars[++i] = Character.lowSurrogate(codePoint); + } else { + chars[i] = (char) codePoint; + } + } catch (NumberFormatException e) { + throw new LocalizedResourceConfigException(""); } } return chars; diff --git a/gradle.properties b/gradle.properties index edcf8da9f..aff8fe40a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.51 +project_version=0.0.52-beta.1 config_version=30 lang_version=8 project_group=net.momirealms