Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/*
* This file is part of Neutron, licensed under the MIT License
*
* Copyright (c) 2020 Crypnotic <crypnoticofficial@gmail.com>
* Copyright (c) 2020 Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
* This file is part of Neutron, licensed under the MIT License
*
* Copyright (c) 2020 Crypnotic <crypnoticofficial@gmail.com>
* Copyright (c) 2020 Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
Comment on lines +2 to +24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might I ask why the formatting was changed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not sure, might have been my editor and I didn't realize until I submitted the PR (not super familiar with git).

package me.crypnotic.neutron.module.serverlist;

import java.util.Arrays;
Expand All @@ -48,6 +48,10 @@ public class ServerListConfig {
@Setting("server-preview")
private ServerPreview serverPreview = new ServerPreview();

@Getter
@Setting("online-player-count")
private OnlinePlayerCount onlinePlayerCount = new OnlinePlayerCount();

@ConfigSerializable
public static class PlayerCount {

Expand Down Expand Up @@ -92,4 +96,27 @@ public static enum ServerPreviewAction {
PLAYERS;
}
}
}

@ConfigSerializable
public static class OnlinePlayerCount {

@Getter
@Setting(value = "action", comment = " # The online player count has three different actions:\r\n" + " # \r\n"
+ " # STATIC - online players will always be the value of `online-player-count`\r\n"
+ " # PING - online player count shows the sum of all backend servers' online player counts. Cached every 5 minutes\r\n"
+ " # CURRENT - online players matches number of players connected to the proxy\r\n" + " #\r\n"
+ " # `online-player-count` is only used with the STATIC action")

private OnlinePlayerCountAction action = OnlinePlayerCountAction.CURRENT;

@Getter
@Setting("online-player-count")
private int onlinePlayerCount = 32;

public static enum OnlinePlayerCountAction {
STATIC,
PING,
CURRENT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,23 @@ public void onServerListPing(ProxyPingEvent event) {
Builder builder = ServerPing.builder();

builder.version(original.getVersion());
builder.onlinePlayers(playerCount);

original.getFavicon().ifPresent(builder::favicon);

builder.description(config.getMotd());

switch (config.getOnlinePlayerCount().getAction()) {
case STATIC:
builder.onlinePlayers(playerCount);
break;
case PING:
builder.onlinePlayers(module.getOnlinePlayerPing());
break;
case CURRENT:
builder.onlinePlayers(module.getNeutron().getProxy().getPlayerCount());
break;
}

switch (config.getPlayerCount().getAction()) {
case CURRENT:
builder.maximumPlayers(playerCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ServerListModule extends Module {
private ServerListHandler handler;
@Getter
private int maxPlayerPing;
@Getter
private int onlinePlayerPing;

@Override
public StateResult init() {
Expand Down Expand Up @@ -90,6 +92,7 @@ public String getName() {
public class PingTask implements Runnable {

int buffer = 0;
int onlineBuffer = 0;

@Override
public void run() {
Expand All @@ -100,6 +103,7 @@ public void run() {

if (players.isPresent()) {
buffer += players.get().getMax();
onlineBuffer += players.get().getOnline();
}
} catch (InterruptedException | ExecutionException exception) {
/* Catch silently */
Expand All @@ -108,7 +112,9 @@ public void run() {
}

maxPlayerPing = buffer;
onlinePlayerPing = onlineBuffer;
buffer = 0;
onlineBuffer = 0;
}
}
}