changed namespace to com.massivecraft

This commit is contained in:
Olof Larsson
2011-07-18 22:06:02 +02:00
parent 60603892c6
commit 8aefae5679
151 changed files with 988 additions and 949 deletions

View File

@ -0,0 +1,89 @@
package com.massivecraft.factions.util;
import java.util.*;
import org.bukkit.ChatColor;
public class AsciiCompass {
public enum Point {
N('N'),
NE('/'),
E('E'),
SE('\\'),
S('S'),
SW('/'),
W('W'),
NW('\\');
public final char asciiChar;
private Point(final char asciiChar) {
this.asciiChar = asciiChar;
}
@Override
public String toString() {
return String.valueOf(this.asciiChar);
}
public String toString(boolean isActive, ChatColor colorActive, ChatColor colorDefault) {
return (isActive ? colorActive : colorDefault)+String.valueOf(this.asciiChar);
}
}
public static AsciiCompass.Point getCompassPointForDirection(double inDegrees) {
double degrees = (inDegrees - 90) % 360 ;
if (degrees < 0)
degrees += 360;
if (0 <= degrees && degrees < 22.5)
return AsciiCompass.Point.N;
else if (22.5 <= degrees && degrees < 67.5)
return AsciiCompass.Point.NE;
else if (67.5 <= degrees && degrees < 112.5)
return AsciiCompass.Point.E;
else if (112.5 <= degrees && degrees < 157.5)
return AsciiCompass.Point.SE;
else if (157.5 <= degrees && degrees < 202.5)
return AsciiCompass.Point.S;
else if (202.5 <= degrees && degrees < 247.5)
return AsciiCompass.Point.SW;
else if (247.5 <= degrees && degrees < 292.5)
return AsciiCompass.Point.W;
else if (292.5 <= degrees && degrees < 337.5)
return AsciiCompass.Point.NW;
else if (337.5 <= degrees && degrees < 360.0)
return AsciiCompass.Point.N;
else
return null;
}
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, ChatColor colorDefault) {
ArrayList<String> ret = new ArrayList<String>();
String row;
row = "";
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
ret.add(row);
row = "";
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
row += colorDefault+"+";
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
ret.add(row);
row = "";
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
ret.add(row);
return ret;
}
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, ChatColor colorDefault) {
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
}
}

View File

@ -0,0 +1,33 @@
package com.massivecraft.factions.util;
import java.io.*;
/**
* Harddisc related methods such as read and write.
*/
public class DiscUtil {
/**
* Convenience function for writing a string to a file.
*/
public static void write(File file, String content) throws IOException {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF8"));
out.write(content);
out.close();
}
/**
* Convenience function for reading a file as a string.
*/
public static String read(File file) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String ret = new String(new byte[0], "UTF-8");
String line;
while ((line = in.readLine()) != null) {
ret += line;
}
in.close();
return ret;
}
}

View File

@ -0,0 +1,18 @@
package com.massivecraft.factions.util;
import org.bukkit.entity.Creature;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
public class EntityUtil {
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);
}
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.factions.util;
public class MiscUtil {
// 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;
}
}

View File

@ -0,0 +1,88 @@
package com.massivecraft.factions.util;
import java.util.*;
import org.bukkit.Material;
import com.massivecraft.factions.Conf;
public class TextUtil {
public static String titleize(String str) {
String line = Conf.colorChrome+repeat("_", 60);
String center = ".[ " + Conf.colorSystem + str + Conf.colorChrome + " ].";
int pivot = line.length() / 2;
int eatLeft = center.length() / 2;
int eatRight = center.length() - eatLeft;
if (eatLeft < pivot)
return line.substring(0, pivot - eatLeft) + center + line.substring(pivot + eatRight);
else
return center;
}
public static String repeat(String s, int times) {
if (times <= 0) return "";
else return s + repeat(s, times-1);
}
public static ArrayList<String> split(String str) {
return new ArrayList<String>(Arrays.asList(str.trim().split("\\s+")));
}
public static String implode(List<String> list, String glue) {
String ret = "";
for (int i=0; i<list.size(); i++) {
if (i!=0) {
ret += glue;
}
ret += list.get(i);
}
return ret;
}
public static String implode(List<String> list) {
return implode(list, " ");
}
/*public static String commandHelp(List<String> aliases, String param, String desc) {
ArrayList<String> parts = new ArrayList<String>();
parts.add(Conf.colorCommand+Conf.aliasBase.get(0));
parts.add(TextUtil.implode(aliases, ", "));
if (param.length() > 0) {
parts.add(Conf.colorParameter+param);
}
if (desc.length() > 0) {
parts.add(Conf.colorSystem+desc);
}
//Log.debug(TextUtil.implode(parts, " "));
return TextUtil.implode(parts, " ");
}*/
public static String getMaterialName(Material material) {
String ret = material.toString();
ret = ret.replace('_', ' ');
ret = ret.toLowerCase();
return ret.substring(0, 1).toUpperCase()+ret.substring(1);
}
/// 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 = "";
for (char c : str.toCharArray()) {
if (substanceChars.contains(String.valueOf(c))) {
ret += c;
}
}
return ret.toLowerCase();
}
}