Skip to content

Commit

Permalink
♻️ Member nickname expression is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Oct 1, 2024
1 parent 57b1292 commit 15f46ef
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import info.itsthesky.disky.DiSky;
import info.itsthesky.disky.api.skript.EasyElement;
import info.itsthesky.disky.core.Utils;
import info.itsthesky.disky.elements.changers.IAsyncChangeableExpression;
import net.dv8tion.jda.api.entities.Member;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,7 +18,8 @@
"USe 'effective name' expression to get member's name of its nickname is not set."})
@Examples({"reply with member nickname of event-member",
"set member nickname of event-member to \"ayo?!\""})
public class MemberNickname extends MemberProperty<String> {
public class MemberNickname extends MemberProperty<String>
implements IAsyncChangeableExpression {

static {
register(
Expand All @@ -44,8 +46,7 @@ public class MemberNickname extends MemberProperty<String> {
return new Class[0];
}

@Override
public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.ChangeMode mode) {
public void change(Event e, Object[] delta, Changer.ChangeMode mode, boolean async) {
if (!EasyElement.isValid(delta))
return;
final Member member = EasyElement.parseSingle(getExpr(), e, null);
Expand All @@ -59,7 +60,18 @@ public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.C
return;
}

member.modifyNickname(name).queue(null, ex -> DiSky.getErrorHandler().exception(e, ex));
final var action = member.modifyNickname(name);
if (async) action.complete();
else action.queue();
}

@Override
public void change(@NotNull Event e, @NotNull Object[] delta, @NotNull Changer.ChangeMode mode) {
change(e, delta, mode, false);
}

@Override
public void changeAsync(Event e, Object[] delta, Changer.ChangeMode mode) {
change(e, delta, mode, true);
}
}

0 comments on commit 15f46ef

Please sign in to comment.