use of com.denizenscript.denizen.npc.traits.HungerTrait 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.");
}
}
Aggregations