Skip to content

Commit

Permalink
type check in sleep command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 20, 2021
1 parent 6163cc0 commit bcf48c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Expand Up @@ -22,12 +22,9 @@ public class SleepingTrait extends Trait {

@Override
public void run() {
if (npc == null || bedLocation == null) {
if (npc == null || bedLocation == null || !npc.isSpawned()) {
return;
}

//if (npc.getEntity().getPassenger() == null && sitting) eh.mount(eh);

if (!Utilities.checkLocation((LivingEntity) npc.getEntity(), bedLocation, 1)) {
wakeUp();
}
Expand All @@ -46,14 +43,17 @@ public void internalSleepNow() {
return;
}
}
else { // Player
else if (npc.getEntity() instanceof Player) {
if (bedLocation.getBlock().getBlockData() instanceof Bed) {
((Player) npc.getEntity()).sleep(bedLocation.clone(), true);
}
else {
PlayerAnimation.SLEEP.play((Player) npc.getEntity());
}
}
else {
return;
}
sleeping = true;
}

Expand All @@ -79,11 +79,6 @@ public void toSleep(Location location) {
if (sleeping) {
return;
}

/*
* Teleport NPC to the location before
* playing sleep animation.
*/
//TODO Adjust the .add()
npc.getEntity().teleport(location.clone().add(0.5, 0, 0.5));
bedLocation = location.clone();
Expand Down
Expand Up @@ -417,9 +417,9 @@ else if (npc.hasTrait(SleepingTrait.class)) {

@Command(
aliases = {"npc"}, usage = "sleep (--location x,y,z,world) (--anchor anchor_name)",
desc = "Makes the NPC sleep.", modifiers = {"sleep"},
desc = "Makes the NPC sleep.", modifiers = {"sleep" },
min = 1, max = 3, permission = "denizen.npc.sleep")
@Requirements(selected = true, ownership = true)
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER, EntityType.PLAYER })
public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SleepingTrait trait = npc.getOrAddTrait(SleepingTrait.class);
if (trait.isSleeping()) {
Expand Down

0 comments on commit bcf48c8

Please sign in to comment.