Saber-Factions/src/main/java/com/massivecraft/factions/util/AsciiCompass.java

111 lines
3.4 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.util;
2011-02-06 13:36:11 +01:00
import com.massivecraft.factions.zcore.util.TL;
2015-05-13 06:17:22 +02:00
import org.bukkit.ChatColor;
2014-04-04 20:55:21 +02:00
import java.util.ArrayList;
public class AsciiCompass {
2014-04-04 20:55:21 +02:00
public enum Point {
2014-04-04 20:55:21 +02:00
N('N'),
NE('/'),
E('E'),
SE('\\'),
S('S'),
SW('/'),
W('W'),
NW('\\');
public final char asciiChar;
2017-12-19 11:18:13 +01:00
Point(final char asciiChar) {
2014-04-04 20:55:21 +02:00
this.asciiChar = asciiChar;
}
@Override
public String toString() {
return String.valueOf(this.asciiChar);
}
2015-05-13 06:17:22 +02:00
public String getTranslation() {
if (this == N) {
return TL.COMPASS_SHORT_NORTH.toString();
}
if (this == E) {
return TL.COMPASS_SHORT_EAST.toString();
}
if (this == S) {
return TL.COMPASS_SHORT_SOUTH.toString();
}
if (this == W) {
return TL.COMPASS_SHORT_WEST.toString();
}
return toString();
}
2014-04-04 20:55:21 +02:00
public String toString(boolean isActive, ChatColor colorActive, String colorDefault) {
return (isActive ? colorActive : colorDefault) + getTranslation();
2014-04-04 20:55:21 +02:00
}
}
2018-03-26 23:43:15 +02:00
public static Point getCompassPointForDirection(double inDegrees) {
2014-07-01 22:10:18 +02:00
double degrees = (inDegrees - 180) % 360;
if (degrees < 0) {
degrees += 360;
}
2014-07-01 21:49:42 +02:00
2014-07-01 21:52:40 +02:00
if (0 <= degrees && degrees < 22.5) {
2018-03-26 23:43:15 +02:00
return Point.N;
2014-07-01 21:52:40 +02:00
} else if (22.5 <= degrees && degrees < 67.5) {
2018-03-26 23:43:15 +02:00
return Point.NE;
2014-07-01 21:52:40 +02:00
} else if (67.5 <= degrees && degrees < 112.5) {
2018-03-26 23:43:15 +02:00
return Point.E;
2014-07-01 21:52:40 +02:00
} else if (112.5 <= degrees && degrees < 157.5) {
2018-03-26 23:43:15 +02:00
return Point.SE;
2014-07-01 21:52:40 +02:00
} else if (157.5 <= degrees && degrees < 202.5) {
2018-03-26 23:43:15 +02:00
return Point.S;
2014-07-01 21:52:40 +02:00
} else if (202.5 <= degrees && degrees < 247.5) {
2018-03-26 23:43:15 +02:00
return Point.SW;
2014-07-01 21:52:40 +02:00
} else if (247.5 <= degrees && degrees < 292.5) {
2018-03-26 23:43:15 +02:00
return Point.W;
2014-07-01 21:52:40 +02:00
} else if (292.5 <= degrees && degrees < 337.5) {
2018-03-26 23:43:15 +02:00
return Point.NW;
2014-07-01 22:10:18 +02:00
} else if (337.5 <= degrees && degrees < 360.0) {
2018-03-26 23:43:15 +02:00
return Point.N;
2014-07-01 22:10:18 +02:00
} else {
return null;
}
2014-04-04 20:55:21 +02:00
}
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
2017-12-19 11:18:13 +01:00
ArrayList<String> ret = new ArrayList<>();
2014-07-01 22:10:18 +02:00
String row;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
row = "";
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
2014-04-04 20:55:21 +02:00
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
2014-07-01 22:10:18 +02:00
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
ret.add(row);
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
row = "";
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
row += colorDefault + "+";
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
ret.add(row);
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
row = "";
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
2014-04-04 20:55:21 +02:00
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
2014-07-01 22:10:18 +02:00
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
ret.add(row);
2014-04-04 20:55:21 +02:00
return ret;
}
2011-02-06 13:36:11 +01:00
2014-04-04 20:55:21 +02:00
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault) {
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
}
2011-02-06 13:36:11 +01:00
}