Appease checkstyle, minor cleanups, align defaults with paper

This commit is contained in:
Shane Freeder
2025-09-20 17:17:15 +01:00
parent 347972f34d
commit fd41d512da
4 changed files with 22 additions and 15 deletions

View File

@@ -998,22 +998,28 @@ public class VelocityConfiguration implements ProxyConfig {
}
}
/**
* Configuration for packet limiting.
*
* @param interval the interval in seconds to measure packets over
* @param pps the maximum number of packets per second allowed
* @param bytes the maximum number of bytes per second allowed
*/
/**
* Configuration for packet limiting.
*
* @param interval the interval in seconds to measure packets over
* @param pps the maximum number of packets per second allowed
* @param bytes the maximum number of bytes per second allowed
*/
public record PacketLimiterConfig(int interval, int pps, int bytes) {
public static PacketLimiterConfig DEFAULT = new PacketLimiterConfig(7, 500, -1);
/**
* returns a PacketLimiterConfig from a config section, or the default if the section is null.
*
* @param config the configuration object to parse
* @return the packet limiter config, or the default if {@code config} is null
*/
public static PacketLimiterConfig fromConfig(CommentedConfig config) {
if (config != null) {
return new PacketLimiterConfig(
config.getIntOrElse("interval", DEFAULT.interval()),
config.getIntOrElse("pps", DEFAULT.pps()),
config.getIntOrElse("bytes", DEFAULT.bytes())
config.getIntOrElse("packets-per-second", DEFAULT.pps()),
config.getIntOrElse("bytes-per-second", DEFAULT.bytes())
);
} else {
return DEFAULT;

View File

@@ -77,12 +77,12 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
VelocityConfiguration.PacketLimiterConfig packetLimiterConfig =
server.getConfiguration().getPacketLimiterConfig();
int configuredInterval = packetLimiterConfig.interval();
int configuredPPS = packetLimiterConfig.pps();
int configuredPacketsPerSecond = packetLimiterConfig.pps();
int configuredBytes = packetLimiterConfig.bytes();
if (configuredInterval > 0 && (configuredBytes > 0 || configuredPPS > 0)) {
if (configuredInterval > 0 && (configuredBytes > 0 || configuredPacketsPerSecond > 0)) {
ch.pipeline().get(MinecraftVarintFrameDecoder.class).setPacketLimiter(
new SimpleBytesPerSecondLimiter(configuredPPS, configuredBytes, configuredInterval)
new SimpleBytesPerSecondLimiter(configuredPacketsPerSecond, configuredBytes, configuredInterval)
);
}
if (this.server.getConfiguration().isProxyProtocol()) {

View File

@@ -30,6 +30,7 @@ package com.velocitypowered.proxy.util;
* <p>This class is not thread-safe. If multiple threads access an instance concurrently,
* external synchronization is required.</p>
*/
@SuppressWarnings("checkstyle:WhitespaceAfter") // Not our class
public final class IntervalledCounter {
private static final int INITIAL_SIZE = 8;

View File

@@ -75,9 +75,9 @@ sample-players-in-ping = false
enable-player-address-logging = true
[packet-limiter]
interval = 3000
pps = 100
bytes = 1000
interval = 7
packets-per-second = 500
bytes-per-second = -1
[servers]
# Configure your servers here. Each key represents the server's name, and the value