修改了CommandEntity.java、CommandHandler.java、ElementOriginLib.java和SerializeHelper.java文件,优化了相关功能实现。
This commit is contained in:
parent
d846d7ffe2
commit
1de44ba982
|
@ -7,10 +7,7 @@ import com.io.yutian.elementoriginlib.listener.PlayerChatInputListener;
|
||||||
import com.io.yutian.elementoriginlib.logger.Logger;
|
import com.io.yutian.elementoriginlib.logger.Logger;
|
||||||
import com.io.yutian.elementoriginlib.manager.CommandManager;
|
import com.io.yutian.elementoriginlib.manager.CommandManager;
|
||||||
import com.io.yutian.elementoriginlib.redis.RedisIO;
|
import com.io.yutian.elementoriginlib.redis.RedisIO;
|
||||||
import net.byteflux.libby.*;
|
|
||||||
import net.byteflux.libby.logging.LogLevel;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class ElementOriginLib extends JavaPlugin {
|
public final class ElementOriginLib extends JavaPlugin {
|
||||||
|
@ -28,8 +25,6 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
// loadLibraries();
|
|
||||||
|
|
||||||
new GuiHandlerListener(this);
|
new GuiHandlerListener(this);
|
||||||
new PlayerChatInputListener(this);
|
new PlayerChatInputListener(this);
|
||||||
|
|
||||||
|
@ -40,22 +35,6 @@ public final class ElementOriginLib extends JavaPlugin {
|
||||||
redisIO = new RedisIO();
|
redisIO = new RedisIO();
|
||||||
redisIO.init(this);
|
redisIO.init(this);
|
||||||
|
|
||||||
logger.info("Successfully load ElementOriginLib v"+getPluginMeta().getVersion());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadLibraries() {
|
|
||||||
logger.info("Loading libraries...");
|
|
||||||
LibraryManager libraryManager = new BukkitLibraryManager(this);
|
|
||||||
libraryManager.addMavenCentral();
|
|
||||||
libraryManager.setLogLevel(LogLevel.WARN);
|
|
||||||
libraryManager.loadLibrary(Library.builder().groupId("org{}apache{}commons").artifactId("commons-compress").version("1.27.1").build());
|
|
||||||
libraryManager.loadLibrary(Library.builder().groupId("com{}github{}luben").artifactId("zstd-jni").version("1.5.6-9").build());
|
|
||||||
libraryManager.loadLibrary(Library.builder().groupId("com{}fasterxml{}jackson{}core").artifactId("jackson-databind").version("2.18.2").build());
|
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("com{}zaxxer").artifactId("HikariCP").version("6.2.1").build());
|
|
||||||
// libraryManager.loadLibrary(Library.builder().groupId("org{}xerial").artifactId("sqlite-jdbc").version("3.46.0.0").build());
|
|
||||||
libraryManager.loadLibrary(Library.builder().groupId("redis{}clients").id("jedis").artifactId("jedis").version("5.2.0").build());
|
|
||||||
logger.info("Successfully loaded libraries.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -237,7 +237,7 @@ public class CommandEntity {
|
||||||
if (!suggestionType.isEmpty()) {
|
if (!suggestionType.isEmpty()) {
|
||||||
Suggest suggest = Suggests.getSuggest(suggestionType);
|
Suggest suggest = Suggests.getSuggest(suggestionType);
|
||||||
if (suggest == null) {
|
if (suggest == null) {
|
||||||
throwParseException(clazz, "建议类型 " + parameter.getType().getName() + " 不存在");
|
throwParseException(clazz, "建议类型 " + suggestionType + " 不存在");
|
||||||
} else {
|
} else {
|
||||||
argument.suggest(suggest);
|
argument.suggest(suggest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,9 +109,8 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
Map<String, ArgumentValue> parsedArguments = new HashMap<>();
|
Map<String, ArgumentValue> parsedArguments = new HashMap<>();
|
||||||
List<Object> methodParams = new ArrayList<>();
|
List<Object> methodParams = new ArrayList<>();
|
||||||
|
|
||||||
for (Argument argument : arguments) {
|
for (int argIndex = 0; argIndex < arguments.size(); argIndex++) {
|
||||||
int argIndex = startIndex + arguments.indexOf(argument);
|
Argument argument = arguments.get(argIndex);
|
||||||
|
|
||||||
if (argIndex >= args.length) {
|
if (argIndex >= args.length) {
|
||||||
if (!argument.isOptional()) {
|
if (!argument.isOptional()) {
|
||||||
sender.sendMessage(Lang.get("command.short-arg", argument.getName()));
|
sender.sendMessage(Lang.get("command.short-arg", argument.getName()));
|
||||||
|
@ -123,7 +122,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
if (argument.isOptional() && argIndex >= args.length) {
|
if (argument.isOptional() && argIndex >= args.length) {
|
||||||
rawValue = argument.getDefaultValue();
|
rawValue = argument.getDefaultValue();
|
||||||
} else {
|
} else {
|
||||||
rawValue = args[argIndex];
|
rawValue = args[argIndex + startIndex];
|
||||||
}
|
}
|
||||||
if (!argument.getArgumentsType().test(rawValue)) {
|
if (!argument.getArgumentsType().test(rawValue)) {
|
||||||
sender.sendMessage(Lang.get("command.error-arg", argIndex + 1, rawValue));
|
sender.sendMessage(Lang.get("command.error-arg", argIndex + 1, rawValue));
|
||||||
|
@ -134,12 +133,12 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
methodParams.add(parsedValue);
|
methodParams.add(parsedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedArguments;
|
return parsedArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
execute(sender, label, args);
|
execute(sender, label, args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -193,9 +192,10 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||||
entries = commandEntry.getChildrens();
|
entries = commandEntry.getChildrens();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (entries.size() == 0) {
|
if (entries.size() == 0) {
|
||||||
List<Argument> arguments = commandEntry.getArguments();
|
List<Argument> arguments = commandEntry.getArguments();
|
||||||
int index = (int) (currentDepth - commandEntry.getDepth() - 1);
|
int index = (int) (currentDepth - commandEntry.getDepth() - 2);
|
||||||
if (index >= arguments.size()) {
|
if (index >= arguments.size()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.io.yutian.elementoriginlib.logger.Logger;
|
||||||
import com.io.yutian.elementoriginlib.serialize.serializers.*;
|
import com.io.yutian.elementoriginlib.serialize.serializers.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SerializeHelper {
|
public class SerializeHelper {
|
||||||
|
@ -76,16 +77,17 @@ public class SerializeHelper {
|
||||||
try {
|
try {
|
||||||
return objectWriter.writeValueAsString(obj);
|
return objectWriter.writeValueAsString(obj);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
LOGGER.error("Failed to serialize object: " + obj, e);
|
LOGGER.error("序列化对象失败: " + obj, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T deserialize(String json, Class<T> clazz) {
|
public static <T> T deserialize(String json, Class<T> clazz) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
return objectReader.forType(clazz).readValue(json);
|
return objectReader.forType(clazz).readValue(json);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
LOGGER.error("Failed to deserialize object: " + json, e);
|
LOGGER.error("反序列化对象失败: " + json, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user