3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

More Checkstyle.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-10-28 02:36:03 -04:00
Ursprung 64380de497
Commit 9806d57a13
13 geänderte Dateien mit 94 neuen und 92 gelöschten Zeilen

Datei anzeigen

@ -104,8 +104,7 @@ public class VelocityCommand implements Command {
.build(); .build();
TextComponent copyright = TextComponent TextComponent copyright = TextComponent
.of("Copyright 2018 " + version.getVendor() + ". " + version.getName() .of("Copyright 2018 " + version.getVendor() + ". " + version.getName()
+ " is freely licensed under the terms of the " + + " is freely licensed under the terms of the MIT License.");
"MIT License.");
source.sendMessage(velocity); source.sendMessage(velocity);
source.sendMessage(copyright); source.sendMessage(copyright);

Datei anzeigen

@ -20,7 +20,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
/** /**
* Simple annotation and fields based TOML configuration serializer * Simple annotation and fields based TOML configuration serializer.
*/ */
public abstract class AnnotatedConfig { public abstract class AnnotatedConfig {
@ -31,7 +31,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Indicates that a field is a table * Indicates that a field is a table.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@ -41,7 +41,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Creates a comment * Creates a comment.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@ -51,7 +51,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* How field will be named in config * How field will be named in config.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@ -61,7 +61,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Indicates that a field is a map and we need to save all map data to config * Indicates that a field is a map and we need to save all map data to config.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@ -70,7 +70,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Indicates that a field is a string converted to byte[] * Indicates that a field is a string converted to byte[].
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
@ -79,7 +79,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Indicates that a field should be skipped * Indicates that a field should be skipped.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD}) @Target({ElementType.FIELD})
@ -88,7 +88,7 @@ public abstract class AnnotatedConfig {
} }
/** /**
* Dumps this configuration to list of strings using {@link #dumpConfig(Object)} * Dumps this configuration to list of strings using {@link #dumpConfig(Object)}.
* *
* @return configuration dump * @return configuration dump
*/ */
@ -123,22 +123,23 @@ public abstract class AnnotatedConfig {
} }
} }
// Get a key name for config // Get a key name for config. Use field name if @ConfigKey annotation is not present.
ConfigKey key = field.getAnnotation(ConfigKey.class); ConfigKey key = field.getAnnotation(ConfigKey.class);
String name = safeKey(key == null ? field.getName() final String name = safeKey(key == null ? field.getName() : key.value());
: key.value()); // Use field name if @ConfigKey annotation is not present
Object value = field.get(dumpable);
// Check if field is table. // Check if field is table.
Table table = field.getAnnotation(Table.class); Table table = field.getAnnotation(Table.class);
if (table != null) { if (table != null) {
lines.add(table.value()); // Write [name] lines.add(table.value()); // Write [name]
lines.addAll(dumpConfig(field.get(dumpable))); // Dump fields of table lines.addAll(dumpConfig(value)); // Dump fields of table
continue; continue;
} }
if (field.getAnnotation(IsMap.class) != null) { // Check if field is a map if (field.getAnnotation(IsMap.class) != null) { // Check if field is a map
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) field.get(dumpable); Map<String, ?> map = (Map<String, ?>) value;
for (Entry<String, ?> entry : map.entrySet()) { for (Entry<String, ?> entry : map.entrySet()) {
lines.add( lines.add(
safeKey(entry.getKey()) + " = " + serialize(entry.getValue())); // Save map data safeKey(entry.getKey()) + " = " + serialize(entry.getValue())); // Save map data
@ -147,8 +148,6 @@ public abstract class AnnotatedConfig {
continue; continue;
} }
Object value = field.get(dumpable);
// Check if field is a byte[] representation of a string // Check if field is a byte[] representation of a string
if (field.getAnnotation(StringAsBytes.class) != null) { if (field.getAnnotation(StringAsBytes.class) != null) {
value = new String((byte[]) value, StandardCharsets.UTF_8); value = new String((byte[]) value, StandardCharsets.UTF_8);

Datei anzeigen

@ -522,9 +522,9 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
@Override @Override
public String toString() { public String toString() {
return "ForcedHosts{" + return "ForcedHosts{"
"forcedHosts=" + forcedHosts + + "forcedHosts=" + forcedHosts
'}'; + '}';
} }
} }
@ -601,14 +601,14 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
@Override @Override
public String toString() { public String toString() {
return "Advanced{" + return "Advanced{"
"compressionThreshold=" + compressionThreshold + + "compressionThreshold=" + compressionThreshold
", compressionLevel=" + compressionLevel + + ", compressionLevel=" + compressionLevel
", loginRatelimit=" + loginRatelimit + + ", loginRatelimit=" + loginRatelimit
", connectionTimeout=" + connectionTimeout + + ", connectionTimeout=" + connectionTimeout
", readTimeout=" + readTimeout + + ", readTimeout=" + readTimeout
", proxyProtocol=" + proxyProtocol + + ", proxyProtocol=" + proxyProtocol
'}'; + '}';
} }
} }
@ -667,12 +667,12 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
@Override @Override
public String toString() { public String toString() {
return "Query{" + return "Query{"
"queryEnabled=" + queryEnabled + + "queryEnabled=" + queryEnabled
", queryPort=" + queryPort + + ", queryPort=" + queryPort
", queryMap='" + queryMap + '\'' + + ", queryMap='" + queryMap + '\''
", showPlugins=" + showPlugins + + ", showPlugins=" + showPlugins
'}'; + '}';
} }
} }
} }

