New quest IDs use leading zeros

This commit is contained in:
PikaMug 2023-12-06 18:47:54 -05:00
parent 45a64a05ed
commit 5805b47e88
2 changed files with 11 additions and 8 deletions

View File

@ -562,7 +562,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
* @param fileName Name of file to attempt move
*/
private void moveStorageResource(String fileName) {
File storageFile = new File(getDataFolder(), fileName);
final File storageFile = new File(getDataFolder(), fileName);
if (!storageFile.isFile()) {
return;
}
@ -575,9 +575,9 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
+ outDir.canWrite() + ")");
}
}
boolean q = storageFile.renameTo(outFile);
if (!q) {
getLogger().severe("Unable to move " + fileName + " file. Check folder permissions and restart.");
final boolean moved = storageFile.renameTo(outFile);
if (!moved) {
getLogger().severe("Unable to move " + fileName + " file. Check folder permissions and restart server.");
getServer().getPluginManager().disablePlugin(this);
setEnabled(false);
}

View File

@ -45,6 +45,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@ -866,15 +867,17 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
ConfigurationSection newSection = null;
if (context.getSessionData(Key.Q_ID) == null) {
// Creating
int customNum = 1;
int num = 1;
final int padding = 6;
final String customNum = String.format(Locale.US, "%0" + padding + "d", num);
while (true) {
if (questSection.contains("custom" + customNum)) {
customNum++;
if (questSection.contains(customNum)) {
num++;
} else {
break;
}
}
newSection = questSection.createSection("custom" + customNum);
newSection = questSection.createSection(customNum);
} else {
// Editing
final String qid = (String)context.getSessionData(Key.Q_ID);