use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class DropCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag quantity = scriptEntry.getElement("quantity");
ElementTag action = scriptEntry.getElement("action");
ElementTag speed = scriptEntry.getElement("speed");
List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
EntityTag entity = scriptEntry.getObjectTag("entity");
DurationTag delay = scriptEntry.getObjectTag("delay");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, location, quantity, db("items", items), entity, speed, delay);
}
ListTag entityList = new ListTag();
switch(Action.valueOf(action.asString())) {
case DROP_EXP:
EntityTag orb = new EntityTag(location.getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB));
((ExperienceOrb) orb.getBukkitEntity()).setExperience(quantity.asInt());
entityList.addObject(orb);
break;
case DROP_ITEM:
for (ItemTag item : items) {
if (item.getMaterial().getMaterial() == Material.AIR) {
continue;
}
if (quantity.asInt() > 1 && item.isUnique()) {
Debug.echoDebug(scriptEntry, "Cannot drop multiples of this item because it is Unique!");
}
for (int x = 0; x < quantity.asInt(); x++) {
EntityTag e = new EntityTag(location.getWorld().dropItem(location, item.getItemStack()));
if (e.isValid()) {
e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d));
if (delay != null) {
((Item) e.getBukkitEntity()).setPickupDelay(delay.getTicksAsInt());
}
}
entityList.addObject(e);
}
}
break;
case DROP_ENTITY:
if (quantity.asInt() > 1 && entity.isUnique()) {
Debug.echoDebug(scriptEntry, "Cannot drop multiples of this entity because it is Unique!");
entity.spawnAt(location);
entityList.addObject(entity);
break;
}
for (int x = 0; x < quantity.asInt(); x++) {
ArrayList<Mechanism> mechanisms = new ArrayList<>();
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
mechanisms.add(new Mechanism(mechanism.getName(), mechanism.value, scriptEntry.context));
}
EntityTag ent = new EntityTag(entity.getEntityType(), mechanisms);
ent.spawnAt(location);
entityList.addObject(ent);
}
break;
}
scriptEntry.addObject("dropped_entities", entityList);
if (entityList.size() == 1) {
scriptEntry.addObject("dropped_entity", entityList.getObject(0));
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityBreedScriptEvent method onEntityBreeds.
@EventHandler
public void onEntityBreeds(EntityBreedEvent event) {
Entity entity = event.getEntity();
this.entity = new EntityTag(entity);
breeder = event.getBreeder() == null ? null : new EntityTag(event.getBreeder());
father = new EntityTag(event.getFather());
mother = new EntityTag(event.getMother());
item = event.getBredWith() == null ? null : new ItemTag(event.getBredWith());
experience = event.getExperience();
this.event = event;
EntityTag.rememberEntity(entity);
fire(event);
EntityTag.forgetEntity(entity);
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityDrinkingPotion method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("drinking_potion") && mechanism.requireObject(ItemTag.class)) {
ItemTag potion = mechanism.valueAsType(ItemTag.class);
if (potion.getBukkitMaterial() != Material.POTION) {
mechanism.echoError("Invalid item input '" + potion + "': item must be a potion");
return;
}
getWitch().setDrinkingPotion(potion.getItemStack());
}
// -->
if (mechanism.matches("potion_drink_duration") && mechanism.requireObject(DurationTag.class)) {
getWitch().setPotionUseTimeLeft(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class DisplayItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ItemTag item = scriptEntry.getObjectTag("item");
DurationTag duration = scriptEntry.getObjectTag("duration");
LocationTag location = scriptEntry.getObjectTag("location");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), item, duration, location);
}
// Drop the item
final Item dropped = location.getWorld().dropItem(location.getBlockLocation().clone().add(0.5, 1.5, 0.5), item.getItemStack());
dropped.setVelocity(new Vector(0, 0, 0));
dropped.setGravity(false);
dropped.setPickupDelay(32767);
int ticks = duration.getTicksAsInt();
NMSHandler.getEntityHelper().setTicksLived(dropped, ticks <= 0 ? -32768 : -ticks);
if (!dropped.isValid()) {
Debug.echoDebug(scriptEntry, "Item failed to spawned (likely blocked by some plugin).");
return;
}
final UUID itemUUID = dropped.getUniqueId();
protectedEntities.add(itemUUID);
scriptEntry.addObject("dropped", new EntityTag(dropped));
if (ticks > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
protectedEntities.remove(itemUUID);
if (dropped.isValid() && !dropped.isDead()) {
dropped.remove();
}
}, ticks);
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EquipCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Map<String, ItemTag> equipment = (Map<String, ItemTag>) scriptEntry.getObject("equipment");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), db("equipment", equipment));
}
for (EntityTag entity : entities) {
if (entity.isGeneric()) {
Debug.echoError(scriptEntry, "Cannot equip generic entity " + entity.identify() + "!");
} else if (entity.isCitizensNPC()) {
NPCTag npc = entity.getDenizenNPC();
if (npc != null) {
Equipment trait = npc.getEquipmentTrait();
if (equipment.get("hand") != null) {
trait.set(0, equipment.get("hand").getItemStack());
}
if (equipment.get("head") != null) {
trait.set(1, equipment.get("head").getItemStack());
}
if (equipment.get("chest") != null) {
trait.set(2, equipment.get("chest").getItemStack());
}
if (equipment.get("legs") != null) {
trait.set(3, equipment.get("legs").getItemStack());
}
if (equipment.get("boots") != null) {
trait.set(4, equipment.get("boots").getItemStack());
}
if (equipment.get("offhand") != null) {
trait.set(5, equipment.get("offhand").getItemStack());
}
if (npc.isSpawned()) {
LivingEntity livingEntity = npc.getLivingEntity();
// TODO: Citizens API for this blob?
if (livingEntity instanceof AbstractHorse) {
if (equipment.get("saddle") != null) {
((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
}
if (equipment.get("horse_armor") != null) {
if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
}
}
} else if (livingEntity instanceof Steerable) {
if (equipment.get("saddle") != null) {
ItemTag saddle = equipment.get("saddle");
if (saddle.getBukkitMaterial() == Material.SADDLE) {
((Steerable) livingEntity).setSaddle(true);
} else {
((Steerable) livingEntity).setSaddle(false);
}
}
}
}
}
} else {
LivingEntity livingEntity = entity.getLivingEntity();
if (livingEntity != null) {
if (livingEntity instanceof AbstractHorse) {
if (equipment.get("saddle") != null) {
((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
}
if (equipment.get("horse_armor") != null) {
if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
}
}
} else if (livingEntity instanceof Steerable) {
if (equipment.get("saddle") != null) {
ItemTag saddle = equipment.get("saddle");
if (saddle.getBukkitMaterial() == Material.SADDLE) {
((Steerable) livingEntity).setSaddle(true);
} else {
((Steerable) livingEntity).setSaddle(false);
}
}
} else {
if (equipment.get("hand") != null) {
livingEntity.getEquipment().setItemInMainHand(equipment.get("hand").getItemStack());
}
if (equipment.get("head") != null) {
livingEntity.getEquipment().setHelmet(equipment.get("head").getItemStack());
}
if (equipment.get("chest") != null) {
livingEntity.getEquipment().setChestplate(equipment.get("chest").getItemStack());
}
if (equipment.get("legs") != null) {
livingEntity.getEquipment().setLeggings(equipment.get("legs").getItemStack());
}
if (equipment.get("boots") != null) {
livingEntity.getEquipment().setBoots(equipment.get("boots").getItemStack());
}
if (equipment.get("offhand") != null) {
livingEntity.getEquipment().setItemInOffHand(equipment.get("offhand").getItemStack());
}
}
}
}
}
}
Aggregations