Use returned value for setEntityType, attempt fixing name setting

This commit is contained in:
vemacs 2015-06-17 10:54:23 -04:00
parent 51b52ac343
commit 121b262d1b
2 changed files with 16 additions and 4 deletions

View File

@ -135,17 +135,17 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
if (mat == null) {
throw new Exception(tl("unknownItemId", itemid));
}
final ItemStack retval = new ItemStack(mat);
retval.setAmount(mat.getMaxStackSize());
ItemStack retval = new ItemStack(mat);
if (mat == Material.MOB_SPAWNER) {
try {
ess.getSpawnerProvider().setEntityType(retval, EntityType.fromId(metaData));
retval = ess.getSpawnerProvider().setEntityType(retval, EntityType.fromId(metaData));
} catch (IllegalArgumentException e) {
throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners.");
}
} else {
retval.setDurability(metaData);
}
retval.setAmount(mat.getMaxStackSize());
return retval;
}

View File

@ -2,9 +2,11 @@ package net.ess3.nms.v1_8_R1;
import net.ess3.nms.SpawnerProvider;
import net.minecraft.server.v1_8_R1.NBTTagCompound;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class v1_8_R1SpawnerProvider extends SpawnerProvider {
@Override
@ -22,7 +24,17 @@ public class v1_8_R1SpawnerProvider extends SpawnerProvider {
}
tag = itemStack.getTag().getCompound("BlockEntityTag");
tag.setString("EntityId", type.getName());
return CraftItemStack.asCraftMirror(itemStack);
ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
ItemMeta meta = bukkitItemStack.getItemMeta();
String displayName;
if (entityToDisplayName.containsKey(type)) {
displayName = entityToDisplayName.get(type);
} else {
displayName = type.getName();
}
meta.setDisplayName(ChatColor.RESET + displayName + " Spawner");
bukkitItemStack.setItemMeta(meta);
return bukkitItemStack;
}
@Override