Skip to content

Commit 9d067ad

Browse files
committed
22w19a
1 parent 2f1f2ac commit 9d067ad

34 files changed

Lines changed: 364 additions & 88 deletions

java/src/me/dustin/chatbot/entity/player/ClientPlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.dustin.chatbot.entity.player;
22

33
import me.dustin.chatbot.ChatBot;
4+
import me.dustin.chatbot.block.BlockPos;
5+
import me.dustin.chatbot.block.BlockState;
46
import me.dustin.chatbot.helper.KeyHelper;
57
import me.dustin.chatbot.helper.StopWatch;
68
import me.dustin.chatbot.network.ClientConnection;

java/src/me/dustin/chatbot/helper/KeyHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public static SaltAndSig generateSaltAndSig(Instant instant, String message) {
6565
}
6666

6767
public static KeyContainer getKeyContainer(KeyPairResponse keyPairResponse) {
68+
if (keyPairResponse == null)
69+
return null;
6870
return new KeyContainer(getPrivateKey(keyPairResponse.getPrivateKey()), new PublicKeyContainer(Instant.parse(keyPairResponse.getExpiresAt()), keyPairResponse.getPublicKey(), keyPairResponse.getPublicKeySignature()), Instant.parse(keyPairResponse.getRefreshedAfter()));
6971
}
7072

java/src/me/dustin/chatbot/nbt/NbtByte.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonPrimitive;
6+
37
import java.io.DataInput;
48
import java.io.DataOutput;
59
import java.io.IOException;
@@ -24,6 +28,11 @@ public Object getValue() {
2428
return b;
2529
}
2630

31+
@Override
32+
public JsonElement toJson() {
33+
return new JsonPrimitive(b);
34+
}
35+
2736
@Override
2837
public String toString() {
2938
return "NbtByte{" +

java/src/me/dustin/chatbot/nbt/NbtByteArray.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
5+
36
import java.io.DataInput;
47
import java.io.DataOutput;
58
import java.io.IOException;
@@ -18,6 +21,15 @@ public Object getValue() {
1821
return bs;
1922
}
2023

24+
@Override
25+
public JsonElement toJson() {
26+
JsonArray jsonArray = new JsonArray();
27+
for (byte b : bs) {
28+
jsonArray.add(new NbtByte(b).toJson());
29+
}
30+
return jsonArray;
31+
}
32+
2133
public static NbtByteArray read(DataInput input, int depth) throws IOException {
2234
int size = input.readInt();
2335
byte[] bs = new byte[size];

java/src/me/dustin/chatbot/nbt/NbtCompound.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonElement;
6+
import com.google.gson.JsonObject;
7+
38
import java.io.DataInput;
49
import java.io.DataOutput;
510
import java.io.IOException;
@@ -52,17 +57,34 @@ public void put(String name, NbtElement element) {
5257

5358
@Override
5459
public String toString() {
55-
return "NbtCompound{" +
56-
"elements=" + elements +
57-
'}';
60+
Gson prettyGson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
61+
return "NbtCompound: " + prettyGson.toJson(toJson());
5862
}
5963

6064
public Map<String, NbtElement> getElements() {
6165
return elements;
6266
}
6367

68+
public boolean has(String element) {
69+
return getElements().containsKey(element);
70+
}
71+
6472
@Override
6573
public Object getValue() {
6674
return elements;
6775
}
76+
77+
public NbtElement get(String element) {
78+
return getElements().get(element);
79+
}
80+
81+
@Override
82+
public JsonElement toJson() {
83+
JsonObject o = new JsonObject();
84+
for (String s1 : elements.keySet()) {
85+
NbtElement nbtElement = elements.get(s1);
86+
o.add(s1, nbtElement.toJson());
87+
}
88+
return o;
89+
}
6890
}

java/src/me/dustin/chatbot/nbt/NbtDouble.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonPrimitive;
5+
36
import java.io.DataInput;
47
import java.io.DataOutput;
58
import java.io.IOException;
@@ -16,6 +19,11 @@ public Object getValue() {
1619
return d;
1720
}
1821

22+
@Override
23+
public JsonElement toJson() {
24+
return new JsonPrimitive(d);
25+
}
26+
1927
public static NbtDouble read(DataInput input, int depth) throws IOException {
2028
return new NbtDouble(input.readDouble());
2129
}

java/src/me/dustin/chatbot/nbt/NbtElement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
35
import java.io.DataInput;
46
import java.io.DataOutput;
57
import java.io.IOException;
@@ -100,8 +102,5 @@ public default int getType() {
100102

101103
void write(DataOutput dataOutput) throws IOException;
102104
Object getValue();
103-
104-
public default String asString() {
105-
return toString();
106-
}
105+
JsonElement toJson();
107106
}

java/src/me/dustin/chatbot/nbt/NbtEnd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
35
import java.io.DataInput;
46
import java.io.DataOutput;
57
import java.io.IOException;
@@ -21,4 +23,9 @@ public void write(DataOutput dataOutput) throws IOException {
2123
public Object getValue() {
2224
return null;
2325
}
26+
27+
@Override
28+
public JsonElement toJson() {
29+
return null;
30+
}
2431
}

java/src/me/dustin/chatbot/nbt/NbtFloat.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonPrimitive;
5+
36
import java.io.DataInput;
47
import java.io.DataOutput;
58
import java.io.IOException;
@@ -16,6 +19,11 @@ public Object getValue() {
1619
return f;
1720
}
1821

22+
@Override
23+
public JsonElement toJson() {
24+
return new JsonPrimitive(f);
25+
}
26+
1927
public static NbtFloat read(DataInput input, int depth) throws IOException {
2028
return new NbtFloat(input.readFloat());
2129
}

java/src/me/dustin/chatbot/nbt/NbtInt.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.dustin.chatbot.nbt;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonPrimitive;
5+
36
import java.io.DataInput;
47
import java.io.DataOutput;
58
import java.io.IOException;
@@ -16,6 +19,11 @@ public Object getValue() {
1619
return i;
1720
}
1821

22+
@Override
23+
public JsonElement toJson() {
24+
return new JsonPrimitive(i);
25+
}
26+
1927
public static NbtInt read(DataInput input, int depth) throws IOException {
2028
return new NbtInt(input.readInt());
2129
}

0 commit comments

Comments
 (0)