Search in sources :

Example 86 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class RenameCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    Element name = (Element) scriptEntry.getObject("name");
    dB.report(scriptEntry, getName(), name.debug());
    NPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen();
    Location prev = npc.isSpawned() ? npc.getEntity().getLocation() : null;
    npc.despawn(DespawnReason.PENDING_RESPAWN);
    npc.setName(name.asString().length() > 128 ? name.asString().substring(0, 128) : name.asString());
    if (prev != null) {
        npc.spawn(prev);
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Element(net.aufdemrand.denizencore.objects.Element) Location(org.bukkit.Location)

Example 87 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class TraitCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element toggle = scriptEntry.getElement("state");
    Element traitName = scriptEntry.getElement("trait");
    NPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen();
    dB.report(scriptEntry, getName(), traitName.debug() + toggle.debug() + ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().debug());
    Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString());
    if (trait == null) {
        dB.echoError(scriptEntry.getResidingQueue(), "Trait not found: " + traitName.asString());
        return;
    }
    switch(Toggle.valueOf(toggle.asString())) {
        case TRUE:
        case ON:
            if (npc.hasTrait(trait)) {
                dB.echoError(scriptEntry.getResidingQueue(), "NPC already has trait '" + traitName.asString() + "'");
            } else {
                npc.addTrait(trait);
            }
            break;
        case FALSE:
        case OFF:
            if (!npc.hasTrait(trait)) {
                dB.echoError(scriptEntry.getResidingQueue(), "NPC does not have trait '" + traitName.asString() + "'");
            } else {
                npc.removeTrait(trait);
            }
            break;
        case TOGGLE:
            if (npc.hasTrait(trait)) {
                npc.removeTrait(trait);
            } else {
                npc.addTrait(trait);
            }
            break;
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Element(net.aufdemrand.denizencore.objects.Element)

Example 88 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class TriggerCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element toggle = scriptEntry.getElement("toggle");
    Element trigger = scriptEntry.getElement("trigger");
    Element radius = scriptEntry.getElement("radius");
    Duration cooldown = (Duration) scriptEntry.getObject("cooldown");
    dNPC npc = scriptEntry.hasObject("npc") ? (dNPC) scriptEntry.getObject("npc") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    dB.report(scriptEntry, getName(), trigger.debug() + toggle.debug() + (radius != null ? radius.debug() : "") + (cooldown != null ? cooldown.debug() : "") + npc.debug());
    // Add trigger trait
    if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
        npc.getCitizen().addTrait(TriggerTrait.class);
    }
    TriggerTrait trait = npc.getCitizen().getTrait(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());
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) TriggerTrait(net.aufdemrand.denizen.npc.traits.TriggerTrait) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration)

Example 89 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PistonExtendsScriptEvent method onPistonExtends.

@EventHandler
public void onPistonExtends(BlockPistonExtendEvent event) {
    location = new dLocation(event.getBlock().getLocation());
    material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
    sticky = new Element(event.isSticky() ? "true" : "false");
    relative = new dLocation(event.getBlock().getRelative(event.getDirection()).getLocation());
    blocks = new dList();
    for (Block block : event.getBlocks()) {
        blocks.add(new dLocation(block.getLocation()).identify());
    }
    length = new Element(blocks.size());
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 90 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PistonRetractsScriptEvent method onPistonRetracts.

@EventHandler
public void onPistonRetracts(BlockPistonRetractEvent event) {
    location = new dLocation(event.getBlock().getLocation());
    material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
    sticky = new Element(event.isSticky() ? "true" : "false");
    relative = new dLocation(event.getBlock().getRelative(event.getDirection().getOppositeFace()).getLocation());
    blocks = new dList();
    for (Block block : event.getBlocks()) {
        blocks.add(new dLocation(block.getLocation()).identify());
    }
    retract_location = new dLocation(event.getBlock().getRelative(event.getDirection().getOppositeFace(), 2).getLocation());
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9