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);
}
}
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;
}
}
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());
}
}
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);
}
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);
}
Aggregations