mirror of
https://github.com/TotalFreedomMC/TFGuilds.git
synced 2024-12-22 16:05:00 +00:00
page /g list
This commit is contained in:
parent
3a97a7428b
commit
e2017b3fd2
4 changed files with 112 additions and 21 deletions
|
@ -25,20 +25,7 @@
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: me.totalfreedom:TotalFreedomMod:2020.9" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: me.totalfreedom:TotalFreedomMod:2020.11.5" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.7" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.9" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TFPatches:TF-LibsDisguises:0cfa32159a" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:7.3.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.protocol:ProtocolLib:4.5.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: me.rayzr522:jsonmessage:1.0.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.reflections:reflections:0.9.11" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javassist:javassist:3.12.1.GA" level="project" />
|
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-core:3.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-core:3.0" level="project" />
|
||||||
|
@ -68,6 +55,7 @@
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: xml-apis:xml-apis:1.3.04" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: xml-apis:xml-apis:1.3.04" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpclient:4.0.2" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpclient:4.0.2" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.3" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-validator:commons-validator:1.3.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-validator:commons-validator:1.3.1" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-digester:commons-digester:1.6" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-digester:commons-digester:1.6" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
|
||||||
|
@ -87,6 +75,7 @@
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-taglib:1.3.8" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-taglib:1.3.8" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-tiles:1.3.8" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-tiles:1.3.8" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.doxia:doxia-integration-tools:1.6" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.doxia:doxia-integration-tools:1.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:1.4" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:3.8.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:3.8.1" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
|
||||||
|
@ -105,6 +94,6 @@
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.14" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.16" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
6
pom.xml
6
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>me.totalfreedom</groupId>
|
<groupId>me.totalfreedom</groupId>
|
||||||
<artifactId>TFGuilds</artifactId>
|
<artifactId>TFGuilds</artifactId>
|
||||||
<version>0.2.17</version>
|
<version>0.2.18</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>TFGuilds</name>
|
<name>TFGuilds</name>
|
||||||
|
@ -83,13 +83,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.totalfreedom</groupId>
|
<groupId>me.totalfreedom</groupId>
|
||||||
<artifactId>TotalFreedomMod</artifactId>
|
<artifactId>TotalFreedomMod</artifactId>
|
||||||
<version>2020.9</version>
|
<version>2020.11.5</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.14</version>
|
<version>1.18.16</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.command;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.tfguilds.Common;
|
import me.totalfreedom.tfguilds.Common;
|
||||||
import me.totalfreedom.tfguilds.guild.Guild;
|
import me.totalfreedom.tfguilds.guild.Guild;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import me.totalfreedom.tfguilds.util.PaginationList;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -14,7 +14,14 @@ public class ListSubcommand extends Common implements CommandExecutor
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||||
{
|
{
|
||||||
|
if (args.length > 2)
|
||||||
|
{
|
||||||
|
sender.sendMessage(tl(PREFIX + "Proper usage: /g list [page]"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> guilds = Guild.getGuildList();
|
List<String> guilds = Guild.getGuildList();
|
||||||
|
PaginationList<String> paged = new PaginationList<>(10);
|
||||||
|
|
||||||
if (guilds.isEmpty())
|
if (guilds.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -22,8 +29,37 @@ public class ListSubcommand extends Common implements CommandExecutor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%)"));
|
paged.addAll(guilds);
|
||||||
sender.sendMessage(tl("%s%- %p%" + StringUtils.join(guilds, "\n%s%- %p%")));
|
|
||||||
|
int pageIndex = 1;
|
||||||
|
|
||||||
|
if (args.length >= 2)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pageIndex = Integer.parseInt(args[1]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageIndex > paged.getPageCount() || pageIndex + 1 < paged.getPageCount())
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.RED + "Not a valid page number");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
paged.getPage(pageIndex);
|
||||||
|
List<String> page = paged.getPage(pageIndex);
|
||||||
|
|
||||||
|
sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
|
||||||
|
|
||||||
|
for (String guild : page)
|
||||||
|
{
|
||||||
|
sender.sendMessage(tl("%s%- %p%" + guild));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package me.totalfreedom.tfguilds.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PaginationList<T> extends ArrayList<T>
|
||||||
|
{
|
||||||
|
private final int epp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a new Pagination List.
|
||||||
|
* @param epp Elements per page - how many elements will be included on a page of the list.
|
||||||
|
*/
|
||||||
|
public PaginationList(int epp)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.epp = epp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a new Pagination List.
|
||||||
|
* @param epp Elements per page - how many elements will be included on a page of the list.
|
||||||
|
* @param elements Elements to add to the list immediately.
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PaginationList(int epp, T... elements)
|
||||||
|
{
|
||||||
|
super(Arrays.asList(elements));
|
||||||
|
this.epp = epp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The number of pages this list holds.
|
||||||
|
*/
|
||||||
|
public int getPageCount()
|
||||||
|
{
|
||||||
|
return (int) Math.ceil((double) size() / (double) epp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a page from the list.
|
||||||
|
* @param page Page you want to access.
|
||||||
|
* @return A sublist of only the elements from that page.
|
||||||
|
*/
|
||||||
|
public List<T> getPage(int page)
|
||||||
|
{
|
||||||
|
if (page < 1 || page > getPageCount()) return null;
|
||||||
|
int startIndex = (page - 1) * epp;
|
||||||
|
int endIndex = Math.min(startIndex + (epp - 1), this.size() - 1);
|
||||||
|
return subList(startIndex, endIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder res = new StringBuilder();
|
||||||
|
for (int i = 1; i <= getPageCount(); i++)
|
||||||
|
{
|
||||||
|
res.append("Page ").append(i).append(": ").append("\n");
|
||||||
|
for (T element : getPage(i))
|
||||||
|
res.append(" - ").append(element).append("\n");
|
||||||
|
}
|
||||||
|
return res.toString();
|
||||||
|
}*/
|
||||||
|
}
|
Loading…
Reference in a new issue