mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-27 02:47:55 +01:00
Merge pull request #1190 from creeper123123321/master
NPE fixes, warn instead of exception
This commit is contained in:
commit
0886fdabd3
@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -14,6 +15,7 @@ import us.myles.ViaVersion.packets.State;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class Protocol {
|
||||
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
|
||||
@ -104,7 +106,10 @@ public abstract class Protocol {
|
||||
public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
Pair<State, Integer> pair = new Pair<>(state, newPacketID);
|
||||
if (!override && incoming.containsKey(pair)) throw new IllegalArgumentException(pair + " already registered");
|
||||
if (!override && incoming.containsKey(pair)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
||||
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||
}
|
||||
incoming.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
@ -134,7 +139,10 @@ public abstract class Protocol {
|
||||
public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
Pair<State, Integer> pair = new Pair<>(state, oldPacketID);
|
||||
if (!override && outgoing.containsKey(pair)) throw new IllegalArgumentException(pair + " already registered");
|
||||
if (!override && outgoing.containsKey(pair)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
||||
" If override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||
}
|
||||
outgoing.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
public class ChunkSectionType1_8 extends Type<ChunkSection> {
|
||||
|
||||
@ -19,12 +17,10 @@ public class ChunkSectionType1_8 extends Type<ChunkSection> {
|
||||
ChunkSection chunkSection = new ChunkSection();
|
||||
chunkSection.clearPalette();
|
||||
|
||||
byte[] blockData = new byte[ChunkSection.SIZE * 2];
|
||||
buffer.readBytes(blockData);
|
||||
ShortBuffer blockBuf = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||
ByteBuf littleEndianView = buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
for (int i = 0; i < ChunkSection.SIZE; i++) {
|
||||
int mask = blockBuf.get();
|
||||
int mask = littleEndianView.readShort();
|
||||
int type = mask >> 4;
|
||||
int data = mask & 0xF;
|
||||
chunkSection.setBlock(i, type, data);
|
||||
|
@ -29,7 +29,11 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
|
||||
int blockId = storage.get(position).getOriginal();
|
||||
|
||||
int color = (int) tag.get("Base").getValue();
|
||||
Tag base = tag.get("Base");
|
||||
int color = 0;
|
||||
if (base != null) {
|
||||
color = ((Number) tag.get("Base").getValue()).intValue();
|
||||
}
|
||||
// Standing banner
|
||||
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
|
||||
blockId += ((15 - color) * 16);
|
||||
@ -43,8 +47,10 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
if (tag.get("Patterns") instanceof ListTag) {
|
||||
for (Tag pattern : (ListTag) tag.get("Patterns")) {
|
||||
if (pattern instanceof CompoundTag) {
|
||||
IntTag c = ((CompoundTag) pattern).get("Color");
|
||||
c.setValue(15 - c.getValue()); // Invert color id
|
||||
Tag c = ((CompoundTag) pattern).get("Color");
|
||||
if (c instanceof IntTag) {
|
||||
((IntTag)c).setValue(15 - (int) c.getValue()); // Invert color id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,10 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
// RED_BED + FIRST_BED
|
||||
int blockId = storage.get(position).getOriginal() - 972 + 748;
|
||||
|
||||
int color = (int) tag.get("color").getValue();
|
||||
blockId += (color * 16);
|
||||
Tag color = tag.get("color");
|
||||
if (color != null) {
|
||||
blockId += (((Number) color.getValue()).intValue() * 16);
|
||||
}
|
||||
|
||||
return blockId;
|
||||
}
|
||||
|
@ -25,9 +25,12 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
int id = storage.get(position).getOriginal();
|
||||
|
||||
if (id >= SKULL_WALL_START && id <= SKULL_END) {
|
||||
id += (byte) tag.get("SkullType").getValue() * 20;
|
||||
Tag skullType = tag.get("SkullType");
|
||||
if (skullType != null) {
|
||||
id += ((Number) tag.get("SkullType").getValue()).intValue() * 20;
|
||||
}
|
||||
if (tag.contains("Rot")) {
|
||||
id += (byte) tag.get("Rot").getValue();
|
||||
id += ((Number) tag.get("Rot").getValue()).intValue();
|
||||
}
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);
|
||||
|
@ -91,7 +91,7 @@ public class BlockConnectionStorage extends StoredObject {
|
||||
|
||||
public void unloadChunk(int x, int z) {
|
||||
for (int y = 0; y < 256; y += 16) {
|
||||
blockStorage.remove(getChunkSectionIndex(x, y, z));
|
||||
blockStorage.remove(getChunkSectionIndex(x << 4, y, z << 4));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user