From daac2baf8e6a8006d26d42c822590a3bfc190938 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Mon, 7 Jan 2019 14:06:23 -0200 Subject: [PATCH 1/2] Resend viaversion team when removed from the current team --- .../packets/PlayerPackets.java | 28 ++++++++++++++++++- .../packets/WorldPackets.java | 18 +----------- .../storage/EntityTracker.java | 2 ++ 3 files changed, 30 insertions(+), 18 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 de975f900..6d901e74e 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 @@ -132,20 +132,33 @@ public class PlayerPackets { String[] players = wrapper.read(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); for (String player : players) { if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) { if (mode == 4) { // since removing add to auto team entityTracker.sendTeamPacket(true, false); - + entityTracker.setCurrentTeam("viaversion"); } else { // since adding remove from auto team entityTracker.sendTeamPacket(false, true); + entityTracker.setCurrentTeam(teamName); } } } wrapper.write(Type.STRING_ARRAY, players); } + + if (mode == 1) { // Remove team + final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); + String teamName = wrapper.get(Type.STRING, 0); + if (entityTracker.isAutoTeam() + && teamName.equals(entityTracker.getCurrentTeam())) { + // team was removed + entityTracker.sendTeamPacket(true, false); + entityTracker.setCurrentTeam("viaversion"); + } + } } }); } @@ -190,6 +203,19 @@ public class PlayerPackets { } } ); + + // Scoreboard will be cleared when join game is received + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + if (Via.getConfig().isAutoTeam()) { + EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); + entityTracker.setAutoTeam(true); + entityTracker.sendTeamPacket(true, false); + entityTracker.setCurrentTeam("viaversion"); + } + } + }); } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 1d1a284db..5e45bdade 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -211,23 +211,6 @@ public class WorldPackets { } }); - // Server Difficulty Packet - protocol.registerOutgoing(State.PLAY, 0x41, 0x0D, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - if (Via.getConfig().isAutoTeam()) { - EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); - entityTracker.setAutoTeam(true); - entityTracker.sendTeamPacket(true, true); - } - } - }); - } - }); - // Block Change Packet protocol.registerOutgoing(State.PLAY, 0x23, 0x0B, new PacketRemapper() { @Override @@ -240,6 +223,7 @@ public class WorldPackets { protocol.registerOutgoing(State.PLAY, 0x25, 0x08); // Block Break Animation Packet protocol.registerOutgoing(State.PLAY, 0x24, 0x0A); // Block Action Packet + protocol.registerOutgoing(State.PLAY, 0x41, 0x0D); // Server Difficulty Packet protocol.registerOutgoing(State.PLAY, 0x22, 0x10); // Multi Block Change Packet protocol.registerOutgoing(State.PLAY, 0x27, 0x1C); // Explosion Packet protocol.registerOutgoing(State.PLAY, 0x2A, 0x22); // Particle Packet 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 9a9dce713..212bae1e2 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 @@ -53,6 +53,8 @@ public class EntityTracker extends StoredObject { private GameMode gameMode; @Setter private int mainHand; + @Setter + private String currentTeam; public EntityTracker(UserConnection user) { super(user); From 933e8cbaed0491df2fe87cc6962a1d1f76bac2d6 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 8 Jan 2019 05:25:46 -0200 Subject: [PATCH 2/2] set auto-team to false on join packet --- .../protocols/protocol1_9to1_8/packets/PlayerPackets.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 6d901e74e..af823f1c7 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 @@ -208,11 +208,13 @@ public class PlayerPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { + EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); if (Via.getConfig().isAutoTeam()) { - EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); entityTracker.setAutoTeam(true); entityTracker.sendTeamPacket(true, false); entityTracker.setCurrentTeam("viaversion"); + } else { + entityTracker.setAutoTeam(false); } } });