public void execute(Player player, String message) {
// Set up an integer array to hold the maximum area size
int[] maxSize = getAreaMax(player); // X, Z
Config config = player.getServer().config;
String arguments[] = extractArguments(message);
if (arguments.length == 0) {
player.addTCaptionedMessage("Usage", commandPrefix() + "myarea [start|end|save|unsave|rename]");
return;
}
if (arguments[0].equals("start")) {
player.areastart = player.position();
player.areastart = player.areastart.setY(0); // no height limit
player.addTMessage(Color.GRAY, "Start coordinate set.");
} else if (arguments[0].equals("end")) {
player.areaend = player.position();
player.areaend = player.areaend.setY(255); // no height limit
player.addTMessage(Color.GRAY, "End coordinate set.");
} else if (arguments[0].equals("save")) {
if (player.areastart == null || player.areaend == null) {
player.addTMessage(Color.RED, "Define start and end coordinates for your area first!");
return;
}
if (!areaSizeOk(player, maxSize)) {
player.addTMessage(Color.RED, "Your area is allowed to have a maximum size of " +
maxSize[0] + "x" + maxSize[1] + "!");
return;
}
if (player.getServer().config.playerArea(player) != null) {
player.addTMessage(Color.RED, "New area can not be saved before you remove your old one!");
return;
}
Area area = createPlayerArea(player);
Set<Area> overlaps = config.dimensions.overlaps(area);
if (!overlaps.isEmpty()) {
player.addTMessage(Color.RED, "Your area overlaps with other areas and could therefore not be saved!");
StringBuilder str = new StringBuilder();
for (Area overlap : overlaps) {
str.append(overlap.name);
str.append(", ");
}
str.delete(str.length() - 2, str.length() - 1);
player.addTCaptionedMessage("Overlapping areas", "%s", str);
return;
}
saveArea(area, player);
player.addTMessage(Color.GRAY, "Your area has been saved!");
} else if (arguments[0].equals("unsave") || arguments[0].equals("remove")) {
AreaStoragePair area = config.playerArea(player);
if (area == null) {
player.addTMessage(Color.RED, "You currently have no personal area which can be removed!");
return;
}
area.storage.remove(area.area);
player.addTMessage(Color.GRAY, "Your area has been removed!");
player.getServer().saveConfig();
} else if (arguments[0].equals("rename")) {
AreaStoragePair area = config.playerArea(player);
if (area == null) {
player.addTMessage(Color.RED, "You currently have no personal area which can be renamed!");
return;
}