Skip to content

Commit 880dba0

Browse files
authored
support color to filled map item (#2504)
* support color to filled map item * add condition to check filled map item doesn't have color * add mapMeta to getPropertyString * return null if filled_map doesn't have color * tidy up parentheses * clean up parentheses
1 parent c6102db commit 880dba0

File tree

1 file changed

+26
-4
lines changed
  • plugin/src/main/java/com/denizenscript/denizen/objects/properties/item

1 file changed

+26
-4
lines changed

plugin/src/main/java/com/denizenscript/denizen/objects/properties/item/ItemColor.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bukkit.Color;
1111
import org.bukkit.Material;
1212
import org.bukkit.inventory.meta.LeatherArmorMeta;
13+
import org.bukkit.inventory.meta.MapMeta;
1314
import org.bukkit.inventory.meta.PotionMeta;
1415

1516
public class ItemColor implements Property {
@@ -19,15 +20,16 @@ public static boolean describes(ObjectTag item) {
1920
return false;
2021
}
2122
Material mat = ((ItemTag) item).getBukkitMaterial();
22-
// Leather armor and potions
23+
// Leather armor, potions, and filled map
2324
return mat == Material.LEATHER_BOOTS
2425
|| mat == Material.LEATHER_CHESTPLATE
2526
|| mat == Material.LEATHER_HELMET
2627
|| mat == Material.LEATHER_LEGGINGS
2728
|| mat == Material.LEATHER_HORSE_ARMOR
2829
|| mat == Material.POTION
2930
|| mat == Material.SPLASH_POTION
30-
|| mat == Material.LINGERING_POTION;
31+
|| mat == Material.LINGERING_POTION
32+
|| mat == Material.FILLED_MAP;
3133
}
3234

3335
public static ItemColor getFrom(ObjectTag _item) {
@@ -66,7 +68,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
6668
// @mechanism ItemTag.color
6769
// @group properties
6870
// @description
69-
// Returns the color of the leather armor item or potion item.
71+
// Returns the color of the leather armor item, potion item, or filled map item.
7072
// -->
7173
if (attribute.startsWith("color") || attribute.startsWith("dye_color")) {
7274
Material mat = item.getBukkitMaterial();
@@ -79,6 +81,13 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
7981
}
8082
return BukkitColorExtensions.fromColor(pm.getColor()).getObjectAttribute(attribute.fulfill((1)));
8183
}
84+
if (mat == Material.FILLED_MAP) {
85+
MapMeta mapMeta = (MapMeta) item.getItemMeta();
86+
if (!mapMeta.hasColor()) {
87+
return null;
88+
}
89+
return BukkitColorExtensions.fromColor(mapMeta.getColor()).getObjectAttribute(attribute.fulfill(1));
90+
}
8291
return BukkitColorExtensions.fromColor(((LeatherArmorMeta) item.getItemMeta()).getColor()).getObjectAttribute(attribute.fulfill(1));
8392
}
8493

@@ -97,6 +106,13 @@ public String getPropertyString() {
97106
}
98107
return BukkitColorExtensions.fromColor(pm.getColor()).identify();
99108
}
109+
if (mat == Material.FILLED_MAP) {
110+
MapMeta mapMeta = (MapMeta) item.getItemMeta();
111+
if (!mapMeta.hasColor()) {
112+
return null;
113+
}
114+
return BukkitColorExtensions.fromColor(mapMeta.getColor()).identify();
115+
}
100116
return BukkitColorExtensions.fromColor(((LeatherArmorMeta) item.getItemMeta()).getColor()).identify();
101117
}
102118

@@ -113,7 +129,7 @@ public void adjust(Mechanism mechanism) {
113129
// @name color
114130
// @input ColorTag
115131
// @description
116-
// Sets the leather armor item's dye color or the potion item's color.
132+
// Sets the leather armor item's dye color, potion item's color, or filled map item's color.
117133
// @tags
118134
// <ItemTag.color>
119135
// -->
@@ -127,6 +143,12 @@ public void adjust(Mechanism mechanism) {
127143
item.setItemMeta(meta);
128144
return;
129145
}
146+
if (mat == Material.FILLED_MAP) {
147+
MapMeta meta = (MapMeta) item.getItemMeta();
148+
meta.setColor(BukkitColorExtensions.getColor(color));
149+
item.setItemMeta(meta);
150+
return;
151+
}
130152
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
131153
meta.setColor(BukkitColorExtensions.getColor(color));
132154
item.setItemMeta(meta);

0 commit comments

Comments
 (0)