+ fix tellraw

This commit is contained in:
坏黑 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> <groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId> <artifactId>TabooLib</artifactId>
<version>4.7</version> <version>4.71</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -65,34 +65,37 @@ public class InternalTellraw implements AbstractTellraw {
@Override @Override
public ItemStack optimizeShulkerBox(ItemStack item) { public ItemStack optimizeShulkerBox(ItemStack item) {
if (item.getType().name().endsWith("SHULKER_BOX")) { try {
ItemStack itemClone = item.clone(); if (item.getType().name().endsWith("SHULKER_BOX")) {
BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta(); ItemStack itemClone = item.clone();
ShulkerBox shulkerBox = (ShulkerBox) blockStateMeta.getBlockState(); BlockStateMeta blockStateMeta = (BlockStateMeta) itemClone.getItemMeta();
ItemStack[] contents = shulkerBox.getInventory().getContents(); ShulkerBox shulkerBox = (ShulkerBox) blockStateMeta.getBlockState();
ItemStack[] contentsClone = new ItemStack[contents.length]; ItemStack[] contents = shulkerBox.getInventory().getContents();
for (int i = 0; i < contents.length; i++) { ItemStack[] contentsClone = new ItemStack[contents.length];
ItemStack content = contents[i]; for (int i = 0; i < contents.length; i++) {
if (!ItemUtils.isNull(content)) { ItemStack content = contents[i];
ItemStack contentClone = new ItemStack(Material.STONE, content.getAmount(), content.getDurability()); if (!ItemUtils.isNull(content)) {
if (content.getItemMeta().hasDisplayName()) { ItemStack contentClone = new ItemStack(Material.STONE, content.getAmount(), content.getDurability());
ItemUtils.setName(contentClone, content.getItemMeta().getDisplayName()); 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); } catch (Throwable ignored) {
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;
} }
return item; return item;
} }