From d962ef09ffe3d5c479b8c33851d595c25b3ebf14 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 23 Feb 2019 13:44:41 -0300 Subject: [PATCH 1/5] workaround packet order for team packets --- .../bungee/handlers/BungeeServerHandler.java | 8 ++++++++ .../protocol1_9to1_8/packets/PlayerPackets.java | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java index 8383e73ca..3740c9e16 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java @@ -22,6 +22,7 @@ import us.myles.ViaVersion.bungee.storage.BungeeStorage; 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.protocols.protocol1_9to1_8.storage.EntityTracker; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -95,6 +96,7 @@ public class BungeeServerHandler implements Listener { if (e.getServer() != null) { if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) { + EntityTracker oldEntityTracker = user.get(EntityTracker.class); String serverName = e.getServer().getInfo().getName(); storage.setCurrentServer(serverName); @@ -174,6 +176,12 @@ public class BungeeServerHandler implements Listener { protocol.init(user); } + EntityTracker newTracker = user.get(EntityTracker.class); + if (newTracker != null && oldEntityTracker != null) { + newTracker.setAutoTeam(oldEntityTracker.isAutoTeam()); + newTracker.setCurrentTeam(oldEntityTracker.getCurrentTeam()); + } + Object wrapper = channelWrapper.get(player); setVersion.invoke(wrapper, protocolId); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 37f9439f5..b5135ba07 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -137,7 +137,9 @@ public class PlayerPackets { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { if (mode == 4) { // since removing add to auto team - entityTracker.sendTeamPacket(true, false); + wrapper.send(Protocol1_9TO1_8.class, true, true); + wrapper.cancel(); + entityTracker.sendTeamPacket(true, true); entityTracker.setCurrentTeam("viaversion"); } else { // since adding remove from auto team @@ -155,7 +157,9 @@ public class PlayerPackets { if (entityTracker.isAutoTeam() && teamName.equals(entityTracker.getCurrentTeam())) { // team was removed - entityTracker.sendTeamPacket(true, false); + wrapper.send(Protocol1_9TO1_8.class, true, true); + wrapper.cancel(); + entityTracker.sendTeamPacket(true, true); entityTracker.setCurrentTeam("viaversion"); } } @@ -211,7 +215,9 @@ public class PlayerPackets { EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); if (Via.getConfig().isAutoTeam()) { entityTracker.setAutoTeam(true); - entityTracker.sendTeamPacket(true, false); + wrapper.send(Protocol1_9TO1_8.class, true, true); + wrapper.cancel(); + entityTracker.sendTeamPacket(true, true); entityTracker.setCurrentTeam("viaversion"); } else { entityTracker.setAutoTeam(false); From 96366aae42e22d954c47b69bb03464964a1d54bc Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 23 Feb 2019 20:11:44 -0300 Subject: [PATCH 2/5] Fix NPE when block connection is disabled --- .../protocols/protocol1_13to1_12_2/packets/WorldPackets.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 63bbe1613..e5b223084 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -308,7 +308,7 @@ public class WorldPackets { } boolean willSaveConnection = false; - if (ConnectionData.needStoreBlocks() && Via.getConfig().isServersideBlockConnections()) { + if (Via.getConfig().isServersideBlockConnections() && ConnectionData.needStoreBlocks()) { for (int p = 0; p < section.getPaletteSize(); p++) { int newId = section.getPaletteEntry(p); if (ConnectionData.isWelcome(newId)) { From f46a2bb618f89e2cd46ac98a6ee9e3d79c3763fd Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 24 Feb 2019 15:02:09 -0300 Subject: [PATCH 3/5] Bungee auto-team, bump BungeeCord version, workaround for block connections --- bungee/pom.xml | 7 +++- .../bungee/handlers/BungeeServerHandler.java | 34 +++++++++++++++-- .../blockconnections/ConnectionData.java | 2 +- .../packets/WorldPackets.java | 37 +++++++++++++------ .../packets/PlayerPackets.java | 3 ++ 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/bungee/pom.xml b/bungee/pom.xml index 384d30083..3d86a4c12 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -11,6 +11,11 @@ viaversion-bungee + + 1.8 + 1.8 + + @@ -29,7 +34,7 @@ net.md-5 bungeecord-api - 1.10-SNAPSHOT + 1.13-SNAPSHOT provided diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java index 3740c9e16..0bc890ae4 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeServerHandler.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.api.score.Team; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; import net.md_5.bungee.protocol.packet.PluginMessage; @@ -89,6 +90,7 @@ public class BungeeServerHandler implements Listener { public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception { if (user == null) return; + // Auto-team handling // Handle server/version change if (user.has(BungeeStorage.class)) { BungeeStorage storage = user.get(BungeeStorage.class); @@ -96,7 +98,14 @@ public class BungeeServerHandler implements Listener { if (e.getServer() != null) { if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) { + // Clear auto-team EntityTracker oldEntityTracker = user.get(EntityTracker.class); + if (oldEntityTracker != null) { + if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) { + oldEntityTracker.sendTeamPacket(false, true); + } + } + String serverName = e.getServer().getInfo().getName(); storage.setCurrentServer(serverName); @@ -177,9 +186,28 @@ public class BungeeServerHandler implements Listener { } EntityTracker newTracker = user.get(EntityTracker.class); - if (newTracker != null && oldEntityTracker != null) { - newTracker.setAutoTeam(oldEntityTracker.isAutoTeam()); - newTracker.setCurrentTeam(oldEntityTracker.getCurrentTeam()); + if (newTracker != null) { + if (Via.getConfig().isAutoTeam()) { + String currentTeam = null; + for (Team team : player.getScoreboard().getTeams()) { + if (team.getPlayers().contains(info.getUsername())) { + currentTeam = team.getName(); + + } + } + + // Reinitialize auto-team + newTracker.setAutoTeam(true); + if (currentTeam == null) { + // Send auto-team as it was cleared above + newTracker.sendTeamPacket(true, true); + newTracker.setCurrentTeam("viaversion"); + } else { + // Auto-team will be sent when bungee send remove packet + newTracker.setAutoTeam(Via.getConfig().isAutoTeam()); + newTracker.setCurrentTeam(currentTeam); + } + } } Object wrapper = channelWrapper.get(player); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 62da996c7..4825adf82 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -42,7 +42,7 @@ public class ConnectionData { blockUpdatePacket.write(Type.POSITION, pos); blockUpdatePacket.write(Type.VAR_INT, newBlockState); try { - blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false); + blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, true); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index e5b223084..edd985e12 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -173,19 +173,23 @@ public class WorldPackets { Position position = wrapper.get(Type.POSITION, 0); int newId = toNewId(wrapper.get(Type.VAR_INT, 0)); + UserConnection userConnection = wrapper.user(); if (Via.getConfig().isServersideBlockConnections()) { - UserConnection userConnection = wrapper.user(); ConnectionData.updateBlockStorage(userConnection, position, newId); if (ConnectionData.connects(newId)) { newId = ConnectionData.connect(userConnection, position, newId); } - + } + wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId)); + // Workaround for packet order issue + wrapper.send(Protocol1_13To1_12_2.class, true, true); + wrapper.cancel(); + if (Via.getConfig().isServersideBlockConnections()) { ConnectionData.update(userConnection, position); } - wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId)); } }); } @@ -204,8 +208,9 @@ public class WorldPackets { int chunkX = wrapper.get(Type.INT, 0); int chunkZ = wrapper.get(Type.INT, 1); UserConnection userConnection = wrapper.user(); + BlockChangeRecord[] records = wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0); // Convert ids - for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { + for (BlockChangeRecord record : records) { int newBlock = toNewId(record.getBlockId()); Position position = new Position( (long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), @@ -218,23 +223,33 @@ public class WorldPackets { record.setBlockId(checkStorage(wrapper.user(), position, newBlock)); } - for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { - int blockState = record.getBlockId(); + if (Via.getConfig().isServersideBlockConnections()) { + for (BlockChangeRecord record : records) { + int blockState = record.getBlockId(); - Position position = new Position( - (long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), - (long) record.getY(), - (long) (record.getHorizontal() & 15) + (chunkZ * 16)); + Position position = new Position( + (long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), + (long) record.getY(), + (long) (record.getHorizontal() & 15) + (chunkZ * 16)); - if (Via.getConfig().isServersideBlockConnections()) { if (ConnectionData.connects(blockState)) { blockState = ConnectionData.connect(userConnection, position, blockState); record.setBlockId(blockState); } + } + // Workaround for packet order issue + wrapper.send(Protocol1_13To1_12_2.class, true, true); + wrapper.cancel(); + for (BlockChangeRecord record : records) { + Position position = new Position( + (long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), + (long) record.getY(), + (long) (record.getHorizontal() & 15) + (chunkZ * 16)); ConnectionData.update(userConnection, position); } } + } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index b5135ba07..43301fb23 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -137,6 +137,7 @@ public class PlayerPackets { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { if (mode == 4) { // since removing add to auto team + // Workaround for packet order issue wrapper.send(Protocol1_9TO1_8.class, true, true); wrapper.cancel(); entityTracker.sendTeamPacket(true, true); @@ -157,6 +158,7 @@ public class PlayerPackets { if (entityTracker.isAutoTeam() && teamName.equals(entityTracker.getCurrentTeam())) { // team was removed + // Workaround for packet order issue wrapper.send(Protocol1_9TO1_8.class, true, true); wrapper.cancel(); entityTracker.sendTeamPacket(true, true); @@ -215,6 +217,7 @@ public class PlayerPackets { EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); if (Via.getConfig().isAutoTeam()) { entityTracker.setAutoTeam(true); + // Workaround for packet order issue wrapper.send(Protocol1_9TO1_8.class, true, true); wrapper.cancel(); entityTracker.sendTeamPacket(true, true); From 44be8b37919f60e467e43b34a365b7100c4510c4 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 24 Feb 2019 15:07:34 -0300 Subject: [PATCH 4/5] unnecessary cancel when auto-team is disabled --- .../protocol1_13to1_12_2/packets/WorldPackets.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index edd985e12..fdd0089fb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -183,10 +183,10 @@ public class WorldPackets { } } wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId)); - // Workaround for packet order issue - wrapper.send(Protocol1_13To1_12_2.class, true, true); - wrapper.cancel(); if (Via.getConfig().isServersideBlockConnections()) { + // Workaround for packet order issue + wrapper.send(Protocol1_13To1_12_2.class, true, true); + wrapper.cancel(); ConnectionData.update(userConnection, position); } From 82838164183def9893a36770a0b4c65bde5de71b Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 24 Feb 2019 15:53:43 -0300 Subject: [PATCH 5/5] Fix team remove --- .../protocols/protocol1_9to1_8/packets/PlayerPackets.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 43301fb23..84cabf12d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -129,7 +129,7 @@ public class PlayerPackets { } if (mode == 0 || mode == 3 || mode == 4) { - String[] players = wrapper.read(Type.STRING_ARRAY); // Players + String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); String myName = wrapper.user().get(ProtocolInfo.class).getUsername(); String teamName = wrapper.get(Type.STRING, 0); @@ -149,7 +149,6 @@ public class PlayerPackets { } } } - wrapper.write(Type.STRING_ARRAY, players); } if (mode == 1) { // Remove team