2024/01/19更新 API版本6.0.6

[UltiTools-API]
1. 优化了JSON数据存储方式的文件读取效率
[Home]
1. 修复了无法获取家列表的问题
[MysqlConnector]
1. 修复了同名字段覆盖的问题
pull/91/head
wisdommen 2 years ago
parent 85932e9247
commit c1985efe8d

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -92,8 +92,7 @@
<configuration>
<name>BasicFunctions</name>
<identifyString>UltiTools-Basic-Functions</identifyString>
<shortDescription>开服必装所有的杂七杂八的小功能哦包括不限于TPA飞行模式更改白名单随机传送。
</shortDescription>
<shortDescription>开服必装所有的杂七杂八的小功能哦包括不限于TPA飞行模式更改白名单随机传送。</shortDescription>
<accessKeyFile>access_key.txt</accessKeyFile>
<pluginFolder>F:\SpigotServers\Paper\1.20.4\plugins\UltiTools\plugins</pluginFolder>
</configuration>

@ -28,7 +28,7 @@ public class HomeCommands extends AbstractCommendExecutor {
@CmdMapping(format = "create <name>")
public void createHome(@CmdSender Player player,
@CmdParam(value = "name", suggest = "getHomeList") String name) {
@CmdParam(value = "name", suggest = "[name]") String name) {
boolean created = homeService.createHome(player, name);
if (created) {
player.sendMessage(ChatColor.YELLOW + PluginMain.getPluginMain().i18n("已创建!"));

@ -17,17 +17,16 @@ import java.util.*;
@Service
public class HomeServiceImpl implements HomeService {
private final HomeConfig homeConfig;
private final DataOperator<HomeEntity> dataOperator;
private final TeleportService teleportService;
public HomeServiceImpl(DataOperator<HomeEntity> dataOperator, HomeConfig homeConfig, TeleportService teleportService) {
public HomeServiceImpl(HomeConfig homeConfig, TeleportService teleportService) {
this.homeConfig = homeConfig;
this.dataOperator = dataOperator;
this.teleportService = teleportService;
}
@Override
public HomeEntity getHomeByName(UUID playerId, String name) {
DataOperator<HomeEntity> dataOperator = PluginMain.getPluginMain().getDataOperator(HomeEntity.class);
Collection<HomeEntity> homeEntities = dataOperator.getAll(
WhereCondition.builder().column("playerId").value(playerId).build(),
WhereCondition.builder().column("name").value(name).build()
@ -40,6 +39,7 @@ public class HomeServiceImpl implements HomeService {
@Override
public List<HomeEntity> getHomeList(UUID playerId) {
DataOperator<HomeEntity> dataOperator = PluginMain.getPluginMain().getDataOperator(HomeEntity.class);
Collection<HomeEntity> all = dataOperator.getAll(
WhereCondition.builder().column("playerId").value(playerId).build()
);
@ -62,6 +62,7 @@ public class HomeServiceImpl implements HomeService {
player.sendMessage(ChatColor.RED + PluginMain.getPluginMain().i18n("你没法创建更多的家!"));
return false;
}
DataOperator<HomeEntity> dataOperator = PluginMain.getPluginMain().getDataOperator(HomeEntity.class);
boolean exist = dataOperator.exist(
WhereCondition.builder().column("playerId").value(player.getUniqueId()).build(),
WhereCondition.builder().column("name").value(name).build()
@ -70,6 +71,7 @@ public class HomeServiceImpl implements HomeService {
return false;
}
HomeEntity homeEntity = new HomeEntity();
homeEntity.setId(new Date().getTime());
homeEntity.setPlayerId(player.getUniqueId());
homeEntity.setLocation(new WorldLocation(player.getLocation()));
homeEntity.setName(name);
@ -79,6 +81,7 @@ public class HomeServiceImpl implements HomeService {
@Override
public void deleteHome(UUID playerId, String name) {
DataOperator<HomeEntity> dataOperator = PluginMain.getPluginMain().getDataOperator(HomeEntity.class);
dataOperator.del(
WhereCondition.builder().column("playerId").value(playerId).build(),
WhereCondition.builder().column("name").value(name).build()

@ -21,7 +21,7 @@
<dependency>
<groupId>com.ultikits</groupId>
<artifactId>UltiTools-API</artifactId>
<version>6.0.0.202310142230</version>
<version>6.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -90,7 +90,7 @@
<identifyString>MysqlConnector</identifyString>
<shortDescription>连接MySQL数据库的必须前置模块</shortDescription>
<accessKeyFile>access_key.txt</accessKeyFile>
<pluginFolder>F:\SpigotServers\Servers\1.19.4\plugins\UltiTools\plugins</pluginFolder>
<pluginFolder>F:\SpigotServers\Paper\1.20.4\plugins\UltiTools\plugins</pluginFolder>
</configuration>
</plugin>
</plugins>

@ -191,25 +191,22 @@ public class MysqlDataOperator<T extends AbstractDataEntity> implements DataOper
private Entity copyEntity(T obj) throws IllegalAccessException {
Entity entity = Entity.create(tableName);
List<Field> fieldList = new ArrayList<>();
Class tempClass = obj.getClass();
while (tempClass != null) {
fieldList.addAll(Arrays.asList(tempClass.getDeclaredFields()));
tempClass = tempClass.getSuperclass();
}
for (Field field : fieldList) {
Field[] fields = ReflectUtil.getFields(obj.getClass());
for (Field field : fields) {
if (field.isAnnotationPresent(Column.class)) {
field.setAccessible(true);
Column column = field.getAnnotation(Column.class);
if (ClassUtil.isBasicType(field.getType())) {
entity.set(column.value(), field.get(obj));
} else {
Object value = field.get(obj);
if (!ClassUtil.isBasicType(field.getType())) {
String jsonString = JSON.toJSONString(field.get(obj));
if (jsonString.startsWith("\"") && jsonString.endsWith("\"")) {
jsonString = jsonString.substring(1);
jsonString = jsonString.substring(0, jsonString.lastIndexOf("\""));
}
entity.set(column.value(), jsonString);
value = jsonString;
}
if (entity.get(column.value()) == null) {
entity.set(column.value(), value);
}
}
}

@ -38,19 +38,17 @@ public class SimpleJsonDataOperator<T extends AbstractDataEntity> implements Dat
public SimpleJsonDataOperator(String storeLocation, Class<T> type) {
this.storeLocation = storeLocation;
this.type = type;
synchronized (this) {
File file = new File(storeLocation);
File[] files = file.listFiles();
if (files != null) {
for (File dataFile : files) {
try {
JSON json = JSONUtil.readJSON(dataFile, Charset.defaultCharset());
cache.put(FileNameUtil.mainName(dataFile), json.toBean(type));
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, ChatColor.RED + "发现一个数据损坏!位置:" + dataFile.getAbsolutePath());
}
File file = new File(storeLocation);
File[] files = file.listFiles();
if (files != null) {
Arrays.stream(files).parallel().forEach(dataFile -> {
try {
JSON json = JSONUtil.readJSON(dataFile, Charset.defaultCharset());
cache.put(FileNameUtil.mainName(dataFile), json.toBean(type));
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, ChatColor.RED + "发现一个数据损坏!位置:" + dataFile.getAbsolutePath());
}
}
});
}
}

Loading…
Cancel
Save