Paginator paginates first Page 2 Time
TheHolyFire opened this issue · 7 comments
Checklist
Make sure that you've checked all the items below.
- [✔️] Bot has the following permissions:
- MESSAGE_ADD_REACTION
- MESSAGE_EXT_EMOJI
- MESSAGE_READ/WRITE
- VIEW_CHANNEL
- [✔️] If using
JDABuilder.createLight()
, you added the following gateway intents:- GUILD_MESSAGES
- GUILD_MESSAGE_REACTIONS
- [✔️] If using
.setRemoveOnReact(true)
, you have the following permission:- MESSAGE_MANAGE
- [✔️] PaginationUtils is up-to-date.
- [✔️] You have activated the library as descripted in the README.
Library info
What libraries versions are you using.
- JDA version 4.3.0_298
- PaginationUtils version 2.3.0
Describe the bug
The first page is shown twice and when trying to go back as the first thing it does nothing
To Reproduce
Steps to reproduce the behavior:
- Add 3 Pages
- Click on back or next
- See error
Expected behavior
it only should show the first page once
Screenshots
Code:
Additional context
What's the value of i
?
i is givin by the user! Command: /check [user] [type] [i]
should i post the whole Class?
There should be something else causing that issue since the library itself doesn't send the first page (this is done on your side).
If possible, I'd like to see the rest of the class yes.
Edit: removed all unimportant imports
import com.github.ygimenez.method.Pages;
import com.github.ygimenez.model.Page;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.TextChannel;
public class CheckAPI {
public static void CheckPlayer(String ChannelID,String userName,String type){
ArrayList<Page> pages = new ArrayList<>();
DataConfig config = (DataConfig) FileManager.getConfig("data.json",DataConfig.class);
UUID uuid = getKeyByValue(config.playerList,userName);
TextChannel channel = FreedomCoreBungee.getInstance().api.getTextChannelById(ChannelID);
if(channel != null) {
EmbedBuilder builder = new EmbedBuilder(),page1 = new EmbedBuilder();
page1.setTitle("Check");
builder.setTitle("Check");
builder.setColor(Color.RED);
page1.setDescription(Util.formatName(userName));
builder.setDescription(Util.formatName(userName));
if (uuid != null) {
int mutes = 0,bans = 0,ipBans = 0,i;
String ip = config.playerIPList.get(uuid);
if (FileManager.configExists("players/" + uuid + "/data.json")) {
UserConfig userConfig = (UserConfig) FileManager.getConfig("players/" + uuid + "/data.json",UserConfig.class);
mutes = userConfig.mute;
bans = userConfig.ban;
}
if (FileManager.configExists("ips/" + ip + "/data.json")) {
IPConfig ipConfig = (IPConfig) FileManager.getConfig("ips/" + ip + "/data.json",IPConfig.class);
ipBans = ipConfig.ipban;
}
if (type.equalsIgnoreCase("all")) {
builder.addField("Mutes:", String.valueOf(mutes),false);
builder.addField("Bans:", String.valueOf(bans),false);
builder.addField("IP-Bans:", String.valueOf(ipBans),false);
channel.sendMessageEmbeds(builder.build()).queue();
}
else if (type.startsWith("ban")) {
String[] listType = type.split(" ");
try {
i = Integer.parseInt(listType[1]);
if (i > bans || i <= 0) {
if (bans != 1) {
sendError(builder,channel,"Player only has " + bans + " bans");
} else {
sendError(builder,channel,"Player only has " + bans + " ban");
}
return;
}
} catch (NumberFormatException e) {
sendError(builder,channel,"!check <name> <all|ban|mute|ipban> <number>");
return;
}
page1.setFooter("There are no earlier Interferences");
pages.add(new Page(page1.build()));
for (int f = 0;f < bans;f++){
pages.add(new Page(getNextInterference("ban",uuid,f+1)));
}
page1.setFooter("There are no later Interferences");
pages.add(new Page(page1.build()));
channel.sendMessageEmbeds((MessageEmbed) pages.get(i).getContent()).queue(success -> Pages.paginate(success,pages));
}
else if (type.startsWith("mute")) {
String[] listType = type.split(" ");
try {
i = Integer.parseInt(listType[1]);
if (i > mutes || i <= 0) {
if (mutes != 1) {
sendError(builder,channel,"Player only has " + mutes + " mutes");
} else {
sendError(builder,channel,"Player only has " + mutes + " mute");
}
return;
}
} catch (NumberFormatException e) {
sendError(builder,channel,"!check <name> <all|ban|mute|ipban> <number>");
return;
}
page1.setFooter("There are no earlier Interferences");
pages.add(new Page(page1.build()));
for (int f = 0;f < mutes;f++){
pages.add(new Page(getNextInterference("mute", uuid, f+1)));
}
page1.setFooter("There are no later Interferences");
pages.add(new Page(page1.build()));
channel.sendMessageEmbeds((MessageEmbed) pages.get(i).getContent()).queue(success -> Pages.paginate(success,pages));
}
else if (type.startsWith("ipban")) {
String[] listType = type.split(" ");
try {
i = Integer.parseInt(listType[1]);
if (i > ipBans || i <= 0) {
if (ipBans != 1) {
sendError(builder,channel,"Player only has " + ipBans + " ip-bans");
} else {
sendError(builder,channel,"Player only has " + ipBans + " ip-ban");
}
return;
}
} catch (NumberFormatException e) {
sendError(builder,channel,"!check <name> <all|ban|mute|ipban> <number>");
return;
}
page1.setFooter("There are no earlier Interferences");
pages.add(new Page(page1.build()));
for (int f = 0;f < ipBans;f++){
pages.add(new Page(getNextInterference("ipban",uuid,f+1)));
}
page1.setFooter("There are no later Interferences");
pages.add(new Page(page1.build()));
channel.sendMessageEmbeds((MessageEmbed) pages.get(i).getContent()).queue(success -> Pages.paginate(success,pages));
}
} else {
builder.setColor(Color.RED);
builder.addField("Error", "Player never joined the Server",false);
channel.sendMessageEmbeds(builder.build()).queue();
}
} else {
System.out.println("no channel found");
}
}
public static MessageEmbed getNextInterference(String type,UUID uuid,int i){
EmbedBuilder builder = new EmbedBuilder();
DataConfig config = (DataConfig) FileManager.getConfig("data.json",DataConfig.class);
builder.setTitle("Check");
builder.setColor(Color.YELLOW);
String userName = config.playerList.get(uuid);
String ip = "";
if(type.equalsIgnoreCase("ipban")){
ip = config.playerIPList.get(uuid);
}
builder.setDescription(Util.formatName(userName));
if(type.equalsIgnoreCase("ban")){
UserConfig userConfig = (UserConfig) FileManager.getConfig("players/" + uuid + "/data.json",UserConfig.class);
PunishmentConfig punishmentConfig = userConfig.bans.get(i);
long left = Util.getLeft(punishmentConfig.start, punishmentConfig.time);
builder.addField("Staff",formatName(punishmentConfig.staffName),false);
builder.addField("Time", punishmentConfig.time,false);
if (left < 0) {
if (punishmentConfig.current) {
builder.addField("Status","Unbanned",false);
} else {
builder.addField("Status","Expired",false);
}
} else {
String[] WholeTime = Util.milliToTime(Util.getLeft(punishmentConfig.start, punishmentConfig.time)).split(", ");
List<String> playtime = new ArrayList<>(Arrays.asList(WholeTime));
builder.addField("Status",playtime + " left",false);
}
builder.addField("Reason", punishmentConfig.reason,false);
builder.addField("ID", String.valueOf(punishmentConfig.ID),false);
}
else if(type.equalsIgnoreCase("mute")) {
UserConfig userConfig = (UserConfig) FileManager.getConfig("players/" + uuid + "/data.json", UserConfig.class);
PunishmentConfig punishmentConfig = userConfig.mutes.get(i);
long left = Util.getLeft(punishmentConfig.start, punishmentConfig.time);
builder.addField("Staff", formatName(punishmentConfig.staffName), false);
builder.addField("Time", punishmentConfig.time, false);
if (punishmentConfig.current) {
builder.addField("Status", "Unbanned", false);
} else {
if (left < 0) {
builder.addField("Status", "Expired", false);
} else {
String[] WholeTime = Util.milliToTime(Util.getLeft(punishmentConfig.start, punishmentConfig.time)).split(", ");
List<String> playtime = new ArrayList<>(Arrays.asList(WholeTime));
builder.addField("Status", playtime + " left", false);
}
}
builder.addField("Reason", punishmentConfig.reason, false);
builder.addField("ID", String.valueOf(punishmentConfig.ID), false);
}
else if(type.equalsIgnoreCase("ipban")){
IPConfig ipConfig = (IPConfig) FileManager.getConfig("ips/" + ip + "/data.json",IPConfig.class);
PunishmentConfig punishmentConfig = ipConfig.ipbans.get(i);
long left = Util.getLeft(punishmentConfig.start, punishmentConfig.time);
builder.addField("Staff",formatName(punishmentConfig.staffName),false);
builder.addField("Time", punishmentConfig.time,false);
if (left < 0) {
if (punishmentConfig.current) {
builder.addField("Status","Unbanned",false);
} else {
builder.addField("Status","Expired",false);
}
} else {
String[] WholeTime = Util.milliToTime(Util.getLeft(punishmentConfig.start, punishmentConfig.time)).split(", ");
List<String> playtime = new ArrayList<>(Arrays.asList(WholeTime));
builder.addField("Status",playtime + " left",false);
}
builder.addField("Reason", punishmentConfig.reason,false);
builder.addField("ID", String.valueOf(punishmentConfig.ID),false);
}
return builder.build();
}
private static void sendError(EmbedBuilder builder,TextChannel channel,String message){
builder.addField("Error",message,false);
channel.sendMessageEmbeds(builder.build()).queue();
}
}
Sorry for taking so long to answer, could you please try the code below?
List<Page> pages = new ArrayList<>();
EmbedBuilder eb = new EmbedBuilder();
for (int i = 0; i < 10; i++) {
eb.setTitle("Page " + (i + 1));
pages.add(new Page(eb.build()));
}
channel.sendMessageEmbeds((MessageEmbed) pages.get(0)).queue(s -> Pages.paginate(s, pages));
Hey yeah I will try later
I'm closing this due to no response, if needed please reopen.