diff --git a/README.md b/README.md index 560f9177e..cc4b9c37b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ViaVersion 2.0.1 - Spigot, Sponge, BungeeCord, Velocity +# ViaVersion 2.1.1 - Spigot, Sponge, BungeeCord, Velocity [![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/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 87cf8bd2e..8f2ff1233 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java index 993cd8f14..a44dc1e74 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java @@ -1,7 +1,9 @@ package us.myles.ViaVersion.bukkit.listeners.multiversion; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import us.myles.ViaVersion.ViaVersionPlugin; @@ -9,13 +11,11 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener; -import us.myles.ViaVersion.bukkit.platform.BukkitViaLoader; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class PlayerSneakListener extends ViaBukkitListener { private static final float STANDING_HEIGHT = 1.8F; @@ -24,13 +24,14 @@ public class PlayerSneakListener extends ViaBukkitListener { private static final float DEFAULT_WIDTH = 0.6F; private Map sneaking; // true = 1.14+, else false + private Set sneakingUuids; private Method getHandle; private Method setSize; private boolean is1_9Fix; private boolean is1_14Fix; private boolean useCache; - public PlayerSneakListener(ViaVersionPlugin plugin, BukkitViaLoader viaLoader, boolean is1_9Fix, boolean is1_14Fix) { + public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) { super(plugin, null); this.is1_9Fix = is1_9Fix; this.is1_14Fix = is1_14Fix; @@ -41,16 +42,11 @@ public class PlayerSneakListener extends ViaBukkitListener { } catch (ClassNotFoundException | NoSuchMethodException e) { e.printStackTrace(); } + // From 1.9 upwards the server hitbox is set in every entity tick, so we have to reset it everytime if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getId()) { - sneaking = new HashMap<>(); + sneaking = new WeakHashMap<>(); useCache = true; - viaLoader.storeListener(new ViaBukkitListener(plugin, null) { - @EventHandler - public void playerQuit(PlayerQuitEvent event) { - sneaking.remove(event.getPlayer()); - } - }).register(); plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() { @Override public void run() { @@ -60,6 +56,11 @@ public class PlayerSneakListener extends ViaBukkitListener { } }, 1, 1); } + + // Suffocation removal only required for 1.14+ clients. + if (is1_14Fix) { + sneakingUuids = new HashSet<>(); + } } @EventHandler(ignoreCancelled = true) @@ -73,6 +74,11 @@ public class PlayerSneakListener extends ViaBukkitListener { int protocolVersion = info.getProtocolVersion(); if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) { setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT); + if (event.isSneaking()) + sneakingUuids.add(player.getUniqueId()); + else + sneakingUuids.remove(player.getUniqueId()); + if (!useCache) return; if (event.isSneaking()) sneaking.put(player, true); @@ -88,6 +94,32 @@ public class PlayerSneakListener extends ViaBukkitListener { } } + @EventHandler(ignoreCancelled = true) + public void playerDamage(EntityDamageEvent event) { + if (!is1_14Fix) return; + if (event.getCause() != EntityDamageEvent.DamageCause.SUFFOCATION) return; + if (event.getEntityType() != EntityType.PLAYER) return; + + Player player = (Player) event.getEntity(); + if (!sneakingUuids.contains(player.getUniqueId())) return; + + // Don't cancel when they should actually be suffocating; Essentially cancel when the head is in the top block only ever so slightly + // ~0.041 should suffice, but gotta stay be safe + double y = player.getEyeLocation().getY() + 0.045; + y -= (int) y; + if (y < 0.09) { + event.setCancelled(true); + } + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) { + if (sneaking != null) + sneaking.remove(event.getPlayer()); + if (sneakingUuids != null) + sneakingUuids.remove(event.getPlayer().getUniqueId()); + } + private void setHeight(Player player, float height) { try { setSize.invoke(getHandle.invoke(player), DEFAULT_WIDTH, height); @@ -95,4 +127,4 @@ public class PlayerSneakListener extends ViaBukkitListener { e.printStackTrace(); } } -} +} \ No newline at end of file diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index ca5fc776f..b2e3e82e8 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -82,7 +82,7 @@ public class BukkitViaLoader implements ViaPlatformLoader { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) { boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId(); if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) { - storeListener(new PlayerSneakListener(plugin, this, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register(); + storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register(); } } diff --git a/bungee/pom.xml b/bungee/pom.xml index 9a6abe901..3dc946c9c 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 2ec21e778..6f79eec06 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java index f58eeaa10..0ca70f176 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java @@ -77,7 +77,6 @@ public class Entity1_13Types { ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL), // agr PARROT(50, ABSTRACT_PARROT), // agk - // Horses ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL), // aha CHESTED_HORSE(-1, ABSTRACT_HORSE), // agz @@ -152,6 +151,7 @@ public class Entity1_13Types { ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT), // agx SQUID(70, ABSTRACT_WATERMOB), // agt + DOLPHIN(12, ABSTRACT_WATERMOB), // Slimes SLIME(64, ABSTRACT_INSENTIENT), // aka diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java index 8ef1f4511..df81d6e6e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java @@ -61,6 +61,7 @@ public class Entity1_14Types { CHICKEN(8, ABSTRACT_ANIMAL), COW(10, ABSTRACT_ANIMAL), MOOSHROOM(49, COW), + PANDA(52, ABSTRACT_INSENTIENT), PIG(54, ABSTRACT_ANIMAL), POLAR_BEAR(57, ABSTRACT_ANIMAL), RABBIT(59, ABSTRACT_ANIMAL), 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 a56806bc3..42fca79f9 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 @@ -16,6 +16,7 @@ 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_14_1to1_14.Protocol1_14_1To1_14; +import us.myles.ViaVersion.protocols.protocol1_14_2to1_14_1.Protocol1_14_2To1_14_1; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_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; @@ -64,6 +65,7 @@ public class ProtocolRegistry { registerProtocol(new Protocol1_14To1_13_2(), Arrays.asList(ProtocolVersion.v1_14.getId()), ProtocolVersion.v1_13_2.getId()); registerProtocol(new Protocol1_14_1To1_14(), Arrays.asList(ProtocolVersion.v1_14_1.getId()), ProtocolVersion.v1_14.getId()); + registerProtocol(new Protocol1_14_2To1_14_1(), Arrays.asList(ProtocolVersion.v1_14_2.getId()), ProtocolVersion.v1_14_1.getId()); } /** 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 67be0178d..85351fbaa 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 @@ -37,6 +37,7 @@ public class ProtocolVersion { public static final ProtocolVersion v1_13_2; public static final ProtocolVersion v1_14; public static final ProtocolVersion v1_14_1; + public static final ProtocolVersion v1_14_2; public static final ProtocolVersion unknown; private final int id; @@ -70,6 +71,7 @@ public class ProtocolVersion { register(v1_13_2 = new ProtocolVersion(404, "1.13.2")); register(v1_14 = new ProtocolVersion(477, "1.14")); register(v1_14_1 = new ProtocolVersion(480, "1.14.1")); + register(v1_14_2 = new ProtocolVersion(485, "1.14.2")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 6bfb3aec9..9e5a2e4a1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -178,7 +178,12 @@ public class InventoryPackets { Via.getPlatform().getLogger().warning("Ignoring plugin channel in outgoing REGISTER: " + channels[i]); } } - wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); + if (!rewrittenChannels.isEmpty()) { + wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); + } else { + wrapper.cancel(); + return; + } } } wrapper.set(Type.STRING, 0, channel); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java new file mode 100644 index 000000000..25a7ab132 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java @@ -0,0 +1,17 @@ +package us.myles.ViaVersion.protocols.protocol1_14_2to1_14_1; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.Protocol; + +public class Protocol1_14_2To1_14_1 extends Protocol { + + @Override + protected void registerPackets() { + + } + + @Override + public void init(UserConnection userConnection) { + + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java index b9f381164..922b6e853 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java @@ -47,6 +47,7 @@ public class EntityTypeRewriter { regEnt(41, 43); // command_block_minecart regEnt(42, 44); // furnace_minecart regEnt(43, 45); // hopper_minecart + regEnt(44, 46); // spawner_minecart regEnt(45, 47); // tnt_minecart regEnt(46, 48); // mule regEnt(47, 49); // mooshroom diff --git a/jar/pom.xml b/jar/pom.xml index c2bd43181..674d3a4ad 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index 9d283fb48..43af1a58e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 2.1.0 + 2.1.2-SNAPSHOT pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index 4ea138948..a7729e7f4 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index 9059e9156..03257f0f6 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/velocity/pom.xml b/velocity/pom.xml index d5be30b57..d0fad747e 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 2.1.0 + 2.1.2-SNAPSHOT 4.0.0 diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java index 39fbc44da..bf2c32133 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityServerHandler.java @@ -16,15 +16,14 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; -import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.velocity.service.ProtocolDetectorService; import us.myles.ViaVersion.velocity.storage.VelocityStorage; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.UUID; import java.util.concurrent.Semaphore; @@ -34,7 +33,6 @@ public class VelocityServerHandler { private static Method getMinecraftConnection; private static Method getNextProtocolVersion; private static Method getKnownChannels; - private static Class clientPlaySessionHandler; static { try { @@ -42,13 +40,11 @@ public class VelocityServerHandler { .getDeclaredMethod("setProtocolVersion", ProtocolVersion.class); setNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") .getDeclaredMethod("setNextProtocolVersion", ProtocolVersion.class); - getMinecraftConnection = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer") - .getDeclaredMethod("getMinecraftConnection"); + Class connectedPlayer = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer"); + getMinecraftConnection = connectedPlayer.getDeclaredMethod("getMinecraftConnection"); getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") .getDeclaredMethod("getNextProtocolVersion"); - clientPlaySessionHandler = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler"); - getKnownChannels = clientPlaySessionHandler - .getDeclaredMethod("getKnownChannels"); + getKnownChannels = connectedPlayer.getDeclaredMethod("getKnownChannels"); } catch (NoSuchMethodException | ClassNotFoundException e) { e.printStackTrace(); } @@ -79,7 +75,6 @@ public class VelocityServerHandler { @Subscribe(order = PostOrder.LATE) public void connectedEvent(ServerConnectedEvent e) { - UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { @@ -144,37 +139,29 @@ public class VelocityServerHandler { // Add version-specific base Protocol pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); - // Workaround 1.13 server change - Object sessionHandler = ReflectionUtil.invoke( - getMinecraftConnection.invoke(e.getPlayer()), - "getSessionHandler" - ); - - if (clientPlaySessionHandler.isInstance(sessionHandler)) { // It may be InitialConnectSessionHandler on the first server connection - Set knownChannels = (Set) getKnownChannels.invoke(sessionHandler); - if (previousServerProtocol != -1) { - int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol(); - if (previousServerProtocol < id1_13 && protocolId >= id1_13) { - ArrayList newChannels = new ArrayList<>(); - for (String oldChannel : knownChannels) { - String transformed = InventoryPackets.getNewPluginChannelId(oldChannel); - if (transformed != null) { - newChannels.add(transformed); - } + Collection knownChannels = (Collection) getKnownChannels.invoke(e.getPlayer()); + if (previousServerProtocol != -1) { + int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol(); + if (previousServerProtocol < id1_13 && protocolId >= id1_13) { + List newChannels = new ArrayList<>(); + for (String oldChannel : knownChannels) { + String transformed = InventoryPackets.getNewPluginChannelId(oldChannel); + if (transformed != null) { + newChannels.add(transformed); } - knownChannels.clear(); - knownChannels.addAll(newChannels); - } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { - ArrayList newChannels = new ArrayList<>(); - for (String oldChannel : knownChannels) { - String transformed = InventoryPackets.getOldPluginChannelId(oldChannel); - if (transformed != null) { - newChannels.add(transformed); - } - } - knownChannels.clear(); - knownChannels.addAll(newChannels); } + knownChannels.clear(); + knownChannels.addAll(newChannels); + } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { + List newChannels = new ArrayList<>(); + for (String oldChannel : knownChannels) { + String transformed = InventoryPackets.getOldPluginChannelId(oldChannel); + if (transformed != null) { + newChannels.add(transformed); + } + } + knownChannels.clear(); + knownChannels.addAll(newChannels); } }