Fixes admin blueprint delete command

https://github.com/BentoBoxWorld/BentoBox/issues/1382
This commit is contained in:
tastybento 2020-06-01 12:15:49 -07:00
parent 9df54ff07f
commit a6d6895676
2 changed files with 18 additions and 11 deletions

View File

@ -49,7 +49,9 @@ public class Blueprint {
/**
* @return the name
*/
@NonNull
public String getName() {
if (name == null) name = "unnamed";
// Force lower case
return name.toLowerCase(Locale.ENGLISH);
}

View File

@ -12,6 +12,7 @@ import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -407,18 +408,22 @@ public class BlueprintsManager {
*/
public void deleteBlueprint(GameModeAddon addon, String name) {
List<Blueprint> addonBlueprints = blueprints.get(addon);
addonBlueprints.stream().filter(b -> b.getName().equals(name)).forEach(b -> {
addonBlueprints.remove(b);
blueprints.put(addon, addonBlueprints);
Iterator<Blueprint> it = addonBlueprints.iterator();
while (it.hasNext()) {
Blueprint b = it.next();
if (b.getName().equalsIgnoreCase(name)) {
it.remove();
blueprints.put(addon, addonBlueprints);
File file = new File(getBlueprintsFolder(addon), name + BLUEPRINT_SUFFIX);
// Delete the file
try {
Files.deleteIfExists(file.toPath());
} catch (IOException e) {
plugin.logError("Could not delete Blueprint " + e.getLocalizedMessage());
}
});
File file = new File(getBlueprintsFolder(addon), b.getName() + BLUEPRINT_SUFFIX);
// Delete the file
try {
Files.deleteIfExists(file.toPath());
} catch (IOException e) {
plugin.logError("Could not delete Blueprint " + e.getLocalizedMessage());
}
}
}
}
/**