use of com.wasteofplastic.org.jnbt.StringTag in project askyblock by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
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_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", 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()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of com.wasteofplastic.org.jnbt.StringTag in project askyblock by tastybento.
the class IslandBlock method setSign.
/**
* Sets this block's sign data
* @param tileData
*/
public void setSign(Map<String, Tag> tileData) {
signText = new ArrayList<String>();
List<String> text = new ArrayList<String>();
for (int i = 1; i < 5; i++) {
String line = ((StringTag) tileData.get("Text" + String.valueOf(i))).getValue();
// This value can actually be a string that says null sometimes.
if (line.equalsIgnoreCase("null")) {
line = "";
}
// System.out.println("DEBUG: line " + i + " = '"+ line + "' of length " + line.length());
text.add(line);
}
JSONParser parser = new JSONParser();
ContainerFactory containerFactory = new ContainerFactory() {
public List creatArrayContainer() {
return new LinkedList();
}
public Map createObjectContainer() {
return new LinkedHashMap();
}
};
// This just removes all the JSON formatting and provides the raw text
for (int line = 0; line < 4; line++) {
String lineText = "";
if (!text.get(line).equals("\"\"") && !text.get(line).isEmpty()) {
// Bukkit.getLogger().info("DEBUG: sign text = '" + text.get(line) + "'");
if (text.get(line).startsWith("{")) {
// JSON string
try {
Map json = (Map) parser.parse(text.get(line), containerFactory);
List list = (List) json.get("extra");
// System.out.println("DEBUG1:" + JSONValue.toJSONString(list));
if (list != null) {
Iterator iter = list.iterator();
while (iter.hasNext()) {
Object next = iter.next();
String format = JSONValue.toJSONString(next);
// This doesn't see right, but appears to be the easiest way to identify this string as JSON...
if (format.startsWith("{")) {
// JSON string
Map jsonFormat = (Map) parser.parse(format, containerFactory);
Iterator formatIter = jsonFormat.entrySet().iterator();
while (formatIter.hasNext()) {
Map.Entry entry = (Map.Entry) formatIter.next();
// System.out.println("DEBUG3:" + entry.getKey() + "=>" + entry.getValue());
String key = entry.getKey().toString();
String value = entry.getValue().toString();
if (key.equalsIgnoreCase("color")) {
try {
lineText += ChatColor.valueOf(value.toUpperCase());
} catch (Exception noColor) {
Bukkit.getLogger().warning("Unknown color " + value + " in sign when pasting schematic, skipping...");
}
} else if (key.equalsIgnoreCase("text")) {
lineText += value;
} else {
// Formatting - usually the value is always true, but check just in case
if (key.equalsIgnoreCase("obfuscated") && value.equalsIgnoreCase("true")) {
lineText += ChatColor.MAGIC;
} else if (key.equalsIgnoreCase("underlined") && value.equalsIgnoreCase("true")) {
lineText += ChatColor.UNDERLINE;
} else {
// The rest of the formats
try {
lineText += ChatColor.valueOf(key.toUpperCase());
} catch (Exception noFormat) {
// Ignore
// System.out.println("DEBUG3:" + key + "=>" + value);
Bukkit.getLogger().warning("Unknown format " + value + " in sign when pasting schematic, skipping...");
}
}
}
}
} else {
// any previous formatting
if (format.length() > 1) {
lineText += ChatColor.RESET + format.substring(format.indexOf('"') + 1, format.lastIndexOf('"'));
}
}
}
} else {
// No extra tag
json = (Map) parser.parse(text.get(line), containerFactory);
String value = (String) json.get("text");
// System.out.println("DEBUG text only?:" + value);
lineText += value;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// This is unformatted text (not JSON). It is included in "".
if (text.get(line).length() > 1) {
try {
lineText = text.get(line).substring(text.get(line).indexOf('"') + 1, text.get(line).lastIndexOf('"'));
} catch (Exception e) {
// There may not be those "'s, so just use the raw line
lineText = text.get(line);
}
} else {
// just in case it isn't - show the raw line
lineText = text.get(line);
}
}
// Bukkit.getLogger().info("Line " + line + " is " + lineText);
}
signText.add(lineText);
}
}
use of com.wasteofplastic.org.jnbt.StringTag in project askyblock by tastybento.
the class BannerBlock method prep.
@SuppressWarnings("deprecation")
public boolean prep(Map<String, Tag> tileData) {
// x = Int
try {
// Do the base color
int baseColor = 15 - ((IntTag) tileData.get("Base")).getValue();
// //ASkyBlock.getPlugin().getLogger().info("Base value = " +
// baseColor);
// baseColor green = 10
bannerBaseColor = DyeColor.getByDyeData((byte) baseColor);
// Do the patterns (no idea if this will work or not)
bannerPattern = new ArrayList<Pattern>();
ListTag patterns = (ListTag) tileData.get("Patterns");
if (patterns != null) {
for (Tag pattern : patterns.getValue()) {
// Translate pattern to PatternType
if (pattern instanceof CompoundTag) {
CompoundTag patternColor = (CompoundTag) pattern;
// The tag is made up of pattern (String) and color
// (int)
Map<String, Tag> patternValue = patternColor.getValue();
StringTag mark = (StringTag) patternValue.get("Pattern");
Integer markColor = 15 - ((IntTag) patternValue.get("Color")).getValue();
// ASkyBlock.getPlugin().getLogger().info("mark = " +
// mark.getValue());
// ASkyBlock.getPlugin().getLogger().info("color = " +
// markColor);
DyeColor dColor = DyeColor.getByDyeData(markColor.byteValue());
// + dColor.toString());
if (patternKey.containsKey(mark.getValue())) {
Pattern newPattern = new Pattern(dColor, patternKey.get(mark.getValue()));
bannerPattern.add(newPattern);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
use of com.wasteofplastic.org.jnbt.StringTag in project askyblock by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
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_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", 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()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of com.wasteofplastic.org.jnbt.StringTag in project askyblock by tastybento.
the class NMSHandler method setPotion.
/* (non-Javadoc)
* @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag)
*/
@SuppressWarnings({ "unchecked" })
@Override
public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) {
Map<String, Tag> cont = (Map<String, Tag>) ((CompoundTag) itemTags).getValue();
if (cont != null) {
if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
StringTag stringTag = ((StringTag) contents.get("Potion"));
if (stringTag != null) {
String tag = ((StringTag) contents.get("Potion")).getValue();
// Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
tagCompound.setString("Potion", tag);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
}
}
// Schematic is old, the potions do not have tags
// Set it to zero so that the potion bottles don't look like giant purple and black blocks
chestItem.setDurability((short) 0);
Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water.");
return chestItem;
}
Aggregations