Restructure code for cleanliness

This commit is contained in:
fullwall 2024-09-29 16:22:16 +08:00
parent 59534df8c0
commit 2ba1a1580d

View File

@ -392,24 +392,20 @@ public class CitizensNPC extends AbstractNPC {
LivingEntity entity = (LivingEntity) getEntity(); LivingEntity entity = (LivingEntity) getEntity();
entity.setRemoveWhenFarAway(false); entity.setRemoveWhenFarAway(false);
if ((!hasTrait(AttributeTrait.class) if (type == EntityType.PLAYER || Util.isHorse(type)) {
|| !getTrait(AttributeTrait.class).hasAttribute(Attribute.GENERIC_STEP_HEIGHT)) if (SUPPORT_ATTRIBUTES && !hasTrait(AttributeTrait.class)
&& (type == EntityType.PLAYER || Util.isHorse(type))) { || !getTrait(AttributeTrait.class).hasAttribute(Attribute.GENERIC_STEP_HEIGHT)) {
NMS.setStepHeight(entity, 1); NMS.setStepHeight(entity, 1);
}
} }
if (type == EntityType.PLAYER) { if (type == EntityType.PLAYER) {
PlayerUpdateTask.registerPlayer(getEntity()); PlayerUpdateTask.registerPlayer(getEntity());
} else if (data().has(NPC.Metadata.AGGRESSIVE)) { } else if (data().has(NPC.Metadata.AGGRESSIVE)) {
NMS.setAggressive(entity, data().<Boolean> get(NPC.Metadata.AGGRESSIVE)); NMS.setAggressive(entity, data().<Boolean> get(NPC.Metadata.AGGRESSIVE));
} }
if (SUPPORT_NODAMAGE_TICKS && (Setting.DEFAULT_SPAWN_NODAMAGE_DURATION.asTicks() != 20 if (SUPPORT_NODAMAGE_TICKS) {
|| data().has(NPC.Metadata.SPAWN_NODAMAGE_TICKS))) { entity.setNoDamageTicks(data().get(NPC.Metadata.SPAWN_NODAMAGE_TICKS,
try { Setting.DEFAULT_SPAWN_NODAMAGE_DURATION.asTicks()));
entity.setNoDamageTicks(data().get(NPC.Metadata.SPAWN_NODAMAGE_TICKS,
Setting.DEFAULT_SPAWN_NODAMAGE_DURATION.asTicks()));
} catch (NoSuchMethodError err) {
SUPPORT_NODAMAGE_TICKS = false;
}
} }
} }
if (requiresNameHologram() && !hasTrait(HologramTrait.class)) { if (requiresNameHologram() && !hasTrait(HologramTrait.class)) {
@ -609,6 +605,7 @@ public class CitizensNPC extends AbstractNPC {
} }
private static final SetMultimap<ChunkCoord, NPC> CHUNK_LOADERS = HashMultimap.create(); private static final SetMultimap<ChunkCoord, NPC> CHUNK_LOADERS = HashMultimap.create();
private static boolean SUPPORT_ATTRIBUTES = false;
private static boolean SUPPORT_GLOWING = false; private static boolean SUPPORT_GLOWING = false;
private static boolean SUPPORT_NODAMAGE_TICKS = false; private static boolean SUPPORT_NODAMAGE_TICKS = false;
private static boolean SUPPORT_PICKUP_ITEMS = false; private static boolean SUPPORT_PICKUP_ITEMS = false;
@ -635,5 +632,10 @@ public class CitizensNPC extends AbstractNPC {
SUPPORT_PICKUP_ITEMS = true; SUPPORT_PICKUP_ITEMS = true;
} catch (NoSuchMethodException | SecurityException e) { } catch (NoSuchMethodException | SecurityException e) {
} }
try {
Class.forName("org.bukkit.attribute.Attribute");
SUPPORT_ATTRIBUTES = true;
} catch (ClassNotFoundException e) {
}
} }
} }