Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeMortal committed Apr 5, 2020
2 parents 066244e + 0ae6d9b commit 925f472
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void decode() {
this.type = (int) this.getUnsignedVarInt();
this.id = this.getUUID();

this.input = this.getArray(BinaryStream::getSlot);
this.output = this.getArray(BinaryStream::getSlot);
this.input = this.getArray(Item.class, BinaryStream::getSlot);
this.output = this.getArray(Item.class, BinaryStream::getSlot);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/network/protocol/TextPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void decode() {
case TYPE_POPUP:
case TYPE_JUKEBOX_POPUP:
this.message = this.getString();
this.parameters = this.getArray(BinaryStream::getString);
this.parameters = this.getArray(String.class, BinaryStream::getString);
}
this.xboxUserId = this.getString();
this.platformChatId = this.getString();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/cn/nukkit/utils/BinaryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.nbt.tag.StringTag;
import cn.nukkit.network.protocol.types.EntityLink;
import com.google.common.collect.Iterables;
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream;

import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.*;
Expand Down Expand Up @@ -669,13 +671,13 @@ public EntityLink getEntityLink() {
}

@SuppressWarnings("unchecked")
public <T> T[] getArray(Function<BinaryStream, T> function) {
ArrayDeque<T> array = new ArrayDeque<>();
public <T> T[] getArray(Class<T> clazz, Function<BinaryStream, T> function) {
ArrayDeque<T> deque = new ArrayDeque<>();
int count = (int) getUnsignedVarInt();
for (int i = 0; i < count; i++) {
array.add(function.apply(this));
deque.add(function.apply(this));
}
return (T[]) array.toArray();
return deque.toArray((T[]) Array.newInstance(clazz, 0));
}

public boolean feof() {
Expand Down

0 comments on commit 925f472

Please sign in to comment.