Skip to content

Commit 1661cec

Browse files
authored
An Easter basket bearing gifts! (PaperMC#191)
* Delay switch to new server until after JoinGame is sent. Unfortunately, in some cases (especially vanilla Minecraft) some login disconnects are sent after ServerLoginSuccess but before JoinGame. We've been using ServerLoginSuccess but it has caused too many problems. Now Velocity will switch to a stripped-down version of the play session handler until JoinGame is received. This handler does very little by itself: it simply forwards plugin messages (for Forge) and waits for the JoinGame packet from the server. This is an initial version: only vanilla Minecraft 1.12.2 was tested. However this is the way Waterfall without entity rewriting does server switches (which, in turn, is inherited from BungeeCord). * Move to Gradle 5 and Error Prone.
1 parent c8e33ee commit 1661cec

35 files changed

+475
-309
lines changed

api/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ plugins {
22
id 'java'
33
id 'maven-publish'
44
id 'checkstyle'
5+
id "net.ltgt.errorprone" version "0.8"
56
}
67

7-
apply from: '../gradle/checkerframework.gradle'
88
apply from: '../gradle/checkstyle.gradle'
9+
apply from: '../gradle/errorprone.gradle'
910
apply plugin: 'com.github.johnrengelman.shadow'
1011

1112
sourceSets {

api/src/ap/java/com/velocitypowered/api/plugin/ap/PluginAnnotationProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public SourceVersion getSupportedSourceVersion() {
3838
}
3939

4040
@Override
41-
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
41+
public synchronized boolean process(Set<? extends TypeElement> annotations,
42+
RoundEnvironment roundEnv) {
4243
if (roundEnv.processingOver()) {
4344
return false;
4445
}

api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.stream.Collectors;
1313
import org.checkerframework.checker.nullness.qual.Nullable;
1414

15-
public class SerializedPluginDescription {
15+
public final class SerializedPluginDescription {
1616

1717
public static final Pattern ID_PATTERN = Pattern.compile("[a-z][a-z0-9-_]{0,63}");
1818

@@ -123,7 +123,7 @@ public String toString() {
123123
+ '}';
124124
}
125125

126-
public static class Dependency {
126+
public static final class Dependency {
127127

128128
private final String id;
129129
private final boolean optional;

api/src/main/java/com/velocitypowered/api/proxy/Player.java

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
7070
*
7171
* @param component the chat message to send
7272
*/
73+
@Override
7374
default void sendMessage(Component component) {
7475
sendMessage(component, MessagePosition.CHAT);
7576
}

api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.annotations.VisibleForTesting;
44
import com.google.common.base.MoreObjects;
55
import com.google.common.base.Preconditions;
6+
import com.google.common.collect.ImmutableCollection;
67
import com.google.common.collect.ImmutableList;
78
import com.velocitypowered.api.proxy.config.ProxyConfig;
89
import java.util.ArrayList;
@@ -26,14 +27,14 @@ public final class QueryResponse {
2627
private final int maxPlayers;
2728
private final String proxyHost;
2829
private final int proxyPort;
29-
private final Collection<String> players;
30+
private final ImmutableCollection<String> players;
3031
private final String proxyVersion;
31-
private final Collection<PluginInformation> plugins;
32+
private final ImmutableCollection<PluginInformation> plugins;
3233

3334
@VisibleForTesting
3435
QueryResponse(String hostname, String gameVersion, String map, int currentPlayers,
35-
int maxPlayers, String proxyHost, int proxyPort, Collection<String> players,
36-
String proxyVersion, Collection<PluginInformation> plugins) {
36+
int maxPlayers, String proxyHost, int proxyPort, ImmutableCollection<String> players,
37+
String proxyVersion, ImmutableCollection<PluginInformation> plugins) {
3738
this.hostname = hostname;
3839
this.gameVersion = gameVersion;
3940
this.map = map;
@@ -403,7 +404,7 @@ public QueryResponse build() {
403404
/**
404405
* Represents a plugin in the query response.
405406
*/
406-
public static class PluginInformation {
407+
public static final class PluginInformation {
407408

408409
private final String name;
409410
private final @Nullable String version;

gradle/checkerframework.gradle

-70
This file was deleted.

gradle/errorprone.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dependencies {
2+
errorprone("com.google.errorprone:error_prone_core:2.3.3")
3+
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
4+
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip

native/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
plugins {
22
id 'java'
33
id 'checkstyle'
4+
id "net.ltgt.errorprone" version "0.8"
45
}
56

6-
apply from: '../gradle/checkerframework.gradle'
77
apply from: '../gradle/checkstyle.gradle'
8+
apply from: '../gradle/errorprone.gradle'
89

910
dependencies {
1011
compile "com.google.guava:guava:${guavaVersion}"

native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class NativeConstraints {
2121
return NATIVES_ENABLED
2222
&& CAN_GET_MEMORYADDRESS
2323
&& System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X")
24-
&& System.getProperty("os.arch").equals("x86_64");
24+
&& System.getProperty("os.arch", "").equals("x86_64");
2525
};
2626

2727
static final BooleanSupplier LINUX = () -> {
2828
return NATIVES_ENABLED
2929
&& CAN_GET_MEMORYADDRESS
3030
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
31-
&& System.getProperty("os.arch").equals("amd64");
31+
&& System.getProperty("os.arch", "").equals("amd64");
3232
};
3333
}

proxy/build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
2+
13
plugins {
24
id 'java'
35
id 'checkstyle'
6+
id "net.ltgt.errorprone" version "0.8"
47
}
58

6-
apply from: '../gradle/checkerframework.gradle'
79
apply from: '../gradle/checkstyle.gradle'
10+
apply from: '../gradle/errorprone.gradle'
811
apply plugin: 'com.github.johnrengelman.shadow'
912

1013
jar {
@@ -20,7 +23,7 @@ jar {
2023
}
2124

2225
shadowJar {
23-
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer)
26+
transform(Log4j2PluginsCacheFileTransformer)
2427
}
2528

2629
tasks.withType(Checkstyle) {

proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public KeyPair getServerKeyPair() {
109109
return ensureInitialized(serverKeyPair);
110110
}
111111

112+
@Override
112113
public VelocityConfiguration getConfiguration() {
113114
return ensureInitialized(this.configuration);
114115
}

proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public List<String> offerSuggestions(CommandSource source, String cmdLine) {
9393
String alias = split[0];
9494
if (split.length == 1) {
9595
// Offer to fill in commands.
96-
List<String> availableCommands = new ArrayList<>();
96+
ImmutableList.Builder<String> availableCommands = ImmutableList.builder();
9797
for (Map.Entry<String, Command> entry : commands.entrySet()) {
9898
if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length())
9999
&& entry.getValue().hasPermission(source, new String[0])) {
100100
availableCommands.add("/" + entry.getKey());
101101
}
102102
}
103-
return availableCommands;
103+
return availableCommands.build();
104104
}
105105

106106
Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
@@ -116,7 +116,7 @@ public List<String> offerSuggestions(CommandSource source, String cmdLine) {
116116
return ImmutableList.of();
117117
}
118118

119-
return command.suggest(source, actualArgs);
119+
return ImmutableList.copyOf(command.suggest(source, actualArgs));
120120
} catch (Exception e) {
121121
throw new RuntimeException(
122122
"Unable to invoke suggestions for command " + alias + " for " + source, e);

proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@ public InetSocketAddress getBind() {
245245
return AddressUtil.parseAddress(bind);
246246
}
247247

248+
@Override
248249
public boolean isQueryEnabled() {
249250
return query.isQueryEnabled();
250251
}
251252

253+
@Override
252254
public int getQueryPort() {
253255
return query.getQueryPort();
254256
}
255257

258+
@Override
256259
public String getQueryMap() {
257260
return query.getQueryMap();
258261
}
@@ -271,6 +274,7 @@ public String getMotd() {
271274
*
272275
* @return the MOTD
273276
*/
277+
@Override
274278
public Component getMotdComponent() {
275279
if (motdAsComponent == null) {
276280
if (motd.startsWith("{")) {
@@ -282,10 +286,12 @@ public Component getMotdComponent() {
282286
return motdAsComponent;
283287
}
284288

289+
@Override
285290
public int getShowMaxPlayers() {
286291
return showMaxPlayers;
287292
}
288293

294+
@Override
289295
public boolean isOnlineMode() {
290296
return onlineMode;
291297
}
@@ -298,42 +304,52 @@ public byte[] getForwardingSecret() {
298304
return forwardingSecret;
299305
}
300306

307+
@Override
301308
public Map<String, String> getServers() {
302309
return servers.getServers();
303310
}
304311

312+
@Override
305313
public List<String> getAttemptConnectionOrder() {
306314
return servers.getAttemptConnectionOrder();
307315
}
308316

317+
@Override
309318
public Map<String, List<String>> getForcedHosts() {
310319
return forcedHosts.getForcedHosts();
311320
}
312321

322+
@Override
313323
public int getCompressionThreshold() {
314324
return advanced.getCompressionThreshold();
315325
}
316326

327+
@Override
317328
public int getCompressionLevel() {
318329
return advanced.getCompressionLevel();
319330
}
320331

332+
@Override
321333
public int getLoginRatelimit() {
322334
return advanced.getLoginRatelimit();
323335
}
324336

337+
@Override
325338
public Optional<Favicon> getFavicon() {
326339
return Optional.ofNullable(favicon);
327340
}
328341

342+
@Override
329343
public boolean isAnnounceForge() {
330344
return announceForge;
331345
}
332346

347+
@Override
333348
public int getConnectTimeout() {
334349
return advanced.getConnectionTimeout();
335350
}
336351

352+
@Override
337353
public int getReadTimeout() {
338354
return advanced.getReadTimeout();
339355
}
@@ -402,15 +418,9 @@ public static VelocityConfiguration read(Path path) throws IOException {
402418
advanced,
403419
query
404420
);
405-
upgradeConfig(configuration, toml);
406421
return configuration;
407422
}
408423

409-
private static void upgradeConfig(VelocityConfiguration configuration, Toml toml) {
410-
// Will be implemented once there has been a backwards-incompatible change in the config file
411-
// format.
412-
}
413-
414424
private static String generateRandomString(int length) {
415425
String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
416426
StringBuilder builder = new StringBuilder();
@@ -547,7 +557,7 @@ private static class Advanced {
547557
"compress all packets, and setting it to -1 will disable compression entirely."
548558
})
549559
@ConfigKey("compression-threshold")
550-
private int compressionThreshold = 1024;
560+
private int compressionThreshold = 256;
551561

552562
@Comment({"How much compression should be done (from 0-9). The default is -1, which uses the",
553563
"default level of 6."})
@@ -579,7 +589,7 @@ private Advanced() {
579589

580590
private Advanced(Toml toml) {
581591
if (toml != null) {
582-
this.compressionThreshold = toml.getLong("compression-threshold", 1024L).intValue();
592+
this.compressionThreshold = toml.getLong("compression-threshold", 256L).intValue();
583593
this.compressionLevel = toml.getLong("compression-level", -1L).intValue();
584594
this.loginRatelimit = toml.getLong("login-ratelimit", 3000L).intValue();
585595
this.connectionTimeout = toml.getLong("connection-timeout", 5000L).intValue();

0 commit comments

Comments
 (0)