Added ability to have player heads with custom name (#1007)

* Added new attribute playerHeadName

* Added method PanelItem#getPlayerHeadName() and PanelItemBuilder#getPlayerHeadName()

* Added playerHeadName attribute

* getPlayerHeadName instead of getName
This commit is contained in:
YellowZaki 2019-10-24 14:00:14 +02:00 committed by Florian CUNY
parent 551975d6c9
commit 87ea48443f
3 changed files with 24 additions and 7 deletions

View File

@ -30,11 +30,13 @@ public class PanelItem {
private boolean glow;
private ItemMeta meta;
private final boolean playerHead;
private String playerHeadName;
private boolean invisible;
public PanelItem(PanelItemBuilder builtItem) {
this.icon = builtItem.getIcon();
this.playerHead = builtItem.isPlayerHead();
this.playerHeadName = builtItem.getPlayerHeadName();
// Get the meta
meta = icon.getItemMeta();
if (meta != null) {
@ -135,6 +137,13 @@ public class PanelItem {
public boolean isPlayerHead() {
return playerHead;
}
/**
* @return the playerHeadName
*/
public String getPlayerHeadName() {
return playerHeadName;
}
/**
* Click handler interface

View File

@ -20,6 +20,7 @@ public class PanelItemBuilder {
private boolean glow = false;
private PanelItem.ClickHandler clickHandler;
private boolean playerHead;
private String playerHeadName;
private boolean invisible;
/**
@ -45,7 +46,7 @@ public class PanelItemBuilder {
*/
public PanelItemBuilder icon(String playerName) {
this.icon = new ItemStack(Material.PLAYER_HEAD, 1);
this.name = playerName;
this.playerHeadName = playerName;
this.playerHead = true;
return this;
}
@ -149,6 +150,13 @@ public class PanelItemBuilder {
public boolean isPlayerHead() {
return playerHead;
}
/**
* @return the playerHead
*/
public String getPlayerHeadName() {
return playerHeadName;
}
/**
* @return the invisible

View File

@ -62,16 +62,16 @@ public class HeadGetter {
*/
public static void getHead(PanelItem panelItem, HeadRequester requester) {
// Check if in cache
if (cachedHeads.containsKey(panelItem.getName())) {
panelItem.setHead(cachedHeads.get(panelItem.getName()).clone());
if (cachedHeads.containsKey(panelItem.getPlayerHeadName())) {
panelItem.setHead(cachedHeads.get(panelItem.getPlayerHeadName()).clone());
requester.setHead(panelItem);
} else {
// Get the name
headRequesters.putIfAbsent(panelItem.getName(), new HashSet<>());
Set<HeadRequester> requesters = headRequesters.get(panelItem.getName());
headRequesters.putIfAbsent(panelItem.getPlayerHeadName(), new HashSet<>());
Set<HeadRequester> requesters = headRequesters.get(panelItem.getPlayerHeadName());
requesters.add(requester);
headRequesters.put(panelItem.getName(), requesters);
names.put(panelItem.getName(), panelItem);
headRequesters.put(panelItem.getPlayerHeadName(), requesters);
names.put(panelItem.getPlayerHeadName(), panelItem);
}
}