mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
改进伤害免疫
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ warning.config.furniture.hitbox.invalid_type: "<yellow>Issue found in file <arg:
|
||||
warning.config.furniture.hitbox.custom.invalid_entity: "<yellow>Issue found in file <arg:0> - The furniture '<arg:1>' is using a custom hitbox with invalid entity type '<arg:2>'.</yellow>"
|
||||
warning.config.item.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated item '<arg:1>'. Please check if there is the same configuration in other files.</yellow>"
|
||||
warning.config.item.settings.unknown: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an unknown setting type '<arg:2>'.</yellow>"
|
||||
warning.config.item.settings.invulnerable-unknown: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an unknown damage cause type '<arg:2>'.</yellow>"
|
||||
warning.config.item.settings.invulnerable.invalid_damage_source: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an unknown damage source '<arg:2>'. Allowed sources: [<arg:3>].</yellow>"
|
||||
warning.config.item.missing_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>"
|
||||
warning.config.item.invalid_custom_model_data: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using a negative custom model data '<arg:2>' which is invalid.</yellow>"
|
||||
|
||||
@@ -153,7 +153,7 @@ warning.config.furniture.hitbox.invalid_type: "<yellow>在文件 <arg:0> 发现
|
||||
warning.config.furniture.hitbox.custom.invalid_entity: "<yellow>在文件 <arg:0> 发现问题 - 家具 '<arg:1>' 的自定义碰撞箱使用了无效的实体类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的物品 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>"
|
||||
warning.config.item.settings.unknown: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了未知的设置类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.settings.invulnerable-unknown: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 物品使用了未知的受伤害类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.settings.invulnerable.invalid_damage_source: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 物品使用了未知的伤害来源类型 '<arg:2>' 允许的来源: [<arg:3>]</yellow>"
|
||||
warning.config.item.missing_material: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少必需的 'material' 参数</yellow>"
|
||||
warning.config.item.invalid_material: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了无效的材料类型 '<arg:2>'</yellow>"
|
||||
warning.config.item.invalid_custom_model_data: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 使用了无效的负数模型值 '<arg:2>'.</yellow>"
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ItemSettings {
|
||||
FoodData foodData = null;
|
||||
Key consumeReplacement = null;
|
||||
Key craftRemainder = null;
|
||||
List<DamageCause> invulnerable = List.of();
|
||||
List<DamageSource> invulnerable = List.of();
|
||||
|
||||
private ItemSettings() {}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ItemSettings {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public List<DamageCause> invulnerable() {
|
||||
public List<DamageSource> invulnerable() {
|
||||
return invulnerable;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class ItemSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings invulnerable(List<DamageCause> invulnerable) {
|
||||
public ItemSettings invulnerable(List<DamageSource> invulnerable) {
|
||||
this.invulnerable = invulnerable;
|
||||
return this;
|
||||
}
|
||||
@@ -321,12 +321,12 @@ public class ItemSettings {
|
||||
return settings -> settings.foodData(data);
|
||||
}));
|
||||
registerFactory("invulnerable", (value -> {
|
||||
List<DamageCause> 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<DamageSource> 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);
|
||||
}));
|
||||
|
||||
@@ -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<String, DamageCause> BY_NAME = new HashMap<>();
|
||||
public static final Map<String, DamageSource> 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user