mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-12-25 07:08:52 +00:00
feat: 去除弃用方法
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
bf8e6b55a4
commit
2263ac395d
@ -15,14 +15,12 @@ public class CommandArgument {
|
||||
private final Command command;
|
||||
private final String alias;
|
||||
private final String[] args;
|
||||
private final CommandParse parses;
|
||||
|
||||
public CommandArgument(final CommandSender sender, final Command command, final String alias, final String[] args) {
|
||||
this.sender = sender;
|
||||
this.command = command;
|
||||
this.alias = alias;
|
||||
this.args = args;
|
||||
parses = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,8 +149,8 @@ public class CommandHelp {
|
||||
if (page == 1 && defCmd != null) {
|
||||
helpList.add(formatCommand(defCmd, label));
|
||||
}
|
||||
final int start = this.LINES_PER_PAGE * (page - 1);
|
||||
final int end = start + this.LINES_PER_PAGE;
|
||||
final int start = LINES_PER_PAGE * (page - 1);
|
||||
final int end = start + LINES_PER_PAGE;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (this.cmdlist.size() > i) {
|
||||
// 帮助列表
|
||||
|
@ -1,10 +1,6 @@
|
||||
package pw.yumc.YumCore.commands;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -15,6 +11,9 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import pw.yumc.YumCore.commands.annotation.Default;
|
||||
import pw.yumc.YumCore.commands.annotation.KeyValue;
|
||||
import pw.yumc.YumCore.commands.annotation.Limit;
|
||||
import pw.yumc.YumCore.commands.exception.CommandException;
|
||||
import pw.yumc.YumCore.commands.exception.CommandParseException;
|
||||
|
||||
@ -47,18 +46,7 @@ public class CommandParse {
|
||||
throw new CommandParseException(String.format("无法解析的参数类型 %s !", clazz.getName()));
|
||||
}
|
||||
final Parse parse = allparses.get(clazz).clone();
|
||||
for (final Annotation annotation : annotations) {
|
||||
if (annotation.annotationType() == Default.class) {
|
||||
parse.setAttr("default", ((Default) annotation).value());
|
||||
} else if (annotation.annotationType() == Limit.class) {
|
||||
parse.setAttr("min", ((Limit) annotation).min());
|
||||
parse.setAttr("max", ((Limit) annotation).max());
|
||||
} else if (annotation.annotationType() == KeyValue.class) {
|
||||
final KeyValue kv = (KeyValue) annotation;
|
||||
parse.setAttr(kv.key(), kv.value());
|
||||
}
|
||||
}
|
||||
this.parse.add(parse);
|
||||
this.parse.add(parse.parseAnnotation(annotations));
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,18 +93,6 @@ public class CommandParse {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认参数
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Default {
|
||||
String value();
|
||||
}
|
||||
|
||||
public static class IntegerParse extends Parse<Integer> {
|
||||
public IntegerParse() {
|
||||
allparses.put(Integer.class, this);
|
||||
@ -137,46 +113,6 @@ public class CommandParse {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义参数
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface KeyValue {
|
||||
/**
|
||||
* @return 键
|
||||
*/
|
||||
String key();
|
||||
|
||||
/**
|
||||
* @return 值
|
||||
*/
|
||||
String value() default "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数限制
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Limit {
|
||||
/**
|
||||
* @return 最大长度(最大值)
|
||||
*/
|
||||
int max() default 255;
|
||||
|
||||
/**
|
||||
* @return 最小长度(或最小值)
|
||||
*/
|
||||
int min();
|
||||
}
|
||||
|
||||
public static class LongParse extends Parse<Long> {
|
||||
public LongParse() {
|
||||
allparses.put(Long.class, this);
|
||||
@ -224,6 +160,21 @@ public class CommandParse {
|
||||
|
||||
public abstract RT parse(String arg) throws CommandParseException;
|
||||
|
||||
public Parse<RT> parseAnnotation(final Annotation[] annotations) {
|
||||
for (final Annotation annotation : annotations) {
|
||||
if (annotation.annotationType() == Default.class) {
|
||||
setAttr("default", ((Default) annotation).value());
|
||||
} else if (annotation.annotationType() == Limit.class) {
|
||||
setAttr("min", ((Limit) annotation).min());
|
||||
setAttr("max", ((Limit) annotation).max());
|
||||
} else if (annotation.annotationType() == KeyValue.class) {
|
||||
final KeyValue kv = (KeyValue) annotation;
|
||||
setAttr(kv.key(), kv.value());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAttr(final String name, final Object value) {
|
||||
attrs.put(name, value);
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ import org.bukkit.entity.minecart.CommandMinecart;
|
||||
* aliases 命令别名
|
||||
* minimumArguments 最小参数 默认0
|
||||
* permission 权限
|
||||
* onlyPlayer 只允许玩家 false
|
||||
* onlyConsole 只允许控制台 false
|
||||
* executor 执行者 所有
|
||||
* </pre>
|
||||
*
|
||||
* @since 2016年7月23日 上午8:59:05
|
||||
@ -46,20 +45,6 @@ public @interface Cmd {
|
||||
*/
|
||||
int minimumArguments() default 0;
|
||||
|
||||
/**
|
||||
* @deprecated 详见 {@link Executor}
|
||||
* @return 只允许控制台执行
|
||||
*/
|
||||
@Deprecated
|
||||
boolean onlyConsole() default false;
|
||||
|
||||
/**
|
||||
* @deprecated 详见 {@link Executor}
|
||||
* @return 只允许玩家执行
|
||||
*/
|
||||
@Deprecated
|
||||
boolean onlyPlayer() default false;
|
||||
|
||||
/**
|
||||
* @return 当前命令权限
|
||||
*/
|
||||
@ -80,66 +65,37 @@ public @interface Cmd {
|
||||
/**
|
||||
* 玩家
|
||||
*/
|
||||
PLAYER {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "玩家";
|
||||
}
|
||||
},
|
||||
PLAYER("玩家"),
|
||||
/**
|
||||
* 控制台
|
||||
*/
|
||||
CONSOLE {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "控制台";
|
||||
}
|
||||
},
|
||||
CONSOLE("控制台"),
|
||||
/**
|
||||
* 命令方块
|
||||
*/
|
||||
BLOCK {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "命令方块";
|
||||
}
|
||||
},
|
||||
BLOCK("命令方块"),
|
||||
/**
|
||||
* 命令矿车
|
||||
*/
|
||||
COMMANDMINECART {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "命令矿车";
|
||||
}
|
||||
},
|
||||
COMMANDMINECART("命令矿车"),
|
||||
/**
|
||||
* 远程控制台
|
||||
*/
|
||||
REMOTECONSOLE {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "远程控制台";
|
||||
}
|
||||
},
|
||||
REMOTECONSOLE("远程控制台"),
|
||||
/**
|
||||
* 所有
|
||||
*/
|
||||
ALL {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "所有执行者";
|
||||
}
|
||||
},
|
||||
ALL("所有执行者"),
|
||||
/**
|
||||
* 未知
|
||||
*/
|
||||
UNKNOW {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "未知";
|
||||
}
|
||||
};
|
||||
UNKNOW("未知");
|
||||
private String name;
|
||||
|
||||
private Executor(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Executor
|
||||
*
|
||||
@ -166,6 +122,8 @@ public @interface Cmd {
|
||||
/**
|
||||
* @return 执行者名称
|
||||
*/
|
||||
public abstract String getName();
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package pw.yumc.YumCore.commands.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 默认参数
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Default {
|
||||
String value();
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package pw.yumc.YumCore.commands.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义参数
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface KeyValue {
|
||||
/**
|
||||
* @return 键
|
||||
*/
|
||||
String key();
|
||||
|
||||
/**
|
||||
* @return 值
|
||||
*/
|
||||
String value() default "";
|
||||
}
|
26
src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java
Normal file
26
src/main/java/pw/yumc/YumCore/commands/annotation/Limit.java
Normal file
@ -0,0 +1,26 @@
|
||||
package pw.yumc.YumCore.commands.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 参数限制
|
||||
*
|
||||
* @since 2016年7月23日 上午9:00:27
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Limit {
|
||||
/**
|
||||
* @return 最大长度(最大值)
|
||||
*/
|
||||
int max() default 255;
|
||||
|
||||
/**
|
||||
* @return 最小长度(或最小值)
|
||||
*/
|
||||
int min();
|
||||
}
|
@ -7,7 +7,6 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
@ -28,8 +27,6 @@ import pw.yumc.YumCore.commands.exception.CommandException;
|
||||
*/
|
||||
public class CommandInfo {
|
||||
public static final CommandInfo Unknow = new CommandInfo();
|
||||
private static final String onlyPlayer = "§c控制台无法使用此命令(§4请在游戏内执行§c)!";
|
||||
private static final String onlyConsole = "§c玩家无法使用此命令(§4请使用控制台执行§c)!";
|
||||
private static final String onlyExecutor = "§c当前命令仅允许 §b%s §c执行!";
|
||||
private static final String losePerm = "§c你需要有 %s 的权限才能执行此命令!";
|
||||
private static final String cmdErr = "§6错误原因: §4命令参数不正确!";
|
||||
@ -225,17 +222,6 @@ public class CommandInfo {
|
||||
Log.toSender(sender, String.format(onlyExecutor, executorStr));
|
||||
return false;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
if (command.onlyConsole()) {
|
||||
Log.toSender(sender, onlyConsole);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (command.onlyPlayer()) {
|
||||
Log.toSender(sender, onlyPlayer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user