diff --git a/pom.xml b/pom.xml
index 0af2904..210b083 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
com.github.ucchyocean
LunaChat
- 2.8.12
+ 2.8.13
A powerfull chat channel plugin with IME (Kana-Kanji conversion) support
@@ -140,7 +140,7 @@
org.bukkit
bukkit
- 1.14.4-R0.1-SNAPSHOT
+ 1.15.2-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/com/github/ucchyocean/lc/Resources.java b/src/main/java/com/github/ucchyocean/lc/Resources.java
index aa61951..cc9dd60 100644
--- a/src/main/java/com/github/ucchyocean/lc/Resources.java
+++ b/src/main/java/com/github/ucchyocean/lc/Resources.java
@@ -66,12 +66,12 @@ public class Resources {
YamlConfiguration messages = new YamlConfiguration();
JarFile jarFile = null;
+ BufferedReader reader = null;
try {
jarFile = new JarFile(LunaChat.getPluginJarFile());
ZipEntry zipEntry = jarFile.getEntry(FILE_NAME);
InputStream inputStream = jarFile.getInputStream(zipEntry);
- BufferedReader reader =
- new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
+ reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line;
while ( (line = reader.readLine()) != null ) {
if ( line.contains(":") && !line.startsWith("#") ) {
@@ -85,6 +85,13 @@ public class Resources {
} catch (IOException e) {
e.printStackTrace();
} finally {
+ if ( reader != null ) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // do nothing.
+ }
+ }
if ( jarFile != null ) {
try {
jarFile.close();
diff --git a/src/main/java/com/github/ucchyocean/lc/command/ListCommand.java b/src/main/java/com/github/ucchyocean/lc/command/ListCommand.java
index 8243308..63bac69 100644
--- a/src/main/java/com/github/ucchyocean/lc/command/ListCommand.java
+++ b/src/main/java/com/github/ucchyocean/lc/command/ListCommand.java
@@ -6,6 +6,8 @@
package com.github.ucchyocean.lc.command;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -22,6 +24,7 @@ import com.github.ucchyocean.lc.channel.ChannelPlayer;
public class ListCommand extends SubCommandAbst {
private static final String LIST_FIRSTLINE = Resources.get("listFirstLine");
+ private static final String LIST_FIRSTLINE_PAGING = Resources.get("listFirstLinePaging");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
@@ -29,6 +32,8 @@ public class ListCommand extends SubCommandAbst {
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
private static final String USAGE_KEY = "usageList";
+ private static final int PAGE_SIZE = 8;
+
/**
* コマンドを取得します。
* @return コマンド
@@ -88,8 +93,13 @@ public class ListCommand extends SubCommandAbst {
player = (Player) sender;
}
+ int page = 0;
+ if ( args.length >= 2 && args[1].matches("[0-9]") ) {
+ page = Integer.parseInt(args[1]);
+ }
+
// リストを取得して表示する
- ArrayList list = getList(player);
+ ArrayList list = getList(player, page);
for (String msg : list) {
sender.sendMessage(msg);
}
@@ -99,9 +109,39 @@ public class ListCommand extends SubCommandAbst {
/**
* リスト表示用のリストを返す
* @param player プレイヤー、指定しない場合はnullにする
+ * @param page 表示するページ、0を指定した場合は全表示
* @return リスト
*/
- private ArrayList getList(Player player) {
+ private ArrayList getList(Player player, int page) {
+
+ ArrayList list = getPlayerList(player);
+ int size = list.size();
+ int maxPage = (int)(size / PAGE_SIZE) + 1;
+
+ if ( page < 0 ) page = 0;
+ if ( page > maxPage ) page = maxPage;
+
+ ArrayList items = new ArrayList<>();
+ if ( page == 0 ) { // 全表示
+ items.add(LIST_FIRSTLINE);
+ items.addAll(list);
+ items.add(LIST_ENDLINE);
+ } else { // ページ表示
+ items.add(String.format(LIST_FIRSTLINE_PAGING, page, maxPage));
+ int endIndex = (page * PAGE_SIZE > size) ? size : page * PAGE_SIZE;
+ items.addAll(list.subList((page - 1) * PAGE_SIZE, endIndex));
+ items.add(LIST_ENDLINE);
+ }
+
+ return items;
+ }
+
+ /**
+ * 指定されたプレイヤーに対するチャンネルリストを返す
+ * @param player プレイヤー
+ * @return チャンネルリスト
+ */
+ private ArrayList getPlayerList(Player player) {
ArrayList items = new ArrayList();
String dchannel = "";
@@ -117,8 +157,16 @@ public class ListCommand extends SubCommandAbst {
}
ChannelPlayer cp = ChannelPlayer.getChannelPlayer(player);
- items.add(LIST_FIRSTLINE);
- for ( Channel channel : api.getChannels() ) {
+ // チャンネルを取得して、チャンネル名でソートする
+ ArrayList channels = new ArrayList<>(api.getChannels());
+ Collections.sort(channels, new Comparator() {
+ public int compare(Channel c1, Channel c2) {
+ return c1.getName().compareTo(c2.getName());
+ }
+ });
+
+ // 指定されたプレイヤー名に合うように、フィルタ&表示用整形する。
+ for ( Channel channel : channels ) {
// BANされているチャンネルは表示しない
if ( channel.getBanned().contains(cp) ) {
@@ -155,7 +203,6 @@ public class ListCommand extends SubCommandAbst {
LIST_FORMAT, disp, onlineNum, memberNum, desc);
items.add(item);
}
- items.add(LIST_ENDLINE);
return items;
}
diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml
index eed65ec..a990594 100644
--- a/src/main/resources/messages.yml
+++ b/src/main/resources/messages.yml
@@ -25,6 +25,7 @@ removeModeratorMessage: '&f[%color%ch&f]&7%player さんがチャンネルのモ
noRecipientMessage: '&f[%color%ch&f]&7あなたの発言は、誰にも届きませんでした。'
listFirstLine: '&7---------- &bチャンネルリスト &7----------'
+listFirstLinePaging: '&7---------- &bチャンネルリスト&7(&c%d&7/&c%d&7) ----------'
listEndLine: '&7----------------------------------'
listFormat: '&7| &f%s&7(&c%d&7/&c%d&7) &a%s'
listPlainPrefix: '&7| '