Datei anzeigen

@ -58,7 +58,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
private @Nullable MinecraftConnectionAssociation association; private @Nullable MinecraftConnectionAssociation association;
private boolean isLegacyForge; private boolean isLegacyForge;
private final VelocityServer server; private final VelocityServer server;
private boolean canSendLegacyFMLResetPacket = false; private boolean canSendLegacyFmlResetPacket = false;
public MinecraftConnection(Channel channel, VelocityServer server) { public MinecraftConnection(Channel channel, VelocityServer server) {
this.channel = channel; this.channel = channel;
@ -287,12 +287,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
this.isLegacyForge = isForge; this.isLegacyForge = isForge;
} }
public boolean canSendLegacyFMLResetPacket() { public boolean canSendLegacyFmlResetPacket() {
return canSendLegacyFMLResetPacket; return canSendLegacyFmlResetPacket;
} }
public void setCanSendLegacyFMLResetPacket(boolean canSendLegacyFMLResetPacket) { public void setCanSendLegacyFmlResetPacket(boolean canSendLegacyFMLResetPacket) {
this.canSendLegacyFMLResetPacket = isLegacyForge && canSendLegacyFMLResetPacket; this.canSendLegacyFmlResetPacket = isLegacyForge && canSendLegacyFMLResetPacket;
} }
public int getNextProtocolVersion() { public int getNextProtocolVersion() {

Datei anzeigen

@ -173,16 +173,16 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
if (mc == null) { if (mc == null) {
return false; return false;
} }
boolean isMCOrFMLMessage; boolean minecraftOrFmlMessage;
if (mc.getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) { if (mc.getProtocolVersion() <= ProtocolConstants.MINECRAFT_1_12_2) {
String channel = message.getChannel(); String channel = message.getChannel();
isMCOrFMLMessage = channel.startsWith("MC|") || channel minecraftOrFmlMessage = channel.startsWith("MC|") || channel
.startsWith(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL); .startsWith(ForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL);
} else { } else {
isMCOrFMLMessage = message.getChannel().startsWith("minecraft:"); minecraftOrFmlMessage = message.getChannel().startsWith("minecraft:");
} }
return isMCOrFMLMessage || playerSessionHandler.getClientPluginMsgChannels() return minecraftOrFmlMessage
.contains(message.getChannel()) || || playerSessionHandler.getKnownChannels().contains(message.getChannel())
server.getChannelRegistrar().registered(message.getChannel()); || server.getChannelRegistrar().registered(message.getChannel());
} }
} }

Datei anzeigen

