Skip to content

Commit

Permalink
Fix EffConnect NPE with no players (#4387)
Browse files Browse the repository at this point in the history
  • Loading branch information
TPGamesNL authored Nov 3, 2021
1 parent 23354e5 commit cc7b792
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/ch/njol/skript/effects/EffConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public class EffConnect extends Effect {
@Override
protected void execute(Event e) {
String server = this.server.getSingle(e);
if (server == null)
Player[] players = this.players.getArray(e);
if (server == null || players.length == 0)
return;

// the message channel is case sensitive so let's fix that
Expand All @@ -68,7 +69,7 @@ protected void execute(Event e) {
// for loop isn't as pretty a stream, but will be faster with tons of servers
for (String validServer : response.readUTF().split(", ")) {
if (validServer.equalsIgnoreCase(server)) {
for (Player player : players.getArray(e))
for (Player player : players)
Utils.sendPluginMessage(player, BUNGEE_CHANNEL, CONNECT_CHANNEL, validServer);
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/ch/njol/skript/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,13 @@ public static CompletableFuture<ByteArrayDataInput> sendPluginMessage(Player pla
* @param data the data to add to the outgoing message
* @return a completable future for the message of the responding plugin message, if there is one.
* this completable future will complete exceptionally if the player is null.
* @throws IllegalStateException when there are no players online
*/
public static CompletableFuture<ByteArrayDataInput> sendPluginMessage(String channel,
Predicate<ByteArrayDataInput> messageVerifier, String... data) {
Predicate<ByteArrayDataInput> messageVerifier, String... data) throws IllegalStateException {
Player firstPlayer = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
if (firstPlayer == null)
throw new IllegalStateException("There are no players online");
return sendPluginMessage(firstPlayer, channel, messageVerifier, data);
}

Expand Down

0 comments on commit cc7b792

Please sign in to comment.