use of com.denizenscript.denizen.objects.LocationTag 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.denizen.objects.LocationTag 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.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class BlockCrackCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
ElementTag progress = scriptEntry.getElement("progress");
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag stack = scriptEntry.getElement("stack");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("players", players), progress, location, stack);
}
Location loc = location.getBlock().getLocation();
if (!progressTracker.containsKey(loc)) {
progressTracker.put(loc, new HashMap<>());
lastBase += 10;
}
Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
boolean stackVal = stack.asBoolean();
PacketHelper packetHelper = NMSHandler.getPacketHelper();
for (PlayerTag player : players) {
if (!player.isOnline()) {
Debug.echoError("Players must be online!");
continue;
}
Player playerEnt = player.getPlayerEntity();
UUID uuid = playerEnt.getUniqueId();
if (!uuidInt.containsKey(uuid)) {
IntHolder newIntHolder = new IntHolder();
newIntHolder.theInt = lastBase;
newIntHolder.base = lastBase;
uuidInt.put(uuid, newIntHolder);
}
IntHolder intHolder = uuidInt.get(uuid);
if (!stackVal && intHolder.theInt > intHolder.base) {
for (int i = intHolder.base; i <= intHolder.theInt; i++) {
packetHelper.showBlockCrack(playerEnt, i, loc, -1);
}
intHolder.theInt = intHolder.base;
} else if (stackVal && intHolder.theInt - intHolder.base > 10) {
continue;
}
int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
}
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class ShowFakeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NetworkInterceptHelper.enable();
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag cancel = scriptEntry.getElement("cancel");
List<MaterialTag> materials = (List<MaterialTag>) scriptEntry.getObject("materials");
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), duration, cancel, db("materials", materials), db("locations", locations), db("players", players));
}
boolean shouldCancel = cancel.asBoolean();
int i = 0;
for (LocationTag loc : locations) {
if (!shouldCancel) {
FakeBlock.showFakeBlockTo(players, loc.getBlockLocation(), materials.get(i % materials.size()), duration, locations.size() < 5);
} else {
FakeBlock.stopShowingTo(players, loc.getBlockLocation());
}
i++;
}
}
use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.
the class AnimateChestCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag action = scriptEntry.getElement("action");
ElementTag sound = scriptEntry.getElement("sound");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, db("block type", location.getBlock().getType().name()), action, sound, db("players", players));
}
PacketHelper packetHelper = NMSHandler.getPacketHelper();
switch(ChestAction.valueOf(action.asString().toUpperCase())) {
case OPEN:
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
break;
case CLOSE:
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
break;
}
}
Aggregations