Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DMS coordinates as parameters for /tpll #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/main/java/io/github/terra121/control/TerraTeleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
args[0] = args[0].substring(0, args[0].length() - 1);
if(args.length>1&&args[1].endsWith(","))
args[1] = args[1].substring(0, args[1].length() - 1);

String[] dmsCoordsLat = args[0].split("\"|'|\u00B0");
String[] dmsCoordsLon = args[1].split("\"|'|\u00B0");
if (dmsCoordsLat.length == 4 && dmsCoordsLat.length == 4) {
try {
double latDec = Double.parseDouble(dmsCoordsLat[0]) + (Double.parseDouble(dmsCoordsLat[1])/60.0) + (Double.parseDouble(dmsCoordsLat[2])/3600.0);
double lonDec = Double.parseDouble(dmsCoordsLon[0]) + (Double.parseDouble(dmsCoordsLon[1])/60.0) + (Double.parseDouble(dmsCoordsLon[2])/3600.0);

if(dmsCoordsLat[3].equalsIgnoreCase("S")) {
latDec *= -1;
}

if(dmsCoordsLon[3].equalsIgnoreCase("W")) {
lonDec *= -1;
}


args[0] = Double.toString(latDec);
args[1] = Double.toString(lonDec);
} catch (Exception e) {
throw new CommandException("terra121.error.numbers", new Object[0]);
}

if (args.length == 3) {
alt = args[2];
}
}

if(args.length!=2&&args.length!=3) {
throw new WrongUsageException(getUsage(sender), new Object[0]);
}
Expand Down