feat: 去除弃用方法

Signed-off-by: 502647092 <admin@yumc.pw>
merge/1/MERGE
502647092 2016-10-10 20:43:12 +08:00
parent bf8e6b55a4
commit 2263ac395d
8 changed files with 108 additions and 145 deletions

View File

@ -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;
}
/**

View File

@ -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) {
// 帮助列表

View File

@ -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 2016723 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 2016723 9:00:27
* @author
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface KeyValue {
/**
* @return
*/
String key();
/**
* @return
*/
String value() default "";
}
/**
*
*
* @since 2016723 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);
}

View File

@ -21,8 +21,7 @@ import org.bukkit.entity.minecart.CommandMinecart;
* aliases
* minimumArguments 0
* permission
* onlyPlayer false
* onlyConsole false
* executor
* </pre>
*
* @since 2016723 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;
}
}
}

View File

@ -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 2016723 9:00:27
* @author
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Default {
String value();
}

View 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 2016723 9:00:27
* @author
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface KeyValue {
/**
* @return
*/
String key();
/**
* @return
*/
String value() default "";
}

View 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 2016723 9:00:27
* @author
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Limit {
/**
* @return ()
*/
int max() default 255;
/**
* @return ()
*/
int min();
}

View File

@ -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;
}