@ -32,6 +32,9 @@ import net.kyori.text.TextComponent;
public class LoginSessionHandler implements MinecraftSessionHandler { public class LoginSessionHandler implements MinecraftSessionHandler {
private static final TextComponent MODERN_IP_FORWARDING_FAILURE = TextComponent
.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?");
private final VelocityServer server; private final VelocityServer server;
private final VelocityServerConnection serverConn; private final VelocityServerConnection serverConn;
private final CompletableFuture<ConnectionRequestBuilder.Result> resultFuture; private final CompletableFuture<ConnectionRequestBuilder.Result> resultFuture;
@ -100,9 +103,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
public boolean handle(ServerLoginSuccess packet) { public boolean handle(ServerLoginSuccess packet) {
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& !informationForwarded) { && !informationForwarded) {
resultFuture.complete(ConnectionRequestResults.forDisconnect( resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE));
TextComponent
.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?")));
serverConn.disconnect(); serverConn.disconnect();
return true; return true;
} }

Datei anzeigen

@ -198,7 +198,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
return legacyForge; return legacyForge;
} }
public void setLegacyForge(boolean modded) { void setLegacyForge(boolean modded) {
legacyForge = modded; legacyForge = modded;
} }
@ -210,7 +210,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
this.hasCompletedJoin = hasCompletedJoin; this.hasCompletedJoin = hasCompletedJoin;
} }
public boolean isGracefulDisconnect() { boolean isGracefulDisconnect() {
return gracefulDisconnect; return gracefulDisconnect;
} }
@ -222,7 +222,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
return lastPingSent; return lastPingSent;
} }
public void setLastPingId(long lastPingId) { void setLastPingId(long lastPingId) {
this.lastPingId = lastPingId; this.lastPingId = lastPingId;
this.lastPingSent = System.currentTimeMillis(); this.lastPingSent = System.currentTimeMillis();
} }

Datei anzeigen

