use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class MaterialNote method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.note_octave>
// @returns ElementTag(Number)
// @mechanism MaterialTag.note
// @group properties
// @description
// Returns the octave of note played from this note block, as 0, 1, or 2.
// -->
PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note_octave", (attribute, material) -> {
return new ElementTag(material.getNoteBlock().getNote().getOctave());
});
// <--[tag]
// @attribute <MaterialTag.note_tone>
// @returns ElementTag
// @mechanism MaterialTag.note
// @group properties
// @description
// Returns the tone of note played from this note block, as a letter from A to F, sometimes with a # to indicate sharp.
// Like A or A#.
// -->
PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note_tone", (attribute, material) -> {
Note note = material.getNoteBlock().getNote();
return new ElementTag(note.getTone().name() + (note.isSharped() ? "#" : ""));
});
// <--[tag]
// @attribute <MaterialTag.note>
// @returns ElementTag(Number)
// @mechanism MaterialTag.note
// @group properties
// @description
// Returns the note played from this note block, as an ID number from 0 to 24.
// -->
PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note", (attribute, material) -> {
return new ElementTag(material.getNoteBlock().getNote().getId());
});
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class LookcloseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag realistic = scriptEntry.getElement("realistic");
ElementTag range = scriptEntry.getElement("range");
ElementTag toggle = scriptEntry.getElement("toggle");
NPCTag npc = scriptEntry.getObjectTag("npc");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, realistic, range, toggle);
}
LookClose trait = npc.getCitizen().getOrAddTrait(LookClose.class);
if (toggle != null) {
trait.lookClose(toggle.asBoolean());
}
if (realistic != null && realistic.asBoolean()) {
trait.setRealisticLooking(true);
} else {
trait.setRealisticLooking(false);
}
if (range != null) {
trait.setRange(range.asInt());
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PoseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
TargetType target = (TargetType) scriptEntry.getObject("target");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
Action action = (Action) scriptEntry.getObject("action");
ElementTag idElement = scriptEntry.getElement("pose_id");
LocationTag pose_loc = scriptEntry.getObjectTag("pose_loc");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Target", target), (target == TargetType.PLAYER ? Utilities.getEntryPlayer(scriptEntry) : ""), npc, db("Action", action), idElement, pose_loc);
}
if (!npc.getCitizen().hasTrait(Poses.class)) {
npc.getCitizen().addTrait(Poses.class);
}
Poses poses = npc.getCitizen().getOrAddTrait(Poses.class);
String id = idElement.asString();
switch(action) {
case ASSUME:
if (!poses.hasPose(id)) {
Debug.echoError("Pose \"" + id + "\" doesn't exist for " + npc.toString());
}
if (target.name().equals("NPC")) {
poses.assumePose(id);
} else {
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
Location location = player.getLocation();
location.setYaw(poses.getPose(id).getYaw());
location.setPitch(poses.getPose(id).getPitch());
// The only way to change a player's yaw and pitch in Bukkit is to use teleport on them
player.teleport(location);
}
break;
case ADD:
if (!poses.addPose(id, pose_loc)) {
Debug.echoError(npc.toString() + " already has that pose!");
}
break;
case REMOVE:
if (!poses.removePose(id)) {
Debug.echoError(npc.toString() + " does not have that pose!");
}
break;
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class TriggerCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag toggle = scriptEntry.getElement("toggle");
ElementTag trigger = scriptEntry.getElement("trigger");
ElementTag radius = scriptEntry.getElement("radius");
DurationTag cooldown = scriptEntry.getObjectTag("cooldown");
NPCTag npc = scriptEntry.hasObject("npc") ? (NPCTag) scriptEntry.getObject("npc") : Utilities.getEntryNPC(scriptEntry);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), trigger, toggle, radius, cooldown, npc);
}
// Add trigger trait
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
npc.getCitizen().addTrait(TriggerTrait.class);
}
TriggerTrait trait = npc.getCitizen().getOrAddTrait(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 com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ActionBarCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
String text = scriptEntry.getElement("text").asString();
ScriptTag formatObj = scriptEntry.getObjectTag("format");
ElementTag perPlayerObj = scriptEntry.getElement("per_player");
boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
if (!perPlayer) {
text = TagManager.tag(text, context);
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("message", text), db("targets", targets), formatObj, perPlayerObj);
}
FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
for (PlayerTag player : targets) {
if (player != null) {
if (!player.isOnline()) {
Debug.echoDebug(scriptEntry, "Player is offline, can't send actionbar to them. Skipping.");
continue;
}
String personalText = text;
if (perPlayer) {
context.player = player;
personalText = TagManager.tag(personalText, context);
}
player.getPlayerEntity().spigot().sendMessage(ChatMessageType.ACTION_BAR, FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE));
} else {
Debug.echoError("Sent actionbar to non-existent player!?");
}
}
}
Aggregations