mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 01:06:01 +01:00
Change ItemFrame to actually provide a defensive copy. Fixes BUKKIT-2784
If a defensive copy is not used in the API, changes to the item are reflected in memory, but never updated to the client. It also goes against the general contract provided in Bukkit, where setItem should be the only way to change the underlying item frame. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
parent
725d2e84dc
commit
1816b5b800
2 changed files with 14 additions and 1 deletions
|
@ -27,7 +27,7 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
|||
|
||||
public org.bukkit.inventory.ItemStack getItem() {
|
||||
ItemStack i = getHandle().i();
|
||||
return i == null ? new org.bukkit.inventory.ItemStack(Material.AIR) : new CraftItemStack(i);
|
||||
return i == null ? new org.bukkit.inventory.ItemStack(Material.AIR) : CraftItemStack.asBukkitStack(i);
|
||||
}
|
||||
|
||||
public Rotation getRotation() {
|
||||
|
|
|
@ -169,6 +169,10 @@ public class CraftItemStack extends ItemStack {
|
|||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
return getEnchantments(item);
|
||||
}
|
||||
|
||||
public static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
|
||||
Map<Enchantment, Integer> result = new HashMap<Enchantment, Integer>();
|
||||
NBTTagList list = (item == null) ? null : item.getEnchantments();
|
||||
|
||||
|
@ -233,4 +237,13 @@ public class CraftItemStack extends ItemStack {
|
|||
}
|
||||
return new CraftItemStack(original).getHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the NMS stack to return as a strictly-Bukkit stack
|
||||
*/
|
||||
public static ItemStack asBukkitStack(net.minecraft.server.ItemStack original) {
|
||||
ItemStack stack = new ItemStack(original.id, original.count, (short) original.getData());
|
||||
stack.addUnsafeEnchantments(getEnchantments(original));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue