mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 02:55:46 +01:00
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:
parent
c80b76e732
commit
8b40f415be
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user