Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EffActionBar NullPointException when message is null #5833

Merged
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);
}

}