3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +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();
TextComponent copyright = TextComponent
.of("Copyright 2018 " + version.getVendor() + ". " + version.getName()
+ " is freely licensed under the terms of the " +
"MIT License.");
+ " is freely licensed under the terms of the MIT License.");
source.sendMessage(velocity);
source.sendMessage(copyright);

Datei anzeigen

@ -20,7 +20,7 @@ import org.apache.logging.log4j.LogManager;
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 {
@ -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)
@Target({ElementType.FIELD, ElementType.TYPE})
@ -41,7 +41,7 @@ public abstract class AnnotatedConfig {
}
/**
* Creates a comment
* Creates a comment.
*/
@Retention(RetentionPolicy.RUNTIME)
@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)
@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)
@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)
@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)
@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
*/
@ -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);
String name = safeKey(key == null ? field.getName()
: key.value()); // Use field name if @ConfigKey annotation is not present
final String name = safeKey(key == null ? field.getName() : key.value());
Object value = field.get(dumpable);
// Check if field is table.
Table table = field.getAnnotation(Table.class);
if (table != null) {
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;
}
if (field.getAnnotation(IsMap.class) != null) { // Check if field is a map
@SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) field.get(dumpable);
Map<String, ?> map = (Map<String, ?>) value;
for (Entry<String, ?> entry : map.entrySet()) {
lines.add(
safeKey(entry.getKey()) + " = " + serialize(entry.getValue())); // Save map data
@ -147,8 +148,6 @@ public abstract class AnnotatedConfig {
continue;
}
Object value = field.get(dumpable);
// Check if field is a byte[] representation of a string
if (field.getAnnotation(StringAsBytes.class) != null) {
value = new String((byte[]) value, StandardCharsets.UTF_8);

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -52,7 +52,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player;
private boolean spawned = false;
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 VelocityServer server;
private @Nullable TabCompleteRequest outstandingTabComplete;
@ -163,11 +163,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet);
for (String channel : channels) {
if (clientPluginMsgChannels.size() >= MAX_PLUGIN_CHANNELS &&
!clientPluginMsgChannels.contains(channel)) {
if (knownChannels.size() >= MAX_PLUGIN_CHANNELS &&
!knownChannels.contains(channel)) {
throw new IllegalStateException("Too many plugin message channels registered");
}
if (clientPluginMsgChannels.add(channel)) {
if (knownChannels.add(channel)) {
actuallyRegistered.add(channel);
}
}
@ -179,7 +179,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
}
} else if (PluginMessageUtil.isMCUnregister(packet)) {
List<String> channels = PluginMessageUtil.getChannels(packet);
clientPluginMsgChannels.removeAll(channels);
knownChannels.removeAll(channels);
backendConn.write(packet);
} else if (PluginMessageUtil.isMCBrand(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.
//
// The call will handle if the player is not a Forge player appropriately.
player.getConnection().setCanSendLegacyFMLResetPacket(true);
player.getConnection().setCanSendLegacyFmlResetPacket(true);
} else {
// Clear tab list to avoid duplicate entries
player.getTabList().clearAll();
@ -334,7 +334,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Tell the server about this client's plugin message channels.
int serverVersion = serverMc.getProtocolVersion();
Collection<String> toRegister = new HashSet<>(clientPluginMsgChannels);
Collection<String> toRegister = new HashSet<>(knownChannels);
if (serverVersion >= ProtocolConstants.MINECRAFT_1_13) {
toRegister.addAll(server.getChannelRegistrar().getModernChannelIds());
} 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.
//
// 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;
}
public Set<String> getClientPluginMsgChannels() {
return clientPluginMsgChannels;
public Set<String> getKnownChannels() {
return knownChannels;
}
public void handleTabCompleteResponse(TabCompleteResponse response) {

Datei anzeigen

@ -450,9 +450,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
}
public void sendLegacyForgeHandshakeResetPacket() {
if (connection.canSendLegacyFMLResetPacket()) {
if (connection.canSendLegacyFmlResetPacket()) {
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.Queue;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
public class PluginDependencyUtils {
@ -23,8 +22,15 @@ public class PluginDependencyUtils {
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.
MutableGraph<PluginDescription> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
Map<String, PluginDescription> candidateMap = Maps
@ -69,7 +75,7 @@ public class PluginDependencyUtils {
return sorted;
}
public static Queue<PluginDescription> getNoDependencyCandidates(Graph<PluginDescription> graph) {
private static Queue<PluginDescription> getNoDependencyCandidates(Graph<PluginDescription> graph) {
Queue<PluginDescription> found = new ArrayDeque<>();
for (PluginDescription node : graph.nodes()) {
@ -81,7 +87,7 @@ public class PluginDependencyUtils {
return found;
}
public static String createLoopInformation(Graph<PluginDescription> graph) {
private static String createLoopInformation(Graph<PluginDescription> graph) {
StringBuilder repr = new StringBuilder("{");
for (EndpointPair<PluginDescription> edge : graph.edges()) {
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 LOGIN_ID = 2;
public final PacketRegistry CLIENTBOUND = new PacketRegistry(
ProtocolConstants.Direction.CLIENTBOUND);
public final PacketRegistry SERVERBOUND = new PacketRegistry(
ProtocolConstants.Direction.SERVERBOUND);
public final PacketRegistry CLIENTBOUND = new PacketRegistry(Direction.CLIENTBOUND);
public final PacketRegistry SERVERBOUND = new PacketRegistry(Direction.SERVERBOUND);
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));
}
private final ProtocolConstants.Direction direction;
private final Direction direction;
private final IntObjectMap<ProtocolVersion> versions = new IntObjectHashMap<>(16);
private boolean fallback = true;
public PacketRegistry(Direction direction) {
PacketRegistry(Direction direction) {
this.direction = direction;
ProtocolConstants.SUPPORTED_VERSIONS
.forEach(version -> versions.put(version, new ProtocolVersion(version)));
@ -267,10 +265,10 @@ public enum StateRegistry {
public class ProtocolVersion {
public final int version;
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier = new IntObjectHashMap<>(
16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId = new Object2IntOpenHashMap<>(
16, 0.5f);
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier =
new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId =
new Object2IntOpenHashMap<>(16, 0.5f);
ProtocolVersion(final int version) {
this.version = version;
@ -312,11 +310,11 @@ public enum StateRegistry {
@Override
public String toString() {
return "PacketMapping{" +
"id=" + id +
", protocolVersion=" + protocolVersion +
", encodeOnly=" + encodeOnly +
'}';
return "PacketMapping{"
+ "id=" + id
+ ", protocolVersion=" + protocolVersion
+ ", encodeOnly=" + encodeOnly
+ '}';
}
@Override
@ -328,9 +326,9 @@ public enum StateRegistry {
return false;
}
PacketMapping that = (PacketMapping) o;
return id == that.id &&
protocolVersion == that.protocolVersion &&
encodeOnly == that.encodeOnly;
return id == that.id
&& protocolVersion == that.protocolVersion
&& encodeOnly == that.encodeOnly;
}
@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 version Protocol version

Datei anzeigen

@ -31,8 +31,8 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
}
Preconditions.checkState(uncompressedSize >= threshold,
"Uncompressed size %s doesn't make sense with threshold %s", uncompressedSize, threshold);
// Try to use the uncompressed size, but place a cap if it might be too big (possibly malicious).
"Uncompressed size %s is greater than threshold %s",
uncompressedSize, threshold);
ByteBuf uncompressed = ctx.alloc()
.buffer(Math.min(uncompressedSize, MAXIMUM_INITIAL_BUFFER_SIZE));
try {
@ -41,7 +41,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
"Mismatched compression sizes");
out.add(uncompressed);
} catch (Exception e) {
// If something went wrong, rethrow the exception, but ensure we free our temporary buffer first.
uncompressed.release();
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_B = new Object();
public 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_A = new FakePluginContainer("a", PLUGIN_A);
private static final PluginContainer PC_B = new FakePluginContainer("b", PLUGIN_B);
@Override
public @NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance) {