tangled
alpha
login
or
join now
codexarchonic.nekoweb.org
/
ProjectInfinity
0
fork
atom
Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
0
fork
atom
overview
issues
6
pulls
pipelines
safer string reader test
authored by
Lera
and committed by
cassian.cc
4 months ago
46b11422
7e67b824
+63
-2
3 changed files
expand all
collapse all
unified
split
common
src
main
java
net
lerariemann
infinity
util
core
CommonIO.java
SaferStringReader.java
resources
config
easter
classic.json
+1
-1
common/src/main/java/net/lerariemann/infinity/util/core/CommonIO.java
···
72
72
try {
73
73
if (file.exists()) {
74
74
content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
75
75
-
NbtCompound c = StringNbtReader.parse(content);
75
75
+
NbtCompound c = SaferStringReader.parse(content);
76
76
c.remove("infinity_version");
77
77
return c;
78
78
}
+41
common/src/main/java/net/lerariemann/infinity/util/core/SaferStringReader.java
···
1
1
+
package net.lerariemann.infinity.util.core;
2
2
+
3
3
+
import com.mojang.brigadier.StringReader;
4
4
+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5
5
+
import net.minecraft.nbt.NbtCompound;
6
6
+
import net.minecraft.nbt.StringNbtReader;
7
7
+
8
8
+
public class SaferStringReader extends StringReader {
9
9
+
public SaferStringReader(String string) {
10
10
+
super(string);
11
11
+
}
12
12
+
13
13
+
public static NbtCompound parse(String string) throws CommandSyntaxException {
14
14
+
SaferStringReader readerInner = new SaferStringReader(string);
15
15
+
StringNbtReader reader = new StringNbtReader(readerInner);
16
16
+
17
17
+
NbtCompound nbtCompound = reader.parseCompound();
18
18
+
readerInner.skipWhitespace();
19
19
+
if (readerInner.canRead()) {
20
20
+
throw StringNbtReader.TRAILING.createWithContext(readerInner);
21
21
+
} else {
22
22
+
return nbtCompound;
23
23
+
}
24
24
+
}
25
25
+
26
26
+
@Override
27
27
+
public String readStringUntil(char terminator) throws CommandSyntaxException {
28
28
+
StringBuilder result = new StringBuilder();
29
29
+
30
30
+
while(this.canRead()) {
31
31
+
char c = this.read();
32
32
+
if (c == terminator) {
33
33
+
return result.toString();
34
34
+
}
35
35
+
36
36
+
result.append(c);
37
37
+
}
38
38
+
39
39
+
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedEndOfQuote().createWithContext(this);
40
40
+
}
41
41
+
}
+21
-1
common/src/main/resources/config/easter/classic.json
···
1
1
{
2
2
-
"infinity_version": 2004002,
2
2
+
"infinity_version": 2004005,
3
3
"aliases": "origin",
4
4
"options": {
5
5
"portal_color": 65535,
···
51
51
"surface_rule": {
52
52
"type": "minecraft:sequence",
53
53
"sequence": [
54
54
+
{
55
55
+
"type": "minecraft:condition",
56
56
+
"if_true": {
57
57
+
"type": "minecraft:not",
58
58
+
"invert": {
59
59
+
"type": "y_above",
60
60
+
"anchor": {
61
61
+
"absolute": 1
62
62
+
},
63
63
+
"surface_depth_multiplier": 0,
64
64
+
"add_stone_depth": false
65
65
+
}
66
66
+
},
67
67
+
"then_run": {
68
68
+
"type": "minecraft:block",
69
69
+
"result_state": {
70
70
+
"Name": "minecraft:lava"
71
71
+
}
72
72
+
}
73
73
+
},
54
74
{
55
75
"type": "minecraft:condition",
56
76
"if_true": {