mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +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) {
|
} catch (Exception e) {
|
||||||
Log.d("P 类初始化失败 %s:%s", e.getClass().getName(), e.getMessage());
|
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++) {
|
for (int i = 0; i < parses.size(); i++) {
|
||||||
try {
|
try {
|
||||||
Parse p = parses.get(i);
|
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()) {
|
if (i + 1 == parses.size() && args.length >= parses.size()) {
|
||||||
param = join(Arrays.copyOfRange(args, i, args.length), " ");
|
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) {
|
} catch (Exception e) {
|
||||||
Log.fd(e);
|
Log.fd(e);
|
||||||
throw new ParseException(String.format("第 %s 个参数 %s", isMain ? 1 : 2 + i, e.getMessage()));
|
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 max = Integer.MAX_VALUE;
|
||||||
protected int min = 0;
|
protected int min = 0;
|
||||||
|
|
||||||
public String getDefault() {
|
public String getDefault(CommandSender sender) {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,20 +180,20 @@ public class CommandParse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ValueOfParse extends Parse<Object> {
|
public static class ValueOfParse extends Parse<Object> {
|
||||||
private Class etype;
|
private Class eType;
|
||||||
private Enum[] elist;
|
private Enum[] eList;
|
||||||
private Method method;
|
private Method method;
|
||||||
private Method checker;
|
private Method checker;
|
||||||
|
|
||||||
public ValueOfParse(Class etype, Method method) {
|
public ValueOfParse(Class eType, Method method) {
|
||||||
this.etype = etype;
|
this.eType = eType;
|
||||||
try {
|
try {
|
||||||
checker = etype.getDeclaredMethod("doubleValue");
|
checker = eType.getDeclaredMethod("doubleValue");
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {
|
||||||
}
|
}
|
||||||
this.method = method;
|
this.method = method;
|
||||||
if (etype.isEnum()) {
|
if (eType.isEnum()) {
|
||||||
this.elist = ((Class<Enum>) etype).getEnumConstants();
|
this.eList = ((Class<Enum>) eType).getEnumConstants();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,10 +209,10 @@ public class CommandParse {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
|
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
|
||||||
if (etype.isEnum() && elist.length < 21) {
|
if (eType.isEnum() && eList.length < 21) {
|
||||||
return throwException("%s 不是 %s 有效值为 %s", arg, etype.getSimpleName(), Arrays.toString(elist));
|
return throwException("%s 不是 %s 有效值为 %s", arg, eType.getSimpleName(), Arrays.toString(eList));
|
||||||
} else {
|
} 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> {
|
public static class PlayerParse extends Parse<Player> {
|
||||||
|
boolean sender = false;
|
||||||
boolean check = false;
|
boolean check = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player parse(CommandSender sender, String arg) {
|
public Player parse(CommandSender sender, String arg) {
|
||||||
Player p = Bukkit.getPlayerExact(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;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Parse<Player> handleAttrs() {
|
public Parse<Player> handleAttrs() {
|
||||||
super.handleAttrs();
|
super.handleAttrs();
|
||||||
|
sender = attrs.containsKey("sender");
|
||||||
check = attrs.containsKey("check");
|
check = attrs.containsKey("check");
|
||||||
return this;
|
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> {
|
public static class StringParse extends Parse<String> {
|
||||||
|
@ -70,6 +70,9 @@ public class CommandSub implements TabExecutor {
|
|||||||
*/
|
*/
|
||||||
private List<String> cmdNameCache = new ArrayList<>();
|
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); }
|
if (defCmd != null) { return defCmd.execute(sender, label, args); }
|
||||||
return help.send(sender, label, args);
|
return help.send(sender, label, args);
|
||||||
}
|
}
|
||||||
String subcmd = args[0].toLowerCase();
|
String subCmd = args[0].toLowerCase();
|
||||||
if (subcmd.equalsIgnoreCase("help")) { return help.send(sender, label, args); }
|
if ("help".equalsIgnoreCase(subCmd)) { return help.send(sender, label, args); }
|
||||||
CommandInfo cmd = getByCache(subcmd);
|
CommandInfo cmd = getByCache(subCmd);
|
||||||
String[] subargs = args;
|
String[] subargs = args;
|
||||||
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
||||||
cmd = defCmd;
|
cmd = defCmd;
|
||||||
@ -238,7 +241,7 @@ public class CommandSub implements TabExecutor {
|
|||||||
CommandInfo ci = CommandInfo.parse(method, clazz);
|
CommandInfo ci = CommandInfo.parse(method, clazz);
|
||||||
if (ci != null) {
|
if (ci != null) {
|
||||||
Class[] params = method.getParameterTypes();
|
Class[] params = method.getParameterTypes();
|
||||||
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.getSimpleNames((Object[]) params));
|
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.getSimpleNames(params));
|
||||||
try {
|
try {
|
||||||
Class<? extends CommandSender> sender = params[0];
|
Class<? extends CommandSender> sender = params[0];
|
||||||
// 用于消除unuse警告
|
// 用于消除unuse警告
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||||
import org.bukkit.material.SpawnEgg;
|
import org.bukkit.material.SpawnEgg;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
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 喵♂呜
|
* @author 喵♂呜
|
||||||
|
* @since 2015年12月14日 下午1:33:52
|
||||||
*/
|
*/
|
||||||
public class L10N {
|
public class L10N {
|
||||||
private static String CONFIG_NAME = "Item_zh_CN.yml";
|
private static String CONFIG_NAME = "Item_zh_CN.yml";
|
||||||
@ -35,18 +36,19 @@ public class L10N {
|
|||||||
* 获取物品完整汉化名称(包括原版)
|
* 获取物品完整汉化名称(包括原版)
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* 物品实体
|
* 物品实体
|
||||||
* @return 物品名称
|
* @return 物品名称
|
||||||
*/
|
*/
|
||||||
public static String getFullName(ItemStack i) {
|
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
|
* @param i
|
||||||
* 物品实体
|
* 物品实体
|
||||||
* @return 物品名称
|
* @return 物品名称
|
||||||
*/
|
*/
|
||||||
public static String getItemName(ItemStack i) {
|
public static String getItemName(ItemStack i) {
|
||||||
@ -57,7 +59,7 @@ public class L10N {
|
|||||||
* 获取物品汉化名称(优先显示名称)
|
* 获取物品汉化名称(优先显示名称)
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* 物品实体
|
* 物品实体
|
||||||
* @return 物品名称
|
* @return 物品名称
|
||||||
*/
|
*/
|
||||||
public static String getName(ItemStack i) {
|
public static String getName(ItemStack i) {
|
||||||
@ -77,7 +79,7 @@ public class L10N {
|
|||||||
* 获取物品汉化名称
|
* 获取物品汉化名称
|
||||||
*
|
*
|
||||||
* @param iname
|
* @param iname
|
||||||
* 物品类型名称
|
* 物品类型名称
|
||||||
* @return 物品名称
|
* @return 物品名称
|
||||||
*/
|
*/
|
||||||
private static String getItemName(String iname) {
|
private static String getItemName(String iname) {
|
||||||
@ -96,14 +98,18 @@ public class L10N {
|
|||||||
* 获取物品类型名称
|
* 获取物品类型名称
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* 物品实体
|
* 物品实体
|
||||||
* @return 物品类型
|
* @return 物品类型
|
||||||
*/
|
*/
|
||||||
private static String getItemType(ItemStack i) {
|
private static String getItemType(ItemStack i) {
|
||||||
String name = i.getType().name();
|
String name = i.getType().name();
|
||||||
String dura = "";
|
String dura = "";
|
||||||
if (i.getType() == Material.MONSTER_EGG) {
|
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 {
|
} else {
|
||||||
int dur = i.getDurability();
|
int dur = i.getDurability();
|
||||||
dura = (i.getMaxStackSize() != 1 && dur != 0) ? Integer.toString(dur) : "";
|
dura = (i.getMaxStackSize() != 1 && dur != 0) ? Integer.toString(dur) : "";
|
||||||
|
Loading…
Reference in New Issue
Block a user