Bungee auto-team, bump BungeeCord version, workaround for block connections

This commit is contained in:
creeper123123321 2019-02-24 15:02:09 -03:00
parent 96366aae42
commit f46a2bb618
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
5 changed files with 67 additions and 16 deletions

View File

@ -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>

View File

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

View File

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

View File

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

View File

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