geforkt von Mirrors/Velocity
Plugins can get plugin messages now.
Dieser Commit ist enthalten in:
Ursprung
c36f417b1e
Commit
d9c35a680a
@ -103,10 +103,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
(ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler();
|
||||
if (connection.getMinecraftConnection().getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) {
|
||||
return message.getChannel().startsWith("MC|") ||
|
||||
playerHandler.getClientPluginMsgChannels().contains(message.getChannel());
|
||||
playerHandler.getClientPluginMsgChannels().contains(message.getChannel()) ||
|
||||
VelocityServer.getServer().getChannelRegistrar().registered(message.getChannel());
|
||||
} else {
|
||||
return message.getChannel().startsWith("minecraft:") ||
|
||||
playerHandler.getClientPluginMsgChannels().contains(message.getChannel());
|
||||
playerHandler.getClientPluginMsgChannels().contains(message.getChannel()) ||
|
||||
VelocityServer.getServer().getChannelRegistrar().registered(message.getChannel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
PluginMessage message;
|
||||
if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) {
|
||||
message = PluginMessageUtil.constructChannelsPacket("minecraft:register", VelocityServer.getServer().getChannelRegistrar().getModernChannelIds());
|
||||
} else {
|
||||
message = PluginMessageUtil.constructChannelsPacket("REGISTER", VelocityServer.getServer().getChannelRegistrar().getLegacyChannelIds());
|
||||
}
|
||||
player.getConnection().write(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MinecraftPacket packet) {
|
||||
if (packet instanceof KeepAlive) {
|
||||
@ -174,11 +185,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
serverBossBars.clear();
|
||||
|
||||
// Tell the server about this client's plugin messages. Velocity will forward them on to the client.
|
||||
if (!clientPluginMsgChannels.isEmpty()) {
|
||||
Collection<String> toRegister = new HashSet<>(clientPluginMsgChannels);
|
||||
if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) {
|
||||
toRegister.addAll(VelocityServer.getServer().getChannelRegistrar().getModernChannelIds());
|
||||
} else {
|
||||
toRegister.addAll(VelocityServer.getServer().getChannelRegistrar().getLegacyChannelIds());
|
||||
}
|
||||
if (!toRegister.isEmpty()) {
|
||||
String channel = player.getConnection().getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13 ?
|
||||
"minecraft:register" : "REGISTER";
|
||||
player.getConnectedServer().getMinecraftConnection().delayedWrite(
|
||||
PluginMessageUtil.constructChannelsPacket(channel, clientPluginMsgChannels));
|
||||
player.getConnectedServer().getMinecraftConnection().delayedWrite(PluginMessageUtil.constructChannelsPacket(
|
||||
channel, toRegister));
|
||||
}
|
||||
|
||||
// Flush everything
|
||||
|
@ -6,8 +6,10 @@ import com.velocitypowered.proxy.protocol.packet.PluginMessage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
private static final Logger logger = LogManager.getLogger(VelocityChannelRegistrar.class);
|
||||
@ -55,4 +57,22 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
identifierMap.remove(identifier.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getLegacyChannelIds() {
|
||||
return identifierMap.values().stream()
|
||||
.filter(i -> i instanceof LegacyChannelIdentifier)
|
||||
.map(ChannelIdentifier::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<String> getModernChannelIds() {
|
||||
return identifierMap.values().stream()
|
||||
.filter(i -> i instanceof MinecraftChannelIdentifier)
|
||||
.map(ChannelIdentifier::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean registered(String id) {
|
||||
return identifierMap.containsKey(id);
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren