use of net.minecraft.server.v1_13_R2.ItemStack in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_12_R1 method simulateToolBreak.
@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
ItemStack itemStack = entityPlayer.getItemInMainHand();
WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
assert itemStack != null;
itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
use of net.minecraft.server.v1_13_R2.ItemStack in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method simulateToolBreak.
@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
ItemStack itemStack = entityPlayer.getItemInMainHand();
WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
assert itemStack != null;
itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
use of net.minecraft.server.v1_13_R2.ItemStack in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertJsonToBook.
@SuppressWarnings("ConstantConditions")
@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
List<IChatBaseComponent> pages = new ArrayList<>();
for (JsonElement jsonPage : jsonPages) {
pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
}
this.pagesField.set(bookMeta, pages);
newBook.setItemMeta(bookMeta);
return newBook;
}
use of net.minecraft.server.v1_13_R2.ItemStack in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method convertBookToJson.
@SuppressWarnings({ "unchecked", "ConstantConditions" })
@Override
public JsonObject convertBookToJson(ItemStack book) throws IllegalAccessException {
BookMeta bookMeta = (BookMeta) book.getItemMeta();
List<IChatBaseComponent> pages = bookMeta.hasPages() ? (List<IChatBaseComponent>) this.pagesField.get(bookMeta) : new ArrayList<>();
JsonArray jsonPages = new JsonArray();
for (IChatBaseComponent page : pages) {
jsonPages.add(super.gson.fromJson(IChatBaseComponent.ChatSerializer.a(page), JsonElement.class));
}
JsonPrimitive jsonAuthor = new JsonPrimitive(bookMeta.hasAuthor() ? bookMeta.getAuthor() : "Server");
JsonPrimitive jsonTitle = new JsonPrimitive(bookMeta.hasTitle() ? bookMeta.getTitle() : "Title");
JsonObject jsonBook = new JsonObject();
jsonBook.add("author", jsonAuthor);
jsonBook.add("title", jsonTitle);
jsonBook.add("pages", jsonPages);
return jsonBook;
}
use of net.minecraft.server.v1_13_R2.ItemStack in project CitizensBooks by NicoNekoDev.
the class DistributionHandler method applyPlaceholders.
@SuppressWarnings({ "ConstantConditions", "unchecked" })
@Override
public ItemStack applyPlaceholders(Player player, ItemStack book, NPC npc) throws IllegalAccessException {
Validate.notNull(book, "The ItemStack is null! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
Validate.isTrue(book.getType() == Material.WRITTEN_BOOK, "The ItemStack is not a written book! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
BookMeta bookMeta = (BookMeta) book.getItemMeta();
List<String> pages = bookMeta.hasPages() ? super.papiReplaceStrList.apply(player, ((List<IChatBaseComponent>) this.pagesField.get(bookMeta)).stream().map(IChatBaseComponent.ChatSerializer::a).toList(), Optional.ofNullable(npc)) : new ArrayList<>();
String author = bookMeta.hasAuthor() ? super.papiReplaceStr.apply(player, bookMeta.getAuthor(), Optional.ofNullable(npc)) : "Server";
String title = bookMeta.hasTitle() ? super.papiReplaceStr.apply(player, bookMeta.getTitle(), Optional.ofNullable(npc)) : "Title";
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
bookMeta.setAuthor(author);
bookMeta.setTitle(title);
this.pagesField.set(bookMeta, pages.stream().map(IChatBaseComponent.ChatSerializer::a).toList());
newBook.setItemMeta(bookMeta);
return newBook;
}
Aggregations