• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BukkitObjectOutputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BukkitObjectOutputStream类属于org.bukkit.util.io包,在下文中一共展示了BukkitObjectOutputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: itemStackArrayToBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * 
 * A method to serialize an {@link ItemStack} array to Base64 String.
 * 
 * <p />
 * 
 * Based off of {@link #toBase64(Inventory)}.
 * 
 * @param items to turn into a Base64 String.
 * @return Base64 string of the items.
 * @throws IllegalStateException
 */
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
	try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
        
        // Write the size of the inventory
        dataOutput.writeInt(items.length);
        
        // Save every element in the list
        for (int i = 0; i < items.length; i++) {
            dataOutput.writeObject(items[i]);
        }
        
        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }
}
 
开发者ID:untocodes,项目名称:Vaults,代码行数:33,代码来源:Invtobase.java


示例2: toBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * A method to serialize an inventory to Base64 string.
 * 
 * <p />
 * 
 * Special thanks to Comphenix in the Bukkit forums or also known
 * as aadnk on GitHub.
 * 
 * <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
 * 
 * @param inventory to serialize
 * @return Base64 string of the provided inventory
 * @throws IllegalStateException
 */
public static String toBase64(Inventory inventory) throws IllegalStateException {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
        
        dataOutput.writeInt(inventory.getSize());
        
        for (int i = 0; i < inventory.getSize(); i++) {
            dataOutput.writeObject(inventory.getItem(i));
        }
        
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }
}
 
开发者ID:untocodes,项目名称:Vaults,代码行数:32,代码来源:Invtobase.java


示例3: itemStackArrayToBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * 
 * @param items
 * @return A base64 encoded String
 * @throws IllegalStateException
 * 
 * It encodes an {@link ItemStack} array to a base64 String 
 */
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException
{
   	try {
           ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
           BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
           
           dataOutput.writeInt(items.length);
           
           for (int i = 0; i < items.length; i++) {
               dataOutput.writeObject(items[i]);
           }
           
           dataOutput.close();
           return Base64Coder.encodeLines(outputStream.toByteArray());
       } catch (Exception e) {
           throw new IllegalStateException("Unable to save item stacks.", e);
       }
 }
 
开发者ID:benfah,项目名称:Bags,代码行数:27,代码来源:InventorySerializer.java


示例4: itemStackArrayToBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
	try {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

		// Write the size of the inventory
		dataOutput.writeInt(items.length);

		// Save every element in the list
		for (int i = 0; i < items.length; i++) {
			dataOutput.writeObject(items[i]);
		}

		// Serialize that array
		dataOutput.close();
		return Base64Coder.encodeLines(outputStream.toByteArray());
	} catch (Exception e) {
		throw new IllegalStateException("Unable to save item stacks.", e);
	}
}
 
开发者ID:bobmandude9889,项目名称:iZenith-PVP,代码行数:21,代码来源:Util.java


示例5: serialize

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * Serializes a ItemStack array to a byte array.
 *
 * @param itemStacks The ItemStacks that should be serialized.
 * @return Serialized ItemsStacks as byte array. null if serialization failed.
 */
