Skip to content
Permalink
Browse files

Fixed the area commands for .schem files.

  • Loading branch information...
me4502 committed Nov 20, 2018
1 parent 2b5201d commit 5d9ba28ccd0885e23c2965c7cc0fc3ffb690b0d9
@@ -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.");
@@ -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);
}
@@ -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);
}
@@ -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);
@@ -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;
}
}
}
}
@@ -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; }

0 comments on commit 5d9ba28

Please sign in to comment.
You can’t perform that action at this time.