Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * Copyright (c) 2012 turt2live (Travis Ralston).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Lesser Public License v2.1
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *
- * Contributors:
- * turt2live (Travis Ralston) - initial API and implementation
- ******************************************************************************/
- package com.turt2live.xmail.mail.attachment;
- import java.util.HashMap;
- import java.util.Map;
- import org.bukkit.configuration.MemoryConfiguration;
- import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
- import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
- import org.bukkit.inventory.ItemStack;
- import com.turt2live.xmail.api.AttachmentName;
- import com.turt2live.xmail.player.XMailEntity;
- public class ItemAttachment extends Attachment implements AttachmentName {
- protected ItemStack item;
- public ItemAttachment(ItemStack item){
- super(AttachmentType.ITEM2);
- if(item != null){
- this.item = item.clone();
- }
- }
- public ItemStack getItem(){
- return item;
- }
- public void setValue(String value){
- Map<String, Object> keys = new HashMap<String, Object>();
- Gson gson = new Gson();
- System.out.println(value);
- keys = gson.fromJson(value, new TypeToken<Map<String, Object>>(){}.getType());
- // Repair gson derps
- if(keys.get("amount") != null){
- Double d = (Double) keys.get("amount");
- Integer i = d.intValue();
- keys.put("amount", i);
- }
- //@SuppressWarnings ("unchecked")
- //Map<String, Object> meta = (Map<String, Object>) keys.get("meta");
- MemoryConfiguration mem = new MemoryConfiguration();
- mem.addDefault("theitem", keys);
- this.item = mem.getItemStack("theitem");
- //this.item = ItemStack.deserialize(keys);
- }
- @Override
- public String getValue(){
- Map<String, Object> serial = item.serialize();
- // if(serial.get("meta") != null){
- // ItemMeta itemmeta = item.getItemMeta();
- // Map<String, Object> meta = itemmeta.serialize();
- // serial.put("meta", meta);
- // }
- Gson gson = new Gson();
- return getType().getIdent().getIdent() + "|" + gson.toJson(serial);
- }
- @Override
- public boolean giveTo(XMailEntity entity){
- return true;
- }
- @Override
- public String getSingularName(){
- return "item";
- }
- @Override
- public String getPluralName(){
- return "items";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment