From dffb42527f715cfb0057bc2980b74d9bb2ff822f Mon Sep 17 00:00:00 2001 From: Sky Date: Sat, 26 Mar 2022 20:07:26 +0100 Subject: [PATCH] :bug: Somes fixes --- .../disky/api/events/BukkitEvent.java | 4 +++ .../disky/api/events/SimpleDiSkyEvent.java | 6 ++++ .../disky/elements/commands/DiSkyCommand.java | 1 + .../disky/elements/effects/DestroyEntity.java | 6 +--- .../disky/elements/effects/ReplyWith.java | 19 ++++-------- .../elements/events/DiSkyErrorEvent.java | 1 + .../SlashCommandReceiveEvent.java | 4 ++- .../elements/properties/DiscordMembersOf.java | 29 +++++++++---------- .../disky/managers/DiSkyErrorHandler.java | 7 +++-- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/info/itsthesky/disky/api/events/BukkitEvent.java b/src/main/java/info/itsthesky/disky/api/events/BukkitEvent.java index e2930819..0b0ecf6e 100644 --- a/src/main/java/info/itsthesky/disky/api/events/BukkitEvent.java +++ b/src/main/java/info/itsthesky/disky/api/events/BukkitEvent.java @@ -10,6 +10,10 @@ public class BukkitEvent extends org.bukkit.event.Event { private static final HandlerList handlerList = new HandlerList(); + public BukkitEvent(boolean async) { + super(async); + } + public static HandlerList getHandlerList() { return handlerList; } diff --git a/src/main/java/info/itsthesky/disky/api/events/SimpleDiSkyEvent.java b/src/main/java/info/itsthesky/disky/api/events/SimpleDiSkyEvent.java index 86b363a4..374807ac 100644 --- a/src/main/java/info/itsthesky/disky/api/events/SimpleDiSkyEvent.java +++ b/src/main/java/info/itsthesky/disky/api/events/SimpleDiSkyEvent.java @@ -11,6 +11,12 @@ public class SimpleDiSkyEvent extend private D JDAEvent; private Map, Object> valueMap = new HashMap<>(); + public SimpleDiSkyEvent(boolean async) { + super(async); + } + + public SimpleDiSkyEvent() {super(false);} + public D getJDAEvent() { return JDAEvent; } diff --git a/src/main/java/info/itsthesky/disky/elements/commands/DiSkyCommand.java b/src/main/java/info/itsthesky/disky/elements/commands/DiSkyCommand.java index eb53f792..ca750b58 100644 --- a/src/main/java/info/itsthesky/disky/elements/commands/DiSkyCommand.java +++ b/src/main/java/info/itsthesky/disky/elements/commands/DiSkyCommand.java @@ -95,6 +95,7 @@ public static class EvtDiSkyCommand extends BukkitEvent implements Cancellable { private final MessageReceivedEvent jdaEvent; public EvtDiSkyCommand(CommandObject command, MessageReceivedEvent e) { + super(false); this.command = command; jdaEvent = e; } diff --git a/src/main/java/info/itsthesky/disky/elements/effects/DestroyEntity.java b/src/main/java/info/itsthesky/disky/elements/effects/DestroyEntity.java index a5b22ef7..d256dc0f 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/DestroyEntity.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/DestroyEntity.java @@ -24,7 +24,7 @@ public class DestroyEntity extends WaiterEffect { static { Skript.registerEffect( DestroyEntity.class, - "destroy %guild/message/role/channel/thread/category%" + "destroy %guild/message/role/channel%" ); } @@ -52,10 +52,6 @@ else if (entity instanceof Message) action = ((Message) entity).delete(); else if (entity instanceof Channel) action = ((Channel) entity).delete(); - else if (entity instanceof ThreadChannel) - action = ((ThreadChannel) entity).delete(); - else if (entity instanceof Category) - action = ((Category) entity).delete(); else action = null; if (anyNull(action)) { diff --git a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java index ca40f9d7..017bf3c2 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java @@ -82,7 +82,6 @@ public void runEffect(Event e, Bot bot) { if (isInInteraction) { final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); - final InteractionHook hook = event.getHook(); final Object rawMessage = parseSingle(exprMessage, e, null); final MessageBuilder message = JDAUtils.constructMessage(rawMessage); if (anyNull(event, rawMessage, message)) { @@ -90,20 +89,12 @@ public void runEffect(Event e, Bot bot) { return; } - if (!hook.isExpired()) { - hook.editOriginal(message.build()) - .queue(v -> restart(), ex -> { - DiSky.getErrorHandler().exception(e, ex); - restart(); - }); - } - event.reply(message.build()) - .addActionRows(formatted) - .setEphemeral(hidden) - .queue(v -> restart(), ex -> { - DiSky.getErrorHandler().exception(e, ex); - restart(); + .addActionRows(formatted) + .setEphemeral(hidden) + .queue(v -> restart(), ex -> { + DiSky.getErrorHandler().exception(e, ex); + restart(); }); } else { diff --git a/src/main/java/info/itsthesky/disky/elements/events/DiSkyErrorEvent.java b/src/main/java/info/itsthesky/disky/elements/events/DiSkyErrorEvent.java index 0118ad9c..ac516ad7 100644 --- a/src/main/java/info/itsthesky/disky/elements/events/DiSkyErrorEvent.java +++ b/src/main/java/info/itsthesky/disky/elements/events/DiSkyErrorEvent.java @@ -50,6 +50,7 @@ public static class BukkitDiSkyErrorEvent extends BukkitEvent { private final String eventName; public BukkitDiSkyErrorEvent(Throwable error, String eventName) { + super(false); this.error = error; this.eventName = eventName; } diff --git a/src/main/java/info/itsthesky/disky/elements/events/interactions/SlashCommandReceiveEvent.java b/src/main/java/info/itsthesky/disky/elements/events/interactions/SlashCommandReceiveEvent.java index e274dd23..0da0a9f9 100644 --- a/src/main/java/info/itsthesky/disky/elements/events/interactions/SlashCommandReceiveEvent.java +++ b/src/main/java/info/itsthesky/disky/elements/events/interactions/SlashCommandReceiveEvent.java @@ -117,7 +117,9 @@ protected Object convert(BukkitSlashCommandReceiveEvent e) { } public static class BukkitSlashCommandReceiveEvent extends SimpleDiSkyEvent implements ModalEvent, InteractionEvent { - public BukkitSlashCommandReceiveEvent(SlashCommandReceiveEvent event) {} + public BukkitSlashCommandReceiveEvent(SlashCommandReceiveEvent event) { + super(true); + } @Override public GenericInteractionCreateEvent getInteractionEvent() { diff --git a/src/main/java/info/itsthesky/disky/elements/properties/DiscordMembersOf.java b/src/main/java/info/itsthesky/disky/elements/properties/DiscordMembersOf.java index ec7ab4af..27e68afc 100644 --- a/src/main/java/info/itsthesky/disky/elements/properties/DiscordMembersOf.java +++ b/src/main/java/info/itsthesky/disky/elements/properties/DiscordMembersOf.java @@ -4,43 +4,40 @@ import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import info.itsthesky.disky.api.skript.MultiplyPropertyExpression; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.IMemberContainer; +import net.dv8tion.jda.api.entities.Member; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@Name("Discord Members of ") +@Name("Discord Members of Guild / Channel") @Description({"Returns a list of members.", -"\nFor Message Channels/category it returns members with permission to view the channel", +"\nFor Message text-related channel & category, it returns members with permission to view the channel", "\nFor Audio Channels it returns the currently connected members of the channel."}) -@Examples({"discord members of event-channel", - "discord members of voice channel with id \"0000\""}) +@Examples({"members of event-channel", + "members of voice channel with id \"0000\""}) public class DiscordMembersOf extends MultiplyPropertyExpression { static { register( DiscordMembersOf.class, Member.class, - "discord member[s] [list]", - "voicechannel/textchannel/thread/category/guild" + "member[s] [list]", + "guildchannel/guild" ); } @Override public @Nullable Member[] convert(Object entity) { - if (entity instanceof VoiceChannel) - return ((VoiceChannel) entity).getMembers().toArray(new Member[0]); - if (entity instanceof TextChannel) - return ((TextChannel) entity).getMembers().toArray(new Member[0]); - if (entity instanceof Category) - return ((Category) entity).getMembers().toArray(new Member[0]); + if (entity instanceof IMemberContainer) + return ((IMemberContainer) entity).getMembers().toArray(new Member[0]); if (entity instanceof Guild) return ((Guild) entity).getMembers().toArray(new Member[0]); - if (entity instanceof ThreadChannel) - return ((ThreadChannel) entity).getMembers().toArray(new Member[0]); return new Member[0]; } @Override - public Class getReturnType() { + public @NotNull Class getReturnType() { return Member.class; } diff --git a/src/main/java/info/itsthesky/disky/managers/DiSkyErrorHandler.java b/src/main/java/info/itsthesky/disky/managers/DiSkyErrorHandler.java index 493480e8..1092829f 100644 --- a/src/main/java/info/itsthesky/disky/managers/DiSkyErrorHandler.java +++ b/src/main/java/info/itsthesky/disky/managers/DiSkyErrorHandler.java @@ -2,6 +2,7 @@ import info.itsthesky.disky.DiSky; import info.itsthesky.disky.api.skript.ErrorHandler; +import info.itsthesky.disky.core.SkriptUtils; import info.itsthesky.disky.core.Utils; import info.itsthesky.disky.elements.events.DiSkyErrorEvent; import net.dv8tion.jda.api.entities.Message; @@ -71,8 +72,10 @@ public void exception(@Nullable Event event, @Nullable Throwable ex) { lines = errors.getOrDefault(((ErrorResponseException) ex).getErrorResponse(), def).apply(ex); else lines = def.apply(ex); - if (event != null) - Bukkit.getPluginManager().callEvent(new DiSkyErrorEvent.BukkitDiSkyErrorEvent(ex, event.getEventName())); + if (event != null) { + @Nullable Throwable finalEx = ex; + SkriptUtils.sync(() -> Bukkit.getPluginManager().callEvent(new DiSkyErrorEvent.BukkitDiSkyErrorEvent(finalEx, event.getEventName()))); + } for (String line : lines) send("&4[&c!&4] &c" + line);