From 8f8529d4085936a66a9cbb20537e3d8f6cf4eec6 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sat, 24 May 2014 00:15:39 +0200 Subject: [PATCH] added handling of blueprints without unique ids, close #1842 --- .../blueprints/BlueprintDatabase.java | 26 ++++++++++++------- .../builders/blueprints/BlueprintId.java | 6 ++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/common/buildcraft/builders/blueprints/BlueprintDatabase.java b/common/buildcraft/builders/blueprints/BlueprintDatabase.java index 3d6331a0..d052df03 100644 --- a/common/buildcraft/builders/blueprints/BlueprintDatabase.java +++ b/common/buildcraft/builders/blueprints/BlueprintDatabase.java @@ -166,19 +166,27 @@ public class BlueprintDatabase { for (File blueprintFile : directory.listFiles(filter)) { String fileName = blueprintFile.getName(); - int cutIndex = fileName.lastIndexOf(BuildCraftBuilders.BPT_SEP_CHARACTER); - - String prefix = fileName.substring(0, cutIndex); - String suffix = fileName.substring(cutIndex + 1); - BlueprintId id = new BlueprintId(); - id.name = prefix; - if (suffix.contains(BPT_EXTENSION)) { - id.uniqueId = BlueprintId.toBytes(suffix.replaceAll(BPT_EXTENSION, "")); + int sepIndex = fileName.lastIndexOf(BuildCraftBuilders.BPT_SEP_CHARACTER); + int dotIndex = fileName.lastIndexOf('.'); + + String extension = fileName.substring(dotIndex); + + if (sepIndex > 0) { + String prefix = fileName.substring(0, sepIndex); + String suffix = fileName.substring(sepIndex + 1); + + id.name = prefix; + id.uniqueId = BlueprintId.toBytes(suffix.substring(0, suffix.length() - 4)); + } else { + id.name = fileName.substring(0, dotIndex); + id.uniqueId = new byte[0]; + } + + if (extension.equals(BPT_EXTENSION)) { id.kind = Kind.Blueprint; } else { - id.uniqueId = BlueprintId.toBytes(suffix.replaceAll(TPL_EXTENSION, "")); id.kind = Kind.Template; } diff --git a/common/buildcraft/builders/blueprints/BlueprintId.java b/common/buildcraft/builders/blueprints/BlueprintId.java index 78076a37..fa1294c5 100644 --- a/common/buildcraft/builders/blueprints/BlueprintId.java +++ b/common/buildcraft/builders/blueprints/BlueprintId.java @@ -78,8 +78,12 @@ public final class BlueprintId implements Comparable { public String getCompleteId () { if (completeId == null) { - completeId = name + BuildCraftBuilders.BPT_SEP_CHARACTER + if (uniqueId.length > 0) { + completeId = name + BuildCraftBuilders.BPT_SEP_CHARACTER + toString(uniqueId); + } else { + completeId = name; + } } return completeId;