Skip to content

Commit

Permalink
Population check
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Feb 18, 2018
1 parent f32d7aa commit 7db19f7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/teamfruit/serverobserver/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Config {
public final ConfigProperty<Double> notificationPitch;
public final ConfigProperty<Boolean> startWithMultiplayerMenu;
public final ConfigProperty<Boolean> startAndConnect;
public final ConfigProperty<Boolean> ignorePopulation;

public final ConfigProperty<String> targetServerName;
public final ConfigProperty<String> targetServerIP;
Expand Down Expand Up @@ -52,6 +53,7 @@ private Config(final @Nonnull File staticFile, final @Nonnull File dynamicFile,
this.config.getCategory("Miscellaneous").setLanguageKey("serverobserver.config.miscellaneous").setComment("Miscellaneous");
this.startWithMultiplayerMenu = this.config.propertyBoolean(this.config.get("Miscellaneous", "StartWithMultiplayerMenu", false, "After game initialized, show multiplayer menu").setLanguageKey("serverobserver.config.miscellaneous.startwithmultiplayermenu").setRequiresMcRestart(true));
this.startAndConnect = this.config.propertyBoolean(this.config.get("Miscellaneous", "StartAndConnect", false, "After game initialized, connect to the server").setLanguageKey("serverobserver.config.miscellaneous.startandconnect").setRequiresMcRestart(true));
this.ignorePopulation = this.config.propertyBoolean(this.config.get("Miscellaneous", "IgnorePopulation", false, "Try connection if server is full").setLanguageKey("serverobserver.config.miscellaneous.ignorepopulation"));

// init dynamic config
this.dynamicconfig = new ConfigBase(dynamicFile, version);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/net/teamfruit/serverobserver/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,24 @@ public void tickclient() {
final ServerData serverData = this.target.get(mpgui);
if (serverData!=null) {
final Boolean before = this.targetServerStatus;
this.targetServerStatus = this.compat.getPinged(serverData)&&serverData.pingToServer>=0;
boolean checkPopulation = true;
if (!Config.getConfig().ignorePopulation.get()) {
final String populationFormatted = serverData.populationInfo;
if (populationFormatted!=null) {
final String population = populationFormatted.replaceAll("\u00A7[0-9a-fklmnor]", "");
if (StringUtils.contains(population, "/")) {
final String strBefore = StringUtils.substringBefore(population, "/");
final String strAfter = StringUtils.substringAfterLast(population, "/");
try {
final int current = Integer.parseInt(strBefore);
final int overall = Integer.parseInt(strAfter);
checkPopulation = current<overall;
} catch (final NumberFormatException e) {
}
}
}
}
this.targetServerStatus = this.compat.getPinged(serverData)&&serverData.pingToServer>=0&&checkPopulation;
// Log.log.info("pinged: {}, pingms: {}", serverData.pinged, serverData.pingToServer);
if (this.targetServerStatus)
if (before!=null&&!before) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/serverobserver/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ serverobserver.config.miscellaneous.startwithmultiplayermenu=Start with Multipla
serverobserver.config.miscellaneous.startwithmultiplayermenu.tooltip=After game initialized, show multiplayer menu
serverobserver.config.miscellaneous.startandconnect=Start and connect to the server
serverobserver.config.miscellaneous.startandconnect.tooltip=After game initialized, connect to the server
serverobserver.config.miscellaneous.ignorepopulation=Ignore Population
serverobserver.config.miscellaneous.ignorepopulation.tooltip=Try connection if server is full
serverobserver.config.status=Status
serverobserver.config.status.tooltip=Current Status
serverobserver.config.status.initservers=Initialize server list
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/assets/serverobserver/lang/ja_JP.lang
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ serverobserver.gui.backandstop=監視を停止して戻る
serverobserver.gui.backandstop.time=%s: %s秒
serverobserver.config=ServerObserver設定
serverobserver.config.observetarget=監視サーバーのデフォルト設定
serverobserver.config.observetarget.tooltip=監視対象サーバーのデフォルト設定 (この設定はStatusへコピーされてから使用されますModPack作成の際はここを変更してください)
serverobserver.config.observetarget.tooltip=監視対象サーバーのデフォルト設定 (この設定はStatusへコピーされてから使用されます ModPack作成の際はここを変更してください)
serverobserver.config.observetarget.servername=サーバーネーム
serverobserver.config.observetarget.servername.tooltip=監視対象サーバーのサーバーの名前
serverobserver.config.observetarget.serverip=サーバーIP
Expand All @@ -35,9 +35,11 @@ serverobserver.config.notification.pitch.tooltip=サウンドのピッチ (最
serverobserver.config.miscellaneous=その他
serverobserver.config.miscellaneous.tooltip=その他設定
serverobserver.config.miscellaneous.startwithmultiplayermenu=マルチプレイ画面から開始
serverobserver.config.miscellaneous.startwithmultiplayermenu.tooltip=起動したあと、マルチプレイ画面を表示します
serverobserver.config.miscellaneous.startwithmultiplayermenu.tooltip=起動したあと、マルチプレイ画面を表示します
serverobserver.config.miscellaneous.startandconnect=起動後サーバーへ接続
serverobserver.config.miscellaneous.startandconnect.tooltip=起動したあと、サーバーへ接続します。
serverobserver.config.miscellaneous.startandconnect.tooltip=起動したあと、サーバーへ接続します
serverobserver.config.miscellaneous.ignorepopulation=人数を無視
serverobserver.config.miscellaneous.ignorepopulation.tooltip=サーバー人数がいっぱいでもログインを試みます
serverobserver.config.status=ステータス
serverobserver.config.status.tooltip=現在の状態
serverobserver.config.status.initservers=サーバーリストを初期化
Expand Down

0 comments on commit 7db19f7

Please sign in to comment.