mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-26 10:01:46 +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) {
|
if (getEntity() instanceof LivingEntity) {
|
||||||
boolean nameplateVisible = data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true);
|
boolean nameplateVisible = data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true);
|
||||||
((LivingEntity) getEntity()).setCustomNameVisible(nameplateVisible);
|
((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) {
|
} catch (Exception ex) {
|
||||||
Throwable error = Throwables.getRootCause(ex);
|
Throwable error = Throwables.getRootCause(ex);
|
||||||
|
@ -130,8 +130,9 @@ public class CreeperController extends MobEntityController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
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);
|
super.g(x, y, z);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector vector = new Vector(x, y, z);
|
Vector vector = new Vector(x, y, z);
|
||||||
|
@ -737,6 +737,11 @@ public class NMS {
|
|||||||
handle.aP = yaw;
|
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) {
|
public static void setProfile(SkullMeta meta, GameProfile profile) {
|
||||||
if (SKULL_PROFILE_FIELD == null) {
|
if (SKULL_PROFILE_FIELD == null) {
|
||||||
try {
|
try {
|
||||||
@ -894,7 +899,6 @@ public class NMS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Field CRAFT_TEAM_FIELD;
|
|
||||||
private static final float DEFAULT_SPEED = 1F;
|
private static final float DEFAULT_SPEED = 1F;
|
||||||
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
|
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
|
||||||
private static Map<Class<?>, String> ENTITY_CLASS_TO_NAME;
|
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 Field RABBIT_FIELD = getField(EntityRabbit.class, "bv");
|
||||||
private static final Random RANDOM = Util.getFastRandom();
|
private static final Random RANDOM = Util.getFastRandom();
|
||||||
private static Field SKULL_PROFILE_FIELD;
|
private static Field SKULL_PROFILE_FIELD;
|
||||||
|
|
||||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
Loading…
Reference in New Issue
Block a user