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

@@ -1008,12 +1008,18 @@ public class VelocityConfiguration implements ProxyConfig {
public record PacketLimiterConfig(int interval, int pps, int bytes) { public record PacketLimiterConfig(int interval, int pps, int bytes) {
public static PacketLimiterConfig DEFAULT = new PacketLimiterConfig(7, 500, -1); 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) { public static PacketLimiterConfig fromConfig(CommentedConfig config) {
if (config != null) { if (config != null) {
return new PacketLimiterConfig( return new PacketLimiterConfig(
config.getIntOrElse("interval", DEFAULT.interval()), config.getIntOrElse("interval", DEFAULT.interval()),
config.getIntOrElse("pps", DEFAULT.pps()), config.getIntOrElse("packets-per-second", DEFAULT.pps()),
config.getIntOrElse("bytes", DEFAULT.bytes()) config.getIntOrElse("bytes-per-second", DEFAULT.bytes())
); );
} else { } else {
return DEFAULT; return DEFAULT;

View File

@@ -77,12 +77,12 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
VelocityConfiguration.PacketLimiterConfig packetLimiterConfig = VelocityConfiguration.PacketLimiterConfig packetLimiterConfig =
server.getConfiguration().getPacketLimiterConfig(); server.getConfiguration().getPacketLimiterConfig();
int configuredInterval = packetLimiterConfig.interval(); int configuredInterval = packetLimiterConfig.interval();
int configuredPPS = packetLimiterConfig.pps(); int configuredPacketsPerSecond = packetLimiterConfig.pps();
int configuredBytes = packetLimiterConfig.bytes(); int configuredBytes = packetLimiterConfig.bytes();
if (configuredInterval > 0 && (configuredBytes > 0 || configuredPPS > 0)) { if (configuredInterval > 0 && (configuredBytes > 0 || configuredPacketsPerSecond > 0)) {
ch.pipeline().get(MinecraftVarintFrameDecoder.class).setPacketLimiter( ch.pipeline().get(MinecraftVarintFrameDecoder.class).setPacketLimiter(
new SimpleBytesPerSecondLimiter(configuredPPS, configuredBytes, configuredInterval) new SimpleBytesPerSecondLimiter(configuredPacketsPerSecond, configuredBytes, configuredInterval)
); );
} }
if (this.server.getConfiguration().isProxyProtocol()) { 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, * <p>This class is not thread-safe. If multiple threads access an instance concurrently,
* external synchronization is required.</p> * external synchronization is required.</p>
*/ */
@SuppressWarnings("checkstyle:WhitespaceAfter") // Not our class
public final class IntervalledCounter { public final class IntervalledCounter {
private static final int INITIAL_SIZE = 8; private static final int INITIAL_SIZE = 8;

View File

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