diff --git a/src/main/java/info/itsthesky/disky/elements/properties/messages/MessagePoll.java b/src/main/java/info/itsthesky/disky/elements/properties/messages/MessagePoll.java index 5d0f30ae..25d4f2fd 100644 --- a/src/main/java/info/itsthesky/disky/elements/properties/messages/MessagePoll.java +++ b/src/main/java/info/itsthesky/disky/elements/properties/messages/MessagePoll.java @@ -1,19 +1,23 @@ package info.itsthesky.disky.elements.properties.messages; +import ch.njol.skript.classes.Changer; import ch.njol.skript.expressions.base.SimplePropertyExpression; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessagePollBuilder; +import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class MessagePoll extends SimplePropertyExpression { +public class MessagePoll extends SimplePropertyExpression { static { register( MessagePoll.class, net.dv8tion.jda.api.entities.messages.MessagePoll.class, "[discord] [message] poll", - "message" + "message/messagecreatebuilder" ); } @@ -23,12 +27,39 @@ public class MessagePoll extends SimplePropertyExpression getReturnType() { return net.dv8tion.jda.api.entities.messages.MessagePoll.class; } + + @Override + public Class @NotNull [] acceptChange(Changer.@NotNull ChangeMode mode) { + if (mode == Changer.ChangeMode.SET) + return new Class[] {MessagePollBuilder.class}; + + return new Class[0]; + } + + @Override + public void change(@NotNull Event event, Object @NotNull [] delta, Changer.@NotNull ChangeMode mode) { + if (delta.length == 0 || delta[0] == null) + return; + + MessagePollBuilder poll = (MessagePollBuilder) delta[0]; + if (mode == Changer.ChangeMode.SET) { + for (Object entity : getExpr().getArray(event)) { + if (entity instanceof MessageCreateBuilder) { + MessageCreateBuilder message = (MessageCreateBuilder) entity; + message.setPoll(poll.build()); + } + } + } + } } diff --git a/src/main/java/info/itsthesky/disky/elements/sections/message/MessagePoll.java b/src/main/java/info/itsthesky/disky/elements/sections/message/MessagePoll.java deleted file mode 100644 index 48fc45be..00000000 --- a/src/main/java/info/itsthesky/disky/elements/sections/message/MessagePoll.java +++ /dev/null @@ -1,57 +0,0 @@ -package info.itsthesky.disky.elements.sections.message; - -import ch.njol.skript.classes.Changer; -import ch.njol.skript.expressions.base.SimplePropertyExpression; -import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import net.dv8tion.jda.api.utils.messages.MessagePollBuilder; -import org.bukkit.event.Event; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class MessagePoll extends SimplePropertyExpression { - - static { - register( - MessagePoll.class, - MessagePollBuilder.class, - "[discord] [message] poll", - "messagecreatebuilder" - ); - } - - @Override - public @Nullable MessagePollBuilder convert(MessageCreateBuilder from) { - return null; - } - - @Override - protected @NotNull String getPropertyName() { - return "poll"; - } - - @Override - public @NotNull Class getReturnType() { - return MessagePollBuilder.class; - } - - @Override - public Class @NotNull [] acceptChange(Changer.@NotNull ChangeMode mode) { - if (mode == Changer.ChangeMode.SET) - return new Class[] {MessagePollBuilder.class}; - - return new Class[0]; - } - - @Override - public void change(@NotNull Event event, Object @NotNull [] delta, Changer.@NotNull ChangeMode mode) { - if (delta.length == 0 || delta[0] == null) - return; - - MessagePollBuilder poll = (MessagePollBuilder) delta[0]; - if (mode == Changer.ChangeMode.SET) { - for (MessageCreateBuilder message : getExpr().getArray(event)) { - message.setPoll(poll.build()); - } - } - } -}