Added clickable page numbers to lookup pagination

This commit is contained in:
Intelli 2022-02-08 19:25:07 -07:00
parent 673529df54
commit 19efdeff89
10 changed files with 103 additions and 9 deletions

View file

@ -960,7 +960,7 @@ public class LookupCommand {
if (finalArgAction.contains(6) || finalArgAction.contains(7) || finalArgAction.contains(9)) {
Chat.sendMessage(player2, "-----");
}
Chat.sendComponent(player2, Util.getPageNavigation(command.getName(), page, total_pages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>"));
Chat.sendComponent(player2, Util.getPageNavigation(command.getName(), page, total_pages));
}
}
else if (rows > 0) {

View file

@ -181,7 +181,7 @@ public class ConfigFile extends Config {
for (int i = 0; i < lines.size(); i++) {
if (lines.get(i).equalsIgnoreCase(oldLine)) {
if (newLine.length() > 0) {
if (newLine != null && newLine.length() > 0) {
lines.set(i, newLine);
}
else {

View file

@ -135,7 +135,7 @@ public class BlockLookup {
if (found) {
if (count > limit) {
String pageInfo = Color.WHITE + "-----\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "\n";
resultText = resultText + pageInfo;
}
}

View file

@ -123,7 +123,7 @@ public class ChestTransactionLookup {
if (found) {
if (count > limit) {
String pageInfo = Color.WHITE + "-----\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "\n";
result = result + pageInfo;
}
}

View file

@ -115,7 +115,7 @@ public class InteractionLookup {
if (found) {
if (count > limit) {
String pageInfo = Color.WHITE + "-----\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "\n";
result = result + pageInfo;
}
}

View file

@ -115,7 +115,7 @@ public class SignMessageLookup {
if (found) {
if (count > limit) {
result.add(Color.WHITE + "-----");
result.add(Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>"));
result.add(Util.getPageNavigation(command, page, totalPages));
}
}
else {

View file

@ -142,7 +142,6 @@ public class Language {
phrases.put(Phrase.LOOKUP_STORAGE, "{0} {deposited|withdrew} {1} {2}.");
phrases.put(Phrase.LOOKUP_TIME, "{0} ago");
phrases.put(Phrase.LOOKUP_USERNAME, "{0} logged in as {1}.");
phrases.put(Phrase.LOOKUP_VIEW_PAGE, "To view a page, type \"{0}\".");
phrases.put(Phrase.MAXIMUM_RADIUS, "The maximum {lookup|rollback|restore} radius is {0}.");
phrases.put(Phrase.MISSING_ACTION_USER, "To use that action, please specify a user.");
phrases.put(Phrase.MISSING_LOOKUP_TIME, "Please specify the amount of time to {lookup|rollback|restore}.");

View file

@ -123,7 +123,6 @@ public enum Phrase {
LOOKUP_STORAGE,
LOOKUP_TIME,
LOOKUP_USERNAME,
LOOKUP_VIEW_PAGE,
MAXIMUM_RADIUS,
MISSING_ACTION_USER,
MISSING_LOOKUP_TIME,

View file

@ -0,0 +1,20 @@
package net.coreprotect.patch.script;
import java.sql.Statement;
import net.coreprotect.config.ConfigFile;
public class __2_21_0 {
protected static boolean patch(Statement statement) {
try {
ConfigFile.modifyLine("language.yml", "LOOKUP_VIEW_PAGE: \"To view a page, type \\\"{0}\\\".\"", null);
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
}

View file

@ -148,7 +148,83 @@ public class Util extends Queue {
nextArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page + 1) + "|" + nextArrow + Chat.COMPONENT_TAG_CLOSE;
}
return message.append(Color.WHITE + backArrow + Phrase.build(Phrase.LOOKUP_PAGE, page + "/" + totalPages) + nextArrow).toString();
StringBuilder pagination = new StringBuilder();
if (totalPages > 1) {
pagination.append(Color.GREY + "(");
if (page > 3) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + 1 + "|" + "1 " + Chat.COMPONENT_TAG_CLOSE);
if (page > 4 && totalPages > 7) {
pagination.append(Color.GREY + "... ");
}
else {
pagination.append(Color.GREY + "| ");
}
}
int displayStart = (page - 2) < 1 ? 1 : (page - 2);
int displayEnd = (page + 2) > totalPages ? totalPages : (page + 2);
if (page > 999 || (page > 101 && totalPages > 99999)) { // limit to max 5 page numbers
displayStart = (displayStart + 1) < displayEnd ? (displayStart + 1) : displayStart;
displayEnd = (displayEnd - 1) > displayStart ? (displayEnd - 1) : displayEnd;
if (displayStart > (totalPages - 3)) {
displayStart = (totalPages - 3) < 1 ? 1 : (totalPages - 3);
}
}
else { // display at least 7 page numbers
if (displayStart > (totalPages - 5)) {
displayStart = (totalPages - 5) < 1 ? 1 : (totalPages - 5);
}
if (displayEnd < 6) {
displayEnd = 6 > totalPages ? totalPages : 6;
}
}
if (page > 99999) { // limit to max 3 page numbers
displayStart = (displayStart + 1) < displayEnd ? (displayStart + 1) : displayStart;
displayEnd = (displayEnd - 1) >= displayStart ? (displayEnd - 1) : displayEnd;
if (page == (totalPages - 1)) {
displayEnd = totalPages - 1;
}
if (displayStart < displayEnd) {
displayStart = displayEnd;
}
}
if (page > 3 && displayStart == 1) {
displayStart = 2;
}
for (int displayPage = displayStart; displayPage <= displayEnd; displayPage++) {
if (page != displayPage) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + displayPage + "|" + displayPage + (displayPage < totalPages ? " " : "") + Chat.COMPONENT_TAG_CLOSE);
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + displayPage + Color.RESET + (displayPage < totalPages ? " " : ""));
}
if (displayPage < displayEnd) {
pagination.append(Color.GREY + "| ");
}
}
if (displayEnd < totalPages) {
if (displayEnd < (totalPages - 1)) {
pagination.append(Color.GREY + "... ");
}
else {
pagination.append(Color.GREY + "| ");
}
if (page != totalPages) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + totalPages + "|" + totalPages + Chat.COMPONENT_TAG_CLOSE);
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + totalPages);
}
}
pagination.append(Color.GREY + ")");
}
return message.append(Color.WHITE + backArrow + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_PAGE, Color.WHITE + page + "/" + totalPages) + nextArrow + pagination).toString();
}
public static String getTimeSince(long resultTime, long currentTime, boolean component) {