13
0
geforkt von Mirrors/Velocity

Make changes based on PR comments

Dieser Commit ist enthalten in:
Alex Thomson 2018-10-11 10:41:40 +13:00
Ursprung c5a27bb135
Commit 245828e337
3 geänderte Dateien mit 28 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,9 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.util.ModInfo;
/**
* This event is fired when the players ModInfo is changed.
*/
public final class PlayerModInfoEvent {
private final Player player;
private final ModInfo modInfo;

Datei anzeigen

@ -145,9 +145,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getConnectedServer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
} else if (player.getConnectedServer().isLegacyForge() && !player.getConnectedServer().hasCompletedJoin()) {
if (packet.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
List<ModInfo.Mod> mods = PluginMessageUtil.readModList(packet);
if (!mods.isEmpty()) {
player.setModInfo(new ModInfo("FML", mods));
if (!player.getModInfo().isPresent()) {
PluginMessageUtil.readModList(packet).ifPresent(mods -> player.setModInfo(new ModInfo("FML", mods)));
}
// Always forward the FML handshake to the remote server.

Datei anzeigen

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.proxy.connection.VelocityConstants;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
@ -13,6 +14,7 @@ import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class PluginMessageUtil {
public static final String BRAND_CHANNEL_LEGACY = "MC|Brand";
@ -79,22 +81,31 @@ public class PluginMessageUtil {
return newMsg;
}
public static List<ModInfo.Mod> readModList(PluginMessage message) {
List<ModInfo.Mod> mods = Lists.newArrayList();
public static Optional<List<ModInfo.Mod>> readModList(PluginMessage message) {
Preconditions.checkNotNull(message, "message");
Preconditions.checkArgument(message.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL),
"message is not a FML HS plugin message");
ByteBuf byteBuf = Unpooled.wrappedBuffer(message.getData());
byte discriminator = byteBuf.readByte();
try {
byte discriminator = byteBuf.readByte();
if (discriminator == 2) {
int modCount = ProtocolUtils.readVarInt(byteBuf);
if (discriminator == 2) {
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder();
int modCount = ProtocolUtils.readVarInt(byteBuf);
for (int index = 0; index < modCount; index++) {
String id = ProtocolUtils.readString(byteBuf);
String version = ProtocolUtils.readString(byteBuf);
mods.add(new ModInfo.Mod(id, version));
for (int index = 0; index < modCount; index++) {
String id = ProtocolUtils.readString(byteBuf);
String version = ProtocolUtils.readString(byteBuf);
mods.add(new ModInfo.Mod(id, version));
}
return Optional.of(mods.build());
}
}
return ImmutableList.copyOf(mods);
return Optional.empty();
} finally {
byteBuf.release();
}
}
}