fix: 修复配置更新 修复无参命令未显示

Signed-off-by: 502647092 <admin@yumc.pw>
merge/1/MERGE
502647092 2016-10-27 01:13:51 +08:00
parent 571c270248
commit ec5cb657cc
4 changed files with 112 additions and 109 deletions

View File

@ -1,13 +1,6 @@
package pw.yumc.YumCore.commands;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -155,9 +148,9 @@ public class CommandHelp {
helpList.add(formatCommand(cmdlist.get(i), label));
}
}
// 帮助结尾
helpList.add(String.format(helpFooter, label, HELPPAGECOUNT));
}
// 帮助结尾
helpList.add(String.format(helpFooter, label, HELPPAGECOUNT));
cacheHelp.put(helpkey, helpList.toArray(new String[0]));
}
sender.sendMessage(cacheHelp.get(helpkey));

View File

@ -4,21 +4,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -116,8 +105,7 @@ public class CommandManager implements TabExecutor {
lookupNames.put(name, plugin);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
}
if ((cmd = plugin.getCommand(name)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 "
+ name + " 命令!"); }
if ((cmd = plugin.getCommand(name)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!"); }
}
cmd.setExecutor(this);
cmd.setTabCompleter(this);
@ -189,8 +177,7 @@ public class CommandManager implements TabExecutor {
List<String> matchedPlayers = new ArrayList<>();
for (Player player : C.Player.getOnlinePlayers()) {
String name = player.getName();
if ((senderPlayer == null || senderPlayer.canSee(player))
&& StringUtil.startsWithIgnoreCase(name, lastWord)) {
if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
matchedPlayers.add(name);
}
}
@ -254,7 +241,7 @@ public class CommandManager implements TabExecutor {
registerTab(method, clazz);
}
}
help = new CommandHelp(cmds);
help = new CommandHelp(defCmd, cmds);
buildCmdNameCache();
}

View File

@ -74,7 +74,7 @@ public class CommandTabInfo {
try {
return (List<String>) method.invoke(origin, cmdArgs);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new CommandException("调用Tab自动补全发生错误 请反馈给开发者 " + Arrays.toString(P.instance.getDescription().getAuthors().toArray()) + " !", e);
throw new CommandException("调用Tab自动补全发生错误 请反馈给开发者 " + Arrays.toString(P.getDescription().getAuthors().toArray()) + " !", e);
}
}

View File

