Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
ServerListEvent: fix errors when list is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Sep 16, 2023
1 parent 2721ed0 commit 34b2d7d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/net/flectone/listeners/ServerListPingListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import java.util.List;
import java.util.Random;

import static net.flectone.managers.FileManager.locale;
import static net.flectone.managers.FileManager.config;
import static net.flectone.managers.FileManager.locale;

public class ServerListPingListener implements Listener {

Expand All @@ -30,10 +30,10 @@ public void updateServerList(@NotNull ServerListPingEvent event) {

if (config.getBoolean("server.motd.messages.enable")) {
List<String> motds = locale.getStringList("server.motd.messages");

int numberMotd = new Random().nextInt(0, motds.size());

event.setMotd(ObjectUtil.formatString(motds.get(numberMotd), null));
if (!motds.isEmpty()) {
int numberMotd = new Random().nextInt(0, motds.size());
event.setMotd(ObjectUtil.formatString(motds.get(numberMotd), null));
}
}

if (config.getBoolean("server.online.count.enable")) {
Expand All @@ -42,11 +42,13 @@ public void updateServerList(@NotNull ServerListPingEvent event) {

if (config.getBoolean("server.icon.enable")) {
List<String> iconNames = config.getStringList("server.icon.names");
if (!iconNames.isEmpty()) {
int numberIcon = config.getString("server.icon.mode").equals("single")
? 0
: new Random().nextInt(0, iconNames.size());

int numberIcon = config.getString("server.icon.mode").equals("single") ? 0 :
new Random().nextInt(0, iconNames.size());

setIcon(event, iconNames.get(numberIcon));
setIcon(event, iconNames.get(numberIcon));
}
}
}

Expand Down

0 comments on commit 34b2d7d

Please sign in to comment.