Set sleep status every tick for now (only necessary on 1.14 and below)

This commit is contained in:
fullwall 2022-11-15 21:30:23 +08:00
parent d9c55b97b0
commit 9d0028541e
2 changed files with 7 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.trait;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.MemoryNPCDataStore; import net.citizensnpcs.api.npc.MemoryNPCDataStore;
@ -53,6 +54,8 @@ public class SitTrait extends Trait {
if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) { if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) {
NMS.mount(holder.getEntity(), npc.getEntity()); NMS.mount(holder.getEntity(), npc.getEntity());
} }
holder.teleport(sittingAt, TeleportCause.PLUGIN);
} }
public void setSitting(Location at) { public void setSitting(Location at) {

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.block.Bed; import org.bukkit.block.Bed;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
@ -30,18 +29,14 @@ public class SleepTrait extends Trait {
public void run() { public void run() {
if (!npc.isSpawned()) if (!npc.isSpawned())
return; return;
if (sleeping) {
if (at == null) { if (at == null) {
if (sleeping) {
wakeup(); wakeup();
} else {
npc.teleport(at, TeleportCause.PLUGIN);
} }
return; return;
} }
if (at == null)
return;
if (SUPPORT_BLOCKDATA == null) { if (SUPPORT_BLOCKDATA == null) {
try { try {
SUPPORT_BLOCKDATA = true; SUPPORT_BLOCKDATA = true;
@ -50,6 +45,7 @@ public class SleepTrait extends Trait {
SUPPORT_BLOCKDATA = false; SUPPORT_BLOCKDATA = false;
} }
} }
if (npc.getEntity() instanceof Player) { if (npc.getEntity() instanceof Player) {
Player player = (Player) npc.getEntity(); Player player = (Player) npc.getEntity();
if ((SUPPORT_BLOCKDATA && at.getBlock().getBlockData() instanceof Bed) if ((SUPPORT_BLOCKDATA && at.getBlock().getBlockData() instanceof Bed)