diff --git a/README.md b/README.md
index a47dcfe0d..11cd7a931 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# ViaVersion 1.5.0 - Spigot, Sponge, BungeeCord
+# ViaVersion 1.5.2 - Spigot, Sponge, BungeeCord
[![Build Status](https://travis-ci.org/MylesIsCool/ViaVersion.svg?branch=master)](https://travis-ci.org/MylesIsCool/ViaVersion)
[![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord)
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 2020e0a56..69802552a 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java
index 70aa1e133..776003017 100644
--- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java
+++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java
@@ -14,8 +14,6 @@ public class HandItemCache extends BukkitRunnable {
private static Map handCache = new ConcurrentHashMap<>();
public static Item getHandItem(UUID player) {
- if (!handCache.containsKey(player))
- return null;
return handCache.get(player);
}
diff --git a/bungee/pom.xml b/bungee/pom.xml
index eb0a46294..1ef5da6d3 100644
--- a/bungee/pom.xml
+++ b/bungee/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java
index c1e0cebd1..e3aa9defe 100644
--- a/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java
+++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/service/ProtocolDetectorService.java
@@ -27,16 +27,19 @@ public class ProtocolDetectorService implements Runnable {
public static Integer getProtocolId(String serverName) {
// Step 1. Check Config
Map servers = ((BungeeConfigAPI) Via.getConfig()).getBungeeServerProtocols();
- if (servers.containsKey(serverName)) {
- return servers.get(serverName);
+ Integer protocol = servers.get(serverName);
+ if (protocol != null) {
+ return protocol;
}
// Step 2. Check Detected
- if (detectedProtocolIds.containsKey(serverName)) {
- return detectedProtocolIds.get(serverName);
+ Integer detectedProtocol = detectedProtocolIds.get(serverName);
+ if (detectedProtocol != null) {
+ return detectedProtocol;
}
// Step 3. Use Default
- if (servers.containsKey("default")) {
- return servers.get("default");
+ Integer defaultProtocol = servers.get("default");
+ if (defaultProtocol != null) {
+ return defaultProtocol;
}
// Step 4: Use bungee lowest supported... *cries*
return BungeeVersionProvider.getLowestSupportedVersion();
@@ -58,10 +61,9 @@ public class ProtocolDetectorService implements Runnable {
detectedProtocolIds.put(key, serverPing.getVersion().getProtocol());
if (((BungeeConfigAPI) Via.getConfig()).isBungeePingSave()) {
Map servers = ((BungeeConfigAPI) Via.getConfig()).getBungeeServerProtocols();
- if (servers.containsKey(key)) {
- if (servers.get(key) == serverPing.getVersion().getProtocol()) {
- return;
- }
+ Integer protocol = servers.get(key);
+ if (protocol != null && protocol == serverPing.getVersion().getProtocol()) {
+ return;
}
// Ensure we're the only ones writing to the config
synchronized (Via.getPlatform().getConfigurationProvider()) {
diff --git a/common/pom.xml b/common/pom.xml
index 6ba2588b4..b54d3349a 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java
index 2268a9e15..f5fc26223 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java
@@ -330,7 +330,7 @@ public class PacketWrapper {
resetReader();
// Apply other protocols
- apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols);
+ apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols);
// Send
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);
diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13_2.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13_2.java
new file mode 100644
index 000000000..a9646a8d0
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_13_2.java
@@ -0,0 +1,37 @@
+package us.myles.ViaVersion.api.minecraft.metadata.types;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
+
+@RequiredArgsConstructor
+@Getter
+public enum MetaType1_13_2 implements MetaType {
+ Byte(0, Type.BYTE),
+ VarInt(1, Type.VAR_INT),
+ Float(2, Type.FLOAT),
+ String(3, Type.STRING),
+ Chat(4, Type.STRING),
+ OptChat(5, Type.OPTIONAL_CHAT),
+ Slot(6, Type.FLAT_VAR_INT_ITEM),
+ Boolean(7, Type.BOOLEAN),
+ Vector3F(8, Type.ROTATION),
+ Position(9, Type.POSITION),
+ OptPosition(10, Type.OPTIONAL_POSITION),
+ Direction(11, Type.VAR_INT),
+ OptUUID(12, Type.OPTIONAL_UUID),
+ BlockID(13, Type.VAR_INT),
+ NBTTag(14, Type.NBT),
+ PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE),
+ Discontinued(99, null);
+
+ private final int typeID;
+ private final Type type;
+
+ public static MetaType1_13_2 byId(int id) {
+ return values()[id];
+ }
+
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java b/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java
index 6911a5217..9aa602423 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java
@@ -18,15 +18,14 @@ public class ViaProviders {
}
public void use(Class provider, T value) {
- if (lonelyProviders.contains(provider)) {
- lonelyProviders.remove(provider);
- }
+ lonelyProviders.remove(provider);
providers.put(provider, value);
}
public T get(Class provider) {
- if (providers.containsKey(provider)) {
- return (T) providers.get(provider);
+ Provider rawProvider = providers.get(provider);
+ if (rawProvider != null) {
+ return (T) rawProvider;
} else {
if (lonelyProviders.contains(provider)) {
throw new IllegalStateException("There was no provider for " + provider + ", one is required!");
diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java
index 53692398b..1b79569bf 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java
@@ -137,10 +137,8 @@ public abstract class Protocol {
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
Pair statePacket = new Pair<>(state, packetWrapper.getId());
Map, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
- ProtocolPacket protocolPacket;
- if (packetMap.containsKey(statePacket)) {
- protocolPacket = packetMap.get(statePacket);
- } else {
+ ProtocolPacket protocolPacket = packetMap.get(statePacket);
+ if (protocolPacket == null) {
return;
}
// write packet id
diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java
index a36e68c4c..76de968b7 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java
@@ -13,6 +13,7 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.Protocol1_12_1TO1_12;
import us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2TO1_12_1;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2TO1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
@@ -57,6 +58,7 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId());
registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId());
+ registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
}
/**
@@ -165,13 +167,14 @@ public class ProtocolRegistry {
if (current.size() > 50) return null; // Fail safe, protocol too complicated.
// First check if there is any protocols for this
- if (!registryMap.containsKey(clientVersion)) {
+ Map inputMap = registryMap.get(clientVersion);
+ if (inputMap == null) {
return null; // Not supported
}
// Next check there isn't an obvious path
- Map inputMap = registryMap.get(clientVersion);
- if (inputMap.containsKey(serverVersion)) {
- current.add(new Pair<>(serverVersion, inputMap.get(serverVersion)));
+ Protocol protocol = inputMap.get(serverVersion);
+ if (protocol != null) {
+ current.add(new Pair<>(serverVersion, protocol));
return current; // Easy solution
}
// There might be a more advanced solution... So we'll see if any of the others can get us there
@@ -211,8 +214,9 @@ public class ProtocolRegistry {
public static List> getProtocolPath(int clientVersion, int serverVersion) {
Pair protocolKey = new Pair<>(clientVersion, serverVersion);
// Check cache
- if (pathCache.containsKey(protocolKey)) {
- return pathCache.get(protocolKey);
+ List> protocolList = pathCache.get(protocolKey);
+ if (protocolList != null) {
+ return protocolList;
}
// Generate path
List> outputPath = getProtocolPath(new ArrayList>(), clientVersion, serverVersion);
diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java
index 597aaee79..e35faf03b 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java
@@ -34,6 +34,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_12_2;
public static final ProtocolVersion v1_13;
public static final ProtocolVersion v1_13_1;
+ public static final ProtocolVersion v1_13_2;
public static final ProtocolVersion unknown;
private final int id;
@@ -64,6 +65,7 @@ public class ProtocolVersion {
register(v1_12_2 = new ProtocolVersion(340, "1.12.2"));
register(v1_13 = new ProtocolVersion(393, "1.13"));
register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
+ register(v1_13_2 = new ProtocolVersion(402, "1.13.2"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}
@@ -77,8 +79,9 @@ public class ProtocolVersion {
}
public static ProtocolVersion getProtocol(int id) {
- if (versions.containsKey(id)) {
- return versions.get(id);
+ ProtocolVersion protocolVersion = versions.get(id);
+ if (protocolVersion != null) {
+ return protocolVersion;
} else {
return new ProtocolVersion(id, "Unknown (" + id + ")");
}
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java
index 3202b27d0..3e1db7013 100644
--- a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java
@@ -76,8 +76,11 @@ public abstract class Type implements ByteBufReader, ByteBufWriter {
/* 1.13 Flat Item (no data) */
public static final Type- FLAT_ITEM = new FlatItemType();
+ public static final Type
- FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
public static final Type
- FLAT_ITEM_ARRAY = new FlatItemArrayType();
+ public static final Type
- FLAT_VAR_INT_ITEM_ARRAY = new FlatVarIntItemArrayType();
public static final Type
- FLAT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_ITEM);
+ public static final Type
- FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM);
/* Actual Class */
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemArrayType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemArrayType.java
new file mode 100644
index 000000000..6316b4c1a
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemArrayType.java
@@ -0,0 +1,30 @@
+package us.myles.ViaVersion.api.type.types.minecraft;
+
+import io.netty.buffer.ByteBuf;
+import us.myles.ViaVersion.api.minecraft.item.Item;
+import us.myles.ViaVersion.api.type.Type;
+
+public class FlatVarIntItemArrayType extends BaseItemArrayType {
+
+ public FlatVarIntItemArrayType() {
+ super("Flat Item Array");
+ }
+
+ @Override
+ public Item[] read(ByteBuf buffer) throws Exception {
+ int amount = Type.SHORT.read(buffer);
+ Item[] array = new Item[amount];
+ for (int i = 0; i < amount; i++) {
+ array[i] = Type.FLAT_VAR_INT_ITEM.read(buffer);
+ }
+ return array;
+ }
+
+ @Override
+ public void write(ByteBuf buffer, Item[] object) throws Exception {
+ Type.SHORT.write(buffer, (short) object.length);
+ for (Item o : object) {
+ Type.FLAT_VAR_INT_ITEM.write(buffer, o);
+ }
+ }
+}
\ No newline at end of file
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemType.java
new file mode 100644
index 000000000..55390d0dd
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/FlatVarIntItemType.java
@@ -0,0 +1,37 @@
+package us.myles.ViaVersion.api.type.types.minecraft;
+
+import io.netty.buffer.ByteBuf;
+import us.myles.ViaVersion.api.minecraft.item.Item;
+import us.myles.ViaVersion.api.type.Type;
+
+public class FlatVarIntItemType extends BaseItemType {
+ public FlatVarIntItemType() {
+ super("FlatVarIntItem");
+ }
+
+ @Override
+ public Item read(ByteBuf buffer) throws Exception {
+ boolean present = buffer.readBoolean();
+ if (!present) {
+ return null;
+ } else {
+ Item item = new Item();
+ item.setId(Type.VAR_INT.read(buffer).shortValue()); //TODO Maybe we should consider changing id field type to int
+ item.setAmount(buffer.readByte());
+ item.setTag(Type.NBT.read(buffer));
+ return item;
+ }
+ }
+
+ @Override
+ public void write(ByteBuf buffer, Item object) throws Exception {
+ if (object == null) {
+ buffer.writeBoolean(false);
+ } else {
+ buffer.writeBoolean(true);
+ Type.VAR_INT.write(buffer, (int) object.getId());
+ buffer.writeByte(object.getAmount());
+ Type.NBT.write(buffer, object.getTag());
+ }
+ }
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java
new file mode 100644
index 000000000..608547c0f
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Metadata1_13_2Type.java
@@ -0,0 +1,29 @@
+package us.myles.ViaVersion.api.type.types.version;
+
+import io.netty.buffer.ByteBuf;
+import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
+import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
+import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
+
+public class Metadata1_13_2Type extends MetaTypeTemplate {
+ @Override
+ public Metadata read(ByteBuf buffer) throws Exception {
+ short index = buffer.readUnsignedByte();
+
+ if (index == 0xff) return null; //End of metadata
+ MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte());
+
+ return new Metadata(index, type, type.getType().read(buffer));
+ }
+
+ @Override
+ public void write(ByteBuf buffer, Metadata object) throws Exception {
+ if (object == null) {
+ buffer.writeByte(255);
+ } else {
+ buffer.writeByte(object.getId());
+ buffer.writeByte(object.getMetaType().getTypeID());
+ object.getMetaType().getType().write(buffer, object.getValue());
+ }
+ }
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/MetadataList1_13_2Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/MetadataList1_13_2Type.java
new file mode 100644
index 000000000..9f38c0936
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/MetadataList1_13_2Type.java
@@ -0,0 +1,32 @@
+package us.myles.ViaVersion.api.type.types.version;
+
+import io.netty.buffer.ByteBuf;
+import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
+import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MetadataList1_13_2Type extends MetaListTypeTemplate {
+ @Override
+ public List read(ByteBuf buffer) throws Exception {
+ List list = new ArrayList<>();
+ Metadata meta;
+ do {
+ meta = Types1_13_2.METADATA.read(buffer);
+ if (meta != null)
+ list.add(meta);
+ } while (meta != null);
+
+ return list;
+ }
+
+ @Override
+ public void write(ByteBuf buffer, List object) throws Exception {
+ for (Metadata m : object)
+ Types1_13_2.METADATA.write(buffer, m);
+
+ // Write end of list
+ Types1_13_2.METADATA.write(buffer, null);
+ }
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java
new file mode 100644
index 000000000..0f3a40173
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13_2.java
@@ -0,0 +1,18 @@
+package us.myles.ViaVersion.api.type.types.version;
+
+import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
+import us.myles.ViaVersion.api.type.Type;
+
+import java.util.List;
+
+public class Types1_13_2 {
+ /**
+ * Metadata list type for 1.13
+ */
+ public static final Type
> METADATA_LIST = new MetadataList1_13_2Type();
+
+ /**
+ * Metadata type for 1.13
+ */
+ public static final Type METADATA = new Metadata1_13_2Type();
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/BlockEntityRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/BlockEntityRewriter.java
index 730358fb9..fa7b490de 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/BlockEntityRewriter.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/BlockEntityRewriter.java
@@ -42,8 +42,10 @@ public class BlockEntityRewriter {
}
public static String toNewIdentifier(String oldId) {
- if (oldToNewNames.containsKey(oldId))
- return oldToNewNames.get(oldId);
+ String newName = oldToNewNames.get(oldId);
+ if (newName != null) {
+ return newName;
+ }
return oldId;
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/EntityIdRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/EntityIdRewriter.java
index a840c182b..94051d977 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/EntityIdRewriter.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/EntityIdRewriter.java
@@ -90,8 +90,9 @@ public class EntityIdRewriter {
public static void toClient(CompoundTag tag) {
if (tag.get("id") instanceof StringTag) {
StringTag id = tag.get("id");
- if (oldToNewNames.containsKey(id.getValue())) {
- id.setValue(oldToNewNames.get(id.getValue()));
+ String newName = oldToNewNames.get(id.getValue());
+ if (newName != null) {
+ id.setValue(newName);
}
}
}
@@ -117,8 +118,9 @@ public class EntityIdRewriter {
CompoundTag entityTag = item.getTag().get("EntityTag");
if (entityTag.get("id") instanceof StringTag) {
StringTag id = entityTag.get("id");
- if (oldToNewNames.inverse().containsKey(id.getValue())) {
- id.setValue(oldToNewNames.inverse().get(id.getValue()));
+ String newName = oldToNewNames.inverse().get(id.getValue());
+ if (newName != null) {
+ id.setValue(newName);
}
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java
index 328be0ec6..f0864562b 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/storage/EntityTracker.java
@@ -33,9 +33,7 @@ public class EntityTracker extends StoredObject {
}
public Optional get(int id) {
- if (!has(id))
- return Optional.absent();
- return Optional.of(clientEntityTypes.get(id));
+ return Optional.fromNullable(clientEntityTypes.get(id));
}
public void addHologram(int entId) {
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java
index 1464d0468..015831329 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/storage/EntityTracker.java
@@ -28,9 +28,7 @@ public class EntityTracker extends StoredObject {
}
public Optional get(int id) {
- if (!has(id))
- return Optional.absent();
- return Optional.of(clientEntityTypes.get(id));
+ return Optional.fromNullable(clientEntityTypes.get(id));
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java
new file mode 100644
index 000000000..0bc2d5534
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java
@@ -0,0 +1,82 @@
+package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1;
+
+import us.myles.ViaVersion.api.PacketWrapper;
+import us.myles.ViaVersion.api.data.UserConnection;
+import us.myles.ViaVersion.api.minecraft.item.Item;
+import us.myles.ViaVersion.api.protocol.Protocol;
+import us.myles.ViaVersion.api.remapper.PacketHandler;
+import us.myles.ViaVersion.api.remapper.PacketRemapper;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.packets.State;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.EntityPackets;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.InventoryPackets;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.WorldPackets;
+import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types.Particle1_13_2Type;
+
+public class Protocol1_13_2To1_13_1 extends Protocol {
+ public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type();
+
+ @Override
+ protected void registerPackets() {
+ InventoryPackets.register(this);
+ WorldPackets.register(this);
+ EntityPackets.register(this);
+
+ //Edit Book
+ registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM);
+ map(Type.BOOLEAN);
+ }
+ });
+
+ // Advancements
+ registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ wrapper.passthrough(Type.BOOLEAN); // Reset/clear
+ int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
+
+ for (int i = 0; i < size; i++) {
+ wrapper.passthrough(Type.STRING); // Identifier
+
+ // Parent
+ if (wrapper.passthrough(Type.BOOLEAN))
+ wrapper.passthrough(Type.STRING);
+
+ // Display data
+ if (wrapper.passthrough(Type.BOOLEAN)) {
+ wrapper.passthrough(Type.STRING); // Title
+ wrapper.passthrough(Type.STRING); // Description
+ Item icon = wrapper.read(Type.FLAT_ITEM);
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, icon);
+ wrapper.passthrough(Type.VAR_INT); // Frame type
+ int flags = wrapper.passthrough(Type.INT); // Flags
+ if ((flags & 1) != 0)
+ wrapper.passthrough(Type.STRING); // Background texture
+ wrapper.passthrough(Type.FLOAT); // X
+ wrapper.passthrough(Type.FLOAT); // Y
+ }
+
+ wrapper.passthrough(Type.STRING_ARRAY); // Criteria
+
+ int arrayLength = wrapper.passthrough(Type.VAR_INT);
+ for (int array = 0; array < arrayLength; array++) {
+ wrapper.passthrough(Type.STRING_ARRAY); // String array
+ }
+ }
+ }
+ });
+ }
+ });
+ }
+
+ @Override
+ public void init(UserConnection userConnection) {
+
+ }
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java
new file mode 100644
index 000000000..5076c268f
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java
@@ -0,0 +1,97 @@
+package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
+
+import us.myles.ViaVersion.api.PacketWrapper;
+import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
+import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
+import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
+import us.myles.ViaVersion.api.protocol.Protocol;
+import us.myles.ViaVersion.api.remapper.PacketHandler;
+import us.myles.ViaVersion.api.remapper.PacketRemapper;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.api.type.types.version.Types1_13;
+import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
+import us.myles.ViaVersion.packets.State;
+
+public class EntityPackets {
+
+ public static void register(Protocol protocol) {
+ // Spawn mob packet
+ protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Type.UUID); // 1 - Entity UUID
+ map(Type.VAR_INT); // 2 - Entity Type
+ map(Type.DOUBLE); // 3 - X
+ map(Type.DOUBLE); // 4 - Y
+ map(Type.DOUBLE); // 5 - Z
+ map(Type.BYTE); // 6 - Yaw
+ map(Type.BYTE); // 7 - Pitch
+ map(Type.BYTE); // 8 - Head Pitch
+ map(Type.SHORT); // 9 - Velocity X
+ map(Type.SHORT); // 10 - Velocity Y
+ map(Type.SHORT); // 11 - Velocity Z
+ map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
+ if (metadata.getMetaType() == MetaType1_13.Slot) {
+ metadata.setMetaType(MetaType1_13_2.Slot);
+ }
+ }
+ }
+ });
+ }
+ });
+
+ // Spawn player packet
+ protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Type.UUID); // 1 - Player UUID
+ map(Type.DOUBLE); // 2 - X
+ map(Type.DOUBLE); // 3 - Y
+ map(Type.DOUBLE); // 4 - Z
+ map(Type.BYTE); // 5 - Yaw
+ map(Type.BYTE); // 6 - Pitch
+ map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
+ if (metadata.getMetaType() == MetaType1_13.Slot) {
+ metadata.setMetaType(MetaType1_13_2.Slot);
+ }
+ }
+ }
+ });
+ }
+ });
+
+
+ // Metadata packet
+ protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
+ if (metadata.getMetaType() == MetaType1_13.Slot) {
+ metadata.setMetaType(MetaType1_13_2.Slot);
+ }
+ }
+ }
+ });
+ }
+ });
+ }
+
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java
new file mode 100644
index 000000000..faa866127
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java
@@ -0,0 +1,151 @@
+package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
+
+import us.myles.ViaVersion.api.PacketWrapper;
+import us.myles.ViaVersion.api.protocol.Protocol;
+import us.myles.ViaVersion.api.remapper.PacketHandler;
+import us.myles.ViaVersion.api.remapper.PacketRemapper;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.packets.State;
+
+public class InventoryPackets {
+
+ public static void register(Protocol protocol) {
+
+ /*
+ Outgoing packets
+ */
+
+ // Set slot packet
+ protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.BYTE); // 0 - Window ID
+ map(Type.SHORT); // 1 - Slot ID
+ map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
+ }
+ });
+
+ // Window items packet
+ protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.UNSIGNED_BYTE); // 0 - Window ID
+ map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
+ }
+ });
+
+ // Plugin message
+ protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.STRING); // Channel
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ String channel = wrapper.get(Type.STRING, 0);
+ if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
+ wrapper.passthrough(Type.INT); // Passthrough Window ID
+
+ int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
+ for (int i = 0; i < size; i++) {
+ // Input Item
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ // Output Item
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+
+ boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
+ if (secondItem) {
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ }
+
+ wrapper.passthrough(Type.BOOLEAN); // Trade disabled
+ wrapper.passthrough(Type.INT); // Number of tools uses
+ wrapper.passthrough(Type.INT); // Maximum number of trade uses
+ }
+ }
+ }
+ });
+ }
+ });
+
+ // Entity Equipment Packet
+ protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Type.VAR_INT); // 1 - Slot ID
+ map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item
+ }
+ });
+
+ // Declare Recipes
+ protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ int recipesNo = wrapper.passthrough(Type.VAR_INT);
+ for (int i = 0; i < recipesNo; i++) {
+ wrapper.passthrough(Type.STRING); // Id
+ String type = wrapper.passthrough(Type.STRING);
+ if (type.equals("crafting_shapeless")) {
+ wrapper.passthrough(Type.STRING); // Group
+ int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
+ for (int i1 = 0; i1 < ingredientsNo; i1++) {
+ wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
+ }
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ } else if (type.equals("crafting_shaped")) {
+ int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
+ wrapper.passthrough(Type.STRING); // Group
+ for (int i1 = 0; i1 < ingredientsNo; i1++) {
+ wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
+ }
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ } else if (type.equals("smelting")) {
+ wrapper.passthrough(Type.STRING); // Group
+ // Ingredient start
+ wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
+ // Ingredient end
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ wrapper.passthrough(Type.FLOAT); // EXP
+ wrapper.passthrough(Type.VAR_INT); // Cooking time
+ }
+ }
+ }
+ });
+ }
+ });
+
+
+ /*
+ Incoming packets
+ */
+
+ // Click window packet
+ protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.UNSIGNED_BYTE); // 0 - Window ID
+ map(Type.SHORT); // 1 - Slot
+ map(Type.BYTE); // 2 - Button
+ map(Type.SHORT); // 3 - Action number
+ map(Type.VAR_INT); // 4 - Mode
+ map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item
+ }
+ }
+ );
+
+ // Creative Inventory Action
+ protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.SHORT); // 0 - Slot
+ map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item
+ }
+ }
+ );
+ }
+
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java
new file mode 100644
index 000000000..b62319af7
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java
@@ -0,0 +1,40 @@
+package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
+
+import us.myles.ViaVersion.api.PacketWrapper;
+import us.myles.ViaVersion.api.protocol.Protocol;
+import us.myles.ViaVersion.api.remapper.PacketHandler;
+import us.myles.ViaVersion.api.remapper.PacketRemapper;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.packets.State;
+
+public class WorldPackets {
+
+ public static void register(Protocol protocol) {
+ //spawn particle
+ protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.INT); // 0 - Particle ID
+ map(Type.BOOLEAN); // 1 - Long Distance
+ map(Type.FLOAT); // 2 - X
+ map(Type.FLOAT); // 3 - Y
+ map(Type.FLOAT); // 4 - Z
+ map(Type.FLOAT); // 5 - Offset X
+ map(Type.FLOAT); // 6 - Offset Y
+ map(Type.FLOAT); // 7 - Offset Z
+ map(Type.FLOAT); // 8 - Particle Data
+ map(Type.INT); // 9 - Particle Count
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ int id = wrapper.get(Type.INT, 0);
+ if (id == 27) {
+ wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
+ }
+ }
+ });
+ }
+ });
+ }
+
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/types/Particle1_13_2Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/types/Particle1_13_2Type.java
new file mode 100644
index 000000000..7f53c1b28
--- /dev/null
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/types/Particle1_13_2Type.java
@@ -0,0 +1,44 @@
+package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types;
+
+import io.netty.buffer.ByteBuf;
+import us.myles.ViaVersion.api.type.Type;
+import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
+
+public class Particle1_13_2Type extends Type {
+ public Particle1_13_2Type() {
+ super("Particle", Particle.class);
+ }
+
+ @Override
+ public void write(ByteBuf buffer, Particle object) throws Exception {
+ Type.VAR_INT.write(buffer, object.getId());
+ for (Particle.ParticleData data : object.getArguments())
+ data.getType().write(buffer, data.getValue());
+ }
+
+ @Override
+ public Particle read(ByteBuf buffer) throws Exception {
+ int type = Type.VAR_INT.read(buffer);
+ Particle particle = new Particle(type);
+
+ switch (type) {
+ // Block / Falling Dust /
+ case 3:
+ case 20:
+ particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, Type.VAR_INT.read(buffer))); // Flat Block
+ break;
+ // Dust
+ case 11:
+ particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Red 0 - 1
+ particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Green 0 - 1
+ particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Blue 0 - 1
+ particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer)));// Scale 0.01 - 4
+ break;
+ // Item
+ case 27:
+ particle.getArguments().add(new Particle.ParticleData(Type.FLAT_VAR_INT_ITEM, Type.FLAT_VAR_INT_ITEM.read(buffer))); // Flat item
+ break;
+ }
+ return particle;
+ }
+}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java
index 30db785d7..df918be0b 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java
@@ -46,11 +46,14 @@ public class EntityNameRewriter {
}
public static String rewrite(String entName) {
- if (entityNames.containsKey(entName))
- return entityNames.get(entName);
- if (entityNames.containsKey("minecraft:" + entName))
- return entityNames.get("minecraft:" + entName);
- else
+ String entityName = entityNames.get(entName);
+ if (entityName != null) {
+ return entityName;
+ }
+ entityName = entityNames.get("minecraft:" + entName);
+ if (entityName != null) {
+ return entityName;
+ } else
return entName;
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java
index bdcde9e68..5c5ccf6b2 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java
@@ -39,15 +39,15 @@ public class BlockEntityProvider implements Provider {
return -1;
String id = (String) tag.get("id").getValue();
-
- if (!handlers.containsKey(id)) {
+ BlockEntityHandler handler = handlers.get(id);
+ if (handler == null) {
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
}
return -1;
}
- int newBlock = handlers.get(id).transform(user, tag);
+ int newBlock = handler.transform(user, tag);
if (sendUpdate && newBlock != -1)
sendBlockChange(user, position, newBlock);
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java
index 505e476cb..819aa808c 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java
@@ -46,10 +46,6 @@ public class PaintingProvider implements Provider {
// Handle older versions
if (!motive.startsWith("minecraft:"))
motive = "minecraft:" + motive.toLowerCase();
-
- if (paintings.containsKey(motive))
- return Optional.of(paintings.get(motive));
-
- return Optional.absent();
+ return Optional.fromNullable(paintings.get(motive));
}
}
\ No newline at end of file
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java
index db7994407..9b23f76da 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/EntityTracker.java
@@ -28,9 +28,7 @@ public class EntityTracker extends StoredObject {
}
public Optional get(int id) {
- if (!has(id))
- return Optional.absent();
- return Optional.of(clientEntityTypes.get(id));
+ return Optional.fromNullable(clientEntityTypes.get(id));
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java
index 769ee1390..aefe7cedb 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/FakeTileEntity.java
@@ -57,8 +57,9 @@ public class FakeTileEntity {
}
public static CompoundTag getFromBlock(int x, int y, int z, int block) {
- if (tileEntities.containsKey(block)) {
- CompoundTag tag = tileEntities.get(block).clone();
+ CompoundTag originalTag = tileEntities.get(block);
+ if (originalTag != null) {
+ CompoundTag tag = originalTag.clone();
tag.put(new IntTag("x", x));
tag.put(new IntTag("y", y));
tag.put(new IntTag("z", z));
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java
index 17df9b020..da848d8f0 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java
@@ -230,8 +230,9 @@ public class ItemRewriter {
tag = new CompoundTag("tag");
}
CompoundTag entityTag = new CompoundTag("EntityTag");
- if (ENTTIY_ID_TO_NAME.containsKey((int) item.getData())) {
- StringTag id = new StringTag("id", ENTTIY_ID_TO_NAME.get((int) item.getData()));
+ String entityName = ENTTIY_ID_TO_NAME.get((int) item.getData());
+ if (entityName != null) {
+ StringTag id = new StringTag("id", entityName);
entityTag.put(id);
tag.put(entityTag);
}
@@ -379,12 +380,14 @@ public class ItemRewriter {
if (oldID >= 16384) {
oldID -= 8192;
}
- if (POTION_INDEX.containsKey(oldID)) {
- return POTION_INDEX.get(oldID);
+
+ Integer index = POTION_INDEX.get(oldID);
+ if (index != null) {
+ return index;
}
oldID = POTION_NAME_TO_ID.get(potionNameFromDamage((short) oldID));
- return POTION_INDEX.containsKey(oldID) ? POTION_INDEX.get(oldID) : 0;
+ return (index = POTION_INDEX.get(oldID)) != null ? index : 0;
}
private static void registerEntity(Integer id, String name) {
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java
index ffe476089..3d2ef48ab 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java
@@ -173,11 +173,7 @@ public enum MetaIndex {
private static Optional getIndex(Entity1_10Types.EntityType type, int index) {
Pair pair = new Pair<>(type, index);
- if (metadataRewrites.containsKey(pair)) {
- return Optional.of(metadataRewrites.get(pair));
- }
-
- return Optional.absent();
+ return Optional.fromNullable(metadataRewrites.get(pair));
}
public static MetaIndex searchIndex(Entity1_10Types.EntityType type, int index) {
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java
index bc4987780..464cf7833 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java
@@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Triple;
import us.myles.ViaVersion.api.Via;
+import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol;
@@ -184,8 +185,9 @@ public class EntityPackets {
List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
- if (tracker.getClientEntityTypes().containsKey(entityID)) {
- MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
+ Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
+ if (type != null) {
+ MetadataRewriter.transform(type, metadataList);
} else {
// Buffer
tracker.addMetadataToBuffer(entityID, metadataList);
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java
index b8382ce53..1dc71045e 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java
@@ -214,8 +214,9 @@ public class SpawnPackets {
List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
- if (tracker.getClientEntityTypes().containsKey(entityID)) {
- MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
+ Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
+ if (type != null) {
+ MetadataRewriter.transform(type, metadataList);
} else {
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityID);
metadataList.clear();
@@ -319,8 +320,9 @@ public class SpawnPackets {
List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
- if (tracker.getClientEntityTypes().containsKey(entityID)) {
- MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
+ Entity1_10Types.EntityType type = tracker.getClientEntityTypes().get(entityID);
+ if (type != null) {
+ MetadataRewriter.transform(type, metadataList);
} else {
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityID);
metadataList.clear();
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java
index 65e5eafb2..985d83386 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java
@@ -284,9 +284,7 @@ public enum SoundEffect {
public static SoundEffect getByName(String name) {
name = name.toLowerCase();
- if (effects.containsKey(name))
- return effects.get(name);
- return null;
+ return effects.get(name);
}
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java
index 8a0356203..d6e99db20 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java
@@ -25,8 +25,7 @@ public class CommandBlockStorage extends StoredObject {
public void unloadChunk(int x, int z) {
Pair chunkPos = new Pair<>(x, z);
- if (storedCommandBlocks.containsKey(chunkPos))
- storedCommandBlocks.remove(chunkPos);
+ storedCommandBlocks.remove(chunkPos);
}
public void addOrUpdateBlock(Position position, CompoundTag tag) {
@@ -54,19 +53,18 @@ public class CommandBlockStorage extends StoredObject {
public Optional getCommandBlock(Position position) {
Pair chunkCoords = getChunkCoords(position);
- if (!storedCommandBlocks.containsKey(chunkCoords))
- return Optional.absent();
-
Map blocks = storedCommandBlocks.get(chunkCoords);
-
- if (!blocks.containsKey(position))
+ if (blocks == null)
return Optional.absent();
- CompoundTag tag = blocks.get(position).clone();
+ CompoundTag tag = blocks.get(position);
+ if (tag == null)
+ return Optional.absent();
+
+ tag = tag.clone();
tag.put(new ByteTag("powered", (byte) 0));
tag.put(new ByteTag("auto", (byte) 0));
tag.put(new ByteTag("conditionMet", (byte) 0));
-
return Optional.of(tag);
}
diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java
index 2824a0a72..bafffa178 100644
--- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java
+++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java
@@ -59,13 +59,13 @@ public class EntityTracker extends StoredObject {
}
public UUID getEntityUUID(int id) {
- if (uuidMap.containsKey(id)) {
- return uuidMap.get(id);
- } else {
- UUID uuid = UUID.randomUUID();
+ UUID uuid = uuidMap.get(id);
+ if (uuid == null) {
+ uuid = UUID.randomUUID();
uuidMap.put(id, uuid);
- return uuid;
}
+
+ return uuid;
}
public void setSecondHand(Item item) {
@@ -117,11 +117,11 @@ public class EntityTracker extends StoredObject {
}
public void handleMetadata(int entityID, List metadataList) {
- if (!clientEntityTypes.containsKey(entityID)) {
+ Entity1_10Types.EntityType type = clientEntityTypes.get(entityID);
+ if (type == null) {
return;
}
- Entity1_10Types.EntityType type = clientEntityTypes.get(entityID);
for (Metadata metadata : new ArrayList<>(metadataList)) {
// Fix: wither (crash fix)
if (type == Entity1_10Types.EntityType.WITHER) {
@@ -272,21 +272,23 @@ public class EntityTracker extends StoredObject {
}
public void addMetadataToBuffer(int entityID, List metadataList) {
- if (metadataBuffer.containsKey(entityID)) {
- metadataBuffer.get(entityID).addAll(metadataList);
+ final List metadata = metadataBuffer.get(entityID);
+ if (metadata != null) {
+ metadata.addAll(metadataList);
} else {
metadataBuffer.put(entityID, metadataList);
}
}
public void sendMetadataBuffer(int entityID) {
- if (metadataBuffer.containsKey(entityID)) {
+ List metadataList = metadataBuffer.get(entityID);
+ if (metadataList != null) {
PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
wrapper.write(Type.VAR_INT, entityID);
- wrapper.write(Types1_9.METADATA_LIST, metadataBuffer.get(entityID));
- MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataBuffer.get(entityID));
- handleMetadata(entityID, metadataBuffer.get(entityID));
- if (metadataBuffer.get(entityID).size() > 0) {
+ wrapper.write(Types1_9.METADATA_LIST, metadataList);
+ MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataList);
+ handleMetadata(entityID, metadataList);
+ if (metadataList.size() > 0) {
try {
wrapper.send(Protocol1_9TO1_8.class);
} catch (Exception e) {
diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java
index 9ae712629..822b9c29f 100644
--- a/common/src/main/java/us/myles/ViaVersion/util/Config.java
+++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java
@@ -14,7 +14,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
public abstract class Config implements ConfigurationProvider {
- private static ThreadLocal yaml = new ThreadLocal() {
+ private static final ThreadLocal YAML = new ThreadLocal() {
@Override
protected Yaml initialValue() {
DumperOptions options = new DumperOptions();
@@ -58,7 +58,7 @@ public abstract class Config implements ConfigurationProvider {
Map config = null;
if (location.exists()) {
try (FileInputStream input = new FileInputStream(location)) {
- config = (Map) yaml.get().load(input);
+ config = (Map) YAML.get().load(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
@@ -71,7 +71,7 @@ public abstract class Config implements ConfigurationProvider {
Map defaults = config;
try (InputStream stream = jarConfigFile.openStream()) {
- defaults = (Map) yaml.get().load(stream);
+ defaults = (Map) YAML.get().load(stream);
for (String option : unsupported) {
defaults.remove(option);
}
@@ -97,7 +97,7 @@ public abstract class Config implements ConfigurationProvider {
public synchronized void saveConfig(File location, Map config) {
try {
- commentStore.writeComments(yaml.get().dump(config), location);
+ commentStore.writeComments(YAML.get().dump(config), location);
} catch (IOException e) {
e.printStackTrace();
}
@@ -128,33 +128,37 @@ public abstract class Config implements ConfigurationProvider {
}
public T get(String key, Class clazz, T def) {
- if (this.config.containsKey(key)) {
- return (T) this.config.get(key);
+ Object o = this.config.get(key);
+ if (o != null) {
+ return (T) o;
} else {
return def;
}
}
public boolean getBoolean(String key, boolean def) {
- if (this.config.containsKey(key)) {
- return (boolean) this.config.get(key);
+ Object o = this.config.get(key);
+ if (o != null) {
+ return (boolean) o;
} else {
return def;
}
}
public String getString(String key, String def) {
- if (this.config.containsKey(key)) {
- return (String) this.config.get(key);
+ final Object o = this.config.get(key);
+ if (o != null) {
+ return (String) o;
} else {
return def;
}
}
public int getInt(String key, int def) {
- if (this.config.containsKey(key)) {
- if (this.config.get(key) instanceof Number) {
- return ((Number) this.config.get(key)).intValue();
+ Object o = this.config.get(key);
+ if (o != null) {
+ if (o instanceof Number) {
+ return ((Number) o).intValue();
} else {
return def;
}
@@ -164,9 +168,10 @@ public abstract class Config implements ConfigurationProvider {
}
public double getDouble(String key, double def) {
- if (this.config.containsKey(key)) {
- if (this.config.get(key) instanceof Number) {
- return ((Number) this.config.get(key)).doubleValue();
+ Object o = this.config.get(key);
+ if (o != null) {
+ if (o instanceof Number) {
+ return ((Number) o).doubleValue();
} else {
return def;
}
@@ -176,8 +181,9 @@ public abstract class Config implements ConfigurationProvider {
}
public List getIntegerList(String key) {
- if (this.config.containsKey(key)) {
- return (List) this.config.get(key);
+ Object o = this.config.get(key);
+ if (o != null) {
+ return (List) o;
} else {
return new ArrayList<>();
}
diff --git a/jar/pom.xml b/jar/pom.xml
index df047c4c9..ea4672cec 100644
--- a/jar/pom.xml
+++ b/jar/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
viaversion-jar
diff --git a/pom.xml b/pom.xml
index 5bd535cb9..14bc38587 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
us.myles
viaversion-parent
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
pom
viaversion-parent
diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml
index d80a5c9d1..4455919b2 100644
--- a/sponge-legacy/pom.xml
+++ b/sponge-legacy/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
diff --git a/sponge/pom.xml b/sponge/pom.xml
index f7876c559..d6bd03ff1 100644
--- a/sponge/pom.xml
+++ b/sponge/pom.xml
@@ -5,7 +5,7 @@
viaversion-parent
us.myles
- 1.5.1-SNAPSHOT
+ 1.5.3-SNAPSHOT
4.0.0
diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
index 59d49f690..fa9833ed7 100644
--- a/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
+++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/listeners/protocol1_9to1_8/HandItemCache.java
@@ -33,8 +33,6 @@ public class HandItemCache implements Runnable {
}
public static Item getHandItem(UUID player) {
- if (!handCache.containsKey(player))
- return null;
return handCache.get(player);
}