-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e21fb06
commit c91ccb1
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
paper/src/main/java/com/denizenscript/denizen/paper/properties/ItemArmorStand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |