use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class MaterialHalf method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.half>
// @returns ElementTag
// @mechanism MaterialTag.half
// @group properties
// @description
// Returns the current half for a bisected material (like a door, double-plant, chest, or a bed).
// Output for "Bisected" blocks (doors/double plants/...) is "BOTTOM" or "TOP".
// Output for beds is "HEAD" or "FOOT".
// Output for chests is "LEFT" or "RIGHT".
// -->
PropertyParser.<MaterialHalf, ElementTag>registerStaticTag(ElementTag.class, "half", (attribute, material) -> {
String halfName = material.getHalfName();
if (halfName == null) {
return null;
}
return new ElementTag(halfName);
});
// <--[tag]
// @attribute <MaterialTag.relative_vector>
// @returns LocationTag
// @mechanism MaterialTag.half
// @group properties
// @description
// Returns a vector location of the other block for a bisected material.
// -->
PropertyParser.<MaterialHalf, LocationTag>registerStaticTag(LocationTag.class, "relative_vector", (attribute, material) -> {
Vector vector = material.getRelativeBlockVector();
if (vector == null) {
return null;
}
return new LocationTag(vector);
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemSpawnerDelay method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("spawner_spawn_delay")) {
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
return new ElementTag(state.getDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("spawner_minimum_spawn_delay")) {
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
return new ElementTag(state.getMinSpawnDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("spawner_maximum_spawn_delay")) {
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
return new ElementTag(state.getMaxSpawnDelay()).getObjectAttribute(attribute.fulfill(1));
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class MaterialAge method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.maximum_age>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns the maximum age for an ageable material. This includes plant growth.
// -->
PropertyParser.PropertyTagWithReturn<MaterialAge, ElementTag> runnable = (attribute, material) -> {
return new ElementTag(material.getMax());
};
PropertyParser.registerStaticTag(ElementTag.class, "maximum_age", runnable);
PropertyParser.registerStaticTag(ElementTag.class, "maximum_plant_growth", runnable);
// <--[tag]
// @attribute <MaterialTag.age>
// @returns ElementTag(Number)
// @mechanism MaterialTag.age
// @group properties
// @description
// Returns the current age for an ageable material. This includes plant growth.
// -->
runnable = (attribute, material) -> {
return new ElementTag(material.getCurrent());
};
PropertyParser.registerStaticTag(ElementTag.class, "age", runnable);
PropertyParser.registerStaticTag(ElementTag.class, "plant_growth", runnable);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) {
scriptEntry.addObject("cancel", new ElementTag("true"));
} else if (!scriptEntry.hasObject("infinite") && arg.matches("infinite")) {
scriptEntry.addObject("infinite", new ElementTag("true"));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("frequency") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("frequency", "f")) {
scriptEntry.addObject("frequency", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("yaw") && arg.matchesPrefix("yaw", "y", "rotation", "r") && arg.matchesFloat()) {
scriptEntry.addObject("yaw", arg.asElement());
} else if (!scriptEntry.hasObject("pitch") && arg.matchesPrefix("pitch", "p", "tilt", "t") && arg.matchesFloat()) {
scriptEntry.addObject("pitch", arg.asElement());
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
scriptEntry.defaultObject("yaw", new ElementTag(10));
scriptEntry.defaultObject("pitch", new ElementTag(0));
scriptEntry.defaultObject("duration", new DurationTag(20));
scriptEntry.defaultObject("frequency", new DurationTag(1L));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final List<EntityTag> entities = new ArrayList<>((List<EntityTag>) scriptEntry.getObject("entities"));
final DurationTag duration = scriptEntry.getObjectTag("duration");
final DurationTag frequency = scriptEntry.getObjectTag("frequency");
final ElementTag yaw = scriptEntry.getElement("yaw");
final ElementTag pitch = scriptEntry.getElement("pitch");
boolean cancel = scriptEntry.hasObject("cancel");
final boolean infinite = scriptEntry.hasObject("infinite");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities), (infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
}
for (EntityTag entity : entities) {
if (cancel) {
rotatingEntities.remove(entity.getUUID());
} else {
rotatingEntities.add(entity.getUUID());
}
}
if (cancel) {
return;
}
BukkitRunnable task = new BukkitRunnable() {
int ticks = 0;
int maxTicks = duration.getTicksAsInt();
ArrayList<EntityTag> unusedEntities = new ArrayList<>();
@Override
public void run() {
if (entities.isEmpty()) {
scriptEntry.setFinished(true);
this.cancel();
} else if (infinite || ticks < maxTicks) {
for (EntityTag entity : entities) {
if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), EntityHelper.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
} else {
rotatingEntities.remove(entity.getUUID());
unusedEntities.add(entity);
}
}
if (!unusedEntities.isEmpty()) {
for (EntityTag unusedEntity : unusedEntities) {
entities.remove(unusedEntity);
}
unusedEntities.clear();
}
ticks = (int) (ticks + frequency.getTicks());
} else {
scriptEntry.setFinished(true);
this.cancel();
}
}
};
task.runTaskTimer(Denizen.getInstance(), 0, frequency.getTicks());
}
Aggregations