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.proxy.Player;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
/**
* This event is fired when the players ModInfo is changed.
*/
public final class PlayerModInfoEvent { public final class PlayerModInfoEvent {
private final Player player; private final Player player;
private final ModInfo modInfo; private final ModInfo modInfo;

Datei anzeigen

@ -145,9 +145,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getConnectedServer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet)); player.getConnectedServer().getConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
} else if (player.getConnectedServer().isLegacyForge() && !player.getConnectedServer().hasCompletedJoin()) { } else if (player.getConnectedServer().isLegacyForge() && !player.getConnectedServer().hasCompletedJoin()) {
if (packet.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) { if (packet.getChannel().equals(VelocityConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
List<ModInfo.Mod> mods = PluginMessageUtil.readModList(packet); if (!player.getModInfo().isPresent()) {
if (!mods.isEmpty()) { PluginMessageUtil.readModList(packet).ifPresent(mods -> player.setModInfo(new ModInfo("FML", mods)));
player.setModInfo(new ModInfo("FML", mods));
} }
// Always forward the FML handshake to the remote server. // 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.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.proxy.connection.VelocityConstants;
import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessage;
@ -13,6 +14,7 @@ import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional;
public class PluginMessageUtil { public class PluginMessageUtil {
public static final String BRAND_CHANNEL_LEGACY = "MC|Brand"; public static final String BRAND_CHANNEL_LEGACY = "MC|Brand";
@ -79,13 +81,17 @@ public class PluginMessageUtil {
return newMsg; return newMsg;
} }
public static List<ModInfo.Mod> readModList(PluginMessage message) { public static Optional<List<ModInfo.Mod>> readModList(PluginMessage message) {
List<ModInfo.Mod> mods = Lists.newArrayList(); 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()); ByteBuf byteBuf = Unpooled.wrappedBuffer(message.getData());
try {
byte discriminator = byteBuf.readByte(); byte discriminator = byteBuf.readByte();
if (discriminator == 2) { if (discriminator == 2) {
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder();
int modCount = ProtocolUtils.readVarInt(byteBuf); int modCount = ProtocolUtils.readVarInt(byteBuf);
for (int index = 0; index < modCount; index++) { for (int index = 0; index < modCount; index++) {
@ -93,8 +99,13 @@ public class PluginMessageUtil {
String version = ProtocolUtils.readString(byteBuf); String version = ProtocolUtils.readString(byteBuf);
mods.add(new ModInfo.Mod(id, version)); mods.add(new ModInfo.Mod(id, version));
} }
return Optional.of(mods.build());
} }
return ImmutableList.copyOf(mods); return Optional.empty();
} finally {
byteBuf.release();
}
} }
} }