Skip to content

Commit

Permalink
NPC commands cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 20, 2020
1 parent 7775a0a commit d24895a
Showing 1 changed file with 28 additions and 5 deletions.
Expand Up @@ -377,14 +377,17 @@ else if (args.hasValueFlag("anchor")) {
Anchors anchors = npc.getTrait(Anchors.class);
if (anchors.getAnchor(args.getFlag("anchor")) != null) {
trait.sit(anchors.getAnchor(args.getFlag("anchor")).getLocation());
Messaging.send(sender, npc.getName() + " is now sitting.");
return;
}
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
return;
}
else {
trait.sit();
}

Messaging.send(sender, npc.getName() + " is now sitting.");
}

/*
Expand All @@ -401,6 +404,7 @@ public void standing(CommandContext args, CommandSender sender, NPC npc) throws
SittingTrait trait = npc.getTrait(SittingTrait.class);
trait.stand();
npc.removeTrait(SittingTrait.class);
Messaging.send(sender, npc.getName() + " is now standing.");
}
else if (npc.hasTrait(SneakingTrait.class)) {
SneakingTrait trait = npc.getTrait(SneakingTrait.class);
Expand All @@ -411,6 +415,21 @@ else if (npc.hasTrait(SneakingTrait.class)) {
}
trait.stand();
npc.removeTrait(SneakingTrait.class);
Messaging.send(sender, npc.getName() + " is now standing.");
}
else if (npc.hasTrait(SleepingTrait.class)) {
SleepingTrait trait = npc.getTrait(SleepingTrait.class);
if (!trait.isSleeping()) {
npc.removeTrait(SleepingTrait.class);
Messaging.sendError(sender, npc.getName() + " is already standing!");
return;
}
trait.wakeUp();
npc.removeTrait(SleepingTrait.class);
Messaging.send(sender, npc.getName() + " is now standing.");
}
else {
Messaging.sendError(sender, npc.getName() + " is already standing!");
}
}

Expand All @@ -435,26 +454,29 @@ public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws
}

if (args.hasValueFlag("location")) {
String[] argsArray = args.getFlag("location").split(",");
if (argsArray.length != 4) {
LocationTag location = LocationTag.valueOf(args.getFlag("location"));
if (location == null) {
Messaging.sendError(sender, "Usage: /npc sleep --location x,y,z,world");
return;
}
trait.toSleep(LocationTag.valueOf(argsArray[0] + "," + argsArray[1] + "," + argsArray[2] + "," + argsArray[3]));
trait.toSleep(location);
}
else if (args.hasValueFlag("anchor")) {
if (npc.hasTrait(Anchors.class)) {
Anchors anchors = npc.getTrait(Anchors.class);
if (anchors.getAnchor(args.getFlag("anchor")) != null) {
trait.toSleep(anchors.getAnchor(args.getFlag("anchor")).getLocation());
Messaging.send(sender, npc.getName() + " is now sleeping.");
return;
}
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
return;
}
else {
trait.toSleep();
}

Messaging.send(sender, npc.getName() + " is now sleeping.");
}

/*
Expand All @@ -479,6 +501,7 @@ public void wakingup(CommandContext args, CommandSender sender, NPC npc) throws

trait.wakeUp();
npc.removeTrait(SleepingTrait.class);
Messaging.send(sender, npc.getName() + " is no longer sleeping.");
}

/*
Expand Down

0 comments on commit d24895a

Please sign in to comment.