Skip to content

Commit

Permalink
Make config adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3-M4513R committed Jul 13, 2023
1 parent f6a1826 commit 97c4694
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
Expand Down Expand Up @@ -44,11 +42,12 @@ public class VelocityPlayerListQuery {
Path dataDirectory;

ServerListEntryBuilder serverListEntryBuilder;
Config config;


@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
final Config config = new PersistenceService(logger, dataDirectory)
config = new PersistenceService(logger, dataDirectory)
.loadConfig();
this.serverListEntryBuilder = new ServerListEntryBuilder(logger, config);

Expand All @@ -63,17 +62,18 @@ public EventTask onServerPing(final ProxyPingEvent event) {
Collection<Player> players = this.server.getAllPlayers();

if (!players.isEmpty()) {
event.setPing(event.getPing().asBuilder()
final ServerPing.Builder ping = event.getPing().asBuilder()
.samplePlayers(
players.stream()
.map(player -> new ServerPing.SamplePlayer(
this.serverListEntryBuilder.buildForPlayer(player),
player.getGameProfile().getId()
))
.toArray(ServerPing.SamplePlayer[]::new)
).onlinePlayers(players.size())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers())
.build());
);
if (config.setMaxPlayers()) ping.maximumPlayers(players.size());
if (config.setOnlinePlayers()) ping.onlinePlayers(players.size());
event.setPing(ping.build());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class Config {
public static final String FILE_NAME = "config.json";

public static final Config DEFAULT_CONFIG = new Config(
"%1$s"
"%1$s",
false,
false
);


Expand All @@ -22,4 +24,6 @@ public class Config {
* </ul>
*/
String serverListEntryFormat;
boolean setOnlinePlayers;
boolean setMaxPlayers;
}

0 comments on commit 97c4694

Please sign in to comment.