Search in sources :

Example 1 with SittingTrait

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

the class SitCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = (dLocation) scriptEntry.getObject("location");
    if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.PLAYER && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.OCELOT && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.WOLF) {
        dB.echoError(scriptEntry.getResidingQueue(), "...only Player, ocelot, or wolf type NPCs can sit!");
        return;
    }
    dB.report(scriptEntry, getName(), aH.debugObj("npc", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC()) + (location != null ? location.debug() : ""));
    if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() == EntityType.OCELOT) {
        ((Ocelot) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setSitting(true);
    } else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() == EntityType.WOLF) {
        ((Wolf) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setSitting(true);
    } else {
        SittingTrait trait = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().getTrait(SittingTrait.class);
        if (!((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().hasTrait(SittingTrait.class)) {
            ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().addTrait(SittingTrait.class);
            dB.echoDebug(scriptEntry, "...added sitting trait");
        }
        if (location != null) {
            trait.sit(location);
        } else {
            trait.sit();
        }
    }
}
Also used : Ocelot(org.bukkit.entity.Ocelot) SittingTrait(net.aufdemrand.denizen.npc.traits.SittingTrait) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 SittingTrait (net.aufdemrand.denizen.npc.traits.SittingTrait)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 Ocelot (org.bukkit.entity.Ocelot)1