mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 12:35:28 +01:00
Fixing pagination
This commit is contained in:
parent
0d4123b20f
commit
66fae7ed39
@ -185,7 +185,7 @@ public class Jobs extends JavaPlugin {
|
||||
} else {
|
||||
if (new PlaceholderAPIHook(this).hook())
|
||||
consoleMsg("&e[Jobs] PlaceholderAPI hooked. This is a deprecated version of PlaceholderAPI. Please update "
|
||||
+ "to the latest version.");
|
||||
+ "to the latest version.");
|
||||
}
|
||||
} catch (NumberFormatException e) { // when using a dev build
|
||||
if (new NewPlaceholderAPIHook(this).register()) {
|
||||
@ -254,7 +254,6 @@ public class Jobs extends JavaPlugin {
|
||||
return DBManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the PointsData
|
||||
* @deprecated Use {@link JobsPlayer#getPointsData()}
|
||||
@ -1391,18 +1390,22 @@ public class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void ShowPagination(CommandSender sender, PageInfo pi, String cmd) {
|
||||
ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), cmd, null);
|
||||
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(), cmd, pagePref);
|
||||
ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, pagePref);
|
||||
}
|
||||
|
||||
public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd) {
|
||||
ShowPagination(sender, pageCount, CurrentPage, cmd, null);
|
||||
}
|
||||
// public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd) {
|
||||
// ShowPagination(sender, pageCount, CurrentPage, cmd, null);
|
||||
// }
|
||||
//
|
||||
// public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd, String pagePref) {
|
||||
// ShowPagination(sender, pageCount, CurrentPage, 0, cmd, pagePref);
|
||||
// }
|
||||
|
||||
public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd, String pagePref) {
|
||||
public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, int totalEntries, String cmd, String pagePref) {
|
||||
if (!(sender instanceof Player))
|
||||
return;
|
||||
if (!cmd.startsWith("/"))
|
||||
@ -1416,11 +1419,22 @@ public class Jobs extends JavaPlugin {
|
||||
Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage;
|
||||
|
||||
RawMessage rm = new RawMessage();
|
||||
// rm.add((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")),
|
||||
// CurrentPage > 1 ? "<<<" : null, CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : null);
|
||||
// rm.add(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount));
|
||||
// rm.add(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"),
|
||||
// pageCount > CurrentPage ? ">>>" : null, pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : null);
|
||||
// if (pageCount != 0)
|
||||
// rm.show(sender);
|
||||
|
||||
rm.add((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")),
|
||||
CurrentPage > 1 ? "<<<" : null, CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : null);
|
||||
rm.add(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount));
|
||||
CurrentPage > 1 ? "<<<" : ">|",
|
||||
CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : cmd + " " + pagePrefix + pageCount);
|
||||
rm.add(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount), lManager.getMessage("command.help.output.pageCountHover", "[totalEntries]",
|
||||
totalEntries));
|
||||
rm.add(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"),
|
||||
pageCount > CurrentPage ? ">>>" : null, pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : null);
|
||||
pageCount > CurrentPage ? ">>>" : "|<",
|
||||
pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : cmd + " " + pagePrefix + 1);
|
||||
if (pageCount != 0)
|
||||
rm.show(sender);
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class JobsCommands implements CommandExecutor {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
plugin.ShowPagination(sender, pi.getTotalPages(), page, label + " ?");
|
||||
plugin.ShowPagination(sender, pi, label + " ?");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -332,9 +332,9 @@ public class JobsCommands implements CommandExecutor {
|
||||
|
||||
if (sender instanceof Player)
|
||||
if (sender.getName().equalsIgnoreCase(player.getName()))
|
||||
plugin.ShowPagination(sender, pi.getTotalPages(), page, "jobs info " + job.getName() + t);
|
||||
plugin.ShowPagination(sender, pi, "jobs info " + job.getName() + t);
|
||||
else
|
||||
plugin.ShowPagination(sender, pi.getTotalPages(), page, "jobs playerinfo " + player.getName() + " " + job.getName() + t);
|
||||
plugin.ShowPagination(sender, pi, "jobs playerinfo " + player.getName() + " " + job.getName() + t);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,7 +115,7 @@ public class browse implements Cmd {
|
||||
|
||||
rm.show(sender);
|
||||
}
|
||||
plugin.ShowPagination(sender, pi.getTotalPages(), page, "jobs browse", "-p:");
|
||||
plugin.ShowPagination(sender, pi, "jobs browse", "-p:");
|
||||
} else {
|
||||
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName()));
|
||||
|
@ -108,7 +108,7 @@ public class editjobs implements Cmd {
|
||||
rm.show(sender);
|
||||
Util.getJobsEditorMap().remove(player.getUniqueId());
|
||||
|
||||
Jobs.getInstance().ShowPagination(sender, pi.getTotalPages(), page, "jobs editjobs list " + job.getName() + " " + actionT.getName());
|
||||
Jobs.getInstance().ShowPagination(sender, pi, "jobs editjobs list " + job.getName() + " " + actionT.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -468,7 +468,7 @@ public class editjobs implements Cmd {
|
||||
if (actionT == ActionType.BREAK || actionT == ActionType.PLACE || actionT == ActionType.STRIPLOGS) {
|
||||
if (!material.isBlock()) {
|
||||
player.sendMessage(ChatColor.GOLD + "Job " + job.getName() + " has an invalid " + actionT.getName() + " type property: " + material
|
||||
+ "(" + key + ")! Material must be a block!");
|
||||
+ "(" + key + ")! Material must be a block!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -503,48 +503,48 @@ public class editjobs implements Cmd {
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
switch (key.toLowerCase()) {
|
||||
case "skeletonwither":
|
||||
type = CMIEntityType.WITHER_SKELETON.name();
|
||||
id = 51;
|
||||
meta = "1";
|
||||
break;
|
||||
case "skeletonstray":
|
||||
type = CMIEntityType.STRAY.name();
|
||||
id = 51;
|
||||
meta = "2";
|
||||
break;
|
||||
case "zombievillager":
|
||||
type = CMIEntityType.ZOMBIE_VILLAGER.name();
|
||||
id = 54;
|
||||
meta = "1";
|
||||
break;
|
||||
case "zombiehusk":
|
||||
type = CMIEntityType.HUSK.name();
|
||||
id = 54;
|
||||
meta = "2";
|
||||
break;
|
||||
case "horseskeleton":
|
||||
type = CMIEntityType.SKELETON_HORSE.name();
|
||||
id = 100;
|
||||
meta = "1";
|
||||
break;
|
||||
case "horsezombie":
|
||||
type = CMIEntityType.ZOMBIE_HORSE.name();
|
||||
id = 100;
|
||||
meta = "2";
|
||||
break;
|
||||
case "guardianelder":
|
||||
type = CMIEntityType.ELDER_GUARDIAN.name();
|
||||
id = 68;
|
||||
meta = "1";
|
||||
break;
|
||||
default:
|
||||
type = CMIEntityType.getByName(myKey.toUpperCase()).name();
|
||||
id = CMIEntityType.getByName(myKey.toUpperCase()).getId();
|
||||
meta = "1";
|
||||
break;
|
||||
}
|
||||
switch (key.toLowerCase()) {
|
||||
case "skeletonwither":
|
||||
type = CMIEntityType.WITHER_SKELETON.name();
|
||||
id = 51;
|
||||
meta = "1";
|
||||
break;
|
||||
case "skeletonstray":
|
||||
type = CMIEntityType.STRAY.name();
|
||||
id = 51;
|
||||
meta = "2";
|
||||
break;
|
||||
case "zombievillager":
|
||||
type = CMIEntityType.ZOMBIE_VILLAGER.name();
|
||||
id = 54;
|
||||
meta = "1";
|
||||
break;
|
||||
case "zombiehusk":
|
||||
type = CMIEntityType.HUSK.name();
|
||||
id = 54;
|
||||
meta = "2";
|
||||
break;
|
||||
case "horseskeleton":
|
||||
type = CMIEntityType.SKELETON_HORSE.name();
|
||||
id = 100;
|
||||
meta = "1";
|
||||
break;
|
||||
case "horsezombie":
|
||||
type = CMIEntityType.ZOMBIE_HORSE.name();
|
||||
id = 100;
|
||||
meta = "2";
|
||||
break;
|
||||
case "guardianelder":
|
||||
type = CMIEntityType.ELDER_GUARDIAN.name();
|
||||
id = 68;
|
||||
meta = "1";
|
||||
break;
|
||||
default:
|
||||
type = CMIEntityType.getByName(myKey.toUpperCase()).name();
|
||||
id = CMIEntityType.getByName(myKey.toUpperCase()).getId();
|
||||
meta = "1";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (actionT == ActionType.ENCHANT) {
|
||||
@ -559,7 +559,7 @@ public class editjobs implements Cmd {
|
||||
}
|
||||
type = myKey;
|
||||
} else if (actionT == ActionType.CUSTOMKILL || actionT == ActionType.SHEAR || actionT == ActionType.MMKILL
|
||||
|| actionT == ActionType.COLLECT || actionT == ActionType.BAKE)
|
||||
|| actionT == ActionType.COLLECT || actionT == ActionType.BAKE)
|
||||
type = myKey;
|
||||
else if (actionT == ActionType.EXPLORE) {
|
||||
type = myKey;
|
||||
|
@ -153,8 +153,7 @@ public class editquests implements Cmd {
|
||||
|
||||
Util.getQuestsEditorMap().remove(player.getUniqueId());
|
||||
|
||||
Jobs.getInstance().ShowPagination(sender, pi.getTotalPages(), page,
|
||||
"jobs editquests list " + job.getName() + " " + quest.getConfigName() + " " + 0);
|
||||
Jobs.getInstance().ShowPagination(sender, pi, "jobs editquests list " + job.getName() + " " + quest.getConfigName() + " " + 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -216,41 +215,41 @@ public class editquests implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig();
|
||||
String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + ".";
|
||||
org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig();
|
||||
String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + ".";
|
||||
|
||||
if (file.isString(j + "Target")) {
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), target);
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName());
|
||||
} else if (file.isList(j + "Objectives")) {
|
||||
List<String> list = file.getStringList(j + "Objectives");
|
||||
for (String s : list) {
|
||||
String[] split = s.split(";");
|
||||
if (split[1].contains(target.toLowerCase())) {
|
||||
list.remove(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
File f = Jobs.getConfigManager().getJobFile();
|
||||
file.set(j + "Objectives", list);
|
||||
|
||||
try {
|
||||
file.save(f);
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<String, QuestObjective> one : obj.entrySet()) {
|
||||
if (one.getKey().equalsIgnoreCase(target)) {
|
||||
obj.remove(one.getKey());
|
||||
if (file.isString(j + "Target")) {
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), target);
|
||||
Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName());
|
||||
} else if (file.isList(j + "Objectives")) {
|
||||
List<String> list = file.getStringList(j + "Objectives");
|
||||
for (String s : list) {
|
||||
String[] split = s.split(";");
|
||||
if (split[1].contains(target.toLowerCase())) {
|
||||
list.remove(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
File f = Jobs.getConfigManager().getJobFile();
|
||||
file.set(j + "Objectives", list);
|
||||
|
||||
try {
|
||||
file.save(f);
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<String, QuestObjective> one : obj.entrySet()) {
|
||||
if (one.getKey().equalsIgnoreCase(target)) {
|
||||
obj.remove(one.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName()
|
||||
+ " " + q.getConfigName() + " 1");
|
||||
+ " " + q.getConfigName() + " 1");
|
||||
|
||||
Util.getQuestsEditorMap().remove(player.getUniqueId());
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class top implements Cmd {
|
||||
int workingIn = Jobs.getUsedSlots(job);
|
||||
PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page);
|
||||
|
||||
List<TopList> FullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart());
|
||||
List<TopList> FullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart() - 1);
|
||||
if (FullList.size() <= 0) {
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfo"));
|
||||
return true;
|
||||
@ -66,14 +66,16 @@ public class top implements Cmd {
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.top.help.info", "%amount%", Jobs.getGCManager().JobsTopAmount));
|
||||
|
||||
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", job.getName(), "%amount%", pi.getPerPageCount()));
|
||||
int i = pi.getStart();
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount));
|
||||
for (TopList One : FullList) {
|
||||
i++;
|
||||
if (pi.isContinue())
|
||||
continue;
|
||||
if (pi.isBreak())
|
||||
break;
|
||||
String PlayerName = One.getPlayerName() != null ? One.getPlayerName() : "Unknown";
|
||||
|
||||
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.list",
|
||||
"%number%", i,
|
||||
"%number%", pi.getPositionForOutput(),
|
||||
"%playername%", PlayerName,
|
||||
"%level%", One.getLevel(),
|
||||
"%exp%", One.getExp()));
|
||||
@ -83,15 +85,13 @@ public class top implements Cmd {
|
||||
|
||||
List<String> ls = new ArrayList<>();
|
||||
|
||||
int i = pi.getStart();
|
||||
int y = 0;
|
||||
for (TopList one : FullList) {
|
||||
i++;
|
||||
y++;
|
||||
if (y > Jobs.getGCManager().JobsTopAmount)
|
||||
if (pi.isContinue())
|
||||
continue;
|
||||
if (pi.isBreak())
|
||||
break;
|
||||
String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown";
|
||||
ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", one.getLevel()));
|
||||
ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", pi.getPositionForOutput(), "%playername%", playername, "%level%", one.getLevel()));
|
||||
}
|
||||
|
||||
plugin.getCMIScoreboardManager().setScoreBoard(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", job.getName()), ls);
|
||||
|
@ -15,7 +15,7 @@ public class PageInfo {
|
||||
public PageInfo(int perPage, int totalEntries, int currentPage) {
|
||||
this.perPage = perPage;
|
||||
this.totalEntries = totalEntries;
|
||||
this.currentPage = currentPage;
|
||||
this.currentPage = currentPage < 1 ? 1 : currentPage;
|
||||
calculate();
|
||||
}
|
||||
|
||||
@ -24,15 +24,15 @@ public class PageInfo {
|
||||
}
|
||||
|
||||
public int getPositionForOutput(int place) {
|
||||
return start + place + 1;
|
||||
return this.start + place + 1;
|
||||
}
|
||||
|
||||
private void calculate() {
|
||||
start = (currentPage - 1) * perPage;
|
||||
end = start + perPage - 1;
|
||||
if (end + 1 > totalEntries)
|
||||
end = totalEntries - 1;
|
||||
totalPages = (int) Math.ceil((double) totalEntries / (double) perPage);
|
||||
this.start = (this.currentPage - 1) * this.perPage;
|
||||
this.end = this.start + this.perPage - 1;
|
||||
if (this.end + 1 > this.totalEntries)
|
||||
this.end = this.totalEntries - 1;
|
||||
this.totalPages = (int) Math.ceil((double) this.totalEntries / (double) this.perPage);
|
||||
}
|
||||
|
||||
public boolean isInRange(int place) {
|
||||
@ -46,16 +46,24 @@ public class PageInfo {
|
||||
return currentEntry - 1 >= start && currentEntry - 1 <= end;
|
||||
}
|
||||
|
||||
public boolean isContinue() {
|
||||
return !isEntryOk();
|
||||
}
|
||||
|
||||
public boolean isContinueNoAdd() {
|
||||
return currentEntry - 1 >= start && currentEntry - 1 <= end;
|
||||
}
|
||||
|
||||
public boolean isBreak() {
|
||||
return currentEntry - 1 > end;
|
||||
}
|
||||
|
||||
public boolean isPageOk() {
|
||||
return isPageOk(currentPage);
|
||||
return isPageOk(this.currentPage);
|
||||
}
|
||||
|
||||
public boolean isPageOk(int page) {
|
||||
if (totalPages < page)
|
||||
if (this.totalPages < page)
|
||||
return false;
|
||||
if (page < 1)
|
||||
return false;
|
||||
@ -81,7 +89,12 @@ public class PageInfo {
|
||||
public int getTotalEntries() {
|
||||
return totalEntries;
|
||||
}
|
||||
public int getPerPageCount(){
|
||||
return perPage;
|
||||
|
||||
public int getNextPageNumber() {
|
||||
return this.getCurrentPage() + 1 > this.getTotalPages() ? this.getTotalPages() : this.getCurrentPage() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPrevPageNumber() {
|
||||
return this.getCurrentPage() - 1 < 1 ? 1 : this.getCurrentPage() - 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user