mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-12 19:30:50 +01:00
Workaround Spigot knockback bug by setting high knockback resistance on protected NPCs
This commit is contained in:
parent
bf1b116735
commit
5fc1fe33db
@ -311,6 +311,12 @@ public class CitizensNPC extends AbstractNPC {
|
||||
if (getEntity() instanceof LivingEntity) {
|
||||
boolean nameplateVisible = data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true);
|
||||
((LivingEntity) getEntity()).setCustomNameVisible(nameplateVisible);
|
||||
|
||||
if (data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(), 1D);
|
||||
} else {
|
||||
NMS.setKnockbackResistance((LivingEntity) getEntity(), 0D);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Throwable error = Throwables.getRootCause(ex);
|
||||
|
@ -130,8 +130,9 @@ public class CreeperController extends MobEntityController {
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
super.g(x, y, z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Vector vector = new Vector(x, y, z);
|
||||
|
@ -737,6 +737,11 @@ public class NMS {
|
||||
handle.aP = yaw;
|
||||
}
|
||||
|
||||
public static void setKnockbackResistance(org.bukkit.entity.LivingEntity entity, double d) {
|
||||
EntityLiving handle = NMS.getHandle(entity);
|
||||
handle.getAttributeInstance(GenericAttributes.c).setValue(d);
|
||||
}
|
||||
|
||||
public static void setProfile(SkullMeta meta, GameProfile profile) {
|
||||
if (SKULL_PROFILE_FIELD == null) {
|
||||
try {
|
||||
@ -894,7 +899,6 @@ public class NMS {
|
||||
}
|
||||
}
|
||||
|
||||
private static Field CRAFT_TEAM_FIELD;
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
|
||||
private static Map<Class<?>, String> ENTITY_CLASS_TO_NAME;
|
||||
@ -909,7 +913,6 @@ public class NMS {
|
||||
private static final Field RABBIT_FIELD = getField(EntityRabbit.class, "bv");
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
|
||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||
|
||||
static {
|
||||
|
Loading…
Reference in New Issue
Block a user