Use ItemStack display name when describing an ItemStackThing (#441)

Use ItemStack display name in ItemStackThing (if available).

This means that named items will appear in the rewards list with their name rather than the ItemStack type. This is useful for "tokens" type items.

Note that named items are still not supported by the built-in item parser, so this commit only affects ItemStackThings created by custom parsers (for now).
This commit is contained in:
Nathan Wolf 2018-04-16 18:10:15 -07:00 committed by garbagemule
parent c80b76e732
commit 8b40f415be

View File

@ -2,6 +2,7 @@ package com.garbagemule.MobArena.things;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class ItemStackThing implements Thing {
private ItemStack stack;
@ -27,14 +28,22 @@ public class ItemStackThing implements Thing {
@Override
public String toString() {
String item = stack.getType()
String name = getName();
int amount = stack.getAmount();
if (amount > 1) {
return amount + "x " + name;
}
return name;
}
private String getName() {
ItemMeta meta = stack.getItemMeta();
if (meta.hasDisplayName()) {
return meta.getDisplayName();
}
return stack.getType()
.name()
.replace("_", " ")
.toLowerCase();
if (stack.getAmount() > 1) {
return stack.getAmount() + "x " + item;
}
return item;
}
}