Search in sources :

Example 1 with PushableTrait

use of net.aufdemrand.denizen.npc.traits.PushableTrait in project Denizen-For-Bukkit by DenizenScript.

the class PushableCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dNPC denizenNPC = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    if (denizenNPC == null) {
        throw new CommandExecutionException("No valid NPC attached to this queue!");
    }
    PushableTrait trait = denizenNPC.getPushableTrait();
    Element state = scriptEntry.getElement("state");
    Duration delay = scriptEntry.getdObject("delay");
    Element returnable = scriptEntry.getElement("return");
    if (state == null && delay == null && returnable == null) {
        state = new Element("TOGGLE");
    }
    dB.report(scriptEntry, getName(), (state != null ? state.debug() : "") + (delay != null ? delay.debug() : "") + (returnable != null ? returnable.debug() : ""));
    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 : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) Duration(net.aufdemrand.denizencore.objects.Duration) PushableTrait(net.aufdemrand.denizen.npc.traits.PushableTrait)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 PushableTrait (net.aufdemrand.denizen.npc.traits.PushableTrait)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)1 Duration (net.aufdemrand.denizencore.objects.Duration)1 Element (net.aufdemrand.denizencore.objects.Element)1