summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-10 19:29:37 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-10 19:29:37 +0000
commitaffa1dd652fc8d46f1188d349a1bd84c25833fed (patch)
tree09927f05b6529497fdd9e8b6e4425fe08ad9e99d
parent44de35240d4f42fd256998e55c840d1222224aa9 (diff)
downloadEssentials-affa1dd652fc8d46f1188d349a1bd84c25833fed.tar
Essentials-affa1dd652fc8d46f1188d349a1bd84c25833fed.tar.gz
Essentials-affa1dd652fc8d46f1188d349a1bd84c25833fed.tar.lz
Essentials-affa1dd652fc8d46f1188d349a1bd84c25833fed.tar.xz
Essentials-affa1dd652fc8d46f1188d349a1bd84c25833fed.zip
[trunk] New /info command, reads text from info.txt.
Chapters are supported. Each line that starts with #name creates a chapter named name. Name does not support spaces and ignores case. If info.txt contains chapters and no chapter is selected with /info command, then it will either print the file until the first chapter or if the first line is a chapter, it will return a list of all chapters. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1164 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandinfo.java147
-rw-r--r--Essentials/src/plugin.yml3
2 files changed, 150 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java
new file mode 100644
index 000000000..b83131165
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java
@@ -0,0 +1,147 @@
+package com.earth2me.essentials.commands;
+
+import com.earth2me.essentials.Essentials;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.bukkit.Server;
+import org.bukkit.command.CommandSender;
+
+public class Commandinfo extends EssentialsCommand {
+
+ public Commandinfo() {
+ super("info");
+ }
+
+ @Override
+ protected void run(Server server, Essentials parent, CommandSender sender, String commandLabel, String[] args) throws Exception {
+ String pageStr = args.length > 0 ? args[0].trim() : null;
+
+ List<String> lines = new ArrayList<String>();
+ List<String> chapters = new ArrayList<String>();
+ Map<String, Integer> bookmarks = new HashMap<String, Integer>();
+ File file = new File(parent.getDataFolder(), "info.txt");
+ if (file.exists())
+ {
+ BufferedReader rx = new BufferedReader(new FileReader(file));
+ int i = 0;
+ for (String l = null; rx.ready() && (l = rx.readLine()) != null; i++)
+ {
+ if (l.startsWith("#")) {
+ bookmarks.put(l.substring(1).toLowerCase(), i);
+ chapters.add(l.substring(1));
+ }
+ lines.add(l.replace('&', '§'));
+ }
+ } else {
+ sender.sendMessage("File info.txt does not exists.");
+ return;
+ }
+
+ if (bookmarks.isEmpty()) {
+ int page = 1;
+ try
+ {
+ page = Integer.parseInt(pageStr);
+ }
+ catch (Exception ex)
+ {
+ page = 1;
+ }
+
+ int start = (page - 1) * 9;
+ int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);
+
+ sender.sendMessage("Page §c" + page + "§f of §c" + pages + "§f:");
+ for (int i = start; i < lines.size() && i < start + 9; i++)
+ {
+ sender.sendMessage(lines.get(i));
+ }
+ return;
+ }
+
+ if (pageStr == null || pageStr.isEmpty() || pageStr.matches("[0-9]+")) {
+ if (lines.get(0).startsWith("#")) {
+ sender.sendMessage("Select chapter:");
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (String string : chapters) {
+ if (!first) {
+ sb.append(", ");
+ }
+ first = false;
+ sb.append(string);
+ }
+ sender.sendMessage(sb.toString());
+ return;
+ } else {
+ int page = 1;
+ try
+ {
+ page = Integer.parseInt(pageStr);
+ }
+ catch (Exception ex)
+ {
+ page = 1;
+ }
+
+ int start = (page - 1) * 9;
+ int end;
+ for (end = 0; end < lines.size(); end++)
+ {
+ String line = lines.get(end);
+ if (line.startsWith("#")) {
+ break;
+ }
+ }
+ int pages = end / 9 + (end % 9 > 0 ? 1 : 0);
+
+ sender.sendMessage("Page §c" + page + "§f of §c" + pages + "§f:");
+ for (int i = start; i < end && i < start + 9; i++)
+ {
+ sender.sendMessage(lines.get(i));
+ }
+ return;
+ }
+ }
+
+ int chapterpage = 0;
+ if (args.length >= 2) {
+ try
+ {
+ chapterpage = Integer.parseInt(args[1]) - 1;
+ }
+ catch (Exception ex)
+ {
+ chapterpage = 0;
+ }
+ }
+
+ if (!bookmarks.containsKey(pageStr.toLowerCase())) {
+ sender.sendMessage("Unknown chapter.");
+ return;
+ }
+ int chapterstart = bookmarks.get(pageStr.toLowerCase()) + 1;
+ int chapterend;
+ for (chapterend = chapterstart; chapterend < lines.size(); chapterend++)
+ {
+ String line = lines.get(chapterend);
+ if (line.startsWith("#")) {
+ break;
+ }
+ }
+ int start = chapterstart + chapterpage * 9;
+ int page = chapterpage + 1;
+ int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0);
+
+ sender.sendMessage("Chapter "+ pageStr +", page §c" + page + "§f of §c" + pages + "§f:");
+ for (int i = start; i < chapterend && i < start + 9; i++)
+ {
+ sender.sendMessage(lines.get(i));
+ }
+ }
+}
diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml
index 8bd096375..be75b17df 100644
--- a/Essentials/src/plugin.yml
+++ b/Essentials/src/plugin.yml
@@ -91,6 +91,9 @@ commands:
home:
description: Teleport to your home.
usage: /<command>
+ info:
+ description: Shows information set by the server owner
+ usage: /<command> [chapter] [page]
invsee:
description: See the inventory of other players.
usage: /<command> <player>