use of net.aufdemrand.denizen.BukkitScriptEntryData 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();
}
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
scriptEntry.addObject("type", Type.ITEMINHAND);
} else if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("qty", arg.asElement());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.BYDISPLAY);
scriptEntry.addObject("displayname", arg.asElement());
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
scriptEntry.addObject("type", Type.BYCOVER);
scriptEntry.addObject("cover", arg.asType(dList.class));
} else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("type", Type.SLOT);
scriptEntry.addObject("slot", arg.asElement());
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(dItem.class)) {
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(dInventory.class)) {
scriptEntry.addObject("inventory", arg.asType(dInventory.class));
} else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
scriptEntry.addObject("type", Type.INVENTORY);
} else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity().getInventory());
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("qty", new Element(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to take from!");
}
if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
throw new InvalidArgumentsException("Must specify item/items!");
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class FlyCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
scriptEntry.addObject("cancel", "");
} else if (!scriptEntry.hasObject("destinations") && arg.matchesPrefix("destination", "destinations", "d")) {
scriptEntry.addObject("destinations", arg.asType(dList.class).filter(dLocation.class));
} else if (!scriptEntry.hasObject("controller") && arg.matchesArgumentType(dPlayer.class) && arg.matchesPrefix("controller", "c")) {
// Check if it matches a dPlayer, but save it as a dEntity
scriptEntry.addObject("controller", (arg.asType(dEntity.class)));
} else if (!scriptEntry.hasObject("origin") && arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("origin", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else if (!scriptEntry.hasObject("rotationThreshold") && arg.matchesPrefix("rotationthreshold", "rotation", "r") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
scriptEntry.addObject("rotationThreshold", arg.asElement());
} else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("speed", arg.asElement());
} else {
arg.reportUnhandled();
}
}
// Use the NPC or player's locations as the location if one is not specified
scriptEntry.defaultObject("origin", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null);
// Use a default speed and rotation threshold if they are not specified
scriptEntry.defaultObject("speed", new Element(1.2));
scriptEntry.defaultObject("rotationThreshold", new Element(15));
// Check to make sure required arguments have been filled
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("origin")) {
throw new InvalidArgumentsException("Must specify an origin!");
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class HealCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("amount", arg.asElement());
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
// Entity arg
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
specified_targets = true;
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
specified_targets = true;
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(-1));
}
if (!specified_targets) {
List<dEntity> entities = new ArrayList<dEntity>();
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
} else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
} else {
throw new InvalidArgumentsException("No valid target entities found.");
}
scriptEntry.addObject("entities", entities);
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class HurtCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("amount") && (arg.matchesPrimitive(aH.PrimitiveType.Double) || arg.matchesPrimitive(aH.PrimitiveType.Integer))) {
scriptEntry.addObject("amount", arg.asElement());
} else if (!scriptEntry.hasObject("source") && arg.matchesPrefix("source", "s") && arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("source", arg.asType(dEntity.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
// Entity arg
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
specified_targets = true;
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
specified_targets = true;
} else if (!scriptEntry.hasObject("cause") && arg.matchesEnum(EntityDamageEvent.DamageCause.values())) {
scriptEntry.addObject("cause", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(1.0d));
}
if (!specified_targets) {
List<dEntity> entities = new ArrayList<dEntity>();
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
} else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
} else {
throw new InvalidArgumentsException("No valid target entities found.");
}
scriptEntry.addObject("entities", entities);
}
}
Aggregations