3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Merge pull request #1202 from creeper123123321/master

Workaround packet order for team packets
Dieser Commit ist enthalten in:
Myles 2019-02-25 17:37:29 +00:00 committet von GitHub
Commit 5d63c359b3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 83 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -11,6 +11,11 @@
<artifactId>viaversion-bungee</artifactId>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<resources>
<resource>
@ -29,7 +34,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.10-SNAPSHOT</version>
<version>1.13-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Datei anzeigen

@ -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;
@ -22,6 +23,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;
@ -88,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);
@ -95,6 +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);
@ -174,6 +185,31 @@ public class BungeeServerHandler implements Listener {
protocol.init(user);
}
EntityTracker newTracker = user.get(EntityTracker.class);
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);
setVersion.invoke(wrapper, protocolId);

Datei anzeigen

@ -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();
}

Datei anzeigen

@ -173,19 +173,23 @@ public class WorldPackets {
Position position = wrapper.get(Type.POSITION, 0);
int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
if (Via.getConfig().isServersideBlockConnections()) {
UserConnection userConnection = wrapper.user();
if (Via.getConfig().isServersideBlockConnections()) {
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));
if (Via.getConfig().isServersideBlockConnections()) {
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.cancel();
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,7 +223,8 @@ public class WorldPackets {
record.setBlockId(checkStorage(wrapper.user(), position, newBlock));
}
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
if (Via.getConfig().isServersideBlockConnections()) {
for (BlockChangeRecord record : records) {
int blockState = record.getBlockId();
Position position = new Position(
@ -226,15 +232,24 @@ public class WorldPackets {
(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);
}
}
}
});
}
@ -308,7 +323,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)) {

Datei anzeigen

@ -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);
@ -137,7 +137,10 @@ public class PlayerPackets {
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
if (mode == 4) {
// since removing add to auto team
entityTracker.sendTeamPacket(true, false);
// Workaround for packet order issue
wrapper.send(Protocol1_9TO1_8.class, true, true);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
} else {
// since adding remove from auto team
@ -146,7 +149,6 @@ public class PlayerPackets {
}
}
}
wrapper.write(Type.STRING_ARRAY, players);
}
if (mode == 1) { // Remove team
@ -155,7 +157,10 @@ public class PlayerPackets {
if (entityTracker.isAutoTeam()
&& teamName.equals(entityTracker.getCurrentTeam())) {
// team was removed
entityTracker.sendTeamPacket(true, false);
// Workaround for packet order issue
wrapper.send(Protocol1_9TO1_8.class, true, true);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
}
}
@ -211,7 +216,10 @@ public class PlayerPackets {
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
if (Via.getConfig().isAutoTeam()) {
entityTracker.setAutoTeam(true);
entityTracker.sendTeamPacket(true, false);
// Workaround for packet order issue
wrapper.send(Protocol1_9TO1_8.class, true, true);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
} else {
entityTracker.setAutoTeam(false);