Skip to content

Commit

Permalink
Moved onRemove configuration to Paginator;
Browse files Browse the repository at this point in the history
Fixed spelling errors in javadocs.
  • Loading branch information
ygimenez committed Sep 18, 2023
1 parent f197e38 commit 10e4845
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.ygimenez</groupId>
<artifactId>Pagination-Utils</artifactId>
<version>4.0.5b</version>
<version>4.0.6</version>
<packaging>jar</packaging>

<name>Pagination Utils</name>
Expand Down Expand Up @@ -33,7 +33,7 @@
<url>https://github.com/ygimenez/Pagination-Utils</url>
<connection>scm:git:git@github.com:ygimenez/Pagination-Utils.git</connection>
<developerConnection>scm:git:git@github.com:ygimenez/Pagination-Utils.git</developerConnection>
<tag>Pagination-Utils-4.0.5b</tag>
<tag>Pagination-Utils-4.0.6</tag>
</scm>

<distributionManagement>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/ygimenez/listener/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent evt) {
String id = getEventId(evt);
Pages.getPaginator().log(PUtilsConfig.LogLevel.LEVEL_4, "Received button event with ID " + id);
if (!events.containsKey(id)) {
evt.deferEdit().submit().whenComplete((hook, t) -> PUtilsConfig.getOnRemove().accept(evt.getHook()));
evt.deferEdit().submit().whenComplete((hook, t) -> Pages.getPaginator().getOnRemove().accept(evt.getHook()));
Pages.getPaginator().log(PUtilsConfig.LogLevel.LEVEL_4, "Event not mapped, skipping");
return;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void onGenericSelectMenuInteraction(@NotNull GenericSelectMenuInteraction
String id = getEventId(evt.getMessage());
Pages.getPaginator().log(PUtilsConfig.LogLevel.LEVEL_4, "Received dropdown values for event with ID " + id);
if (!events.containsKey(id)) {
evt.deferEdit().submit().whenComplete((hook, t) -> PUtilsConfig.getOnRemove().accept(evt.getHook()));
evt.deferEdit().submit().whenComplete((hook, t) -> Pages.getPaginator().getOnRemove().accept(evt.getHook()));
Pages.getPaginator().log(PUtilsConfig.LogLevel.LEVEL_4, "Event not mapped, skipping");
return;
}
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/github/ygimenez/model/PUtilsConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.github.ygimenez.model;

import net.dv8tion.jda.api.interactions.InteractionHook;

/**
* Utility class holding library-wide settings.
*/
public abstract class PUtilsConfig {
private static LogLevel logLevel = LogLevel.LEVEL_1;
private static ThrowingConsumer<InteractionHook> onRemove = hook -> hook.editOriginalComponents().submit();

private PUtilsConfig() {
}
Expand Down Expand Up @@ -55,23 +52,4 @@ public static LogLevel getLogLevel() {
public static void setLogLevel(LogLevel logLevel) {
PUtilsConfig.logLevel = logLevel;
}

/**
* Retrieve the action performed when encounteing an unmapped event.
*
* @return The action to be performed.
*/
public static ThrowingConsumer<InteractionHook> getOnRemove() {
return onRemove;
}

/**
* Set the action to be performed when encountering an unmapped event. This defaults to simply removing the
* message buttons.
*
* @param onRemove The action to be performed (the interaction is automatically acknowledged).
*/
public static void setOnRemove(ThrowingConsumer<InteractionHook> onRemove) {
PUtilsConfig.onRemove = onRemove;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/github/ygimenez/model/Paginator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.internal.utils.JDALogger;
import org.slf4j.Logger;
Expand All @@ -28,6 +29,7 @@ public class Paginator {
private boolean eventLocked = false;
private boolean deleteOnCancel = false;
private Map<Emote, Emoji> emotes = new EnumMap<>(Emote.class);
private ThrowingConsumer<InteractionHook> onRemove = hook -> hook.editOriginalComponents().submit();
private Logger logger = null;

/**
Expand Down Expand Up @@ -57,6 +59,7 @@ public Object getHandler() {

/**
* Set the handler used for event processing.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param handler The handler that'll be used for event processing
Expand All @@ -80,6 +83,7 @@ public boolean isRemoveOnReact() {

/**
* Set whether user reactions will be removed after pressing the button or not.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param removeOnReact Whether reactions will be removed on press or not.
Expand All @@ -100,6 +104,7 @@ public boolean isEventLocked() {

/**
* Set whether evens should be locked to prevent double-activation.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param hashLocking Whether events should be locked.
Expand All @@ -121,6 +126,7 @@ public boolean isDeleteOnCancel() {

/**
* Set whether {@link Message} should be deleted or not when the button handler is removed.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param deleteOnCancel Whether the {@link Message} will be deleted or not.
Expand All @@ -129,6 +135,27 @@ protected void setDeleteOnCancel(boolean deleteOnCancel) {
this.deleteOnCancel = deleteOnCancel;
}

/**
* Retrieve the action performed when encountering an unmapped event.
*
* @return The action to be performed.
*/
public ThrowingConsumer<InteractionHook> getOnRemove() {
return onRemove;
}

/**
* Set the action to be performed when encountering an unmapped event. This defaults to simply removing the
* message buttons.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param onRemove The action to be performed (the interaction is automatically acknowledged).
*/
public void setOnRemove(ThrowingConsumer<InteractionHook> onRemove) {
this.onRemove = onRemove;
}

/**
* The {@link Map} containing configured {@link Emote}s for this {@link Paginator}. This {@link Map}
* must not be modified after construction of this {@link Paginator}.
Expand All @@ -151,6 +178,7 @@ public Emoji getEmoji(Emote emote) {

/**
* Make configured {@link Emote}s final.
* <br>
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*/
protected void finishEmotes() {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/github/ygimenez/model/PaginatorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -178,7 +179,6 @@ public boolean shouldDeleteOnCancel() {

/**
* Set whether {@link Message} should be deleted or not when the button handler is removed.
* <strong>This must only be called by {@link PaginatorBuilder}</strong>.
*
* @param deleteOnCancel Whether the {@link Message} will be deleted or not (default: false).
* @return The {@link PaginatorBuilder} instance for chaining convenience.
Expand All @@ -188,6 +188,25 @@ public PaginatorBuilder setDeleteOnCancel(boolean deleteOnCancel) {
return this;
}

/**
* Retrieve the action performed when encountering an unmapped event.
*
* @return The action to be performed.
*/
public ThrowingConsumer<InteractionHook> getOnRemove() {
return paginator.getOnRemove();
}

/**
* Set the action to be performed when encountering an unmapped event. This defaults to simply removing the
* message buttons.
*
* @param onRemove The action to be performed (the interaction is automatically acknowledged).
*/
public void setOnRemove(ThrowingConsumer<InteractionHook> onRemove) {
paginator.setOnRemove(onRemove);
}

/**
* Retrieves an {@link Emote}'s code from the current emote {@link Map}.
*
Expand Down

0 comments on commit 10e4845

Please sign in to comment.