Skip to content

Commit

Permalink
Fix EffActionBar NullPointException when message is null (#5833)
Browse files Browse the repository at this point in the history
(cherry picked from commit ebc0929)
  • Loading branch information
Fusezion authored and TheLimeGlass committed Jul 17, 2023
1 parent 2d9207f commit 5e37927
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main/java/ch/njol/skript/effects/EffActionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.chat.BungeeConverter;
import ch.njol.skript.util.chat.ChatMessages;
import ch.njol.util.Kleenean;
Expand All @@ -43,36 +43,35 @@
public class EffActionBar extends Effect {

static {
Skript.registerEffect(EffActionBar.class, "send [the] action[ ]bar [with text] %string% to %players%");
Skript.registerEffect(EffActionBar.class, "send [the] action[ ]bar [with text] %string% [to %players%]");
}

@SuppressWarnings("null")
private Expression<String> message;

@SuppressWarnings("null")
private Expression<Player> recipients;

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) {
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
message = (Expression<String>) exprs[0];
recipients = (Expression<Player>) exprs[1];
return true;
}

@SuppressWarnings("deprecation")
@Override
protected void execute(final Event e) {
String msg = message.getSingle(e);
assert msg != null;
@SuppressWarnings("deprecation")
protected void execute(Event event) {
String msg = message.getSingle(event);
if (msg == null)
return;
BaseComponent[] components = BungeeConverter.convert(ChatMessages.parseToArray(msg));
for (Player player : recipients.getArray(e))
for (Player player : recipients.getArray(event))
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, components);
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "send action bar " + message.toString(e, debug) + " to " + recipients.toString(e, debug);
public String toString(@Nullable Event event, boolean debug) {
return "send action bar " + message.toString(event, debug) + " to " + recipients.toString(event, debug);
}

}

0 comments on commit 5e37927

Please sign in to comment.