Skip to content

Commit

Permalink
Merge Version
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3-M4513R committed Jul 16, 2023
1 parent 0dd2fc1 commit 4917c45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class VelocityPlayerListQuery {
@DataDirectory
Path dataDirectory;

Config config;
ServerListEntryBuilder serverListEntryBuilder;
Config config;


@Subscribe
Expand All @@ -66,9 +66,13 @@ public EventTask onServerPing(final ProxyPingEvent event) {

return EventTask.async(() -> {
final ServerPing serverPing = event.getPing();

final boolean versionUnset = serverPing.getVersion() == null ||
serverPing.getVersion().getName().equals("Unknown") ||
serverPing.getVersion().getProtocol() == 0 ||
serverPing.getDescriptionComponent() == null;
final boolean setVersion = config.setVersion() || (config.onlySetUnsetVersion() && versionUnset);
// check if server ping is invalid:
if (serverPing.getVersion() == null || serverPing.getDescriptionComponent() == null) {
if (versionUnset && !setVersion) {
this.logger.info("Server ping is invalid, skipping");
return;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ public EventTask onServerPing(final ProxyPingEvent event) {
.samplePlayers(samplePlayers.toArray(new ServerPing.SamplePlayer[0]));
if (config.setMaxPlayers()) ping.maximumPlayers(this.server.getConfiguration().getShowMaxPlayers());
if (config.setOnlinePlayers()) ping.onlinePlayers(players.size());

if (setVersion) ping.version(new ServerPing.Version(config.versionProtocol(), config.versionName()));
event.setPing(ping.build());
}
});
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/voruti/velocityplayerlistquery/model/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public class Config {
"%1$s",
16,
false,
false
);
false,
false,
false,
"Unknown",
0
);


/**
Expand All @@ -38,4 +42,20 @@ public class Config {
* Should the maximum Player count be replaced with the Velocity configured amount?
*/
boolean setMaxPlayers;
/**
* Should version information be set?
*/
boolean setVersion;
/**
* Will only set version information, if the version information is undefined.
*/
boolean onlySetUnsetVersion;
/**
* The version Name to be set
*/
String versionName;
/**
* The protocol to be set
*/
int versionProtocol;
}

0 comments on commit 4917c45

Please sign in to comment.