/
BukkitBinaryTagProperties.java
85 lines (72 loc) · 2.84 KB
/
BukkitBinaryTagProperties.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.denizenscript.denizen.objects.properties.bukkit;
import com.denizenscript.denizen.nms.util.jnbt.NBTInputStream;
import com.denizenscript.denizen.nms.util.jnbt.NamedTag;
import com.denizenscript.denizen.objects.properties.item.ItemRawNBT;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.BinaryTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import java.io.ByteArrayInputStream;
public class BukkitBinaryTagProperties implements Property {
public static boolean describes(ObjectTag data) {
return data instanceof BinaryTag;
}
public static BukkitBinaryTagProperties getFrom(ObjectTag data) {
if (!describes(data)) {
return null;
}
else {
return new BukkitBinaryTagProperties((BinaryTag) data);
}
}
private BukkitBinaryTagProperties(BinaryTag data) {
this.data = data;
}
public static final String[] handledMechs = new String[] {
}; // None
public BinaryTag data;
public static void registerTags() {
// <--[tag]
// @attribute <BinaryTag.nbt_to_map>
// @returns MapTag
// @group conversion
// @description
// Converts raw NBT binary data to a MapTag.
// This under some circumstances might not return a map, depending on the underlying data.
// Refer to <@link language Raw NBT Encoding>
// @example
// # Reads a player ".dat" file's NBT data
// - ~fileread path:data/<player.uuid>.dat save:x
// - define data <entry[x].data.gzip_decompress.nbt_to_map>
// # Now do something with "<[data]>"
// -->
PropertyParser.registerStaticTag(BukkitBinaryTagProperties.class, ObjectTag.class, "nbt_to_map", (attribute, object) -> {
try {
ByteArrayInputStream stream = new ByteArrayInputStream(object.data.data);
NBTInputStream nbtStream = new NBTInputStream(stream);
NamedTag tag = nbtStream.readNamedTag();
nbtStream.close();
stream.close();
return ItemRawNBT.jnbtTagToObject(tag.getTag());
}
catch (Throwable ex) {
Debug.echoError(ex);
return null;
}
});
}
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "BukkitBinaryTagProperties";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
}