Skip to content

Commit

Permalink
Made WRITTEN_BOOK more robust in schematics. Sometimes not all the
Browse files Browse the repository at this point in the history
elements are included. This only sets what is in the schematic.
  • Loading branch information
tastybento committed May 20, 2016
1 parent 219d17f commit 9271a11
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 225 deletions.
75 changes: 43 additions & 32 deletions src/com/wasteofplastic/askyblock/nms/v1_7_R3/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,51 @@ public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
//Bukkit.getLogger().info("item data");
//Bukkit.getLogger().info(item.toString());

Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = ((StringTag)contents.get("author")).getValue();
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = ((StringTag)contents.get("title")).getValue();
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);

Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
List<String> lore = new ArrayList<String>();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_7_R3.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag)contents.get("author")).getValue();
}
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag)contents.get("title")).getValue();
}
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_7_R3.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
}
tag.set("pages", pages); //Add the pages to the tag
}
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
tag.set("pages", pages); //Add the pages to the tag
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
return chestItem;

}

/* (non-Javadoc)
Expand Down
75 changes: 43 additions & 32 deletions src/com/wasteofplastic/askyblock/nms/v1_7_R4/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,51 @@ public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
//Bukkit.getLogger().info("item data");
//Bukkit.getLogger().info(item.toString());

Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = ((StringTag)contents.get("author")).getValue();
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = ((StringTag)contents.get("title")).getValue();
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);

Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
List<String> lore = new ArrayList<String>();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_7_R4.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag)contents.get("author")).getValue();
}
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag)contents.get("title")).getValue();
}
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_7_R4.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
}
tag.set("pages", pages); //Add the pages to the tag
}
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
tag.set("pages", pages); //Add the pages to the tag
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
return chestItem;

}

/* (non-Javadoc)
Expand Down
75 changes: 43 additions & 32 deletions src/com/wasteofplastic/askyblock/nms/v1_8_R1/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,51 @@ public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
//Bukkit.getLogger().info("item data");
//Bukkit.getLogger().info(item.toString());

Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = ((StringTag)contents.get("author")).getValue();
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = ((StringTag)contents.get("title")).getValue();
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);

Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
List<String> lore = new ArrayList<String>();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag)contents.get("author")).getValue();
}
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag)contents.get("title")).getValue();
}
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
}
tag.set("pages", pages); //Add the pages to the tag
}
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
tag.set("pages", pages); //Add the pages to the tag
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
return chestItem;

}

/* (non-Javadoc)
Expand Down
75 changes: 43 additions & 32 deletions src/com/wasteofplastic/askyblock/nms/v1_8_R2/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,51 @@ public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
//Bukkit.getLogger().info("item data");
//Bukkit.getLogger().info(item.toString());

Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = ((StringTag)contents.get("author")).getValue();
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = ((StringTag)contents.get("title")).getValue();
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);

Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
List<String> lore = new ArrayList<String>();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String,Tag> contents = (Map<String,Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
//BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag)contents.get("author")).getValue();
}
//Bukkit.getLogger().info("Author: " + author);
//bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag)contents.get("title")).getValue();
}
//Bukkit.getLogger().info("Title: " + title);
//bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String,Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag)display.get("Lore")).getValue();
for (Tag s: loreTag) {
lore.add(((StringTag)s).getValue());
}
}
//Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
NBTTagCompound tag = new NBTTagCompound(); //Create the NMS Stack's NBT (item data)
tag.setString("title", title); //Set the book's title
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag)contents.get("pages")).getValue();
for (Tag s: pagesTag) {
pages.add(new NBTTagString(((StringTag)s).getValue()));
}
tag.set("pages", pages); //Add the pages to the tag
}
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
tag.set("pages", pages); //Add the pages to the tag
stack.setTag(tag); //Apply the tag to the item
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
return chestItem;

}

/* (non-Javadoc)
Expand Down
Loading

0 comments on commit 9271a11

Please sign in to comment.