Fixed space and partial matches in wfind command

Added explicit dimension name to wfind command
This commit is contained in:
LemADEC 2017-08-12 10:57:50 +02:00
parent 3ad10b9a73
commit 5e7c0cc300
3 changed files with 35 additions and 14 deletions

View file

@ -34,6 +34,15 @@ public class CommandFind extends CommandBase {
return;
}
nameToken = params[0];
} else {
final StringBuilder nameBuilder = new StringBuilder();
for (final String param : params) {
if (nameBuilder.length() > 0) {
nameBuilder.append(" ");
}
nameBuilder.append(param);
}
nameToken = nameBuilder.toString();
}
final String result = WarpDrive.starMap.find(nameToken);

View file

@ -113,34 +113,31 @@ public class StarMapRegistry {
if (resultMatch.length() > 0) {
resultMatch.append("\n");
}
resultMatch.append(String.format("Ship '%s' found in DIM%d @ (%d %d %d)",
starMapRegistryItem.name,
starMapRegistryItem.dimensionId,
starMapRegistryItem.x, starMapRegistryItem.y, starMapRegistryItem.z));
resultContains.append(String.format("Ship '%s' found in %s",
starMapRegistryItem.name,
starMapRegistryItem.getFormattedLocation()));
} else {
resultMatch.append(".");
}
} else if (starMapRegistryItem.name.equalsIgnoreCase(nameShip)) {
if (resultMatch.length() < MAX_LENGTH) {
if (resultCaseInsensitive.length() < MAX_LENGTH) {
if (resultCaseInsensitive.length() > 0) {
resultCaseInsensitive.append("\n");
}
resultCaseInsensitive.append(String.format("Ship '%s' found in DIM%d @ (%d %d %d)",
starMapRegistryItem.name,
starMapRegistryItem.dimensionId,
starMapRegistryItem.x, starMapRegistryItem.y, starMapRegistryItem.z));
resultContains.append(String.format("Ship '%s' found in %s",
starMapRegistryItem.name,
starMapRegistryItem.getFormattedLocation()));
} else {
resultCaseInsensitive.append(".");
}
} else if (starMapRegistryItem.name.contains(nameShip)) {
if (resultMatch.length() < MAX_LENGTH) {
if (resultContains.length() < MAX_LENGTH) {
if (resultContains.length() > 0) {
resultContains.append("\n");
}
resultContains.append(String.format("Ship '%s' found in DIM%d @ (%d %d %d)",
resultContains.append(String.format("Ship '%s' found in %s",
starMapRegistryItem.name,
starMapRegistryItem.dimensionId,
starMapRegistryItem.x, starMapRegistryItem.y, starMapRegistryItem.z));
starMapRegistryItem.getFormattedLocation()));
} else {
resultContains.append(".");
}
@ -156,7 +153,7 @@ public class StarMapRegistry {
return resultCaseInsensitive.toString();
}
if (resultContains.length() > 0) {
return resultMatch.toString();
return resultContains.toString();
}
return String.format("No ship found with name '%s'", nameShip);
}

View file

@ -2,6 +2,7 @@ package cr0s.warpdrive.data;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IStarMapRegistryTileEntity;
import cr0s.warpdrive.config.WarpDriveConfig;
import java.util.HashMap;
import java.util.UUID;
@ -182,6 +183,20 @@ public class StarMapRegistryItem extends GlobalPosition {
}
}
public String getFormattedLocation() {
final CelestialObject celestialObject = CelestialObjectManager.get(false, dimensionId, x, z);
if (celestialObject == null) {
return String.format("DIM%d @ (%d %d %d)",
dimensionId,
x, y, z);
} else {
return String.format("%s [DIM%d] @ (%d %d %d)",
celestialObject.getDisplayName(),
dimensionId,
x, y, z);
}
}
@Override
public int hashCode() {
return dimensionId << 24 + (x >> 10) << 12 + y << 10 + (z >> 10);