Skip to content

Instantly share code, notes, and snippets.

@Snow-Pyon
Last active April 23, 2018 06:31
Show Gist options
  • Save Snow-Pyon/7fcd4be891b98e1432c9a12d54b16796 to your computer and use it in GitHub Desktop.
Save Snow-Pyon/7fcd4be891b98e1432c9a12d54b16796 to your computer and use it in GitHub Desktop.
Metadata utilities script
# Metadata
# Recommended skript version: 2.2-dev35 or above (https://github.com/bensku/Skript/releases/).
# Minecraft version: 1.12.2 (not guaranteed to work in lower versions)
# Addon dependencies:
# - skript-mirror (https://github.com/btk5h/skript-mirror/releases/)
# TODO:
# - possibly support for add, remove and remove all changers.
import:
org.bukkit.metadata.Metadatable
org.bukkit.metadata.FixedMetadataValue
ch.njol.skript.Skript
# Has Metadata
# Description:
# Checks whether one or more objects have or not the specified metadata values.
# Metadata values are just like variables, just that metadatas are not persistent to restarts, thus they're used when you want store temporary info.
# Examples:
# on respawn:
#
# if player has metadata "accidental-death":
#
# teleport player to metadata "accidental-death" of player
# delete metadata "accidental-death" of player
#
# send "<light green>You have been teleported back to your death point due to an accidental death!"
condition %objects% (has|have|1¦do[es](n't| not) have) [the] metadata [value[s]] %strings%:
check:
if parser mark is 1:
negate the condition
loop expressions-2:
loop expressions-1:
loop-value-2 is an instance of Metadatable
if loop-value-2.hasMetadata(loop-value-1) is false:
set {_value} to true
if {_value} isn't set:
continue
# Metadata Value
# Description:
# Gets the metadata values from one or more objects.
# Examples:
# on death:
#
# if damage wasn't caused by attack:
# set metadata "accidental-death" of victim to event-location
# Changers:
# - set
# - delete
expression metadata [value[s]] %strings% (from|of) %objects%:
get:
loop expressions-1:
loop expressions-2:
loop-value-2 is an instance of Metadatable
if loop-value-1.hasMetadata(loop-value-1):
add loop-value-2.getMetadata(loop-value-1) to {_output::*}
return {_output::*}
set:
set {_value} to new FixedMetadataValue(Skript.getInstance() and change value)
loop expressions-1:
loop expressions-2:
if loop-value-2 is an instance of Metadatable:
loop-value-2.setMetadata(loop-value-1 and {_value});
delete:
loop expressions-1:
loop expressions-2:
loop-value-2 is an instance of Metadatable
if loop-value-1.hasMetadata(loop-value-1):
loop-value-2.removeMetadata(loop-value-1 and Skript.getInstance());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment