-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBase64 inventory Encoding Sample
39 lines (38 loc) · 1.08 KB
/
Base64 inventory Encoding Sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public String toBase64(ItemStack[] itemStacks) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < itemStacks.length; i++)
{
if (i > 0) {
stringBuilder.append(";");
}
if ((itemStacks[i] != null) && (itemStacks[i].getType() != Material.AIR)) {
try
{
stringBuilder.append(StreamSerializer.getDefault().serializeItemStack(itemStacks[i]));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
String string = stringBuilder.toString();
return string;
}
public ItemStack[] fromBase64(String data) {
String[] strings = data.split(";");
ItemStack[] itemStacks = new ItemStack[strings.length];
for (int i = 0; i < strings.length; i++) {
if (!strings[i].equals("")) {
try
{
itemStacks[i] = StreamSerializer.getDefault().deserializeItemStack(strings[i]);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return itemStacks;
}