Saber-Factions/src/com/massivecraft/factions/util/MiscUtil.java

70 lines
1.6 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.util;
2011-04-08 21:01:46 +02:00
import java.util.Arrays;
import java.util.HashSet;
import org.bukkit.ChatColor;
import org.bukkit.entity.Creature;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
public class MiscUtil
2011-10-12 17:25:01 +02:00
{
public static CreatureType creatureTypeFromEntity(Entity entity)
{
if ( ! (entity instanceof Creature))
{
return null;
}
String name = entity.getClass().getSimpleName();
name = name.substring(5); // Remove "Craft"
return CreatureType.fromName(name);
}
2011-04-08 21:01:46 +02:00
// Inclusive range
public static long[] range(long start, long end) {
long[] values = new long[(int) Math.abs(end - start) + 1];
if (end < start) {
long oldstart = start;
start = end;
end = oldstart;
}
for (long i = start; i <= end; i++) {
values[(int) (i - start)] = i;
}
return values;
}
/// TODO create tag whitelist!!
public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String []{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z"
}));
public static String getComparisonString(String str)
{
String ret = "";
str = ChatColor.stripColor(str);
2011-10-22 17:42:13 +02:00
str = str.toLowerCase();
for (char c : str.toCharArray())
{
if (substanceChars.contains(String.valueOf(c)))
{
ret += c;
}
}
return ret.toLowerCase();
}
2011-04-08 21:01:46 +02:00
}