Skip to content

Commit

Permalink
item.armor_stand_data
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 24, 2021
1 parent e21fb06 commit c91ccb1
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static void init() {

// Properties
PropertyParser.registerProperty(EntityCanTick.class, EntityTag.class);
PropertyParser.registerProperty(ItemArmorStand.class, ItemTag.class);

// Paper extension properties
PropertyParser.registerProperty(PaperEntityProperties.class, EntityTag.class);
PropertyParser.registerProperty(PaperItemTagProperties.class, ItemTag.class);
PropertyParser.registerProperty(PaperWorldProperties.class, WorldTag.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.denizenscript.denizen.paper.properties;

import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta;
import org.bukkit.Material;

public class ItemArmorStand implements Property {

public static boolean describes(ObjectTag item) {
return item instanceof ItemTag
&& ((ItemTag) item).getBukkitMaterial() == Material.ARMOR_STAND;
}

public static ItemArmorStand getFrom(ObjectTag item) {
if (!describes(item)) {
return null;
}
return new ItemArmorStand((ItemTag) item);
}

public static final String[] handledMechs = new String[] {
"armor_stand_data"
};

private ItemArmorStand(ItemTag item) {
this.item = item;
}

ItemTag item;

public MapTag getDataMap() {
ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
if (meta == null) {
return null;
}
MapTag result = new MapTag();
result.putObject("base_plate", new ElementTag(!meta.hasNoBasePlate()));
result.putObject("visible", new ElementTag(!meta.isInvisible()));
result.putObject("marker", new ElementTag(meta.isMarker()));
result.putObject("is_small", new ElementTag(meta.isSmall()));
result.putObject("arms", new ElementTag(meta.shouldShowArms()));
return result;
}

@Override
public String getPropertyString() {
MapTag result = getDataMap();
if (result == null) {
return null;
}
return result.toString();
}

@Override
public String getPropertyId() {
return "armor_stand_data";
}

public static void registerTags() {

// <--[tag]
// @attribute <ItemTag.armor_stand_data>
// @returns MapTag
// @mechanism ItemTag.armor_stand_data
// @group properties
// @Plugin Paper
// @description
// Returns a map of basic armor stand data, with keys matching EntityTag property names.
// Keys: base_plate, visible, marker, is_small, arms
// -->
PropertyParser.<ItemArmorStand, MapTag>registerTag(MapTag.class, "armor_stand_data", (attribute, item) -> {
return item.getDataMap();
});
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object ItemTag
// @name armor_stand_data
// @input MapTag
// @Plugin Paper
// @description
// Sets a map of basic armor stand data, with keys matching EntityTag property names.
// Allowed keys: base_plate, visible, marker, is_small, arms
// @tags
// <ItemTag.armor_stand_data>
// -->
if (mechanism.matches("armor_stand_data") && mechanism.requireObject(MapTag.class)) {
MapTag map = mechanism.valueAsType(MapTag.class);
ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
ObjectTag base_plate = map.getObject("base_plate");
ObjectTag visible = map.getObject("visible");
ObjectTag marker = map.getObject("marker");
ObjectTag is_small = map.getObject("is_small");
ObjectTag arms = map.getObject("arms");
if (base_plate != null) {
meta.setNoBasePlate(!((ElementTag) base_plate).asBoolean());
}
if (visible != null) {
meta.setInvisible(!((ElementTag) visible).asBoolean());
}
if (marker != null) {
meta.setMarker(((ElementTag) marker).asBoolean());
}
if (is_small != null) {
meta.setSmall(((ElementTag) is_small).asBoolean());
}
if (arms != null) {
meta.setShowArms(((ElementTag) arms).asBoolean());
}
item.setItemMeta(meta);
}
}
}

0 comments on commit c91ccb1

Please sign in to comment.