Skip to content

Commit

Permalink
Fixed the area commands for .schem files.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Nov 20, 2018
1 parent 2b5201d commit 5d9ba28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/sk89q/craftbook/mechanics/area/Area.java
Expand Up @@ -346,7 +346,7 @@ public void loadConfiguration (YAMLProcessor config, String path) {
config.setComment(path + "allow-redstone", "Allow ToggleAreas to be toggled via redstone.");
allowRedstone = config.getBoolean(path + "allow-redstone", true);

config.setComment(path + "use-schematics", "Use MCEdit Schematics for saving areas. This allows support of all blocks and chest/sign data.");
config.setComment(path + "use-schematics", "Use Schematics for saving areas. This allows support of all blocks and chest/sign data.");
useSchematics = config.getBoolean(path + "use-schematics", true);

config.setComment(path + "shorten-long-names", "If this is enabled, namespaces too long to fit on signs will be shortened.");
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/com/sk89q/craftbook/mechanics/area/AreaCommands.java
Expand Up @@ -170,12 +170,15 @@ public void list(CommandContext context, CommandSender sender) throws CommandExc

List<String> areaList = new ArrayList<>();

FilenameFilter fnf = (dir, name) -> Area.instance.useSchematics ? name.endsWith(".schematic") : name.endsWith(".cbcopy");
FilenameFilter fnf = (dir, name) -> Area.instance.useSchematics
? name.endsWith(".schematic") || name.endsWith(".schem")
: name.endsWith(".cbcopy");

if (folder != null && folder.exists()) {
for (File area : folder.listFiles(fnf)) {
String areaName = area.getName();
areaName = areaName.replace(".schematic", "");
areaName = areaName.replace(".schem", "");
areaName = areaName.replace(".cbcopy", "");
areaList.add(ChatColor.AQUA + folder.getName() + " : " + ChatColor.YELLOW + areaName);
}
Expand All @@ -185,6 +188,7 @@ public void list(CommandContext context, CommandSender sender) throws CommandExc
for (File area : file.listFiles(fnf)) {
String areaName = area.getName();
areaName = areaName.replace(".schematic", "");
areaName = areaName.replace(".schem", "");
areaName = areaName.replace(".cbcopy", "");
areaList.add(ChatColor.AQUA + folder.getName() + " : " + ChatColor.YELLOW + areaName);
}
Expand Down Expand Up @@ -282,9 +286,6 @@ public void delete(CommandContext context, CommandSender sender) throws CommandE
deleteAll = true;
} else throw new CommandException("You need to define an area or -a to delete all areas.");

// add the area suffix
areaId = areaId + (Area.instance.useSchematics ? ".schematic" : ".cbcopy");

File areas = null;
try {
areas = new File(plugin.getDataFolder(), "areas/" + namespace);
Expand All @@ -299,9 +300,17 @@ public void delete(CommandContext context, CommandSender sender) throws CommandE
player.print("All areas in the namespace " + namespace + " have been deleted.");
}
} else {
File file = new File(areas, areaId);
if (file.delete()) {
player.print("The area '" + areaId + " in the namespace '" + namespace + "' has been deleted.");
// add the area suffix
String[] possibleFilenames = {areaId + ".schematic", areaId + ".schem", areaId + ".cbcopy"};

for (String filename : possibleFilenames) {
File file = new File(areas, filename);
if (file.exists()) {
if (file.delete()) {
player.print("The area '" + areaId + " in the namespace '" + namespace + "' has been deleted.");
}
break;
}
}
}
}
Expand All @@ -311,7 +320,9 @@ public void delete(CommandContext context, CommandSender sender) throws CommandE
// If a deletion fails, the method stops attempting to delete and returns false.
private boolean deleteDir(File dir) {

FilenameFilter fnf = (dir1, name) -> Area.instance.useSchematics ? name.endsWith(".schematic") : name.endsWith(".cbcopy");
FilenameFilter fnf = (dir1, name) -> Area.instance.useSchematics
? name.endsWith(".schematic") || name.endsWith(".schem")
: name.endsWith(".cbcopy");

if (dir.isDirectory()) {
for (File aChild : dir.listFiles(fnf)) { if (!aChild.delete()) return false; }
Expand Down

0 comments on commit 5d9ba28

Please sign in to comment.