@@ -141,7 +141,7 @@ public static ClipboardFormat findByAlias(String alias) {
141141 //FAWE start - optimize format detection for builtin / known formats
142142
143143 /**
144- * Detect the format of given a file.
144+ * Detect the format of a given file.
145145 *
146146 * @param file the file
147147 * @return the format, otherwise null if one cannot be detected
@@ -157,7 +157,7 @@ public static ClipboardFormat findByFile(File file) {
157157
158158 /* Conditions for known formats
159159 FAST_V3: Compound_Tag("") -> Compound_Tag("Schematic") -> Int_Tag("Version") == 3
160- MINECRAFT_STRUCTURE: Compound_Tag("") -> len (Nbt_List_Tag("size"))
160+ MINECRAFT_STRUCTURE: Compound_Tag("") -> exist (Nbt_List_Tag("size" || "palette" || "blocks" || "entities "))
161161 FAST_V2: Compound_Tag("Schematic") -> Int_Tag("Version") == 2
162162 SPONGE_V1: Compound_Tag("Schematic") -> Int_Tag("Version") == 1
163163 MC_EDIT: Compound_Tag("Schematic") -> exist(Byte_Array_Tag("Blocks") || String_Tag("Materials"))
@@ -175,7 +175,7 @@ public static ClipboardFormat findByFile(File file) {
175175 final String rootName = new String (inputStream .readNBytes (rootNameTagLength ));
176176 if (rootName .isEmpty ()) {
177177 // Only FAST_V3 and MINECRAFT_STRUCTURE use empty named root compound tags
178- // FAST_V3 only contains a single child component - if that's not present only MINECRAFT_STRUCTURE is possible
178+ // FAST_V3 only contains a single child component - if that's not present, only MINECRAFT_STRUCTURE is possible
179179 do {
180180 byte type = inputStream .readByte ();
181181 if (type == NBTConstants .TYPE_END ) {
@@ -187,7 +187,8 @@ public static ClipboardFormat findByFile(File file) {
187187 break ;
188188 }
189189 // search for almost all known compound children for a fast return path (lowercase is specific enough for now)
190- if (type == NBTConstants .TYPE_LIST && (name .equals ("size" ) || name .equals ("palette" ) || name .equals ("blocks" ) || name .equals ("entities" ))) {
190+ if (type == NBTConstants .TYPE_LIST &&
191+ (name .equals ("size" ) || name .equals ("palette" ) || name .equals ("blocks" ) || name .equals ("entities" ))) {
191192 return BuiltInClipboardFormat .MINECRAFT_STRUCTURE ;
192193 }
193194 nbtInputStream .readTagPayloadLazy (type , 0 ); // skip unwanted tags and continue search
@@ -200,7 +201,8 @@ public static ClipboardFormat findByFile(File file) {
200201 return findByFileInExternalFormats (file );
201202 }
202203 String name = nbtInputStream .readNamedTagName (type );
203- if ((type == NBTConstants .TYPE_BYTE_ARRAY && name .equals ("Blocks" )) || (type == NBTConstants .TYPE_STRING && name .equals ("Materials" ))) {
204+ if ((type == NBTConstants .TYPE_BYTE_ARRAY && name .equals ("Blocks" )) ||
205+ (type == NBTConstants .TYPE_STRING && name .equals ("Materials" ))) {
204206 return BuiltInClipboardFormat .MCEDIT_SCHEMATIC ;
205207 }
206208 if (type == NBTConstants .TYPE_INT && name .equals ("Version" )) {
@@ -227,6 +229,12 @@ public static ClipboardFormat findByFile(File file) {
227229 return findByFileInExternalFormats (file );
228230 }
229231
232+ /**
233+ * Detect the clipboard format for a specified file while skipping optimized builtin formats
234+ *
235+ * @param file the file
236+ * @return the format or {@code null}
237+ */
230238 private static ClipboardFormat findByFileInExternalFormats (File file ) {
231239 if (registeredFormats .size () == FAST_SEARCH_BUILTIN_FORMATS .size ()) {
232240 return null ;
0 commit comments