1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-06 16:27:59 +01:00

Centralizing auto pagination

This commit is contained in:
Zrips 2023-04-21 14:11:17 +03:00
parent 8bdd49d988
commit 5c1321ecd4
7 changed files with 189 additions and 240 deletions

View File

@ -1471,50 +1471,6 @@ public final class Jobs extends JavaPlugin {
} }
public void showPagination(CommandSender sender, PageInfo pi, String cmd) {
showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, null);
}
public void showPagination(CommandSender sender, PageInfo pi, String cmd, String pagePref) {
showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, pagePref);
}
public void showPagination(CommandSender sender, int pageCount, int currentPage, int totalEntries, String cmd, String pagePref) {
if (!(sender instanceof Player))
return;
if (!cmd.startsWith("/"))
cmd = "/" + cmd;
if (pageCount == 1)
return;
String pagePrefix = pagePref == null ? "" : pagePref;
int nextPage = currentPage + 1;
nextPage = currentPage < pageCount ? nextPage : currentPage;
int prevpage = currentPage - 1;
if (currentPage <= 1) {
prevpage = currentPage;
}
RawMessage rm = new RawMessage()
.addText((currentPage > 1 ? LC.info_prevPage.getLocale() : LC.info_prevPageOff.getLocale()))
.addHover(currentPage > 1 ? LC.info_prevPageHover.getLocale() : LC.info_lastPageHover.getLocale())
.addCommand(currentPage > 1 ? cmd + " " + pagePrefix + prevpage : cmd + " " + pagePrefix + pageCount);
rm.addText(LC.info_pageCount.getLocale("[current]", currentPage, "[total]", pageCount))
.addHover(LC.info_pageCountHover.getLocale("[totalEntries]", totalEntries));
rm.addText(pageCount > currentPage ? LC.info_nextPage.getLocale() : LC.info_nextPageOff.getLocale())
.addHover(pageCount > currentPage ? LC.info_nextPageHover.getLocale() : LC.info_firstPageHover.getLocale())
.addCommand(pageCount > currentPage ? cmd + " " + pagePrefix + nextPage : cmd + " " + pagePrefix + 1);
if (pageCount != 0)
rm.show(sender);
}
public static boolean hasLimitedItems() { public static boolean hasLimitedItems() {
return hasLimitedItems; return hasLimitedItems;
} }

View File

@ -14,6 +14,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.list.info;
import com.gamingmesh.jobs.commands.list.playerinfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.Boost; import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.CurrencyType;
@ -28,7 +30,6 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.CMIArray;
import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Container.PageInfo;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.RawMessages.RawMessage;
@ -162,18 +163,12 @@ public class JobsCommands implements CommandExecutor {
boolean pl = sender instanceof Player; boolean pl = sender instanceof Player;
// Old format
// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title"));
for (String one : commands) { for (String one : commands) {
if (!pi.isEntryOk()) if (!pi.isEntryOk())
continue; continue;
if (pi.isBreak()) if (pi.isBreak())
break; break;
// Old format
// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one
// + ".help.info")));
if (pl) { if (pl) {
rm.addText("\n" + getUsage(one)); rm.addText("\n" + getUsage(one));
rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info")); rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info"));
@ -182,12 +177,10 @@ public class JobsCommands implements CommandExecutor {
rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one
+ ".help.info"))); + ".help.info")));
} }
} }
rm.show(sender); rm.show(sender);
plugin.showPagination(sender, pi, LABEL + " ?"); pi.autoPagination(sender, LABEL + " ?");
return true; return true;
} }
@ -333,9 +326,9 @@ public class JobsCommands implements CommandExecutor {
String pName = player.getName(); String pName = player.getName();
if (sender.getName().equalsIgnoreCase(pName)) if (sender.getName().equalsIgnoreCase(pName))
plugin.showPagination(sender, pi, "jobs info " + job.getName() + t); pi.autoPagination(sender, LABEL + " " + info.class.getSimpleName() + " " + job.getName() + t);
else else
plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t); pi.autoPagination(sender, LABEL + " " + playerinfo.class.getSimpleName() + " " + job.getName() + t);
} }
} }

View File

@ -113,7 +113,7 @@ public class browse implements Cmd {
rm.show(sender); rm.show(sender);
} }
plugin.showPagination(sender, pi, "jobs browse", "-p:"); pi.autoPagination(sender, "jobs browse", "-p:");
} else { } else {
sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName()));

View File

@ -117,7 +117,7 @@ public class editjobs implements Cmd {
rm.show(sender); rm.show(sender);
Util.getJobsEditorMap().remove(player.getUniqueId()); Util.getJobsEditorMap().remove(player.getUniqueId());
plugin.showPagination(sender, pi, "jobs editjobs list " + job.getName() + " " + actionT.getName()); pi.autoPagination(sender, "jobs editjobs list " + job.getName() + " " + actionT.getName());
return true; return true;
} }

View File

@ -92,7 +92,7 @@ public class gtop implements Cmd {
CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.gtopline"), ls, Jobs.getGCManager().ToplistInScoreboardInterval); CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.gtopline"), ls, Jobs.getGCManager().ToplistInScoreboardInterval);
} }
plugin.showPagination(sender, pi, "jobs gtop"); pi.autoPagination(sender, "jobs gtop");
return true; return true;
} }
} }

View File

@ -87,7 +87,7 @@ public class placeholders implements Cmd {
} }
if (player != null) if (player != null)
plugin.showPagination(sender, pi, "jobs placeholders", "-p:"); pi.autoPagination(sender, "jobs placeholders", "-p:");
return true; return true;
} }
} }

View File

@ -82,7 +82,7 @@ public class top implements Cmd {
"%exp%", one.getExp())); "%exp%", one.getExp()));
place++; place++;
} }
plugin.showPagination(sender, pi, "jobs top " + job.getName()); pi.autoPagination(sender, "jobs top " + job.getName());
} else { } else {
List<String> ls = new ArrayList<>(); List<String> ls = new ArrayList<>();
@ -96,7 +96,7 @@ public class top implements Cmd {
CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", job.getName()), ls, Jobs.getGCManager().ToplistInScoreboardInterval); CMIScoreboard.show(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", job.getName()), ls, Jobs.getGCManager().ToplistInScoreboardInterval);
plugin.showPagination(sender, pi, "jobs top " + job.getName()); pi.autoPagination(sender, "jobs top " + job.getName());
} }
return true; return true;
} }