use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemArmorPose method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("armor_pose")) {
CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
Tag entPart, posePart;
if (mechanism.hasValue() && mechanism.requireObject(MapTag.class)) {
if (compoundTag == null) {
compoundTag = new CompoundTagBuilder().build();
}
entPart = compoundTag.getValue().get("EntityTag");
if (!(entPart instanceof CompoundTag)) {
entPart = new CompoundTagBuilder().build();
}
CompoundTagBuilder poseBuilder = new CompoundTagBuilder();
MapTag input = mechanism.valueAsType(MapTag.class);
procMechKey(mechanism, poseBuilder, "Head", "head", input);
procMechKey(mechanism, poseBuilder, "Body", "body", input);
procMechKey(mechanism, poseBuilder, "LeftArm", "left_arm", input);
procMechKey(mechanism, poseBuilder, "RightArm", "right_arm", input);
procMechKey(mechanism, poseBuilder, "LeftLeg", "left_leg", input);
procMechKey(mechanism, poseBuilder, "RightLeg", "right_leg", input);
CompoundTag pose = poseBuilder.build();
if (pose.getValue().isEmpty()) {
entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build();
} else {
entPart = ((CompoundTag) entPart).createBuilder().put("Pose", pose).build();
}
} else {
if (compoundTag == null) {
return;
}
entPart = compoundTag.getValue().get("EntityTag");
if (!(entPart instanceof CompoundTag)) {
return;
}
posePart = ((CompoundTag) entPart).getValue().get("Pose");
if (!(posePart instanceof CompoundTag)) {
return;
}
entPart = ((CompoundTag) entPart).createBuilder().remove("Pose").build();
}
if (((CompoundTag) entPart).getValue().isEmpty()) {
compoundTag = compoundTag.createBuilder().remove("EntityTag").build();
} else {
compoundTag = compoundTag.createBuilder().put("EntityTag", entPart).build();
}
ItemStack result = NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag);
item.setItemStack(result);
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemArmorPose method getPoseMap.
public MapTag getPoseMap() {
CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
if (compoundTag == null) {
return null;
}
Tag entPart = compoundTag.getValue().get("EntityTag");
if (!(entPart instanceof CompoundTag)) {
return null;
}
Tag posePart = ((CompoundTag) entPart).getValue().get("Pose");
if (!(posePart instanceof CompoundTag)) {
return null;
}
CompoundTag pose = (CompoundTag) posePart;
MapTag result = new MapTag();
procPart(pose, "Head", "head", result);
procPart(pose, "Body", "body", result);
procPart(pose, "LeftArm", "left_arm", result);
procPart(pose, "RightArm", "right_arm", result);
procPart(pose, "LeftLeg", "left_leg", result);
procPart(pose, "RightLeg", "right_leg", result);
return result;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityPotionEffects method adjust.
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("potion_effects")) {
for (ObjectTag effectObj : CoreUtilities.objectToList(mechanism.value, mechanism.context)) {
PotionEffect effect;
if (effectObj.canBeType(MapTag.class)) {
MapTag effectMap = effectObj.asType(MapTag.class, mechanism.context);
effect = ItemPotion.parseEffect(effectMap, mechanism.context);
} else {
String effectStr = effectObj.toString();
effect = ItemPotion.parseEffect(effectStr, mechanism.context);
}
if (effect == null) {
mechanism.echoError("Invalid potion effect '" + effectObj + "'");
continue;
}
if (entity.isLivingEntity()) {
entity.getLivingEntity().addPotionEffect(effect);
} else if (isArrow()) {
getArrow().addCustomEffect(effect, true);
}
}
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class Conversion method getInventory.
public static AbstractMap.SimpleEntry<Integer, InventoryTag> getInventory(Argument arg, TagContext context) {
boolean isElement = arg.object instanceof ElementTag;
if (arg.object instanceof InventoryTag || (isElement && InventoryTag.matches(arg.getValue()))) {
InventoryTag inv = arg.object instanceof InventoryTag ? (InventoryTag) arg.object : InventoryTag.valueOf(arg.getValue(), context);
if (inv != null) {
return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
}
} else if (arg.object instanceof MapTag || (isElement && arg.getValue().startsWith("map@"))) {
MapTag map = arg.object instanceof MapTag ? (MapTag) arg.object : MapTag.valueOf(arg.getValue(), context);
int maxSlot = 0;
for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
if (!ArgumentHelper.matchesInteger(entry.getKey().str)) {
return null;
}
int slot = new ElementTag(entry.getKey().str).asInt();
if (slot > maxSlot) {
maxSlot = slot;
}
}
InventoryTag inventory = new InventoryTag(Math.min(InventoryTag.maxSlots, (maxSlot / 9) * 9 + 9));
for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
int slot = new ElementTag(entry.getKey().str).asInt();
ItemTag item = ItemTag.getItemFor(entry.getValue(), context);
if (item == null) {
if (context == null || context.debug) {
Debug.echoError("Not a valid item: '" + entry.getValue() + "'");
}
continue;
}
inventory.getInventory().setItem(slot - 1, item.getItemStack());
}
return new AbstractMap.SimpleEntry<>(maxSlot, inventory);
} else if (arg.object instanceof LocationTag || (isElement && LocationTag.matches(arg.getValue()))) {
InventoryTag inv = (arg.object instanceof LocationTag ? (LocationTag) arg.object : LocationTag.valueOf(arg.getValue(), context)).getInventory();
if (inv != null) {
return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
}
} else if (arg.object instanceof EntityTag || arg.object instanceof PlayerTag || arg.object instanceof NPCTag || (isElement && EntityTag.matches(arg.getValue()))) {
InventoryTag inv = EntityTag.valueOf(arg.getValue(), context).getInventory();
if (inv != null) {
return new AbstractMap.SimpleEntry<>(inv.getContents().length, inv);
}
}
ListTag asList = ListTag.getListFor(arg.object, context);
if (asList.containsObjectsFrom(ItemTag.class)) {
List<ItemTag> list = asList.filter(ItemTag.class, context);
ItemStack[] items = convertItems(list).toArray(new ItemStack[list.size()]);
InventoryTag inventory = new InventoryTag(Math.min(InventoryTag.maxSlots, (items.length / 9) * 9 + 9));
inventory.setContents(items);
return new AbstractMap.SimpleEntry<>(items.length, inventory);
}
return null;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class CuboidBlockSet method buildEntities.
public void buildEntities(CuboidTag cuboid, Location center) {
entities = new ListTag();
for (Entity ent : cuboid.getWorld().getEntities()) {
if (cuboid.isInsideCuboid(ent.getLocation())) {
if (copyTypes.contains(ent.getType())) {
EntityTag entTag = new EntityTag(ent);
if (entTag.isPlayer() || entTag.isNPC()) {
continue;
}
MapTag data = new MapTag();
data.putObject("entity", entTag.describe(null));
data.putObject("rotation", new ElementTag(0));
Vector offset = ent.getLocation().toVector().subtract(center.toVector());
data.putObject("offset", new LocationTag((String) null, offset.getX(), offset.getY(), offset.getZ(), ent.getLocation().getYaw(), ent.getLocation().getPitch()));
entities.addObject(data);
}
}
}
}
Aggregations