org.bukkit.metadata.Metadatable Java Examples

The following examples show how to use org.bukkit.metadata.Metadatable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
protected T[] get(Event e) {
	List<Object> values = new ArrayList<>();
	for (String value : this.values.getArray(e)) {
		for (Metadatable holder : holders.getArray(e)) {
			List<MetadataValue> metadata = holder.getMetadata(value);
			if (!metadata.isEmpty())
				values.add(metadata.get(metadata.size() - 1).value()); // adds the most recent metadata value
		}
	}
	try {
		return Converters.convertStrictly(values.toArray(), superType);
	} catch (ClassCastException e1) {
		return (T[]) Array.newInstance(superType, 0);
	}
}
 
Example #2
Source File: CondHasMetadata.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
	holders = (Expression<Metadatable>) exprs[0];
	values = (Expression<String>) exprs[1];
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #3
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	for (String value : values.getArray(e)) {
		for (Metadatable holder : holders.getArray(e)) {
			switch (mode) {
				case SET:
					holder.setMetadata(value, new FixedMetadataValue(Skript.getInstance(), delta[0]));
					break;
				case DELETE:
					holder.removeMetadata(value, Skript.getInstance());
			}
		}
	}
}
 
Example #4
Source File: Meta.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets metadata
 *
 * @param obj object
 * @param key key
 * @return metadata value
 */
public static MetadataValue getMetadata(Metadatable obj, String key) {
	for(MetadataValue value : obj.getMetadata(key)) {
		if(value.getOwningPlugin().getDescription().getName().equals(plugin.getDescription().getName())) {
			return value;
		}
	}

	return null;
}
 
Example #5
Source File: Grenade.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean is(Metadatable entity) {
  return entity.hasMetadata(METADATA_KEY);
}
 
Example #6
Source File: Grenade.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static @Nullable Grenade get(Metadatable entity) {
  return entity.hasMetadata(METADATA_KEY)
      ? (Grenade) entity.getMetadata(METADATA_KEY).get(0).value()
      : null;
}
 
Example #7
Source File: Grenade.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public void set(Plugin plugin, Metadatable entity) {
  entity.setMetadata(METADATA_KEY, new FixedMetadataValue(plugin, this));
}
 
Example #8
Source File: Grenade.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean is(Metadatable entity) {
    return entity.hasMetadata(METADATA_KEY);
}
 
Example #9
Source File: Grenade.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static @Nullable Grenade get(Metadatable entity) {
    return entity.hasMetadata(METADATA_KEY) ? (Grenade) entity.getMetadata(METADATA_KEY).get(0).value() : null;
}
 
Example #10
Source File: Grenade.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public void set(Plugin plugin, Metadatable entity) {
    entity.setMetadata(METADATA_KEY, new FixedMetadataValue(plugin, this));
}
 
Example #11
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
	holders = (Expression<Metadatable>) exprs[matchedPattern ^ 1];
	values = (Expression<String>) exprs[matchedPattern];
	return true;
}
 
Example #12
Source File: Meta.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets metadata
 *
 * @param obj   object
 * @param key   key
 * @param value value
 */
public static void setMetadata(Metadatable obj, String key, Object value) {
	obj.setMetadata(key, new FixedMetadataValue(plugin, value));
}
 
Example #13
Source File: Meta.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Removes metadata
 *
 * @param obj object
 * @param key key
 */
public static void removeMetadata(Metadatable obj, String key) {
	obj.removeMetadata(key, plugin);
}