Skip to content

Commit

Permalink
🐛 Fixed exception when actions were empty when changing permissions o…
Browse files Browse the repository at this point in the history
…f an entity
  • Loading branch information
ItsTheSky committed Oct 10, 2024
1 parent 42ef323 commit 2ff983c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.config.Node;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.Variable;
import ch.njol.skript.util.AsyncEffect;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.skript.INodeHolder;
import info.itsthesky.disky.api.skript.WaiterEffect;
import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,7 +21,7 @@
import static info.itsthesky.disky.api.skript.EasyElement.parseSingle;

@SuppressWarnings("unchecked")
public class CreateAction extends AsyncEffect {
public class CreateAction extends AsyncEffect implements INodeHolder {

static {
Skript.registerEffect(
Expand All @@ -29,11 +32,16 @@ public class CreateAction extends AsyncEffect {

private Expression<Object> exprAction;
private Expression<Object> exprResult;
private Node node;

@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
getParser().setHasDelayBefore(Kleenean.TRUE);
node = getParser().getNode();

exprAction = (Expression<Object>) expressions[0];
exprResult = (Expression<Object>) expressions[1];

return Changer.ChangerUtils.acceptsChange(exprResult, Changer.ChangeMode.SET, Object.class);
}

Expand All @@ -47,7 +55,7 @@ public void execute(Event e) {
try {
result = action.complete();
} catch (Exception ex) {
DiSky.getErrorHandler().exception(e, ex);
DiSkyRuntimeHandler.error(ex, node);
return;
}

Expand All @@ -59,4 +67,10 @@ public void execute(Event e) {
return "create action " + exprAction.toString(e, debug)
+ " and store it in " + exprResult.toString(e, debug);
}

@Override
@NotNull
public Node getNode() {
return node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ protected void execute(@NotNull Event event) {

final Message message;
try {
message = (
start ?
thread.retrieveStartMessage() :
thread.retrieveParentMessage()
).complete();
message = (start ?
thread.retrieveStartMessage() :
thread.retrieveParentMessage()
).complete();
} catch (Exception ex) {
DiSky.getErrorHandler().exception(event, ex);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void changeAsync(Event e, Object[] delta, Changer.ChangeMode mode) {
return holder.getPermissions(channel).toArray(new Permission[0]);
}

public void change(Event e, Object[] delta, Changer.ChangeMode mode, boolean complete) {
public void change(Event e, Object[] delta, Changer.ChangeMode mode, boolean async) {
if (!EasyElement.isValid(delta))
return;

Expand Down Expand Up @@ -150,9 +150,12 @@ public void change(Event e, Object[] delta, Changer.ChangeMode mode, boolean com
break;
}

if (actions.isEmpty())
return;

final RestAction<?> action = RestAction.allOf(actions);
if (complete) action.queue();
else action.complete();
if (async) action.complete();
else action.queue();
}

@Override
Expand Down

0 comments on commit 2ff983c

Please sign in to comment.