@Override
public byte[] serialize(ItemStack[] itemStacks)
{
	byte[] ba = null;
	if(itemStacks != null)
	{
		try(ByteArrayOutputStream b = new ByteArrayOutputStream(); BukkitObjectOutputStream output = new BukkitObjectOutputStream(b))
		{
			output.writeObject(itemStacks);
			output.flush();
			ba = b.toByteArray();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	return ba;
}
 
开发者ID:GeorgH93,项目名称:Bukkit_Bungee_PluginLib,代码行数:26,代码来源:BukkitItemStackSerializer.java


示例6: toBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String toBase64(Inventory inventory) throws IllegalStateException {
	try {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

		// Write the size of the inventory
		dataOutput.writeInt(inventory.getSize());

		// Save every element in the list
		for (int i = 0; i < inventory.getSize(); i++) {
			dataOutput.writeObject(inventory.getItem(i));
		}

		// Serialize that array
		dataOutput.close();
		return Base64Coder.encodeLines(outputStream.toByteArray());
	} catch (Exception e) {
		throw new IllegalStateException("Unable to save item stacks.", e);
	}
}
 
开发者ID:michaelkrauty,项目名称:Kettle,代码行数:21,代码来源:Util.java


示例7: serializeItemStack

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String serializeItemStack(ItemStack inv) {
    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
        bos.writeObject(inv);

        String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());

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


示例8: serializeItemStacks

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String serializeItemStacks(ItemStack[] inv) {
    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
        bos.writeObject(inv);

        String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());

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


示例9: serializePotionEffects

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String serializePotionEffects(Collection<PotionEffect> effects) {
    PotionEffect[] eff = new PotionEffect[effects.size()];
    int count = 0;
    for (PotionEffect effect : effects) {
        eff[count] = effect;
        count++;
    }

    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
        bos.writeObject(eff);

        String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());

        bos.close();
        os.close();
        return hex;
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:DemigodsRPG,项目名称:Stoa,代码行数:24,代码来源:PotionEffectUtil.java


示例10: toBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String toBase64(Inventory inventory) {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
        
        // Write the size of the inventory
        dataOutput.writeInt(inventory.getSize());
        
        // Save every element in the list
        for (int i = 0; i < inventory.getSize(); i++) {
            dataOutput.writeObject(inventory.getItem(i));
        }
        
        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }        
}
 
开发者ID:SecondFlight,项目名称:pvpmain,代码行数:21,代码来源:BukkitSerialization.java


示例11: save

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public void save(NBTCompoundTag rootTag) throws IOException
{
	rootTag.setTag("X", new NBTShortTag((short)(location.getBlockX() - location.getChunk().getX() * 16)));
	rootTag.setTag("Y", new NBTShortTag((short)location.getBlockY()));
	rootTag.setTag("Z", new NBTShortTag((short)(location.getBlockZ() - location.getChunk().getZ() * 16)));
	
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	BukkitObjectOutputStream boos = new BukkitObjectOutputStream(baos);
	boos.writeObject( items );
	
	rootTag.setTag("BukkitItemStackArray", new NBTByteArrayTag(baos.toByteArray()));
	boos.close();
	
	rootTag.setTag("InventoryType", new NBTStringTag(invType.name()));
	
}
 
开发者ID:marsglorious,项目名称:NewNations,代码行数:17,代码来源:NationsContainer.java


示例12: inventoryToString

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * Transfer a inventory into a string
 *
 * @param inventory Inventory
 * @return String
 */
@Deprecated
public static String inventoryToString(Inventory inventory) {
	try {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

		// Write the size of the inventory
		dataOutput.writeInt(inventory.getSize());

		// Save every element in the list
		for (int i = 0; i < inventory.getSize(); i++) {
			dataOutput.writeObject(inventory.getItem(i));
		}

		// Serialize that array
		dataOutput.close();
		return Base64Coder.encodeLines(outputStream.toByteArray());
	} catch (Exception e) {
		throw new IllegalStateException("Unable to save item stacks.", e);
	}
}
 
开发者ID:CodeMyAss,项目名称:CTBAPI,代码行数:28,代码来源:CTBAPI.java


示例13: toBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static String toBase64(Inventory inventory) {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

        // Write the size of the inventory
        dataOutput.writeInt(inventory.getSize());

        // Save every element in the list
        for (int i = 0; i < inventory.getSize(); i++) {
            dataOutput.writeObject(inventory.getItem(i));
        }

        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Cannot into itemstacksz!", e);
    }
}
 
开发者ID:drtshock,项目名称:PlayerVaults,代码行数:21,代码来源:Base64Serialization.java


示例14: itemStackArrayToBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 *
 * A method to serialize an {@link ItemStack} array to Base64 String.
 *
 * <p>
 *
 * Based off of {@link #toBase64(Inventory)}.
 *
 * @param items to turn into a Base64 String.
 * @return Base64 string of the items.
 * @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed
 */
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

        // Write the size of the inventory
        dataOutput.writeInt(items.length);

        // Save every element in the list
        for (ItemStack item : items) {
            dataOutput.writeObject(item);
        }

        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }
}
 
开发者ID:graywolf336,项目名称:Jail,代码行数:33,代码来源:Util.java


示例15: toBase64

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * A method to serialize an inventory to Base64 string.
 *
 * <p>
 *
 * Special thanks to Comphenix in the Bukkit forums or also known
 * as aadnk on GitHub. <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
 *
 * @param inventory to serialize
 * @return Base64 string of the provided inventory
 * @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed
 */
public static String toBase64(Inventory inventory) throws IllegalStateException {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);

        // Write the size of the inventory
        dataOutput.writeInt(inventory.getSize());

        // Save every element in the list
        for (int i = 0; i < inventory.getSize(); i++) {
            dataOutput.writeObject(inventory.getItem(i));
        }

        // Serialize that array
        dataOutput.close();
        return Base64Coder.encodeLines(outputStream.toByteArray());
    } catch (Exception e) {
        throw new IllegalStateException("Unable to save item stacks.", e);
    }
}
 
