mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 13:15:28 +01:00
Fix - saved blueprints were using a null name until reload.
This commit is contained in:
parent
0fd25f02cd
commit
8ac0f08285
@ -9,6 +9,7 @@ import world.bentobox.bentobox.managers.BlueprintsManager;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class AdminBlueprintSaveCommand extends ConfirmableCommand {
|
public class AdminBlueprintSaveCommand extends ConfirmableCommand {
|
||||||
|
|
||||||
@ -31,26 +32,29 @@ public class AdminBlueprintSaveCommand extends ConfirmableCommand {
|
|||||||
|
|
||||||
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();
|
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();
|
||||||
BlueprintClipboard clipboard = parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
|
BlueprintClipboard clipboard = parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
|
||||||
|
String fileName = args.get(0).toLowerCase(Locale.ENGLISH);
|
||||||
if (clipboard.isFull()) {
|
if (clipboard.isFull()) {
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
File newFile = new File(parent.getBlueprintsFolder(), args.get(0) + BlueprintsManager.BLUEPRINT_SUFFIX);
|
File newFile = new File(parent.getBlueprintsFolder(), fileName + BlueprintsManager.BLUEPRINT_SUFFIX);
|
||||||
if (newFile.exists()) {
|
if (newFile.exists()) {
|
||||||
this.askConfirmation(user, user.getTranslation("commands.admin.blueprint.file-exists"), () -> {
|
this.askConfirmation(user, user.getTranslation("commands.admin.blueprint.file-exists"), () -> {
|
||||||
hideAndSave(user, parent, clipboard, args.get(0));
|
hideAndSave(user, parent, clipboard, fileName);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return hideAndSave(user, parent, clipboard, args.get(0));
|
return hideAndSave(user, parent, clipboard, fileName);
|
||||||
} else {
|
} else {
|
||||||
user.sendMessage("commands.admin.blueprint.copy-first");
|
user.sendMessage("commands.admin.blueprint.copy-first");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hideAndSave(User user, AdminBlueprintCommand parent, BlueprintClipboard clipboard, String string) {
|
private boolean hideAndSave(User user, AdminBlueprintCommand parent, BlueprintClipboard clipboard, String name) {
|
||||||
parent.hideClipboard(user);
|
parent.hideClipboard(user);
|
||||||
getPlugin().getBlueprintsManager().addBlueprint((GameModeAddon)getAddon(), clipboard.getBlueprint());
|
boolean result = new BlueprintClipboardManager(getPlugin(), parent.getBlueprintsFolder(), clipboard).save(user, name);
|
||||||
return new BlueprintClipboardManager(getPlugin(), parent.getBlueprintsFolder(), clipboard).save(user, string);
|
if (result) {
|
||||||
|
getPlugin().getBlueprintsManager().addBlueprint((GameModeAddon)getAddon(), clipboard.getBlueprint());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,6 +216,9 @@ public class BlueprintsManager {
|
|||||||
String fileName = file.getName().substring(0, file.getName().length() - BLUEPRINT_SUFFIX.length());
|
String fileName = file.getName().substring(0, file.getName().length() - BLUEPRINT_SUFFIX.length());
|
||||||
try {
|
try {
|
||||||
Blueprint bp = new BlueprintClipboardManager(plugin, bpf).loadBlueprint(fileName);
|
Blueprint bp = new BlueprintClipboardManager(plugin, bpf).loadBlueprint(fileName);
|
||||||
|
if (bp.getName() == null) {
|
||||||
|
bp.setName(fileName);
|
||||||
|
}
|
||||||
blueprints.get(addon).put(bp.getName(), bp);
|
blueprints.get(addon).put(bp.getName(), bp);
|
||||||
plugin.log("Loaded blueprint '" + bp.getName() + "' for " + addon.getDescription().getName());
|
plugin.log("Loaded blueprint '" + bp.getName() + "' for " + addon.getDescription().getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user