+ fix tellraw

master
坏黑 2019-02-05 23:18:31 +08:00
parent 803542c589
commit 2617069878
2 changed files with 29 additions and 26 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId>
<version>4.7</version>
<version>4.71</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -65,34 +65,37 @@ public class InternalTellraw implements AbstractTellraw {
@Override
public ItemStack optimizeShulkerBox(ItemStack item) {
if (item.getType().name().endsWith("SHULKER_BOX")) {
ItemStack itemClone = item.clone();
BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta();
ShulkerBox shulkerBox = (ShulkerBox) blockStateMeta.getBlockState();
ItemStack[] contents = shulkerBox.getInventory().getContents();
ItemStack[] contentsClone = new ItemStack[contents.length];
for (int i = 0; i < contents.length; i++) {
ItemStack content = contents[i];
if (!ItemUtils.isNull(content)) {
ItemStack contentClone = new ItemStack(Material.STONE, content.getAmount(), content.getDurability());
if (content.getItemMeta().hasDisplayName()) {
ItemUtils.setName(contentClone, content.getItemMeta().getDisplayName());
try {
if (item.getType().name().endsWith("SHULKER_BOX")) {
ItemStack itemClone = item.clone();
BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta();
ShulkerBox shulkerBox = (ShulkerBox) blockStateMeta.getBlockState();
ItemStack[] contents = shulkerBox.getInventory().getContents();
ItemStack[] contentsClone = new ItemStack[contents.length];
for (int i = 0; i < contents.length; i++) {
ItemStack content = contents[i];
if (!ItemUtils.isNull(content)) {
ItemStack contentClone = new ItemStack(Material.STONE, content.getAmount(), content.getDurability());
if (content.getItemMeta().hasDisplayName()) {
ItemUtils.setName(contentClone, content.getItemMeta().getDisplayName());
}
contentsClone[i] = contentClone;
}
contentsClone[i] = contentClone;
}
shulkerBox.getInventory().setContents(contentsClone);
blockStateMeta.setBlockState(shulkerBox);
itemClone.setItemMeta(blockStateMeta);
return itemClone;
} else if (item.getItemMeta() instanceof BlockStateMeta && ((BlockStateMeta) item.getItemMeta()).getBlockState() instanceof InventoryHolder) {
ItemStack itemClone = item.clone();
BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta();
InventoryHolder inventoryHolder = (InventoryHolder) blockStateMeta.getBlockState();
inventoryHolder.getInventory().clear();
blockStateMeta.setBlockState((org.bukkit.block.BlockState) inventoryHolder);
itemClone.setItemMeta(blockStateMeta);
return itemClone;
}
shulkerBox.getInventory().setContents(contentsClone);
blockStateMeta.setBlockState(shulkerBox);
itemClone.setItemMeta(blockStateMeta);
return itemClone;
} else if (item.getItemMeta() instanceof BlockStateMeta && ((BlockStateMeta) item.getItemMeta()).getBlockState() instanceof InventoryHolder) {
ItemStack itemClone = item.clone();
BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta();
InventoryHolder inventoryHolder = (InventoryHolder) blockStateMeta.getBlockState();
inventoryHolder.getInventory().clear();
blockStateMeta.setBlockState((org.bukkit.block.BlockState) inventoryHolder);
itemClone.setItemMeta(blockStateMeta);
return itemClone;
} catch (Throwable ignored) {
}
return item;
}