2013-01-25 04:53:02 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
2012-03-03 18:54:16 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2013-02-13 17:45:48 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2012-03-03 18:54:16 +01:00
|
|
|
|
2013-01-30 17:53:51 +01:00
|
|
|
public final class SkillGuide {
|
|
|
|
private SkillGuide() {}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public static int getTotalPageNumber(String address) {
|
2012-04-27 11:47:11 +02:00
|
|
|
String[] addressSplit = LocaleLoader.getString(address).split("\n");
|
2013-01-26 23:01:55 +01:00
|
|
|
|
|
|
|
if (addressSplit.length <= 8) {
|
2012-03-03 19:24:47 +01:00
|
|
|
return 1;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return (addressSplit.length/8)+1;
|
2012-03-03 19:24:47 +01:00
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public static ArrayList<String> grabPageContents(String header, String address, int pagenum) {
|
2012-03-03 18:54:16 +01:00
|
|
|
int pageIndexStart = 0;
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-03-03 18:54:16 +01:00
|
|
|
//Determine what string to start at
|
2013-01-26 23:01:55 +01:00
|
|
|
if (pagenum > 1) {
|
2012-03-03 18:54:16 +01:00
|
|
|
pageIndexStart = 8*(pagenum-1);
|
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-03-03 18:54:16 +01:00
|
|
|
ArrayList<String> allStrings = new ArrayList<String>();
|
2012-04-27 11:47:11 +02:00
|
|
|
String split[] = LocaleLoader.getString(address).split("\n");
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-02-02 08:55:49 +01:00
|
|
|
allStrings.add(LocaleLoader.getString("Guides.Header", header));
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-03-03 18:54:16 +01:00
|
|
|
//Add targeted strings
|
2013-01-26 23:01:55 +01:00
|
|
|
while (allStrings.size() < 9) {
|
|
|
|
if (pageIndexStart+allStrings.size() > split.length) {
|
2012-03-03 19:24:47 +01:00
|
|
|
allStrings.add("");
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-03-03 21:43:50 +01:00
|
|
|
allStrings.add(split[pageIndexStart+allStrings.size()-1]);
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2012-03-03 18:54:16 +01:00
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-03-03 19:24:47 +01:00
|
|
|
allStrings.add("Page "+pagenum+" of "+getTotalPageNumber(address));
|
2012-03-03 18:54:16 +01:00
|
|
|
return allStrings;
|
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public static void clearChat(Player player) {
|
2013-02-12 22:47:11 +01:00
|
|
|
player.sendMessage("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
|
2012-03-03 18:54:16 +01:00
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-02-05 14:50:47 +01:00
|
|
|
public static boolean grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) {
|
2013-01-16 05:40:34 +01:00
|
|
|
String skillName = skilltype.toString();
|
2013-02-13 17:45:48 +01:00
|
|
|
String capitalized = StringUtils.getCapitalized(skillName);
|
2013-01-26 23:01:55 +01:00
|
|
|
String localized = SkillTools.localizeSkillName(skilltype);
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Guides.Available", localized, localized.toLowerCase()));
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-02-05 14:50:47 +01:00
|
|
|
String address = "Guides." + capitalized;
|
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
|
|
|
// We have to specify this, otherwise we get the usage string every time we call /skillname...
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (!args[0].equals("?")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkillGuide.clearChat(player);
|
|
|
|
|
|
|
|
for (String target : SkillGuide.grabPageContents(localized, address, 1)) {
|
|
|
|
player.sendMessage(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2013-01-30 17:53:51 +01:00
|
|
|
int totalPages = SkillGuide.getTotalPageNumber(address);
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-02-13 17:45:48 +01:00
|
|
|
if (!StringUtils.isInt(args[1])) {
|
2013-02-05 14:50:47 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid"));
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-02-13 17:45:48 +01:00
|
|
|
if (Integer.parseInt(args[1]) > totalPages) {
|
2013-02-05 14:50:47 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages));
|
|
|
|
return true;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2013-02-05 14:50:47 +01:00
|
|
|
|
|
|
|
SkillGuide.clearChat(player);
|
|
|
|
|
2013-02-13 17:45:48 +01:00
|
|
|
for (String target : SkillGuide.grabPageContents(localized, address, Integer.parseInt(args[1]))) {
|
2013-02-05 14:50:47 +01:00
|
|
|
player.sendMessage(target);
|
2012-03-03 19:24:47 +01:00
|
|
|
}
|
2013-01-30 18:30:45 +01:00
|
|
|
|
2013-02-05 14:50:47 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2013-01-26 23:01:55 +01:00
|
|
|
}
|
2012-03-03 19:24:47 +01:00
|
|
|
}
|
|
|
|
}
|