Skip to content

Commit 0bf4009

Browse files
committed
Rename to remove specific reference to JNBT
This may be a common error in other NBT libraries as well.
1 parent 6e4c766 commit 0bf4009

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

gui/src/main/java/org/enginehub/linbus/gui/javafx/MainSceneSetup.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public LoadTreeItemTask(Path path, ExecutorService backgroundExecutor, boolean t
256256
protected TreeItem<NbtTreeView.TagEntry> call() throws Exception {
257257
LinReadOptions.Builder options = LinReadOptions.builder();
258258
if (tryingLegacyCompat) {
259-
options.allowJnbtStringEncoding(true);
259+
options.allowNormalUtf8Encoding(true);
260260
}
261261
return NbtTreeView.loadTreeItem(path, options.build());
262262
}
@@ -289,9 +289,15 @@ private static Alert createUtfAlert() {
289289
Alert alert = new Alert(Alert.AlertType.WARNING);
290290
alert.setTitle(LinBusGui.TITLE_BASE + " - Invalid File");
291291
alert.setHeaderText("File contained invalid modified UTF-8");
292-
alert.setContentText("The file you tried to open contained invalid modified UTF-8, " +
293-
"but may be a legacy JNBT file. Would you like to try opening it with JNBT compatibility?\n" +
294-
"Saving the file will convert it to standard NBT format.");
292+
alert.setContentText(
293+
"""
294+
The file you tried to open contained invalid modified UTF-8, \
295+
but may be valid with (non-standard) normal UTF-8.
296+
Would you like to try opening it with that enabled?
297+
298+
Note: Saving the file will convert it to standard NBT format.
299+
"""
300+
);
295301
alert.getButtonTypes().setAll(
296302
ButtonType.YES,
297303
ButtonType.NO

stream/src/main/java/org/enginehub/linbus/stream/LinReadOptions.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,25 @@ public static Builder builder() {
3737
* Builder for {@link LinReadOptions}.
3838
*/
3939
public static final class Builder {
40-
private boolean allowJnbtStringEncoding = false;
40+
private boolean allowNormalUtf8Encoding = false;
4141

4242
private Builder() {
4343
}
4444

4545
/**
46-
* Set whether to allow the string encoding used by JNBT. It is not compliant with the NBT specification and
47-
* uses normal UTF-8 encoding instead of the modified UTF-8 encoding of {@link java.io.DataInput}.
46+
* Set whether to allow normal UTF-8 encoding instead of the modified UTF-8 encoding of
47+
* {@link java.io.DataInput}.
4848
*
4949
* <p>
5050
* Note that this option will force checking the bytes to select the correct encoding, which will be slower.
51+
* It will still accept the modified UTF-8 encoding, but will do its best to disallow mixed encodings.
5152
* </p>
5253
*
53-
* @param allowJnbtStringEncoding whether to allow the string encoding used by JNBT
54+
* @param allowNormalUtf8Encoding whether to allow normal UTF-8 string encoding
5455
* @return this builder
5556
*/
56-
public Builder allowJnbtStringEncoding(boolean allowJnbtStringEncoding) {
57-
this.allowJnbtStringEncoding = allowJnbtStringEncoding;
57+
public Builder allowNormalUtf8Encoding(boolean allowNormalUtf8Encoding) {
58+
this.allowNormalUtf8Encoding = allowNormalUtf8Encoding;
5859
return this;
5960
}
6061

@@ -70,33 +71,34 @@ public LinReadOptions build() {
7071
@Override
7172
public String toString() {
7273
return "LinReadOptions.Builder{" +
73-
"allowJnbtStringEncoding=" + allowJnbtStringEncoding +
74+
"allowNormalUtf8Encoding=" + allowNormalUtf8Encoding +
7475
'}';
7576
}
7677
}
7778

78-
private final boolean allowJnbtStringEncoding;
79+
private final boolean allowNormalUtf8Encoding;
7980

8081
private LinReadOptions(Builder builder) {
81-
this.allowJnbtStringEncoding = builder.allowJnbtStringEncoding;
82+
this.allowNormalUtf8Encoding = builder.allowNormalUtf8Encoding;
8283
}
8384

8485
/**
85-
* {@return whether to allow the string encoding used by JNBT} It is not compliant with the NBT specification and
86-
* uses normal UTF-8 encoding instead of the modified UTF-8 encoding of {@link java.io.DataInput}.
86+
* {@return whether to allow normal UTF-8 encoding instead of the modified UTF-8 encoding of
87+
* {@link java.io.DataInput}}
8788
*
8889
* <p>
8990
* Note that this option will force checking the bytes to select the correct encoding, which will be slower.
91+
* It will still accept the modified UTF-8 encoding, but will do its best to disallow mixed encodings.
9092
* </p>
9193
*/
92-
public boolean allowJnbtStringEncoding() {
93-
return allowJnbtStringEncoding;
94+
public boolean allowNormalUtf8Encoding() {
95+
return allowNormalUtf8Encoding;
9496
}
9597

9698
@Override
9799
public String toString() {
98100
return "LinReadOptions{" +
99-
"allowJnbtStringEncoding=" + allowJnbtStringEncoding +
101+
"allowNormalUtf8Encoding=" + allowNormalUtf8Encoding +
100102
'}';
101103
}
102104
}

stream/src/main/java/org/enginehub/linbus/stream/impl/LinNbtReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ public String decode() throws CharacterCodingException {
248248
public LinNbtReader(DataInput input, LinReadOptions options) {
249249
this.input = input;
250250
this.stateStack = new ArrayDeque<>(List.of(new State.Initial()));
251-
// We only need to check strings if we're allowing JNBT encoding.
252-
this.stringEncoding = options.allowJnbtStringEncoding()
251+
// We only need to check strings if we're allowing normal UTF-8 encoding.
252+
this.stringEncoding = options.allowNormalUtf8Encoding()
253253
? StringEncoding.UNKNOWN : StringEncoding.MODIFIED_UTF_8;
254254
}
255255

stream/src/test/java/org/enginehub/linbus/stream/JnbtCompatibilityIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
public class JnbtCompatibilityIntegrationTest {
4545

46-
private static final LinReadOptions OPTIONS = LinReadOptions.builder().allowJnbtStringEncoding(true).build();
46+
private static final LinReadOptions OPTIONS = LinReadOptions.builder().allowNormalUtf8Encoding(true).build();
4747

4848
private static final String NULL_BYTE_TEST_STRING = "Null: \0";
4949
private static final String TWO_BYTE_TEST_STRING = "2-byte: Ø";
@@ -195,7 +195,7 @@ void doesNotLockInWhenUndetectable(StringEncoding encoding) {
195195
var tokens = ImmutableList.copyOf(
196196
LinBinaryIO.read(
197197
new DataInputStream(new ByteArrayInputStream(bytes)),
198-
LinReadOptions.builder().allowJnbtStringEncoding(true).build()
198+
LinReadOptions.builder().allowNormalUtf8Encoding(true).build()
199199
).asIterator()
200200
);
201201
assertThat(tokens).containsExactly(

0 commit comments

Comments
 (0)