3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Fix bungee and velocity boss bar, implement Velocity channel workaround

Dieser Commit ist enthalten in:
creeper123123321 2019-01-18 08:05:23 -02:00
Ursprung 5ba7c4ba2c
Commit 44ca95bf85
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
3 geänderte Dateien mit 105 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -8,25 +8,27 @@ import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority; import net.md_5.bungee.event.EventPriority;
import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.PluginMessage;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
import us.myles.ViaVersion.bungee.storage.BungeeStorage; import us.myles.ViaVersion.bungee.storage.BungeeStorage;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.UUID;
public class BungeeServerHandler implements Listener { public class BungeeServerHandler implements Listener {
private static Method getHandshake; private static Method getHandshake;
@ -87,13 +89,14 @@ public class BungeeServerHandler implements Listener {
public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception { public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
if (user == null) return; if (user == null) return;
// Manually hide ViaVersion-created BossBars if the childserver was version 1.8.x (#666) // Manually hide ViaVersion-created BossBars if the childserver was version 1.8.x (#666)
if (user.has(EntityTracker.class)) { // Will be cleared by code below or by ServerConnector#handle(Login)
/*if (user.has(EntityTracker.class)) {
EntityTracker tracker = user.get(EntityTracker.class); EntityTracker tracker = user.get(EntityTracker.class);
if (tracker.getBossBarMap() != null) if (tracker.getBossBarMap() != null)
for (BossBar bar : tracker.getBossBarMap().values()) for (BossBar bar : tracker.getBossBarMap().values())
bar.hide(); bar.hide();
} }*/
// Handle server/version change // Handle server/version change
if (user.has(BungeeStorage.class)) { if (user.has(BungeeStorage.class)) {
BungeeStorage storage = user.get(BungeeStorage.class); BungeeStorage storage = user.get(BungeeStorage.class);
@ -107,6 +110,18 @@ public class BungeeServerHandler implements Listener {
int protocolId = ProtocolDetectorService.getProtocolId(serverName); int protocolId = ProtocolDetectorService.getProtocolId(serverName);
if (protocolId <= ProtocolVersion.v1_8.getId()) { // 1.8 doesn't have BossBar packet
if (storage.getBossbar() != null) {
for (UUID uuid : storage.getBossbar()) {
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
wrapper.write(Type.UUID, uuid);
wrapper.write(Type.VAR_INT, 1); // remove
wrapper.send(Protocol1_9TO1_8.class, true, true);
}
storage.getBossbar().clear();
}
}
ProtocolInfo info = user.get(ProtocolInfo.class); ProtocolInfo info = user.get(ProtocolInfo.class);
int previousServerProtocol = info.getServerProtocolVersion(); int previousServerProtocol = info.getServerProtocolVersion();
@ -130,14 +145,12 @@ public class BungeeServerHandler implements Listener {
// Workaround 1.13 server change // Workaround 1.13 server change
Object relayMessages = getRelayMessages.invoke(e.getPlayer().getPendingConnection()); Object relayMessages = getRelayMessages.invoke(e.getPlayer().getPendingConnection());
if (relayMessages instanceof List) {
for (Object message : (List) relayMessages) { for (Object message : (List) relayMessages) {
if (message instanceof PluginMessage) {
PluginMessage plMsg = (PluginMessage) message; PluginMessage plMsg = (PluginMessage) message;
String channel = plMsg.getTag(); String channel = plMsg.getTag();
int id1_13 = ProtocolVersion.v1_13.getId();
if (previousServerProtocol != -1) { if (previousServerProtocol != -1) {
if (previousServerProtocol < ProtocolVersion.v1_13.getId() if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
&& protocolId >= ProtocolVersion.v1_13.getId()) {
channel = InventoryPackets.getNewPluginChannelId(channel); channel = InventoryPackets.getNewPluginChannelId(channel);
if (channel.equals("minecraft:register")) { if (channel.equals("minecraft:register")) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0");
@ -146,8 +159,7 @@ public class BungeeServerHandler implements Listener {
} }
plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8)); plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8));
} }
} else if (previousServerProtocol >= ProtocolVersion.v1_13.getId() } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
&& protocolId < ProtocolVersion.v1_13.getId()) {
channel = InventoryPackets.getOldPluginChannelId(channel); channel = InventoryPackets.getOldPluginChannelId(channel);
if (channel.equals("REGISTER")) { if (channel.equals("REGISTER")) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0");
@ -159,12 +171,6 @@ public class BungeeServerHandler implements Listener {
} }
} }
plMsg.setTag(channel); plMsg.setTag(channel);
} else {
Via.getPlatform().getLogger().warning("relayMessages contains a element that isn't a Handshake " + message);
}
}
} else {
Via.getPlatform().getLogger().warning("relayMessages isn't a List! " + relayMessages);
} }
user.put(info); user.put(info);

Datei anzeigen

@ -5,21 +5,27 @@ import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.ServerPreConnectEvent; import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; 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.service.ProtocolDetectorService;
import us.myles.ViaVersion.velocity.storage.VelocityStorage; import us.myles.ViaVersion.velocity.storage.VelocityStorage;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
public class VelocityServerHandler { public class VelocityServerHandler {
@ -27,6 +33,7 @@ public class VelocityServerHandler {
private static Method setNextProtocolVersion; private static Method setNextProtocolVersion;
private static Method getMinecraftConnection; private static Method getMinecraftConnection;
private static Method getNextProtocolVersion; private static Method getNextProtocolVersion;
private static Method getKnownChannels;
static { static {
try { try {
@ -38,6 +45,8 @@ public class VelocityServerHandler {
.getDeclaredMethod("getMinecraftConnection"); .getDeclaredMethod("getMinecraftConnection");
getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection") getNextProtocolVersion = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
.getDeclaredMethod("getNextProtocolVersion"); .getDeclaredMethod("getNextProtocolVersion");
getKnownChannels = Class.forName("com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler")
.getDeclaredMethod("getKnownChannels");
} catch (NoSuchMethodException | ClassNotFoundException e) { } catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -79,13 +88,14 @@ public class VelocityServerHandler {
public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception { public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
if (user == null) return; if (user == null) return;
// Manually hide ViaVersion-created BossBars if the childserver was version 1.8.x (#666) // Manually hide ViaVersion-created BossBars if the childserver was version 1.8.x (#666)
if (user.has(EntityTracker.class)) { // Will be cleared by code below or by Velocity's handleBackendJoinGame
/*if (user.has(EntityTracker.class)) {
EntityTracker tracker = user.get(EntityTracker.class); EntityTracker tracker = user.get(EntityTracker.class);
if (tracker.getBossBarMap() != null) if (tracker.getBossBarMap() != null)
for (BossBar bar : tracker.getBossBarMap().values()) for (BossBar bar : tracker.getBossBarMap().values())
bar.hide(); bar.hide();
} }*/
// Handle server/version change // Handle server/version change
if (user.has(VelocityStorage.class)) { if (user.has(VelocityStorage.class)) {
// Wait all the scheduled packets be sent // Wait all the scheduled packets be sent
@ -99,6 +109,8 @@ public class VelocityServerHandler {
VelocityStorage storage = user.get(VelocityStorage.class); VelocityStorage storage = user.get(VelocityStorage.class);
if (storage.getBossbar() == null) storage.saveServerBossBars();
if (e.getServer() != null) { if (e.getServer() != null) {
if (!e.getServer().getServerInfo().getName().equals(storage.getCurrentServer())) { if (!e.getServer().getServerInfo().getName().equals(storage.getCurrentServer())) {
String serverName = e.getServer().getServerInfo().getName(); String serverName = e.getServer().getServerInfo().getName();
@ -107,7 +119,20 @@ public class VelocityServerHandler {
int protocolId = ProtocolDetectorService.getProtocolId(serverName); int protocolId = ProtocolDetectorService.getProtocolId(serverName);
if (protocolId <= ProtocolVersion.MINECRAFT_1_8.getProtocol()) { // 1.8 doesn't have BossBar packet
if (storage.getBossbar() != null) {
for (UUID uuid : storage.getBossbar()) {
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
wrapper.write(Type.UUID, uuid);
wrapper.write(Type.VAR_INT, 1); // remove
wrapper.send(Protocol1_9TO1_8.class, true, true);
}
storage.getBossbar().clear();
}
}
ProtocolInfo info = user.get(ProtocolInfo.class); ProtocolInfo info = user.get(ProtocolInfo.class);
int previousServerProtocol = info.getServerProtocolVersion();
// Refresh the pipes // Refresh the pipes
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId);
@ -127,6 +152,33 @@ public class VelocityServerHandler {
// Add version-specific base Protocol // Add version-specific base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
// Workaround 1.13 server change
Set<String> knownChannels = (Set<String>) getKnownChannels.invoke(
ReflectionUtil.invoke(
getMinecraftConnection.invoke(e.getPlayer()),
"getSessionHandler"
)
);
if (previousServerProtocol != -1) {
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
ArrayList<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) {
newChannels.add(InventoryPackets.getNewPluginChannelId(oldChannel));
}
knownChannels.clear();
knownChannels.addAll(newChannels);
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
ArrayList<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) {
newChannels.add(InventoryPackets.getOldPluginChannelId(oldChannel));
}
knownChannels.clear();
knownChannels.addAll(newChannels);
}
}
user.put(info); user.put(info);
user.put(storage); user.put(storage);

Datei anzeigen

@ -5,8 +5,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.util.ReflectionUtil;
import java.util.Set; import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.UUID; import java.util.UUID;
@Data @Data
@ -14,24 +16,24 @@ import java.util.UUID;
public class VelocityStorage extends StoredObject { public class VelocityStorage extends StoredObject {
private Player player; private Player player;
private String currentServer; private String currentServer;
private Set<UUID> bossbar; private List<UUID> bossbar;
public VelocityStorage(UserConnection user, Player player) { public VelocityStorage(UserConnection user, Player player) {
super(user); super(user);
this.player = player; this.player = player;
this.currentServer = ""; this.currentServer = "";
}
public void saveServerBossBars() {
// Get bossbar list if it's supported // Get bossbar list if it's supported
/* TODO make this work - do we need this?
try { try {
Object connection = ReflectionUtil.invoke(player, "getConnection"); Object connection = ReflectionUtil.invoke(player, "getMinecraftConnection");
Object sessionHandler = ReflectionUtil.invoke(connection, "getSessionHandler"); Object sessionHandler = ReflectionUtil.invoke(connection, "getSessionHandler");
if (sessionHandler.getClass().getSimpleName().contains("Play")) { if (sessionHandler.getClass().getSimpleName().contains("Play")) {
bossbar = (Set<UUID>) ReflectionUtil.invoke(sessionHandler, "getServerBossBars"); bossbar = (List<UUID>) ReflectionUtil.invoke(sessionHandler, "getServerBossBars");
} }
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
*/
} }
} }