Skip to content

Commit

Permalink
🐛 Somes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Mar 26, 2022
1 parent 5ba9867 commit dffb425
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class SimpleDiSkyEvent<D extends net.dv8tion.jda.api.events.Event> extend
private D JDAEvent;
private Map<Class<?>, Object> valueMap = new HashMap<>();

public SimpleDiSkyEvent(boolean async) {
super(async);
}

public SimpleDiSkyEvent() {super(false);}

public D getJDAEvent() {
return JDAEvent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
);
}

Expand Down Expand Up @@ -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)) {
Expand Down
19 changes: 5 additions & 14 deletions src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,19 @@ 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)) {
restart();
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ protected Object convert(BukkitSlashCommandReceiveEvent e) {
}

public static class BukkitSlashCommandReceiveEvent extends SimpleDiSkyEvent<SlashCommandInteractionEvent> implements ModalEvent, InteractionEvent {
public BukkitSlashCommandReceiveEvent(SlashCommandReceiveEvent event) {}
public BukkitSlashCommandReceiveEvent(SlashCommandReceiveEvent event) {
super(true);
}

@Override
public GenericInteractionCreateEvent getInteractionEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Member> {

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<? extends Member> getReturnType() {
public @NotNull Class<? extends Member> getReturnType() {
return Member.class;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dffb425

Please sign in to comment.