Some metadata tools and a random tool.

This commit is contained in:
Olof Larsson 2014-02-14 01:47:47 +01:00
parent ef7a4ef69c
commit 4384c5f396
2 changed files with 21 additions and 2 deletions

View File

@ -50,12 +50,19 @@ public class MetadataSimple extends MetadataValueAdapter
metadatable.setMetadata(key, new MetadataSimple(plugin, value));
}
public static Object get(Metadatable metadatable, String key)
public static MetadataValue getMeta(Metadatable metadatable, String key)
{
List<MetadataValue> metaValues = metadatable.getMetadata(key);
if (metaValues == null) return null;
if (metaValues.size() < 1) return null;
return metaValues.get(0).value();
return metaValues.get(0);
}
public static Object get(Metadatable metadatable, String key)
{
MetadataValue metaValue = getMeta(metadatable, key);
if (metaValue == null) return null;
return metaValue.value();
}
}

View File

@ -490,6 +490,18 @@ public class MUtil
return new ArrayList<T>(coll).get(index);
}
public static <T> List<T> random(Collection<T> coll, int count)
{
List<T> ret = new ArrayList<T>(coll);
if (count < 0) count = 0;
while (ret.size() > count)
{
int index = MCore.random.nextInt(ret.size());
ret.remove(index);
}
return ret;
}
// -------------------------------------------- //
// LE NICE EQUALS and compare
// -------------------------------------------- //