Add sitting height offset correction check
This commit is contained in:
parent
483b6565cd
commit
2736f4ab53
|
@ -12,6 +12,7 @@ import net.citizensnpcs.api.npc.NPCRegistry;
|
||||||
import net.citizensnpcs.api.persistence.Persist;
|
import net.citizensnpcs.api.persistence.Persist;
|
||||||
import net.citizensnpcs.api.trait.Trait;
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
import net.citizensnpcs.api.trait.TraitName;
|
import net.citizensnpcs.api.trait.TraitName;
|
||||||
|
import net.citizensnpcs.api.util.SpigotUtil;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
|
|
||||||
@TraitName("sittrait")
|
@TraitName("sittrait")
|
||||||
|
@ -38,7 +39,11 @@ public class SitTrait extends Trait {
|
||||||
if (chair != null) {
|
if (chair != null) {
|
||||||
if (chair.getEntity() != null) {
|
if (chair.getEntity() != null) {
|
||||||
chair.getEntity().eject();
|
chair.getEntity().eject();
|
||||||
npc.getEntity().teleport(npc.getEntity().getLocation().clone().add(0, 0.3, 0));
|
Location npcLoc = npc.getEntity().getLocation().clone();
|
||||||
|
if (requiresPassengerOffsetCorrection()) {
|
||||||
|
npcLoc = npcLoc.add(0, 0.3, 0);
|
||||||
|
}
|
||||||
|
npc.getEntity().teleport(npcLoc);
|
||||||
}
|
}
|
||||||
chair.destroy();
|
chair.destroy();
|
||||||
chair = null;
|
chair = null;
|
||||||
|
@ -50,6 +55,11 @@ public class SitTrait extends Trait {
|
||||||
onDespawn();
|
onDespawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean requiresPassengerOffsetCorrection() {
|
||||||
|
return SpigotUtil.getVersion() != null && SpigotUtil.getVersion().length >= 2
|
||||||
|
&& SpigotUtil.getVersion()[1] <= 19;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!npc.isSpawned() || !isSitting())
|
if (!npc.isSpawned() || !isSitting())
|
||||||
|
@ -86,7 +96,11 @@ public class SitTrait extends Trait {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSitting(Location at) {
|
public void setSitting(Location at) {
|
||||||
this.sittingAt = at != null ? at.clone().add(0, -0.3, 0) : null;
|
this.sittingAt = at != null ? at.clone() : null;
|
||||||
|
if (requiresPassengerOffsetCorrection()) {
|
||||||
|
sittingAt = sittingAt.add(0, 0.3, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (at == null) {
|
if (at == null) {
|
||||||
onDespawn();
|
onDespawn();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue