Last active
January 3, 2016 06:49
-
-
Save DarkBlade12/8425244 to your computer and use it in GitHub Desktop.
This a little util which allows you to easily use Metadata
This file contains hidden or 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
import org.bukkit.metadata.FixedMetadataValue; | |
import org.bukkit.metadata.Metadatable; | |
import org.bukkit.plugin.Plugin; | |
public final class MetadataUtil { | |
private Plugin plugin; | |
private String pluginName; | |
public MetadataUtil(Plugin plugin) { | |
this.plugin = plugin; | |
pluginName = plugin.getName(); | |
} | |
public void set(Metadatable m, String key, Object value) { | |
m.setMetadata(pluginName + "_" + key, new FixedMetadataValue(plugin, value)); | |
} | |
public void remove(Metadatable m, String key) { | |
m.removeMetadata(pluginName + "_" + key, plugin); | |
} | |
public boolean hasKey(Metadatable m, String key) { | |
return m.getMetadata(pluginName + "_" + key).size() > 0; | |
} | |
public boolean hasKeys(Metadatable m, String... keys) { | |
for (String key : keys) | |
if (!hasKey(m, key)) | |
return false; | |
return true; | |
} | |
public Object get(Metadatable m, String key) { | |
return hasKey(m, key) ? m.getMetadata(pluginName + "_" + key).get(0).value() : null; | |
} | |
public void removeAll(Metadatable m, String... keys) { | |
for (String k : keys) | |
remove(m, k); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment