-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support color to filled map item #2504
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86e0b7c
support color to filled map item
pobab 4274ed5
add condition to check filled map item doesn't have color
pobab cf1f6f6
add mapMeta to getPropertyString
pobab 012726e
return null if filled_map doesn't have color
pobab 5fc27b7
tidy up parentheses
pobab 2925c54
clean up parentheses
pobab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import org.bukkit.Color; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.meta.LeatherArmorMeta; | ||
import org.bukkit.inventory.meta.MapMeta; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
|
||
public class ItemColor implements Property { | ||
|
@@ -19,15 +20,16 @@ public static boolean describes(ObjectTag item) { | |
return false; | ||
} | ||
Material mat = ((ItemTag) item).getBukkitMaterial(); | ||
// Leather armor and potions | ||
// Leather armor, potions, and filled map | ||
return mat == Material.LEATHER_BOOTS | ||
|| mat == Material.LEATHER_CHESTPLATE | ||
|| mat == Material.LEATHER_HELMET | ||
|| mat == Material.LEATHER_LEGGINGS | ||
|| mat == Material.LEATHER_HORSE_ARMOR | ||
|| mat == Material.POTION | ||
|| mat == Material.SPLASH_POTION | ||
|| mat == Material.LINGERING_POTION; | ||
|| mat == Material.LINGERING_POTION | ||
|| mat == Material.FILLED_MAP; | ||
} | ||
|
||
public static ItemColor getFrom(ObjectTag _item) { | ||
|
@@ -66,7 +68,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) { | |
// @mechanism ItemTag.color | ||
// @group properties | ||
// @description | ||
// Returns the color of the leather armor item or potion item. | ||
// Returns the color of the leather armor item, potion item, or filled map item. | ||
// --> | ||
if (attribute.startsWith("color") || attribute.startsWith("dye_color")) { | ||
Material mat = item.getBukkitMaterial(); | ||
|
@@ -79,6 +81,13 @@ public ObjectTag getObjectAttribute(Attribute attribute) { | |
} | ||
return BukkitColorExtensions.fromColor(pm.getColor()).getObjectAttribute(attribute.fulfill((1))); | ||
} | ||
if (mat == Material.FILLED_MAP) { | ||
MapMeta mapMeta = (MapMeta) item.getItemMeta(); | ||
if (!mapMeta.hasColor()) { | ||
return null; | ||
} | ||
return BukkitColorExtensions.fromColor((mapMeta.getColor())).getObjectAttribute(attribute.fulfill(1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor format - too many parens here |
||
} | ||
return BukkitColorExtensions.fromColor(((LeatherArmorMeta) item.getItemMeta()).getColor()).getObjectAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
|
@@ -97,6 +106,13 @@ public String getPropertyString() { | |
} | ||
return BukkitColorExtensions.fromColor(pm.getColor()).identify(); | ||
} | ||
if (mat == Material.FILLED_MAP) { | ||
MapMeta mapMeta = (MapMeta) item.getItemMeta(); | ||
if (!mapMeta.hasColor()) { | ||
return null; | ||
} | ||
return BukkitColorExtensions.fromColor(mapMeta.getColor()).identify(); | ||
} | ||
return BukkitColorExtensions.fromColor(((LeatherArmorMeta) item.getItemMeta()).getColor()).identify(); | ||
} | ||
|
||
|
@@ -113,7 +129,7 @@ public void adjust(Mechanism mechanism) { | |
// @name color | ||
// @input ColorTag | ||
// @description | ||
// Sets the leather armor item's dye color or the potion item's color. | ||
// Sets the leather armor item's dye color, potion item's color, or filled map item's color. | ||
// @tags | ||
// <ItemTag.color> | ||
// --> | ||
|
@@ -127,6 +143,12 @@ public void adjust(Mechanism mechanism) { | |
item.setItemMeta(meta); | ||
return; | ||
} | ||
if (mat == Material.FILLED_MAP) { | ||
MapMeta meta = (MapMeta) item.getItemMeta(); | ||
meta.setColor(BukkitColorExtensions.getColor(color)); | ||
item.setItemMeta(meta); | ||
return; | ||
} | ||
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta(); | ||
meta.setColor(BukkitColorExtensions.getColor(color)); | ||
item.setItemMeta(meta); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought it was correct because i follow on this line.... but, i realize and didn't get how
getObjectAttribute
work. should i change this line too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole file is weird and needs cleaning up, but not really required for your PR to fix pre-existing issues (it'd be really handy if you did tho! - check #2355 if you're interested in helping cleanup the codebase)