Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6657465
commit f579d02
Showing
3 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
16 changes: 6 additions & 10 deletions
16
plugin/src/main/java/com/denizenscript/denizen/objects/properties/PropertyRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...n/java/com/denizenscript/denizen/objects/properties/bukkit/BukkitBinaryTagProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.denizen.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.<BukkitBinaryTagProperties, ObjectTag>registerStaticTag(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 | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...main/java/com/denizenscript/denizen/objects/properties/bukkit/BukkitMapTagProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.denizenscript.denizen.objects.properties.bukkit; | ||
|
||
import com.denizenscript.denizen.nms.util.jnbt.NBTOutputStream; | ||
import com.denizenscript.denizen.nms.util.jnbt.Tag; | ||
import com.denizenscript.denizen.objects.properties.item.ItemRawNBT; | ||
import com.denizenscript.denizen.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.core.MapTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
public class BukkitMapTagProperties implements Property { | ||
|
||
public static boolean describes(ObjectTag map) { | ||
return map instanceof MapTag; | ||
} | ||
|
||
public static BukkitMapTagProperties getFrom(ObjectTag map) { | ||
if (!describes(map)) { | ||
return null; | ||
} | ||
else { | ||
return new BukkitMapTagProperties((MapTag) map); | ||
} | ||
} | ||
|
||
private BukkitMapTagProperties(MapTag map) { | ||
this.map = map; | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
}; // None | ||
|
||
public MapTag map; | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <MapTag.map_to_nbt> | ||
// @returns BinaryTag | ||
// @group conversion | ||
// @description | ||
// Converts the NBT-formatted MapTag to raw binary NBT. | ||
// Refer to <@link language Raw NBT Encoding> | ||
// @example | ||
// # Stores a player ".dat" file's NBT data | ||
// # NOTE: replace 'something' with your map data | ||
// - define playerdata something | ||
// - define data <[something].map_to_nbt.gzip_compress> | ||
// - ~filewrite path:data/<player.uuid>.dat data:<[data]> | ||
// --> | ||
PropertyParser.<BukkitMapTagProperties, BinaryTag>registerStaticTag(BinaryTag.class, "map_to_nbt", (attribute, object) -> { | ||
try { | ||
Tag tag = ItemRawNBT.convertObjectToNbt(object.map.toString(), attribute.context, "(root)."); | ||
ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||
NBTOutputStream nbtStream = new NBTOutputStream(output); | ||
nbtStream.writeNamedTag("", tag); | ||
nbtStream.close(); | ||
byte[] data = output.toByteArray(); | ||
output.close(); | ||
return new BinaryTag(data); | ||
} | ||
catch (Throwable ex) { | ||
Debug.echoError(ex); | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "BukkitMapTagProperties"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
// None | ||
} | ||
} |