当前位置: 首页>>代码示例>>Java>>正文


Java BukkitObjectInputStream.readObject方法代码示例

本文整理汇总了Java中org.bukkit.util.io.BukkitObjectInputStream.readObject方法的典型用法代码示例。如果您正苦于以下问题:Java BukkitObjectInputStream.readObject方法的具体用法?Java BukkitObjectInputStream.readObject怎么用?Java BukkitObjectInputStream.readObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.util.io.BukkitObjectInputStream的用法示例。


在下文中一共展示了BukkitObjectInputStream.readObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: itemStackArrayFromBase64

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
/**
     * Gets an array of ItemStacks from Base64 string.
     * 
     * <p />
     * 
     * Base off of {@link #fromBase64(String)}.
     * 
     * @param data Base64 string to convert to ItemStack array.
     * @return ItemStack array created from the Base64 string.
     * @throws IOException
     */
    public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
    	try {
            ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
            BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
            ItemStack[] items = new ItemStack[dataInput.readInt()];
    
            for (int i = 0; i < items.length; i++) {
            	items[i] = (ItemStack) dataInput.readObject();
            }
            
            dataInput.close();
            return items;
        } catch (ClassNotFoundException e) {
            throw new IOException("Unable to decode class type.", e);
        }
}
 
开发者ID:untocodes,项目名称:Vaults,代码行数:28,代码来源:Invtobase.java

示例2: itemStackArrayFromBase64

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
   	try {
           ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
           BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
           ItemStack[] items = new ItemStack[dataInput.readInt()];
   
           for (int i = 0; i < items.length; i++) {
           	items[i] = (ItemStack) dataInput.readObject();
           }
           
           dataInput.close();
           return items;
       } catch (ClassNotFoundException e) {
           throw new IOException("Unable to decode class type.", e);
       }
}
 
开发者ID:benfah,项目名称:Bags,代码行数:17,代码来源:InventorySerializer.java

示例3: itemStackArrayFromBase64

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
	try {
		ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
		BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
		ItemStack[] items = new ItemStack[dataInput.readInt()];

		// Read the serialized inventory
		for (int i = 0; i < items.length; i++) {
			items[i] = (ItemStack) dataInput.readObject();
		}

		dataInput.close();
		return items;
	} catch (ClassNotFoundException e) {
		throw new IOException("Unable to decode class type.", e);
	}
}
 
开发者ID:bobmandude9889,项目名称:iZenith-PVP,代码行数:18,代码来源:Util.java

示例4: loadEnderchest

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
private void loadEnderchest(Inventory inv) {
    inv.clear();
    if(!this.database.contains(this.key + ".enderchest")) {
        return;
    }

    Map<String, Object> enderchest = null;
    try {
        BukkitObjectInputStream in = new BukkitObjectInputStream(new ByteArrayInputStream(this.database.getBytes(this.key + ".enderchest")));
        enderchest = (Map<String, Object>) in.readObject();
    } catch(Exception e) {
        this.module.getLogger().log(Level.SEVERE, "Failed to load enderchest.", e);
        return;
    }

    for(int slot = 0; slot < inv.getSize(); slot++) {
        if(enderchest.containsKey(String.valueOf(slot))) {
            inv.setItem(slot, ItemStack.deserialize((Map<String, Object>) enderchest.get(String.valueOf(slot))));
        } else {
            inv.setItem(slot, null);
        }
    }
}
 
开发者ID:Steveice10,项目名称:Peacecraft,代码行数:24,代码来源:WorldPlayerData.java

