1
0
mirror of https://e.coding.net/circlecloud/Residence.git synced 2025-11-25 21:56:06 +00:00

move src path and modify config file...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-09-01 17:26:17 +08:00
parent 891e9834d6
commit 3fec9f6871
70 changed files with 230 additions and 317 deletions

View File

@@ -0,0 +1,82 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.bekvon.bukkit.residence.text;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.bukkit.configuration.file.FileConfiguration;
/**
*
* @author Administrator
*/
public class Language {
public Map<String, String> text;
public Language() {
text = new HashMap<String, String>();
}
public void setText(String key, String intext) {
text.put(key, intext);
}
private String getText(String key) {
String t = text.get(key);
if (t == null) {
t = "<missing language key: " + key + ">";
}
return t;
}
public String getPhrase(String key) {
String[] split = key.split("\\.");
return getPhrase(split);
}
public String getPhrase(String[] keys) {
return this.getPhrase(keys, (String[]) null);
}
public String getPhrase(String key, String words) {
return this.getPhrase(key.split("\\."), words);
}
public String getPhrase(String[] keys, String words) {
if (words == null) {
return this.getPhrase(keys, (String[]) null);
} else {
return this.getPhrase(keys, words.split("\\."));
}
}
public String getPhrase(String[] keys, String[] words) {
String sentence = "";
for (String key : keys) {
if (sentence.length() == 0) {
sentence = this.getText(key);
} else {
sentence = sentence + " " + this.getText(key).toLowerCase();
}
}
if (words != null) {
for (int i = 0; i < words.length; i++) {
sentence = sentence.replaceAll("%" + (i + 1), words[i]);
}
}
return sentence;
}
public static Language parseText(FileConfiguration node, String topkey) {
Language newholder = new Language();
Set<String> keys = node.getConfigurationSection(topkey).getKeys(false);
for (String key : keys) {
newholder.text.put(key, node.getString(topkey + "." + key));
}
return newholder;
}
}

View File

@@ -0,0 +1,214 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
/**
*
* @author Administrator
*/
public class HelpEntry {
protected String name;
protected String desc;
protected String[] lines;
protected List<HelpEntry> subentrys;
protected static int linesPerPage = 7;
public HelpEntry(String entryname)
{
name = entryname;
subentrys = new ArrayList<HelpEntry>();
lines = new String[0];
}
public String getName() {
if(name==null)
return "";
return name;
}
public void setName(String inname)
{
name = inname;
}
public void setDescription(String description)
{
desc = description;
}
public String getDescription()
{
if(desc==null)
return "";
return desc;
}
public static int getLinesPerPage()
{
return linesPerPage;
}
public static void setLinesPerPage(int lines)
{
linesPerPage = lines;
}
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 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"));
}
}
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 boolean containesEntry(String name)
{
return this.getSubEntry(name)!=null;
}
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;
}
private HelpEntry findSubEntry(String name)
{
for(HelpEntry entry : subentrys)
{
if(entry.getName().equalsIgnoreCase(name))
return entry;
}
return null;
}
public void addSubEntry(HelpEntry entry)
{
if(!subentrys.contains(entry))
{
subentrys.add(entry);
}
}
public void removeSubEntry(HelpEntry entry)
{
if(subentrys.contains(entry))
{
subentrys.remove(entry);
}
}
public int getSubEntryCount()
{
return subentrys.size();
}
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;
}
}

View File

@@ -0,0 +1,61 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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.command.CommandSender;
/**
*
* @author Administrator
*/
public class InformationPager {
public static int linesPerPage=7;
public static int getLinesPerPage()
{
return linesPerPage;
}
public static void setLinesPerPage(int lines)
{
linesPerPage = lines;
}
public static void printInfo(CommandSender sender, String title, String[] lines, int page)
{
InformationPager.printInfo(sender, title, Arrays.asList(lines), page);
}
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+"-----------------------");
}
}