mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-21 01:38:51 +00:00
feat: 兼容新的刷怪蛋 调整一些小问题
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
558157da8a
commit
857a903336
@ -46,6 +46,7 @@ public class P {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("P 类初始化失败 %s:%s", e.getClass().getName(), e.getMessage());
|
||||
Log.d(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,12 +104,14 @@ public class CommandParse {
|
||||
for (int i = 0; i < parses.size(); i++) {
|
||||
try {
|
||||
Parse p = parses.get(i);
|
||||
String param = i < args.length ? args[i] : p.getDefault();
|
||||
String param = i < args.length ? args[i] : null;
|
||||
param = param == null ? p.getDefault(sender) : param;
|
||||
// 参数大于解析器 并且为最后一个参数
|
||||
if (i + 1 == parses.size() && args.length >= parses.size()) {
|
||||
param = join(Arrays.copyOfRange(args, i, args.length), " ");
|
||||
}
|
||||
pobjs.add(param == null ? null : p.parse(sender, param));
|
||||
// 尝试让解析器解析Null参数
|
||||
try { pobjs.add(p.parse(sender, param)); } catch (NullPointerException npe) { pobjs.add(null); }
|
||||
} catch (Exception e) {
|
||||
Log.fd(e);
|
||||
throw new ParseException(String.format("第 %s 个参数 %s", isMain ? 1 : 2 + i, e.getMessage()));
|
||||
@ -125,7 +127,7 @@ public class CommandParse {
|
||||
protected int max = Integer.MAX_VALUE;
|
||||
protected int min = 0;
|
||||
|
||||
public String getDefault() {
|
||||
public String getDefault(CommandSender sender) {
|
||||
return def;
|
||||
}
|
||||
|
||||
@ -178,20 +180,20 @@ public class CommandParse {
|
||||
}
|
||||
|
||||
public static class ValueOfParse extends Parse<Object> {
|
||||
private Class etype;
|
||||
private Enum[] elist;
|
||||
private Class eType;
|
||||
private Enum[] eList;
|
||||
private Method method;
|
||||
private Method checker;
|
||||
|
||||
public ValueOfParse(Class etype, Method method) {
|
||||
this.etype = etype;
|
||||
public ValueOfParse(Class eType, Method method) {
|
||||
this.eType = eType;
|
||||
try {
|
||||
checker = etype.getDeclaredMethod("doubleValue");
|
||||
checker = eType.getDeclaredMethod("doubleValue");
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
this.method = method;
|
||||
if (etype.isEnum()) {
|
||||
this.elist = ((Class<Enum>) etype).getEnumConstants();
|
||||
if (eType.isEnum()) {
|
||||
this.eList = ((Class<Enum>) eType).getEnumConstants();
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,10 +209,10 @@ public class CommandParse {
|
||||
}
|
||||
return result;
|
||||
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
|
||||
if (etype.isEnum() && elist.length < 21) {
|
||||
return throwException("%s 不是 %s 有效值为 %s", arg, etype.getSimpleName(), Arrays.toString(elist));
|
||||
if (eType.isEnum() && eList.length < 21) {
|
||||
return throwException("%s 不是 %s 有效值为 %s", arg, eType.getSimpleName(), Arrays.toString(eList));
|
||||
} else {
|
||||
return throwException("%s 不是一个有效的 %s", arg, etype.getSimpleName());
|
||||
return throwException("%s 不是一个有效的 %s", arg, eType.getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,21 +228,28 @@ public class CommandParse {
|
||||
}
|
||||
|
||||
public static class PlayerParse extends Parse<Player> {
|
||||
boolean sender = false;
|
||||
boolean check = false;
|
||||
|
||||
@Override
|
||||
public Player parse(CommandSender sender, String arg) {
|
||||
Player p = Bukkit.getPlayerExact(arg);
|
||||
if (check && p == null) { return throwException("玩家 %s 不存在或不在线!", arg); }
|
||||
if (this.check && p == null) { return throwException("玩家 %s 不存在或不在线!", arg); }
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parse<Player> handleAttrs() {
|
||||
super.handleAttrs();
|
||||
sender = attrs.containsKey("sender");
|
||||
check = attrs.containsKey("check");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefault(CommandSender sender) {
|
||||
return this.sender && sender instanceof Player ? sender.getName() : super.getDefault(sender);
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringParse extends Parse<String> {
|
||||
|
@ -70,6 +70,9 @@ public class CommandSub implements TabExecutor {
|
||||
*/
|
||||
private List<String> cmdNameCache = new ArrayList<>();
|
||||
|
||||
public CommandSub() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 命令管理器
|
||||
*
|
||||
@ -178,9 +181,9 @@ public class CommandSub implements TabExecutor {
|
||||
if (defCmd != null) { return defCmd.execute(sender, label, args); }
|
||||
return help.send(sender, label, args);
|
||||
}
|
||||
String subcmd = args[0].toLowerCase();
|
||||
if (subcmd.equalsIgnoreCase("help")) { return help.send(sender, label, args); }
|
||||
CommandInfo cmd = getByCache(subcmd);
|
||||
String subCmd = args[0].toLowerCase();
|
||||
if ("help".equalsIgnoreCase(subCmd)) { return help.send(sender, label, args); }
|
||||
CommandInfo cmd = getByCache(subCmd);
|
||||
String[] subargs = args;
|
||||
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
||||
cmd = defCmd;
|
||||
@ -238,7 +241,7 @@ public class CommandSub implements TabExecutor {
|
||||
CommandInfo ci = CommandInfo.parse(method, clazz);
|
||||
if (ci != null) {
|
||||
Class[] params = method.getParameterTypes();
|
||||
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.getSimpleNames((Object[]) params));
|
||||
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.getSimpleNames(params));
|
||||
try {
|
||||
Class<? extends CommandSender> sender = params[0];
|
||||
// 用于消除unuse警告
|
||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||
import org.bukkit.material.SpawnEgg;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
@ -14,8 +15,8 @@ import pw.yumc.YumCore.config.ext.YumConfig;
|
||||
/**
|
||||
* 本地化工具类
|
||||
*
|
||||
* @since 2015年12月14日 下午1:33:52
|
||||
* @author 喵♂呜
|
||||
* @since 2015年12月14日 下午1:33:52
|
||||
*/
|
||||
public class L10N {
|
||||
private static String CONFIG_NAME = "Item_zh_CN.yml";
|
||||
@ -35,18 +36,19 @@ public class L10N {
|
||||
* 获取物品完整汉化名称(包括原版)
|
||||
*
|
||||
* @param i
|
||||
* 物品实体
|
||||
* 物品实体
|
||||
* @return 物品名称
|
||||
*/
|
||||
public static String getFullName(ItemStack i) {
|
||||
return getItemName(getItemType(i)) + (i.hasItemMeta() && i.getItemMeta().hasDisplayName() ? "§r(" + i.getItemMeta().getDisplayName() + "§r)" : "");
|
||||
return getItemName(getItemType(i)) + (i.hasItemMeta() && i.getItemMeta().hasDisplayName() ? "§r(" + i.getItemMeta()
|
||||
.getDisplayName() + "§r)" : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品汉化名称
|
||||
*
|
||||
* @param i
|
||||
* 物品实体
|
||||
* 物品实体
|
||||
* @return 物品名称
|
||||
*/
|
||||
public static String getItemName(ItemStack i) {
|
||||
@ -57,7 +59,7 @@ public class L10N {
|
||||
* 获取物品汉化名称(优先显示名称)
|
||||
*
|
||||
* @param i
|
||||
* 物品实体
|
||||
* 物品实体
|
||||
* @return 物品名称
|
||||
*/
|
||||
public static String getName(ItemStack i) {
|
||||
@ -77,7 +79,7 @@ public class L10N {
|
||||
* 获取物品汉化名称
|
||||
*
|
||||
* @param iname
|
||||
* 物品类型名称
|
||||
* 物品类型名称
|
||||
* @return 物品名称
|
||||
*/
|
||||
private static String getItemName(String iname) {
|
||||
@ -96,14 +98,18 @@ public class L10N {
|
||||
* 获取物品类型名称
|
||||
*
|
||||
* @param i
|
||||
* 物品实体
|
||||
* 物品实体
|
||||
* @return 物品类型
|
||||
*/
|
||||
private static String getItemType(ItemStack i) {
|
||||
String name = i.getType().name();
|
||||
String dura = "";
|
||||
if (i.getType() == Material.MONSTER_EGG) {
|
||||
name = ((SpawnEgg) i.getData()).getSpawnedType().name();
|
||||
try {
|
||||
name = ((SpawnEgg) i.getData()).getSpawnedType().name();
|
||||
} catch (NullPointerException npe) {
|
||||
name = ((SpawnEggMeta) i.getItemMeta()).getSpawnedType().name();
|
||||
}
|
||||
} else {
|
||||
int dur = i.getDurability();
|
||||
dura = (i.getMaxStackSize() != 1 && dur != 0) ? Integer.toString(dur) : "";
|
||||
|
Loading…
Reference in New Issue
Block a user