@ -1,17 +1,8 @@
package pw.yumc.YumCore.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.*;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
@ -30,7 +21,7 @@ import pw.yumc.YumCore.bukkit.Log;
* @version 1.0
* @since 2015117 2:36:07
*/
@SuppressWarnings({"unchecked"})
@SuppressWarnings({ "unchecked" })
public class FileConfig extends AbstractConfig {
protected static String VERSION = "Version";
@ -67,7 +58,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param file
* @param file
*
*/
public FileConfig(File file) {
Validate.notNull(file, FILE_NOT_BE_NULL);
@ -77,8 +69,10 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param parent
* @param filename
* @param parent
*
* @param filename
*
*/
public FileConfig(File parent, String filename) {
init(new File(parent, filename), true);
@ -87,7 +81,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param stream
* @param stream
*
*/
public FileConfig(InputStream stream) {
init(stream);
@ -96,7 +91,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param filename
* @param filename
*
*/
public FileConfig(String filename) {
init(new File(plugin.getDataFolder(), filename), true);
@ -105,8 +101,10 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param parent
* @param filename
* @param parent
*
* @param filename
*
*/
public FileConfig(String parent, String filename) {
init(new File(parent, filename), true);
@ -115,9 +113,12 @@ public class FileConfig extends AbstractConfig {
/**
* List
*
* @param <E> List
* @param path
* @param obj
* @param <E>
* List
* @param path
*
* @param obj
*
* @return {@link FileConfig}
*/
public <E> FileConfig addToList(String path, E obj) {
@ -132,8 +133,10 @@ public class FileConfig extends AbstractConfig {
/**
* StringList
*
* @param path
* @param obj
* @param path
*
* @param obj
*
* @return {@link FileConfig}
*/
public FileConfig addToStringList(String path, String obj) {
@ -144,9 +147,12 @@ public class FileConfig extends AbstractConfig {
/**
* StringList
*
* @param path
* @param obj
* @param allowrepeat
* @param path
*
* @param obj
*
* @param allowrepeat
*
* @return {@link FileConfig}
*/
public FileConfig addToStringList(String path, String obj, boolean allowrepeat) {
@ -164,14 +170,13 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param cfgmsg List
* @param cfgmsg
* List
* @return
*/
public List<String> getColorList(List<String> cfgmsg) {
List<String> message = new ArrayList<>();
if (cfgmsg == null) {
return Collections.emptyList();
}
if (cfgmsg == null) { return Collections.emptyList(); }
for (String msg : cfgmsg) {
message.add(ChatColor.translateAlternateColorCodes('&', msg));
}
@ -190,7 +195,8 @@ public class FileConfig extends AbstractConfig {
/**
* Location
*
* @param key
* @param key
*
* @return {@link Location}
*/
public Location getLocation(String key) {
@ -200,8 +206,10 @@ public class FileConfig extends AbstractConfig {
/**
* Location
*
* @param path
* @param def
* @param path
*
* @param def
*
* @return {@link Location}
*/
public Location getLocation(String path, Location def) {
@ -212,7 +220,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param path
* @param path
*
* @return
*/
public String getMessage(String path) {
@ -222,8 +231,10 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param path
* @param def
* @param path
*
* @param def
*
* @return
*/
public String getMessage(String path, String def) {
@ -237,14 +248,13 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param path
* @param path
*
* @return
*/
public List<String> getMessageList(String path) {
List<String> cfgmsg = this.getStringList(path);
if (cfgmsg == null) {
return Collections.emptyList();
}
if (cfgmsg == null) { return Collections.emptyList(); }
for (int i = 0; i < cfgmsg.size(); i++) {
cfgmsg.set(i, ChatColor.translateAlternateColorCodes(ALT_COLOR_CHAR, cfgmsg.get(i)));
}
@ -254,7 +264,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param path
* @param path
*
* @return
*/
public String[] getStringArray(String path) {
@ -276,24 +287,21 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param newver
* @param oldver
* @param newver
*
* @param oldver
*
* @return
*/
public boolean needUpdate(String newver, String oldver) {
if (newver == null) {
return false;
}
if (oldver == null) {
return true;
}
if (newver == null) { return false; }
if (oldver == null) { return true; }
String[] va1 = newver.split("\\.");// 注意此处为正则匹配,不能用"."
String[] va2 = oldver.split("\\.");
int idx = 0;
int minLength = Math.min(va1.length, va2.length);// 取最小长度值
int diff = 0;
while (idx < minLength
&& (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度
while (idx < minLength && (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度
&& (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符
++idx;
}
@ -314,9 +322,12 @@ public class FileConfig extends AbstractConfig {
/**
* List
*
* @param <E> List
* @param path
* @param obj
* @param <E>
* List
* @param path
*
* @param obj
*
* @return {@link FileConfig}
*/
public <E> FileConfig removeFromList(String path, E obj) {
@ -330,8 +341,10 @@ public class FileConfig extends AbstractConfig {
/**
* StringList
*
* @param path
* @param obj
* @param path
*
* @param obj
*
* @return {@link FileConfig}
*/
public FileConfig removeFromStringList(String path, String obj) {
@ -405,7 +418,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param oldcfg
* @param oldcfg
*
*/
protected void backupConfig(FileConfig oldcfg) {
String filename = oldcfg.getConfigName();
@ -423,7 +437,8 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param file
* @param file
*
*/
protected void check(File file) {
String filename = file.getName();
@ -437,9 +452,7 @@ public class FileConfig extends AbstractConfig {
plugin.saveResource(filename, true);
}
} else {
if (stream == null) {
return;
}
if (stream == null) { return; }
FileConfig newcfg = new FileConfig(stream);
FileConfig oldcfg = new FileConfig(file);
if (needUpdate(newcfg, oldcfg)) {
@ -476,7 +489,8 @@ public class FileConfig extends AbstractConfig {
/**
* FileConfig
*
* @param file
* @param file
*
* @return FileConfig
*/
protected FileConfig init(File file) {
@ -487,8 +501,10 @@ public class FileConfig extends AbstractConfig {
/**
* FileConfig
*
* @param file
* @param check
* @param file
*
* @param check
*
* @return FileConfig
*/
protected FileConfig init(File file, boolean check) {
@ -508,7 +524,8 @@ public class FileConfig extends AbstractConfig {
/**
* FileConfig
*
* @param stream
* @param stream
*
* @return FileConfig
*/
protected FileConfig init(InputStream stream) {
@ -516,16 +533,12 @@ public class FileConfig extends AbstractConfig {
try {
this.load(new InputStreamReader(stream, UTF_8));
} catch (InvalidConfigurationException | IllegalArgumentException ex) {
if (file == null) {
throw new IllegalArgumentException(ex);
}
if (file == null) { throw new IllegalArgumentException(ex); }
Log.warning(String.format(CONFIG_FORMAT_ERROR, file.getName()));
Log.warning(ex.getMessage());
saveFromJar();
} catch (IOException ex) {
if (file == null) {
throw new IllegalStateException(ex);
}
if (file == null) { throw new IllegalStateException(ex); }
Log.warning(String.format(CONFIG_READ_ERROR, file.getName()));
}
return this;
@ -534,8 +547,10 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param newcfg
* @param oldcfg
* @param newcfg
*
* @param oldcfg
*
* @return
*/
protected boolean needUpdate(FileConfig newcfg, FileConfig oldcfg) {
@ -545,8 +560,10 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param newcfg
* @param oldcfg
* @param newcfg
*
* @param oldcfg
*
* @return
*/
protected FileConfig updateConfig(FileConfig newCfg, FileConfig oldCfg) {
@ -556,9 +573,12 @@ public class FileConfig extends AbstractConfig {
/**
*
*
* @param newCfg
* @param oldCfg
* @param force
* @param newCfg
*
* @param oldCfg
*
* @param force
*
* @return
*/
protected FileConfig updateConfig(FileConfig newCfg, FileConfig oldCfg, boolean force) {
@ -578,7 +598,10 @@ public class FileConfig extends AbstractConfig {
for (String string : oldConfigKeys) {
Object var = oldCfg.get(string);
// 需要进行节点检查 还有类型检查 不同类型情况下 使用新配置
if (var != null && !(var instanceof MemorySection) && newCfg.get(string).getClass().equals(var.getClass())) {
if (var != null && !(var instanceof MemorySection)) {
if (!newCfg.get(string).getClass().equals(var.getClass())) {
Log.w("警告! 旧数据类型与新配置类型不匹配!");
}
Log.debug(String.format(CONFIG_UPDATE_VALUE, string, var));
newCfg.set(string, var);
}