From 68dceaff13f88ef3ca7c4d5a40ce4a4e94b7e2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Tue, 20 Dec 2022 15:09:35 +0100 Subject: [PATCH] Use enum instead of boolean for page switching This is useless but looks better --- .../hidekobot/commands/base/UrbanDictionary.java | 12 +++++++++--- .../listeners/ButtonInteractionListener.java | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java b/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java index ae7db4d..02cc59e 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/base/UrbanDictionary.java @@ -135,7 +135,7 @@ public class UrbanDictionary } - public static void changePage(ButtonInteractionEvent event, boolean increase) + public static void changePage(ButtonInteractionEvent event, ChangeType changeType) { String messageId = event.getMessageId(); DatabaseSource database = Cache.getDatabaseSource(); @@ -163,9 +163,10 @@ public class UrbanDictionary serializedExamples, serializedContributors, serializedDates); // move to new page - if(increase) + if(changeType == ChangeType.NEXT) page++; - else page--; + else if(changeType == ChangeType.PREVIOUS) + page--; term = UrbanDictionary.sanitizeArgs(term, false); @@ -341,4 +342,9 @@ public class UrbanDictionary } } + public enum ChangeType + { + NEXT, + PREVIOUS; + } } diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java index bf62f37..28869b3 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java @@ -22,8 +22,8 @@ public class ButtonInteractionListener extends ListenerAdapter case "generic_dismiss" -> CommandUtil.delete(event); // urban dictionary navigation - case "urban_nextpage" -> UrbanDictionary.changePage(event, true); - case "urban_previouspage" -> UrbanDictionary.changePage(event, false); + case "urban_nextpage" -> UrbanDictionary.changePage(event, UrbanDictionary.ChangeType.NEXT); + case "urban_previouspage" -> UrbanDictionary.changePage(event, UrbanDictionary.ChangeType.PREVIOUS); }