@ -52,7 +52,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player; private final ConnectedPlayer player;
private boolean spawned = false; private boolean spawned = false;
private final List<UUID> serverBossBars = new ArrayList<>(); private final List<UUID> serverBossBars = new ArrayList<>();
private final Set<String> clientPluginMsgChannels = new HashSet<>(); private final Set<String> knownChannels = new HashSet<>();
private final Queue<PluginMessage> loginPluginMessages = new ArrayDeque<>(); private final Queue<PluginMessage> loginPluginMessages = new ArrayDeque<>();
private final VelocityServer server; private final VelocityServer server;
private @Nullable TabCompleteRequest outstandingTabComplete; private @Nullable TabCompleteRequest outstandingTabComplete;
@ -163,11 +163,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
List<String> actuallyRegistered = new ArrayList<>(); List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet); List<String> channels = PluginMessageUtil.getChannels(packet);
for (String channel : channels) { for (String channel : channels) {
if (clientPluginMsgChannels.size() >= MAX_PLUGIN_CHANNELS && if (knownChannels.size() >= MAX_PLUGIN_CHANNELS &&
!clientPluginMsgChannels.contains(channel)) { !knownChannels.contains(channel)) {
throw new IllegalStateException("Too many plugin message channels registered"); throw new IllegalStateException("Too many plugin message channels registered");
} }
if (clientPluginMsgChannels.add(channel)) { if (knownChannels.add(channel)) {
actuallyRegistered.add(channel); actuallyRegistered.add(channel);
} }
} }
@ -179,7 +179,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
} else if (PluginMessageUtil.isMCUnregister(packet)) { } else if (PluginMessageUtil.isMCUnregister(packet)) {
List<String> channels = PluginMessageUtil.getChannels(packet); List<String> channels = PluginMessageUtil.getChannels(packet);
clientPluginMsgChannels.removeAll(channels); knownChannels.removeAll(channels);
backendConn.write(packet); backendConn.write(packet);
} else if (PluginMessageUtil.isMCBrand(packet)) { } else if (PluginMessageUtil.isMCBrand(packet)) {
backendConn.write(PluginMessageUtil.rewriteMinecraftBrand(packet)); backendConn.write(PluginMessageUtil.rewriteMinecraftBrand(packet));
@ -296,7 +296,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Forge client that we must reset on the next switch. // Forge client that we must reset on the next switch.
// //
// The call will handle if the player is not a Forge player appropriately. // The call will handle if the player is not a Forge player appropriately.
player.getConnection().setCanSendLegacyFMLResetPacket(true); player.getConnection().setCanSendLegacyFmlResetPacket(true);
} else { } else {
// Clear tab list to avoid duplicate entries // Clear tab list to avoid duplicate entries
player.getTabList().clearAll(); player.getTabList().clearAll();
@ -334,7 +334,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Tell the server about this client's plugin message channels. // Tell the server about this client's plugin message channels.
int serverVersion = serverMc.getProtocolVersion(); int serverVersion = serverMc.getProtocolVersion();
Collection<String> toRegister = new HashSet<>(clientPluginMsgChannels); Collection<String> toRegister = new HashSet<>(knownChannels);
if (serverVersion >= ProtocolConstants.MINECRAFT_1_13) { if (serverVersion >= ProtocolConstants.MINECRAFT_1_13) {
toRegister.addAll(server.getChannelRegistrar().getModernChannelIds()); toRegister.addAll(server.getChannelRegistrar().getModernChannelIds());
} else { } else {
@ -370,7 +370,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// don't want to set it false if this is a first connection to a Vanilla server. // don't want to set it false if this is a first connection to a Vanilla server.
// //
// See LoginSessionHandler#handle for where the counterpart to this method is // See LoginSessionHandler#handle for where the counterpart to this method is
player.getConnection().setCanSendLegacyFMLResetPacket(true); player.getConnection().setCanSendLegacyFmlResetPacket(true);
} }
} }
@ -378,8 +378,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
return serverBossBars; return serverBossBars;
} }
public Set<String> getClientPluginMsgChannels() { public Set<String> getKnownChannels() {
return clientPluginMsgChannels; return knownChannels;
} }
public void handleTabCompleteResponse(TabCompleteResponse response) { public void handleTabCompleteResponse(TabCompleteResponse response) {

Datei anzeigen

@ -450,9 +450,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
public void sendLegacyForgeHandshakeResetPacket() { public void sendLegacyForgeHandshakeResetPacket() {
if (connection.canSendLegacyFMLResetPacket()) { if (connection.canSendLegacyFmlResetPacket()) {
connection.write(ForgeConstants.resetPacket()); connection.write(ForgeConstants.resetPacket());
connection.setCanSendLegacyFMLResetPacket(false); connection.setCanSendLegacyFmlResetPacket(false);
} }
} }

Datei anzeigen

@ -15,7 +15,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
public class PluginDependencyUtils { public class PluginDependencyUtils {
@ -23,8 +22,15 @@ public class PluginDependencyUtils {
throw new AssertionError(); throw new AssertionError();
} }
public static List<PluginDescription> sortCandidates( /**
List<@NonNull PluginDescription> candidates) { * Attempts to topographically sort all plugins for the proxy to load by dependencies using
* Kahn's algorithm.
*
* @param candidates the plugins to sort
* @return the sorted list of plugins
* @throws IllegalStateException if there is a circular loop in the dependency graph
*/
public static List<PluginDescription> sortCandidates(List<PluginDescription> candidates) {
// Create our graph, we're going to be using this for Kahn's algorithm. // Create our graph, we're going to be using this for Kahn's algorithm.
MutableGraph<PluginDescription> graph = GraphBuilder.directed().allowsSelfLoops(false).build(); MutableGraph<PluginDescription> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
Map<String, PluginDescription> candidateMap = Maps Map<String, PluginDescription> candidateMap = Maps
@ -69,7 +75,7 @@ public class PluginDependencyUtils {
return sorted; return sorted;
} }
public static Queue<PluginDescription> getNoDependencyCandidates(Graph<PluginDescription> graph) { private static Queue<PluginDescription> getNoDependencyCandidates(Graph<PluginDescription> graph) {
Queue<PluginDescription> found = new ArrayDeque<>(); Queue<PluginDescription> found = new ArrayDeque<>();
for (PluginDescription node : graph.nodes()) { for (PluginDescription node : graph.nodes()) {
@ -81,7 +87,7 @@ public class PluginDependencyUtils {
return found; return found;
} }
public static String createLoopInformation(Graph<PluginDescription> graph) { private static String createLoopInformation(Graph<PluginDescription> graph) {
StringBuilder repr = new StringBuilder("{"); StringBuilder repr = new StringBuilder("{");
for (EndpointPair<PluginDescription> edge : graph.edges()) { for (EndpointPair<PluginDescription> edge : graph.edges()) {
repr.append(edge.target().getId()).append(": ["); repr.append(edge.target().getId()).append(": [");

Datei anzeigen

@ -190,10 +190,8 @@ public enum StateRegistry {
public static final int STATUS_ID = 1; public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2; public static final int LOGIN_ID = 2;
public final PacketRegistry CLIENTBOUND = new PacketRegistry( public final PacketRegistry CLIENTBOUND = new PacketRegistry(Direction.CLIENTBOUND);
ProtocolConstants.Direction.CLIENTBOUND); public final PacketRegistry SERVERBOUND = new PacketRegistry(Direction.SERVERBOUND);
public final PacketRegistry SERVERBOUND = new PacketRegistry(
ProtocolConstants.Direction.SERVERBOUND);
public static class PacketRegistry { public static class PacketRegistry {
@ -210,11 +208,11 @@ public enum StateRegistry {
.put(MINECRAFT_1_13, ImmutableIntArray.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2)); .put(MINECRAFT_1_13, ImmutableIntArray.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2));
} }
private final ProtocolConstants.Direction direction; private final Direction direction;
private final IntObjectMap<ProtocolVersion> versions = new IntObjectHashMap<>(16); private final IntObjectMap<ProtocolVersion> versions = new IntObjectHashMap<>(16);
private boolean fallback = true; private boolean fallback = true;
public PacketRegistry(Direction direction) { PacketRegistry(Direction direction) {
this.direction = direction; this.direction = direction;
ProtocolConstants.SUPPORTED_VERSIONS ProtocolConstants.SUPPORTED_VERSIONS
.forEach(version -> versions.put(version, new ProtocolVersion(version))); .forEach(version -> versions.put(version, new ProtocolVersion(version)));
@ -267,10 +265,10 @@ public enum StateRegistry {
public class ProtocolVersion { public class ProtocolVersion {
public final int version; public final int version;
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier = new IntObjectHashMap<>( final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier =
16, 0.5f); new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId = new Object2IntOpenHashMap<>( final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId =
16, 0.5f); new Object2IntOpenHashMap<>(16, 0.5f);
ProtocolVersion(final int version) { ProtocolVersion(final int version) {
this.version = version; this.version = version;
@ -312,11 +310,11 @@ public enum StateRegistry {
@Override @Override
public String toString() { public String toString() {
return "PacketMapping{" + return "PacketMapping{"
"id=" + id + + "id=" + id
", protocolVersion=" + protocolVersion + + ", protocolVersion=" + protocolVersion
", encodeOnly=" + encodeOnly + + ", encodeOnly=" + encodeOnly
'}'; + '}';
} }
@Override @Override
@ -328,9 +326,9 @@ public enum StateRegistry {
return false; return false;
} }
PacketMapping that = (PacketMapping) o; PacketMapping that = (PacketMapping) o;
return id == that.id && return id == that.id
protocolVersion == that.protocolVersion && && protocolVersion == that.protocolVersion
encodeOnly == that.encodeOnly; && encodeOnly == that.encodeOnly;
} }
@Override @Override
@ -340,7 +338,7 @@ public enum StateRegistry {
} }
/** /**
* Creates a PacketMapping using the provided arguments * Creates a PacketMapping using the provided arguments.
* *
* @param id Packet Id * @param id Packet Id
* @param version Protocol version * @param version Protocol version

Datei anzeigen

@ -31,8 +31,8 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
} }
Preconditions.checkState(uncompressedSize >= threshold, Preconditions.checkState(uncompressedSize >= threshold,
"Uncompressed size %s doesn't make sense with threshold %s", uncompressedSize, threshold); "Uncompressed size %s is greater than threshold %s",
// Try to use the uncompressed size, but place a cap if it might be too big (possibly malicious). uncompressedSize, threshold);
ByteBuf uncompressed = ctx.alloc() ByteBuf uncompressed = ctx.alloc()
.buffer(Math.min(uncompressedSize, MAXIMUM_INITIAL_BUFFER_SIZE)); .buffer(Math.min(uncompressedSize, MAXIMUM_INITIAL_BUFFER_SIZE));
try { try {
@ -41,7 +41,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
"Mismatched compression sizes"); "Mismatched compression sizes");
out.add(uncompressed); out.add(uncompressed);
} catch (Exception e) { } catch (Exception e) {
// If something went wrong, rethrow the exception, but ensure we free our temporary buffer first.
uncompressed.release(); uncompressed.release();
throw e; throw e;
} }

Datei anzeigen

@ -14,8 +14,8 @@ public class FakePluginManager implements PluginManager {
public static final Object PLUGIN_A = new Object(); public static final Object PLUGIN_A = new Object();
public static final Object PLUGIN_B = new Object(); public static final Object PLUGIN_B = new Object();
public static final PluginContainer PC_A = new FakePluginContainer("a", PLUGIN_A); private static final PluginContainer PC_A = new FakePluginContainer("a", PLUGIN_A);
public static final PluginContainer PC_B = new FakePluginContainer("b", PLUGIN_B); private static final PluginContainer PC_B = new FakePluginContainer("b", PLUGIN_B);
@Override @Override
public @NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance) { public @NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance) {