示例5: deserializeItemStack

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static ItemStack deserializeItemStack(String s) {
    try {
        byte[] b = BukkitObjectUtil.hexStringToByteArray(s);
        ByteArrayInputStream bais = new ByteArrayInputStream(b);
        BukkitObjectInputStream bois = new BukkitObjectInputStream(bais);

        ItemStack items = (ItemStack) bois.readObject();

        bois.close();
        bais.close();
        return items;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:DemigodsRPG,项目名称:Stoa,代码行数:17,代码来源:ItemUtil.java

示例6: deserializeItemStacks

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static ItemStack[] deserializeItemStacks(String s) {
    try {
        byte[] b = BukkitObjectUtil.hexStringToByteArray(s);
        ByteArrayInputStream bais = new ByteArrayInputStream(b);
        BukkitObjectInputStream bois = new BukkitObjectInputStream(bais);

        ItemStack[] items = (ItemStack[]) bois.readObject();

        bois.close();
        bais.close();
        return items;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:DemigodsRPG,项目名称:Stoa,代码行数:17,代码来源:ItemUtil.java

示例7: deserializePotionEffects

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static List<PotionEffect> deserializePotionEffects(String s) {
    try {
        byte[] b = BukkitObjectUtil.hexStringToByteArray(s);
        ByteArrayInputStream bais = new ByteArrayInputStream(b);
        BukkitObjectInputStream bois = new BukkitObjectInputStream(bais);

        PotionEffect[] eff = (PotionEffect[]) bois.readObject();

        bois.close();
        bais.close();
        return Arrays.asList(eff);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:DemigodsRPG,项目名称:Stoa,代码行数:17,代码来源:PotionEffectUtil.java

示例8: NationsContainer

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public NationsContainer(NBTCompoundTag rootTag, Chunk chunk) throws IOException, ClassNotFoundException
{		
	int x = ((NBTShortTag)rootTag.getTag("X")).getValue() + chunk.getX() * 16;
	int y = ((NBTShortTag)rootTag.getTag("Y")).getValue();
	int z = ((NBTShortTag)rootTag.getTag("Z")).getValue() + chunk.getZ() * 16;
	
	location = new Location(chunk.getWorld(), x,y,z);
	
	byte[] itemsRaw = ((NBTByteArrayTag)rootTag.getTag("BukkitItemStackArray")).getValue();
	ByteArrayInputStream itemsStream = new ByteArrayInputStream(itemsRaw);		
	BukkitObjectInputStream bois = new BukkitObjectInputStream(itemsStream);
	
	items = (ItemStack[])bois.readObject();		
	bois.close();
	
	invType = InventoryType.valueOf(((NBTStringTag)rootTag.getTag("InventoryType")).getValue());
}
 
开发者ID:marsglorious,项目名称:NewNations,代码行数:18,代码来源:NationsContainer.java

示例9: itemStackArrayFromBase64

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
/**
 * Gets an array of ItemStacks from Base64 string.
 *
 * <p>
 *
 * Base off of {@link #fromBase64(String)}.
 *
 * @param data Base64 string to convert to ItemStack array.
 * @return ItemStack array created from the Base64 string.
 * @throws IOException if we was unable to parse the base64 string
 */
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
    if(data.isEmpty()) return new ItemStack[] {};

    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
        BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
        ItemStack[] items = new ItemStack[dataInput.readInt()];

        // Read the serialized inventory
        for (int i = 0; i < items.length; i++) {
            items[i] = (ItemStack) dataInput.readObject();
        }

        dataInput.close();
        return items;
    } catch (ClassNotFoundException e) {
        throw new IOException("Unable to decode class type.", e);
    }
}
 
开发者ID:graywolf336,项目名称:Jail,代码行数:31,代码来源:Util.java

示例10: fromBase64Obj

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static Object fromBase64Obj(String data)
{
       try {
           ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
           BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
   
           Object obj = dataInput.readObject();
           
           dataInput.close();
           return obj;
       } catch (Exception e) {
           return null;
       }
}
 
开发者ID:benfah,项目名称:Bags,代码行数:15,代码来源:InventorySerializer.java

示例11: loadInventory

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
private void loadInventory(PlayerInventory inv) {
    inv.clear();
    inv.setArmorContents(new ItemStack[] {null, null, null, null});
    if(!this.database.contains(this.key + ".inventory")) {
        return;
    }

    Map<String, Object> inventory = null;
    try {
        BukkitObjectInputStream in = new BukkitObjectInputStream(new ByteArrayInputStream(this.database.getBytes(this.key + ".inventory")));
        inventory = (Map<String, Object>) in.readObject();
    } catch(Exception e) {
        this.module.getLogger().log(Level.SEVERE, "Failed to load inventory.", e);
        return;
    }

    for(int slot = 0; slot < inv.getSize(); slot++) {
        if(inventory.containsKey(String.valueOf(slot))) {
            inv.setItem(slot, ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf(slot))));
        } else {
            inv.setItem(slot, null);
        }
    }

    if(inventory.containsKey("helmet")) {
        inv.setHelmet(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("helmet"))));
    }

    if(inventory.containsKey("chestplate")) {
        inv.setChestplate(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("chestplate"))));
    }

    if(inventory.containsKey("leggings")) {
        inv.setLeggings(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("leggings"))));
    }

    if(inventory.containsKey("boots")) {
        inv.setBoots(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("boots"))));
    }
}
 
开发者ID:Steveice10,项目名称:Peacecraft,代码行数:41,代码来源:WorldPlayerData.java

示例12: deserializeItem

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static ItemStack deserializeItem(JSONObject data, int index) {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data.getString("item")));
        BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
        try {
            return (ItemStack) dataInput.readObject();
        } finally {
            dataInput.close();
        }
    } catch (JSONException | IOException | ClassNotFoundException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
开发者ID:ThisIzEthan,项目名称:NexusInventory,代码行数:15,代码来源:SingleItemSerialization.java

示例13: fromBase64

import org.bukkit.util.io.BukkitObjectInputStream; //导入方法依赖的package包/类
public static Inventory fromBase64(String data) throws IOException {
    try {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
        BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
        int maxItems = dataInput.readInt();
        int invSize = STBUtil.roundUp(maxItems, 9);  // Bukkit inventory size must be multiple of 9
        Inventory inventory = Bukkit.getServer().createInventory(null, invSize);

        // Read the serialized inventory
        for (int i = 0; i < maxItems; i++) {
            ItemStack stack = (ItemStack) dataInput.readObject();
            int nAttrs = dataInput.readInt();
            if (nAttrs > 0) {
                Attributes attributes = new Attributes(stack);
                for (int n = 0; n < nAttrs; n++) {
                    String s = (String) dataInput.readObject();
                    String[] fields = s.split(";;");
                    attributes.add(Attributes.Attribute.newBuilder().
                            name(fields[2]).
                            amount(Double.parseDouble(fields[3])).
                            uuid(UUID.fromString(fields[0])).
                            operation(Attributes.Operation.valueOf(fields[1])).
                            type(Attributes.AttributeType.fromId(fields[4])).
                            build()
                    );
                }
                stack = attributes.getStack();
            }
            if (stack != null) {
                inventory.setItem(i, stack);
            }
        }
        dataInput.close();
        return inventory;
    } catch (ClassNotFoundException e) {
        throw new IOException("Unable to decode class type.", e);
    }
}
 
开发者ID:desht,项目名称:sensibletoolbox,代码行数:39,代码来源:BukkitSerialization.java


注:本文中的org.bukkit.util.io.BukkitObjectInputStream.readObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。