开发者ID:graywolf336,项目名称:Jail,代码行数:33,代码来源:Util.java


示例16: encodeItemStack

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static byte[] encodeItemStack(ItemStack item) {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        try (BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream)) {
            dataOutput.writeObject(item);
            return outputStream.toByteArray();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:11,代码来源:InventorySerialization.java


示例17: encodeItemStacks

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static byte[] encodeItemStacks(ItemStack[] items) {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        try (BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream)) {
            dataOutput.writeInt(items.length);
            for (ItemStack item : items) {
                dataOutput.writeObject(item);
            }
            return outputStream.toByteArray();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:14,代码来源:InventorySerialization.java


示例18: encodeInventory

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
public static byte[] encodeInventory(Inventory inventory) {
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        try (BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream)) {
            dataOutput.writeInt(inventory.getSize());
            for (int i = 0; i < inventory.getSize(); i++) {
                dataOutput.writeObject(inventory.getItem(i));
            }
            return outputStream.toByteArray();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:14,代码来源:InventorySerialization.java


示例19: testSerialize

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
@Test
public void testSerialize() throws Exception
{
	BukkitItemStackSerializer serializer = new BukkitItemStackSerializer();
	assertNull("Serialized data should be null", serializer.serialize(null));
	assertNull("Serialized data should be null when an error occurs", serializer.serialize(new ItemStack[] { new ItemStack(Material.APPLE, 10) }));
	BukkitObjectOutputStream mockedOutputStream = mock(BukkitObjectOutputStream.class);
	doNothing().when(mockedOutputStream).writeObject(any(at.pcgamingfreaks.TestClasses.NMS.ItemStack[].class));
	doNothing().when(mockedOutputStream).flush();
	whenNew(BukkitObjectOutputStream.class).withArguments(any(ByteArrayOutputStream.class)).thenReturn(mockedOutputStream);
	assertNotNull("Serialized data should not be null", serializer.serialize(new ItemStack[] { new ItemStack(Material.APPLE, 10) }));
	doThrow(new IOException()).when(mockedOutputStream).writeObject(any(at.pcgamingfreaks.TestClasses.NMS.ItemStack[].class));
	assertNull("Serialized data should be null when an error occurs", serializer.serialize(new ItemStack[] { new ItemStack(Material.APPLE, 10) }));
}
 
开发者ID:GeorgH93,项目名称:Bukkit_Bungee_PluginLib,代码行数:15,代码来源:BukkitItemStackSerializerTest.java


示例20: serializeItem

import org.bukkit.util.io.BukkitObjectOutputStream; //导入依赖的package包/类
/**
 * Serialize an ItemStack to a JsonObject.
 * <p>
 *     The item itself will be saved as a Base64 encoded string to
 *     simplify the serialization and deserialization process. The result is
 *     not human readable.
 * </p>
 *
 * @param item The item to serialize.
 * @param index The position in the inventory.
 * @return A JsonObject with the serialized item.
 */
public JsonObject serializeItem(ItemStack item, int index) {
    JsonObject values = new JsonObject();
    if (item == null)
        return null;

    /*
     * Check to see if the item is a skull with a null owner.
     * This is because some people are getting skulls with null owners, which causes Spigot to throw an error
     * when it tries to serialize the item. If this ever gets fixed in Spigot, this will be removed.
     */
    if (item.getType() == Material.SKULL_ITEM) {
        SkullMeta meta = (SkullMeta) item.getItemMeta();
        if (meta.hasOwner() && (meta.getOwner() == null || meta.getOwner().isEmpty())) {
            item.setItemMeta(plugin.getServer().getItemFactory().getItemMeta(Material.SKULL_ITEM));
        }
    }

    values.addProperty("index", index);

    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         BukkitObjectOutputStream bos = new BukkitObjectOutputStream(outputStream)) {
        bos.writeObject(item);
        String encoded = Base64Coder.encodeLines(outputStream.toByteArray());

        values.addProperty("item", encoded);
    } catch (IOException ex) {
        ConsoleLogger.severe("Unable to serialize item '" + item.getType().toString() + "':", ex);
        return null;
    }

    return values;
}
 
开发者ID:Gnat008,项目名称:PerWorldInventory,代码行数:45,代码来源:ItemSerializer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FooNumberFormat类代码示例发布时间:2022-05-21
下一篇:
Java ContextTypeRegistry类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap