use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class FeedCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
PlayerTag player = scriptEntry.getObjectTag("targetplayer");
NPCTag npc = scriptEntry.getObjectTag("targetnpc");
ElementTag amount = scriptEntry.getElement("amount");
ElementTag saturation = scriptEntry.getElement("saturation");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
}
if (npc != null) {
if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
Debug.echoError(scriptEntry, "This NPC does not have the HungerTrait enabled! Use /trait hunger");
return;
}
npc.getCitizen().getOrAddTrait(HungerTrait.class).feed(amount.asInt());
} else {
int result = Math.max(0, Math.min(20, player.getPlayerEntity().getFoodLevel() + amount.asInt()));
player.getPlayerEntity().setFoodLevel(result);
float satResult = Math.max(0, Math.min(20, player.getPlayerEntity().getSaturation() + saturation.asFloat()));
player.getPlayerEntity().setSaturation(satResult);
Debug.echoDebug(scriptEntry, "Player food level updated to " + result + " food and " + satResult + " saturation.");
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class LookcloseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag realistic = scriptEntry.getElement("realistic");
ElementTag range = scriptEntry.getElement("range");
ElementTag toggle = scriptEntry.getElement("toggle");
NPCTag npc = scriptEntry.getObjectTag("npc");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, realistic, range, toggle);
}
LookClose trait = npc.getCitizen().getOrAddTrait(LookClose.class);
if (toggle != null) {
trait.lookClose(toggle.asBoolean());
}
if (realistic != null && realistic.asBoolean()) {
trait.setRealisticLooking(true);
} else {
trait.setRealisticLooking(false);
}
if (range != null) {
trait.setRange(range.asInt());
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class PoseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
TargetType target = (TargetType) scriptEntry.getObject("target");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
Action action = (Action) scriptEntry.getObject("action");
ElementTag idElement = scriptEntry.getElement("pose_id");
LocationTag pose_loc = scriptEntry.getObjectTag("pose_loc");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Target", target), (target == TargetType.PLAYER ? Utilities.getEntryPlayer(scriptEntry) : ""), npc, db("Action", action), idElement, pose_loc);
}
if (!npc.getCitizen().hasTrait(Poses.class)) {
npc.getCitizen().addTrait(Poses.class);
}
Poses poses = npc.getCitizen().getOrAddTrait(Poses.class);
String id = idElement.asString();
switch(action) {
case ASSUME:
if (!poses.hasPose(id)) {
Debug.echoError("Pose \"" + id + "\" doesn't exist for " + npc.toString());
}
if (target.name().equals("NPC")) {
poses.assumePose(id);
} else {
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
Location location = player.getLocation();
location.setYaw(poses.getPose(id).getYaw());
location.setPitch(poses.getPose(id).getPitch());
// The only way to change a player's yaw and pitch in Bukkit is to use teleport on them
player.teleport(location);
}
break;
case ADD:
if (!poses.addPose(id, pose_loc)) {
Debug.echoError(npc.toString() + " already has that pose!");
}
break;
case REMOVE:
if (!poses.removePose(id)) {
Debug.echoError(npc.toString() + " does not have that pose!");
}
break;
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class TriggerCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag toggle = scriptEntry.getElement("toggle");
ElementTag trigger = scriptEntry.getElement("trigger");
ElementTag radius = scriptEntry.getElement("radius");
DurationTag cooldown = scriptEntry.getObjectTag("cooldown");
NPCTag npc = scriptEntry.hasObject("npc") ? (NPCTag) scriptEntry.getObject("npc") : Utilities.getEntryNPC(scriptEntry);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), trigger, toggle, radius, cooldown, npc);
}
// Add trigger trait
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
npc.getCitizen().addTrait(TriggerTrait.class);
}
TriggerTrait trait = npc.getCitizen().getOrAddTrait(TriggerTrait.class);
switch(Toggle.valueOf(toggle.asString().toUpperCase())) {
case TOGGLE:
trait.toggleTrigger(trigger.asString());
break;
case TRUE:
trait.toggleTrigger(trigger.asString(), true);
break;
case FALSE:
trait.toggleTrigger(trigger.asString(), false);
break;
}
if (radius != null) {
trait.setLocalRadius(trigger.asString(), radius.asInt());
}
if (cooldown != null) {
trait.setLocalCooldown(trigger.asString(), cooldown.getSeconds());
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class BreakCommand method execute.
// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) {
final LocationTag location = scriptEntry.getObjectTag("location");
final NPCTag npc = scriptEntry.getObjectTag("npc");
ElementTag radius = scriptEntry.getElement("radius");
final HashMap<String, ObjectTag> context = new HashMap<>();
MaterialTag material = new MaterialTag(location.getBlock());
context.put("location", location);
context.put("material", material);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, npc, radius);
}
final ScriptEntry se = scriptEntry;
BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
config.item(npc.getLivingEntity().getEquipment().getItemInMainHand());
config.radius(radius.asDouble());
config.callback(() -> {
npc.action("dig", null, context);
se.setFinished(true);
});
BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
if (breaker.shouldExecute()) {
TaskRunnable run = new TaskRunnable(breaker);
run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.getInstance(), run, 0, 1);
} else {
se.setFinished(true);
}
}
Aggregations