Search in sources :

Example 1 with PushableTrait

use of com.denizenscript.denizen.npc.traits.PushableTrait in project Denizen-For-Bukkit by DenizenScript.

the class PushableCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    NPCTag denizenNPC = Utilities.getEntryNPC(scriptEntry);
    if (denizenNPC == null) {
        Debug.echoError("No valid NPC attached to this queue!");
        return;
    }
    PushableTrait trait = denizenNPC.getPushableTrait();
    ElementTag state = scriptEntry.getElement("state");
    DurationTag delay = scriptEntry.getObjectTag("delay");
    ElementTag returnable = scriptEntry.getElement("return");
    if (state == null && delay == null && returnable == null) {
        state = new ElementTag("TOGGLE");
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), denizenNPC, state, delay, returnable);
    }
    if (delay != null) {
        trait.setDelay(delay.getSecondsAsInt());
    }
    if (returnable != null) {
        trait.setReturnable(returnable.asBoolean());
    }
    if (state != null) {
        switch(Toggle.valueOf(state.asString().toUpperCase())) {
            case TRUE:
            case ON:
                trait.setPushable(true);
                break;
            case FALSE:
            case OFF:
                trait.setPushable(false);
                break;
            case TOGGLE:
                trait.setPushable(!trait.isPushable());
                break;
        }
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) PushableTrait(com.denizenscript.denizen.npc.traits.PushableTrait)

Aggregations

PushableTrait (com.denizenscript.denizen.npc.traits.PushableTrait)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1