Skip to content

Commit d09de1c

Browse files
authored
Merge pull request #2777 from /issues/2774-player-head-cmd
Implements ability for Player Heads to use CMD
2 parents 4552947 + 8dfb904 commit d09de1c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public interface ClickHandler {
193193
public void setHead(ItemStack itemStack) {
194194
// update amount before replacing.
195195
itemStack.setAmount(this.icon.getAmount());
196+
ItemMeta originalMeta = this.icon.getItemMeta();
197+
196198
this.icon = itemStack;
197199

198200
// Get the meta
@@ -203,6 +205,11 @@ public void setHead(ItemStack itemStack) {
203205
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
204206
meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
205207
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
208+
209+
if (originalMeta != null && originalMeta.hasCustomModelDataComponent()) {
210+
meta.setCustomModelDataComponent(originalMeta.getCustomModelDataComponent());
211+
}
212+
206213
icon.setItemMeta(meta);
207214
}
208215
// Create the final item

src/main/java/world/bentobox/bentobox/api/panels/builders/PanelItemBuilder.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,27 @@ public PanelItemBuilder icon(@Nullable ItemStack icon) {
4242
return this;
4343
}
4444

45+
46+
/**
47+
* Assigns icon and player name to the panel item.
48+
* @param playerName the name of player head icon.
49+
* @param icon the original player head icon
50+
* @return PanelItemBuilder
51+
*/
52+
public PanelItemBuilder icon(String playerName, ItemStack icon) {
53+
this.icon = icon;
54+
this.playerHeadName = playerName;
55+
return this;
56+
}
57+
58+
4559
/**
4660
* Set icon to player's head
4761
* @param playerName - player's name
4862
* @return PanelItemBuilder
4963
*/
5064
public PanelItemBuilder icon(String playerName) {
51-
this.icon = new ItemStack(Material.PLAYER_HEAD);
52-
this.playerHeadName = playerName;
53-
return this;
65+
return this.icon(playerName, new ItemStack(Material.PLAYER_HEAD));
5466
}
5567

5668
public PanelItemBuilder name(@Nullable String name) {

0 commit comments

Comments
 (0)