use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityScriptHelper method onChunkUnload.
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
if (event instanceof Cancellable && ((Cancellable) event).isCancelled()) {
return;
}
// CraftBukkit: https://github.com/Bukkit/CraftBukkit/pull/1386
for (Entity ent : event.getChunk().getEntities()) {
if (!(ent instanceof LivingEntity) || ((LivingEntity) ent).getRemoveWhenFarAway()) {
EntityTag.rememberEntity(ent);
EntityDespawnScriptEvent.instance.entity = new EntityTag(ent);
EntityDespawnScriptEvent.instance.cause = new ElementTag("CHUNK_UNLOAD");
EntityDespawnScriptEvent.instance.cancelled = false;
EntityDespawnScriptEvent.instance.fire();
EntityTag.forgetEntity(ent);
}
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class ExplodeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag power = scriptEntry.getElement("power");
ElementTag breakblocks = scriptEntry.getElement("breakblocks");
ElementTag fire = scriptEntry.getElement("fire");
EntityTag source = scriptEntry.getObjectTag("source");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, source, power, breakblocks, fire);
}
location.getWorld().createExplosion(location, power.asFloat(), fire.asBoolean(), breakblocks.asBoolean(), source == null ? null : source.getBukkitEntity());
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class MidiCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
boolean cancel = scriptEntry.hasObject("cancel");
ElementTag filePath = scriptEntry.getElement("file");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
LocationTag location = scriptEntry.getObjectTag("location");
float tempo = scriptEntry.getElement("tempo").asFloat();
float volume = scriptEntry.getElement("volume").asFloat();
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), filePath, db("entities", entities), location, db("tempo", tempo), db("volume", volume));
}
// Play the midi
if (!cancel) {
String fName = scriptEntry.getElement("file").asString();
if (!fName.endsWith(".mid")) {
fName += ".mid";
}
File file = new File(Denizen.getInstance().getDataFolder(), "/midi/" + fName);
if (!Utilities.canReadFile(file)) {
Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
return;
}
if (!file.exists()) {
Debug.echoError(scriptEntry, "Invalid file " + filePath.asString());
return;
}
NoteBlockReceiver rec;
if (location != null) {
rec = MidiUtil.playMidi(file, tempo, volume, location);
} else {
rec = MidiUtil.playMidi(file, tempo, volume, entities);
}
if (rec == null) {
Debug.echoError(scriptEntry, "Something went wrong playing a midi!");
scriptEntry.setFinished(true);
} else {
rec.onFinish = () -> scriptEntry.setFinished(true);
}
} else {
if (location != null) {
MidiUtil.stopMidi(location.identify());
} else {
MidiUtil.stopMidi(entities);
}
scriptEntry.setFinished(true);
}
}
use of com.denizenscript.denizen.objects.EntityTag 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.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final LocationTag location = (LocationTag) scriptEntry.getObject("location");
ElementTag type = scriptEntry.getElement("type");
List<ColorTag> primary = scriptEntry.argForPrefixList("primary", ColorTag.class, true);
if (primary == null) {
primary = Collections.singletonList(new ColorTag(Color.YELLOW));
}
List<ColorTag> fade = scriptEntry.argForPrefixList("fade", ColorTag.class, true);
boolean flicker = scriptEntry.argAsBoolean("flicker");
boolean trail = scriptEntry.argAsBoolean("trail");
ElementTag power = scriptEntry.argForPrefixAsElement("power", "1");
DurationTag life = scriptEntry.argForPrefix("life", DurationTag.class, true);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, type, power, life, db("flicker", flicker), db("trail", trail), db("primary colors", primary), db("fade colors", fade));
}
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(power.asInt());
Builder fireworkBuilder = FireworkEffect.builder();
fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
fireworkBuilder.withColor(Conversion.convertColors(primary));
if (fade != null) {
fireworkBuilder.withFade(Conversion.convertColors(fade));
}
if (flicker) {
fireworkBuilder.withFlicker();
}
if (trail) {
fireworkBuilder.withTrail();
}
fireworkMeta.addEffects(fireworkBuilder.build());
firework.setFireworkMeta(fireworkMeta);
if (life != null) {
NMSHandler.getEntityHelper().setFireworkLifetime(firework, life.getTicksAsInt());
}
scriptEntry.addObject("launched_firework", new EntityTag(firework));
}
Aggregations