mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-25 21:56:06 +00:00
@@ -4,211 +4,191 @@
|
||||
*/
|
||||
|
||||
package com.bekvon.bukkit.residence.text.help;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class HelpEntry {
|
||||
protected String name;
|
||||
protected String desc;
|
||||
protected String[] lines;
|
||||
protected List<HelpEntry> subentrys;
|
||||
protected static int linesPerPage = 7;
|
||||
protected static int linesPerPage = 7;
|
||||
protected String desc;
|
||||
protected String[] lines;
|
||||
protected String name;
|
||||
protected List<HelpEntry> subentrys;
|
||||
Residence plugin;
|
||||
|
||||
public HelpEntry(String entryname)
|
||||
{
|
||||
name = entryname;
|
||||
subentrys = new ArrayList<HelpEntry>();
|
||||
lines = new String[0];
|
||||
}
|
||||
public HelpEntry(final Residence plugin, final String entryname) {
|
||||
this.plugin = plugin;
|
||||
name = entryname;
|
||||
subentrys = new ArrayList<HelpEntry>();
|
||||
lines = new String[0];
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if(name==null)
|
||||
return "";
|
||||
return name;
|
||||
}
|
||||
public static int getLinesPerPage() {
|
||||
return linesPerPage;
|
||||
}
|
||||
|
||||
public void setName(String inname)
|
||||
{
|
||||
name = inname;
|
||||
}
|
||||
public static HelpEntry parseHelp(final Residence plugin, final FileConfiguration node, final String key) {
|
||||
final String split[] = key.split("\\.");
|
||||
final String thisname = split[split.length - 1];
|
||||
final HelpEntry entry = new HelpEntry(plugin, thisname);
|
||||
final ConfigurationSection keysnode = node.getConfigurationSection(key);
|
||||
Set<String> keys = null;
|
||||
if (keysnode != null) {
|
||||
keys = keysnode.getKeys(false);
|
||||
}
|
||||
if (keys != null) {
|
||||
if (keys.contains("Info")) {
|
||||
final List<String> stringList = node.getStringList(key + ".Info");
|
||||
if (stringList != null) {
|
||||
entry.lines = new String[stringList.size()];
|
||||
for (int i = 0; i < stringList.size(); i++) {
|
||||
entry.lines[i] = "- " + stringList.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keys.contains("Description")) {
|
||||
entry.desc = node.getString(key + ".Description");
|
||||
}
|
||||
if (keys.contains("SubCommands")) {
|
||||
final Set<String> subcommandkeys = node.getConfigurationSection(key + ".SubCommands").getKeys(false);
|
||||
for (final String subkey : subcommandkeys) {
|
||||
entry.subentrys.add(HelpEntry.parseHelp(plugin, node, key + ".SubCommands." + subkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
desc = description;
|
||||
}
|
||||
public String getDescription()
|
||||
{
|
||||
if(desc==null)
|
||||
return "";
|
||||
return desc;
|
||||
}
|
||||
public static void setLinesPerPage(final int lines) {
|
||||
linesPerPage = lines;
|
||||
}
|
||||
|
||||
public static int getLinesPerPage()
|
||||
{
|
||||
return linesPerPage;
|
||||
}
|
||||
public void addSubEntry(final HelpEntry entry) {
|
||||
if (!subentrys.contains(entry)) {
|
||||
subentrys.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLinesPerPage(int lines)
|
||||
{
|
||||
linesPerPage = lines;
|
||||
}
|
||||
public boolean containesEntry(final String name) {
|
||||
return this.getSubEntry(name) != null;
|
||||
}
|
||||
|
||||
public void printHelp(CommandSender sender, int page) {
|
||||
List<String> helplines = this.getHelpData();
|
||||
int pagecount = (int) Math.ceil((double)helplines.size() / (double)linesPerPage);
|
||||
if (page > pagecount || page < 1) {
|
||||
sender.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("InvalidHelp"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("HelpPageHeader",ChatColor.YELLOW + name + ChatColor.RED+"."+ChatColor.YELLOW + page + ChatColor.RED+"."+ChatColor.YELLOW + pagecount + ChatColor.RED));
|
||||
sender.sendMessage(ChatColor.DARK_AQUA+Residence.getLanguage().getPhrase("Description")+": "+ChatColor.GREEN + desc);
|
||||
int start = linesPerPage * (page - 1);
|
||||
int end = start + linesPerPage;
|
||||
boolean alternatecolor = false;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (helplines.size() > i) {
|
||||
if(alternatecolor)
|
||||
{
|
||||
sender.sendMessage(ChatColor.YELLOW+helplines.get(i));
|
||||
alternatecolor = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.GOLD+helplines.get(i));
|
||||
alternatecolor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(page<pagecount)
|
||||
sender.sendMessage(ChatColor.GRAY+"---<"+Residence.getLanguage().getPhrase("NextPage")+">---");
|
||||
else
|
||||
sender.sendMessage(ChatColor.GRAY+"-----------------------");
|
||||
}
|
||||
public String getDescription() {
|
||||
if (desc == null) {
|
||||
return "";
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void printHelp(CommandSender sender, int page, String path)
|
||||
{
|
||||
HelpEntry subEntry = this.getSubEntry(path);
|
||||
if(subEntry!=null)
|
||||
{
|
||||
subEntry.printHelp(sender, page);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("InvalidHelp"));
|
||||
}
|
||||
}
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
return "";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private List<String> getHelpData()
|
||||
{
|
||||
List<String> helplines = new ArrayList<String>();
|
||||
helplines.addAll(Arrays.asList(lines));
|
||||
if(subentrys.size()>0)
|
||||
helplines.add(ChatColor.LIGHT_PURPLE+"---"+Residence.getLanguage().getPhrase("SubCommands")+"---");
|
||||
for(HelpEntry entry : subentrys)
|
||||
{
|
||||
helplines.add(ChatColor.GREEN+entry.getName() + ChatColor.YELLOW+" - " + entry.getDescription());
|
||||
}
|
||||
return helplines;
|
||||
}
|
||||
public HelpEntry getSubEntry(final String name) {
|
||||
final String[] split = name.split("\\.");
|
||||
HelpEntry entry = this;
|
||||
for (final String entryname : split) {
|
||||
entry = entry.findSubEntry(entryname);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
public boolean containesEntry(String name)
|
||||
{
|
||||
return this.getSubEntry(name)!=null;
|
||||
}
|
||||
public int getSubEntryCount() {
|
||||
return subentrys.size();
|
||||
}
|
||||
|
||||
public HelpEntry getSubEntry(String name)
|
||||
{
|
||||
String[] split = name.split("\\.");
|
||||
HelpEntry entry = this;
|
||||
for(String entryname : split)
|
||||
{
|
||||
entry = entry.findSubEntry(entryname);
|
||||
if(entry == null)
|
||||
return null;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
public void printHelp(final CommandSender sender, final int page) {
|
||||
final List<String> helplines = this.getHelpData();
|
||||
final int pagecount = (int) Math.ceil((double) helplines.size() / (double) linesPerPage);
|
||||
if (page > pagecount || page < 1) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidHelp"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("HelpPageHeader",
|
||||
ChatColor.YELLOW + name + ChatColor.RED + "." + ChatColor.YELLOW + page + ChatColor.RED + "." + ChatColor.YELLOW + pagecount + ChatColor.RED));
|
||||
sender.sendMessage(ChatColor.DARK_AQUA + plugin.getLanguage().getPhrase("Description") + ": " + ChatColor.GREEN + desc);
|
||||
final int start = linesPerPage * (page - 1);
|
||||
final int end = start + linesPerPage;
|
||||
boolean alternatecolor = false;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (helplines.size() > i) {
|
||||
if (alternatecolor) {
|
||||
sender.sendMessage(ChatColor.YELLOW + helplines.get(i));
|
||||
alternatecolor = false;
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GOLD + helplines.get(i));
|
||||
alternatecolor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (page < pagecount) {
|
||||
sender.sendMessage(ChatColor.GRAY + "---<" + plugin.getLanguage().getPhrase("NextPage") + ">---");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GRAY + "-----------------------");
|
||||
}
|
||||
}
|
||||
|
||||
private HelpEntry findSubEntry(String name)
|
||||
{
|
||||
for(HelpEntry entry : subentrys)
|
||||
{
|
||||
if(entry.getName().equalsIgnoreCase(name))
|
||||
return entry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void printHelp(final CommandSender sender, final int page, final String path) {
|
||||
final HelpEntry subEntry = this.getSubEntry(path);
|
||||
if (subEntry != null) {
|
||||
subEntry.printHelp(sender, page);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidHelp"));
|
||||
}
|
||||
}
|
||||
|
||||
public void addSubEntry(HelpEntry entry)
|
||||
{
|
||||
if(!subentrys.contains(entry))
|
||||
{
|
||||
subentrys.add(entry);
|
||||
}
|
||||
}
|
||||
public void removeSubEntry(final HelpEntry entry) {
|
||||
if (subentrys.contains(entry)) {
|
||||
subentrys.remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSubEntry(HelpEntry entry)
|
||||
{
|
||||
if(subentrys.contains(entry))
|
||||
{
|
||||
subentrys.remove(entry);
|
||||
}
|
||||
}
|
||||
public void setDescription(final String description) {
|
||||
desc = description;
|
||||
}
|
||||
|
||||
public int getSubEntryCount()
|
||||
{
|
||||
return subentrys.size();
|
||||
}
|
||||
public void setName(final String inname) {
|
||||
name = inname;
|
||||
}
|
||||
|
||||
public static HelpEntry parseHelp(FileConfiguration node, String key)
|
||||
{
|
||||
String split[] = key.split("\\.");
|
||||
String thisname = split[split.length-1];
|
||||
HelpEntry entry = new HelpEntry(thisname);
|
||||
ConfigurationSection keysnode = node.getConfigurationSection(key);
|
||||
Set<String> keys = null;
|
||||
if(keysnode!=null)
|
||||
keys = keysnode.getKeys(false);
|
||||
if(keys!=null)
|
||||
{
|
||||
if(keys.contains("Info"))
|
||||
{
|
||||
List<String> stringList = node.getStringList(key + ".Info");
|
||||
if(stringList != null)
|
||||
{
|
||||
entry.lines = new String[stringList.size()];
|
||||
for(int i = 0; i < stringList.size(); i++)
|
||||
{
|
||||
entry.lines[i] = "- " + stringList.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(keys.contains("Description"))
|
||||
{
|
||||
entry.desc = node.getString(key + ".Description");
|
||||
}
|
||||
if(keys.contains("SubCommands"))
|
||||
{
|
||||
Set<String> subcommandkeys = node.getConfigurationSection(key + ".SubCommands").getKeys(false);
|
||||
for(String subkey : subcommandkeys)
|
||||
{
|
||||
entry.subentrys.add(HelpEntry.parseHelp(node, key+".SubCommands."+subkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
private HelpEntry findSubEntry(final String name) {
|
||||
for (final HelpEntry entry : subentrys) {
|
||||
if (entry.getName().equalsIgnoreCase(name)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> getHelpData() {
|
||||
final List<String> helplines = new ArrayList<String>();
|
||||
helplines.addAll(Arrays.asList(lines));
|
||||
if (subentrys.size() > 0) {
|
||||
helplines.add(ChatColor.LIGHT_PURPLE + "---" + plugin.getLanguage().getPhrase("SubCommands") + "---");
|
||||
}
|
||||
for (final HelpEntry entry : subentrys) {
|
||||
helplines.add(ChatColor.GREEN + entry.getName() + ChatColor.YELLOW + " - " + entry.getDescription());
|
||||
}
|
||||
return helplines;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,58 +4,59 @@
|
||||
*/
|
||||
|
||||
package com.bekvon.bukkit.residence.text.help;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class InformationPager {
|
||||
|
||||
public static int linesPerPage=7;
|
||||
|
||||
public static int getLinesPerPage()
|
||||
{
|
||||
return linesPerPage;
|
||||
}
|
||||
public static int linesPerPage = 7;
|
||||
|
||||
public static void setLinesPerPage(int lines)
|
||||
{
|
||||
linesPerPage = lines;
|
||||
}
|
||||
public static int getLinesPerPage() {
|
||||
return linesPerPage;
|
||||
}
|
||||
|
||||
public static void printInfo(CommandSender sender, String title, String[] lines, int page)
|
||||
{
|
||||
InformationPager.printInfo(sender, title, Arrays.asList(lines), page);
|
||||
}
|
||||
public static void printInfo(final Residence plugin, final CommandSender sender, final String title, final List<String> lines, final int page) {
|
||||
final int perPage = 6;
|
||||
final int start = (page - 1) * perPage;
|
||||
final int end = start + perPage;
|
||||
int pagecount = (int) Math.ceil((double) lines.size() / (double) perPage);
|
||||
if (pagecount == 0) {
|
||||
pagecount = 1;
|
||||
}
|
||||
if (page > pagecount) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidPage"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.YELLOW + "---<" + ChatColor.GREEN + title + ChatColor.YELLOW + ">---");
|
||||
sender.sendMessage(ChatColor.YELLOW + "---<"
|
||||
+ plugin.getLanguage().getPhrase("GenericPage", ChatColor.GREEN + String.format("%d", page) + ChatColor.YELLOW + "." + ChatColor.GREEN + pagecount + ChatColor.YELLOW) + ">---");
|
||||
for (int i = start; i < end; i++) {
|
||||
if (lines.size() > i) {
|
||||
sender.sendMessage(ChatColor.GREEN + lines.get(i));
|
||||
}
|
||||
}
|
||||
if (pagecount > page) {
|
||||
sender.sendMessage(ChatColor.GRAY + "---<" + plugin.getLanguage().getPhrase("NextPage") + ">---");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GRAY + "-----------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public static void printInfo(CommandSender sender, String title, List<String> lines, int page) {
|
||||
int perPage = 6;
|
||||
int start = (page-1) * perPage;
|
||||
int end = start + perPage;
|
||||
int pagecount = (int) Math.ceil((double)lines.size()/(double)perPage);
|
||||
if(pagecount == 0)
|
||||
pagecount = 1;
|
||||
if(page>pagecount)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("InvalidPage"));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(ChatColor.YELLOW+"---<"+ChatColor.GREEN+title+ChatColor.YELLOW+">---");
|
||||
sender.sendMessage(ChatColor.YELLOW+"---<"+Residence.getLanguage().getPhrase("GenericPage",ChatColor.GREEN+String.format("%d",page)+ChatColor.YELLOW+"."+ChatColor.GREEN+pagecount+ChatColor.YELLOW)+">---");
|
||||
for(int i = start; i < end; i ++)
|
||||
{
|
||||
if(lines.size()>i)
|
||||
sender.sendMessage(ChatColor.GREEN+lines.get(i));
|
||||
}
|
||||
if(pagecount>page)
|
||||
sender.sendMessage(ChatColor.GRAY+"---<"+Residence.getLanguage().getPhrase("NextPage")+">---");
|
||||
else
|
||||
sender.sendMessage(ChatColor.GRAY+"-----------------------");
|
||||
}
|
||||
public static void printInfo(final Residence plugin, final CommandSender sender, final String title, final String[] lines, final int page) {
|
||||
InformationPager.printInfo(plugin, sender, title, Arrays.asList(lines), page);
|
||||
}
|
||||
|
||||
public static void setLinesPerPage(final int lines) {
|
||||
linesPerPage = lines;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user