diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/DamageCauseUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/DamageCauseUtils.java
index 752c23915..0f0c1be64 100644
--- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/DamageCauseUtils.java
+++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/DamageCauseUtils.java
@@ -1,14 +1,13 @@
package net.momirealms.craftengine.bukkit.util;
-import net.momirealms.craftengine.core.util.DamageCause;
+import net.momirealms.craftengine.core.util.DamageSource;
import org.bukkit.event.entity.EntityDamageEvent;
public class DamageCauseUtils {
private DamageCauseUtils() {}
- @SuppressWarnings("deprecation")
- public static EntityDamageEvent.DamageCause toBukkit(DamageCause cause) {
+ public static EntityDamageEvent.DamageCause toBukkit(DamageSource cause) {
return switch (cause) {
case BLOCK_EXPLOSION -> EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
case CAMPFIRE -> EntityDamageEvent.DamageCause.CAMPFIRE;
@@ -42,48 +41,45 @@ public class DamageCauseUtils {
case VOID -> EntityDamageEvent.DamageCause.VOID;
case WITHER -> EntityDamageEvent.DamageCause.WITHER;
case WORLD_BORDER -> EntityDamageEvent.DamageCause.WORLD_BORDER;
- case DRAGON_BREATH -> EntityDamageEvent.DamageCause.DRAGON_BREATH;
- default -> throw new IllegalArgumentException("Unexpected value: " + cause);
+ default -> null;
};
}
- @SuppressWarnings("deprecation")
- public static DamageCause fromBukkit(EntityDamageEvent.DamageCause cause) {
+ public static DamageSource fromBukkit(EntityDamageEvent.DamageCause cause) {
return switch (cause) {
- case BLOCK_EXPLOSION -> DamageCause.BLOCK_EXPLOSION;
- case CAMPFIRE -> DamageCause.CAMPFIRE;
- case CONTACT -> DamageCause.CONTACT;
- case CRAMMING -> DamageCause.CRAMMING;
- case CUSTOM -> DamageCause.CUSTOM;
- case DROWNING -> DamageCause.DROWNING;
- case DRYOUT -> DamageCause.DRYOUT;
- case ENTITY_ATTACK -> DamageCause.ENTITY_ATTACK;
- case ENTITY_EXPLOSION -> DamageCause.ENTITY_EXPLOSION;
- case ENTITY_SWEEP_ATTACK -> DamageCause.ENTITY_SWEEP_ATTACK;
- case FALL -> DamageCause.FALL;
- case FALLING_BLOCK -> DamageCause.FALLING_BLOCK;
- case FIRE -> DamageCause.FIRE;
- case FIRE_TICK -> DamageCause.FIRE_TICK;
- case FLY_INTO_WALL -> DamageCause.FLY_INTO_WALL;
- case FREEZE -> DamageCause.FREEZE;
- case HOT_FLOOR -> DamageCause.HOT_FLOOR;
- case KILL -> DamageCause.KILL;
- case LAVA -> DamageCause.LAVA;
- case LIGHTNING -> DamageCause.LIGHTNING;
- case MAGIC -> DamageCause.MAGIC;
- case MELTING -> DamageCause.MELTING;
- case POISON -> DamageCause.POISON;
- case PROJECTILE -> DamageCause.PROJECTILE;
- case SONIC_BOOM -> DamageCause.SONIC_BOOM;
- case STARVATION -> DamageCause.STARVATION;
- case SUFFOCATION -> DamageCause.SUFFOCATION;
- case SUICIDE -> DamageCause.SUICIDE;
- case THORNS -> DamageCause.THORNS;
- case VOID -> DamageCause.VOID;
- case WITHER -> DamageCause.WITHER;
- case WORLD_BORDER -> DamageCause.WORLD_BORDER;
- case DRAGON_BREATH -> DamageCause.DRAGON_BREATH;
- default -> throw new IllegalArgumentException("Unexpected value: " + cause);
+ case BLOCK_EXPLOSION -> DamageSource.BLOCK_EXPLOSION;
+ case CAMPFIRE -> DamageSource.CAMPFIRE;
+ case CONTACT -> DamageSource.CONTACT;
+ case CRAMMING -> DamageSource.CRAMMING;
+ case CUSTOM -> DamageSource.CUSTOM;
+ case DROWNING -> DamageSource.DROWNING;
+ case DRYOUT -> DamageSource.DRYOUT;
+ case ENTITY_ATTACK -> DamageSource.ENTITY_ATTACK;
+ case ENTITY_EXPLOSION -> DamageSource.ENTITY_EXPLOSION;
+ case ENTITY_SWEEP_ATTACK -> DamageSource.ENTITY_SWEEP_ATTACK;
+ case FALL -> DamageSource.FALL;
+ case FALLING_BLOCK -> DamageSource.FALLING_BLOCK;
+ case FIRE -> DamageSource.FIRE;
+ case FIRE_TICK -> DamageSource.FIRE_TICK;
+ case FLY_INTO_WALL -> DamageSource.FLY_INTO_WALL;
+ case FREEZE -> DamageSource.FREEZE;
+ case HOT_FLOOR -> DamageSource.HOT_FLOOR;
+ case KILL -> DamageSource.KILL;
+ case LAVA -> DamageSource.LAVA;
+ case LIGHTNING -> DamageSource.LIGHTNING;
+ case MAGIC -> DamageSource.MAGIC;
+ case MELTING -> DamageSource.MELTING;
+ case POISON -> DamageSource.POISON;
+ case PROJECTILE -> DamageSource.PROJECTILE;
+ case SONIC_BOOM -> DamageSource.SONIC_BOOM;
+ case STARVATION -> DamageSource.STARVATION;
+ case SUFFOCATION -> DamageSource.SUFFOCATION;
+ case SUICIDE -> DamageSource.SUICIDE;
+ case THORNS -> DamageSource.THORNS;
+ case VOID -> DamageSource.VOID;
+ case WITHER -> DamageSource.WITHER;
+ case WORLD_BORDER -> DamageSource.WORLD_BORDER;
+ default -> null;
};
}
}
diff --git a/common-files/src/main/resources/translations/en.yml b/common-files/src/main/resources/translations/en.yml
index fb1a0a754..63e387783 100644
--- a/common-files/src/main/resources/translations/en.yml
+++ b/common-files/src/main/resources/translations/en.yml
@@ -153,7 +153,7 @@ warning.config.furniture.hitbox.invalid_type: "Issue found in file Issue found in file - The furniture '' is using a custom hitbox with invalid entity type ''."
warning.config.item.duplicate: "Issue found in file - Duplicated item ''. Please check if there is the same configuration in other files."
warning.config.item.settings.unknown: "Issue found in file - The item '' is using an unknown setting type ''."
-warning.config.item.settings.invulnerable-unknown: "Issue found in file - The item '' is using an unknown damage cause type ''."
+warning.config.item.settings.invulnerable.invalid_damage_source: "Issue found in file - The item '' is using an unknown damage source ''. Allowed sources: []."
warning.config.item.missing_material: "Issue found in file - The item '' is missing the required 'material' argument."
warning.config.item.invalid_material: "Issue found in file - The item '' is using an invalid material type ''."
warning.config.item.invalid_custom_model_data: "Issue found in file - The item '' is using a negative custom model data '' which is invalid."
diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml
index e797bdc59..42e4155d7 100644
--- a/common-files/src/main/resources/translations/zh_cn.yml
+++ b/common-files/src/main/resources/translations/zh_cn.yml
@@ -153,7 +153,7 @@ warning.config.furniture.hitbox.invalid_type: "在文件 发现
warning.config.furniture.hitbox.custom.invalid_entity: "在文件 发现问题 - 家具 '' 的自定义碰撞箱使用了无效的实体类型 ''"
warning.config.item.duplicate: "在文件 发现问题 - 重复的物品 '' 请检查其他文件中是否存在相同配置"
warning.config.item.settings.unknown: "在文件 发现问题 - 物品 '' 使用了未知的设置类型 ''"
-warning.config.item.settings.invulnerable-unknown: "在文件 发现问题 - 物品 '' 物品使用了未知的受伤害类型 ''"
+warning.config.item.settings.invulnerable.invalid_damage_source: "在文件 发现问题 - 物品 '' 物品使用了未知的伤害来源类型 '' 允许的来源: []"
warning.config.item.missing_material: "在文件 发现问题 - 物品 '' 缺少必需的 'material' 参数"
warning.config.item.invalid_material: "在文件 发现问题 - 物品 '' 使用了无效的材料类型 ''"
warning.config.item.invalid_custom_model_data: "在文件 发现问题 - 物品 '' 使用了无效的负数模型值 ''."
diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java
index be100b7c0..7136f8b50 100644
--- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java
+++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemSettings.java
@@ -35,7 +35,7 @@ public class ItemSettings {
FoodData foodData = null;
Key consumeReplacement = null;
Key craftRemainder = null;
- List invulnerable = List.of();
+ List invulnerable = List.of();
private ItemSettings() {}
@@ -147,7 +147,7 @@ public class ItemSettings {
return equipment;
}
- public List invulnerable() {
+ public List invulnerable() {
return invulnerable;
}
@@ -216,7 +216,7 @@ public class ItemSettings {
return this;
}
- public ItemSettings invulnerable(List invulnerable) {
+ public ItemSettings invulnerable(List invulnerable) {
this.invulnerable = invulnerable;
return this;
}
@@ -321,12 +321,12 @@ public class ItemSettings {
return settings -> settings.foodData(data);
}));
registerFactory("invulnerable", (value -> {
- List list = MiscUtils.getAsStringList(value).stream().map(it -> {
- try {
- return DamageCause.byName(it);
- } catch (IllegalArgumentException e) {
- throw new LocalizedResourceConfigException("warning.config.item.settings.invulnerable-unknown", it);
+ List list = MiscUtils.getAsStringList(value).stream().map(it -> {
+ DamageSource source = DamageSource.byName(it);
+ if (source == null) {
+ throw new LocalizedResourceConfigException("warning.config.item.settings.invulnerable.invalid_damage_source", it, EnumUtils.toString(DamageSource.values()));
}
+ return source;
}).toList();
return settings -> settings.invulnerable(list);
}));
diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/DamageCause.java b/core/src/main/java/net/momirealms/craftengine/core/util/DamageSource.java
similarity index 58%
rename from core/src/main/java/net/momirealms/craftengine/core/util/DamageCause.java
rename to core/src/main/java/net/momirealms/craftengine/core/util/DamageSource.java
index bf01e6833..738295b77 100644
--- a/core/src/main/java/net/momirealms/craftengine/core/util/DamageCause.java
+++ b/core/src/main/java/net/momirealms/craftengine/core/util/DamageSource.java
@@ -1,11 +1,13 @@
package net.momirealms.craftengine.core.util;
+import org.jetbrains.annotations.Nullable;
+
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
-public enum DamageCause {
+public enum DamageSource {
BLOCK_EXPLOSION,
CAMPFIRE,
CONTACT,
@@ -37,22 +39,19 @@ public enum DamageCause {
THORNS,
VOID,
WITHER,
- WORLD_BORDER,
- @Deprecated
- @SuppressWarnings("all")
- DRAGON_BREATH;
+ WORLD_BORDER;
- public static final Map BY_NAME = new HashMap<>();
+ public static final Map BY_NAME = new HashMap<>();
static {
- for (DamageCause cause : values()) {
- BY_NAME.put(cause.name().toLowerCase(Locale.ROOT), cause);
+ for (DamageSource cause : values()) {
+ BY_NAME.put(cause.name().toLowerCase(Locale.ENGLISH), cause);
BY_NAME.put(cause.name(), cause);
}
}
- public static DamageCause byName(String name) {
- return Optional.ofNullable(BY_NAME.get(name)).orElseThrow(() -> new IllegalArgumentException("Unknown damage cause: " + name));
+ @Nullable
+ public static DamageSource byName(String name) {
+ return BY_NAME.get(name);
}
-
}