summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2017-02-16 11:49:46 +1100
committermd_5 <git@md-5.net>2017-02-16 11:49:46 +1100
commit4448a7efa4bc1c4db669bc0a9019a3f96a524426 (patch)
tree6769199a59c910e9b4f1ab70166848616e50f7f5 /src/main
parent1a710213df1c7dd1d23cf3ec8fab1f3039d6d534 (diff)
downloadcraftbukkit-4448a7efa4bc1c4db669bc0a9019a3f96a524426.tar
craftbukkit-4448a7efa4bc1c4db669bc0a9019a3f96a524426.tar.gz
craftbukkit-4448a7efa4bc1c4db669bc0a9019a3f96a524426.tar.lz
craftbukkit-4448a7efa4bc1c4db669bc0a9019a3f96a524426.tar.xz
craftbukkit-4448a7efa4bc1c4db669bc0a9019a3f96a524426.zip
SPIGOT-3068: API for localized item names
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index 09e2d246..2a93e40b 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -40,7 +40,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -187,6 +186,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
}
static final ItemMetaKey NAME = new ItemMetaKey("Name", "display-name");
+ static final ItemMetaKey LOCNAME = new ItemMetaKey("LocName", "loc-name");
@Specific(Specific.To.NBT)
static final ItemMetaKey DISPLAY = new ItemMetaKey("display");
static final ItemMetaKey LORE = new ItemMetaKey("Lore", "lore");
@@ -216,6 +216,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable");
private String displayName;
+ private String locName;
private List<String> lore;
private Map<Enchantment, Integer> enchantments;
private int repairCost;
@@ -233,6 +234,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
}
this.displayName = meta.displayName;
+ this.locName = meta.locName;
if (meta.hasLore()) {
this.lore = new ArrayList<String>(meta.lore);
@@ -261,6 +263,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
displayName = display.getString(NAME.NBT);
}
+ if (display.hasKey(LOCNAME.NBT)) {
+ locName = display.getString(LOCNAME.NBT);
+ }
+
if (display.hasKey(LORE.NBT)) {
NBTTagList list = display.getList(LORE.NBT, 8);
lore = new ArrayList<String>(list.size());
@@ -359,6 +365,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
CraftMetaItem(Map<String, Object> map) {
setDisplayName(SerializableMeta.getString(map, NAME.BUKKIT, true));
+ setLocalizedName(SerializableMeta.getString(map, LOCNAME.BUKKIT, true));
Iterable<?> lore = SerializableMeta.getObject(Iterable.class, map, LORE.BUKKIT, true);
if (lore != null) {
@@ -434,6 +441,9 @@ class CraftMetaItem implements ItemMeta, Repairable {
if (hasDisplayName()) {
setDisplayTag(itemTag, NAME.NBT, new NBTTagString(displayName));
}
+ if (hasLocalizedName()){
+ setDisplayTag(itemTag, LOCNAME.NBT, new NBTTagString(locName));
+ }
if (hasLore()) {
setDisplayTag(itemTag, LORE.NBT, createStringList(lore));
@@ -507,7 +517,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
@Overridden
boolean isEmpty() {
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || isUnbreakable());
+ return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || isUnbreakable());
}
public String getDisplayName() {
@@ -522,6 +532,21 @@ class CraftMetaItem implements ItemMeta, Repairable {
return !Strings.isNullOrEmpty(displayName);
}
+ @Override
+ public String getLocalizedName() {
+ return locName;
+ }
+
+ @Override
+ public void setLocalizedName(String name) {
+ this.locName = name;
+ }
+
+ @Override
+ public boolean hasLocalizedName() {
+ return !Strings.isNullOrEmpty(locName);
+ }
+
public boolean hasLore() {
return this.lore != null && !this.lore.isEmpty();
}
@@ -664,6 +689,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
@Overridden
boolean equalsCommon(CraftMetaItem that) {
return ((this.hasDisplayName() ? that.hasDisplayName() && this.displayName.equals(that.displayName) : !that.hasDisplayName()))
+ && (this.hasLocalizedName()? that.hasLocalizedName()&& this.locName.equals(that.locName) : !that.hasLocalizedName())
&& (this.hasEnchants() ? that.hasEnchants() && this.enchantments.equals(that.enchantments) : !that.hasEnchants())
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
@@ -691,6 +717,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
int applyHash() {
int hash = 3;
hash = 61 * hash + (hasDisplayName() ? this.displayName.hashCode() : 0);
+ hash = 61 * hash + (hasLocalizedName()? this.locName.hashCode() : 0);
hash = 61 * hash + (hasLore() ? this.lore.hashCode() : 0);
hash = 61 * hash + (hasEnchants() ? this.enchantments.hashCode() : 0);
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
@@ -731,6 +758,9 @@ class CraftMetaItem implements ItemMeta, Repairable {
if (hasDisplayName()) {
builder.put(NAME.BUKKIT, displayName);
}
+ if (hasLocalizedName()) {
+ builder.put(LOCNAME.BUKKIT, locName);
+ }
if (hasLore()) {
builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));