mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 18:47:20 +01:00
Added relativity options to ExactDestination. Implements #1892.
This commit is contained in:
parent
2b4d386eb2
commit
532ffacf5a
@ -21,9 +21,10 @@ import java.util.List;
|
|||||||
* An exact {@link MVDestination}.
|
* An exact {@link MVDestination}.
|
||||||
*/
|
*/
|
||||||
public class ExactDestination implements MVDestination {
|
public class ExactDestination implements MVDestination {
|
||||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
|
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~)";
|
||||||
private boolean isValid;
|
private boolean isValid;
|
||||||
private Location location;
|
private Location location;
|
||||||
|
private boolean relativeX, relativeY, relativeZ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@ -88,7 +89,20 @@ public class ExactDestination implements MVDestination {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Location getLocation(Entity e) {
|
public Location getLocation(Entity e) {
|
||||||
return this.location;
|
Location loc = this.location.clone();
|
||||||
|
if (relativeX || relativeY || relativeZ) {
|
||||||
|
Location eLoc = e.getLocation();
|
||||||
|
loc.add(relativeX ? eLoc.getX() : 0, relativeY ? eLoc.getY() : 0, relativeZ ? eLoc.getZ() : 0);
|
||||||
|
// Since the location is relative, it makes sense to use the entity's pitch and yaw unless those were
|
||||||
|
// specified in the destination.
|
||||||
|
if (loc.getPitch() == 0) {
|
||||||
|
loc.setPitch(eLoc.getPitch());
|
||||||
|
}
|
||||||
|
if (loc.getYaw() == 0) {
|
||||||
|
loc.setYaw(eLoc.getYaw());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,11 +148,42 @@ public class ExactDestination implements MVDestination {
|
|||||||
double[] coords = new double[3];
|
double[] coords = new double[3];
|
||||||
String[] coordString = parsed.get(2).split(",");
|
String[] coordString = parsed.get(2).split(",");
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
try {
|
String[] relSplit = coordString[i].split("~");
|
||||||
coords[i] = Double.parseDouble(coordString[i]);
|
boolean relative = false;
|
||||||
} catch (NumberFormatException e) {
|
if (relSplit.length == 0) {
|
||||||
this.isValid = false;
|
// coord is "~" form
|
||||||
return;
|
relative = true;
|
||||||
|
coords[i] = 0;
|
||||||
|
} else if (relSplit.length == 1) {
|
||||||
|
// coord is "123" form
|
||||||
|
try {
|
||||||
|
coords[i] = Double.parseDouble(relSplit[0]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
this.isValid = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// coord is "~123" form
|
||||||
|
relative = true;
|
||||||
|
try {
|
||||||
|
coords[i] = Double.parseDouble(relSplit[1]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
this.isValid = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (relative) {
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
relativeX = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
relativeY = true;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
relativeZ = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.location.setX(coords[0]);
|
this.location.setX(coords[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user