Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from Crsuh2er0/main
Browse files Browse the repository at this point in the history
修复enabled配置选项以及高版本json解析相关bug
  • Loading branch information
Crsuh2er0 authored Oct 23, 2022
2 parents a412784 + f371652 commit 3b4f1ea
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lingsmc</groupId>
<artifactId>LingsHTTPUtils</artifactId>
<version>1.2.3</version>
<version>1.2.4</version>
<packaging>jar</packaging>

<name>LingsHTTPUtils</name>
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/cn/lingsmc/lingshttputils/LingsHttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
* &#064;date 2022/8/30
* @apiNote
*/
// TODO 更新配置文件
// TODO 加一个配置文件更新器
// TODO 加一个request调试用指令
// TODO 支持xml
// TODO 支持user-agent
// TODO 支持cookie
// TODO 支持同时获取一组数据
// TODO 支持获取套娃
// TODO 使间隔适用于intime类
// TODO 支持脚本化操作
// TODO 支持模块分文件
// TODO 更新配置文件
// TODO 加一个配置文件更新器
// TODO 加一个request调试用指令
// TODO 支持xml
// TODO 支持user-agent
// TODO 支持cookie
// TODO 支持同时获取一组数据
// TODO 支持获取套娃
// TODO 使间隔适用于intime类
// TODO 支持脚本化操作
// TODO 支持模块分文件

public final class LingsHttpUtils extends JavaPlugin {
public static FileConfiguration config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class WorkerOptions {
static boolean started = true;
static ExecutorService threadPool;

static LingsHttpUtils plugin = LingsHttpUtils.getInstance();


private WorkerOptions() {
}
Expand All @@ -29,7 +31,10 @@ public static void runWorkers() {
Set<String> modules = config.getKeys(false);
modules.remove("version");
modules.removeIf(module -> !Objects.equals(config.getString(String.format("%s.reqMode", module)), "Cycle"));
modules.removeIf(module -> Objects.equals(config.getString(String.format("%s.enabled", module)), "false"));
modules.removeIf(module -> Objects.equals(config.getBoolean(String.format("%s.enabled", module)), false));
if (modules.isEmpty()) {
return;
}

threadPool = new ThreadPoolExecutor(1, modules.size(),
1L, TimeUnit.SECONDS,
Expand Down Expand Up @@ -61,8 +66,12 @@ public static void runWorkers() {
}

public static void stopWorkers() {
LingsHttpUtils.getInstance().getLogger().info("尝试关闭Cycle Workers...");
threadPool.shutdownNow();
plugin.getLogger().info("尝试关闭Cycle Workers...");
try {
threadPool.shutdownNow();
} catch (Exception ignored) {
plugin.getLogger().info("没有Cycle Workers被关闭,因为没有已启用的Cycle Workers");
}
started = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public boolean persist() {
@Override
public String onRequest(OfflinePlayer p, @NotNull String params) {
Set<String> modules = config.getKeys(false);
modules.removeIf(module -> Objects.equals(config.getString(String.format("%s.enabled", module)), "false"));
modules.removeIf(module -> Objects.equals(config.getBoolean(String.format("%s.enabled", module)), false));
if (modules.isEmpty()) {
return null;
}
for (String module : modules) {
if (Objects.equals(params, config.getString(String.format("%s.apiname", module)))) {
if ("inTime".equalsIgnoreCase(config.getString(String.format("%s.reqMode", module)))) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/lingsmc/lingshttputils/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public static JsonObject parseStrGson(String str) {
*/
public static String getValueGson(String str, String @NotNull [] keys) {
JsonObject value = parseStrGson(str);
for (String key : keys) {
value = value.get(key).getAsJsonObject();
for (int i = 0; i < keys.length - 1; i++) {
value = value.get(keys[i]).getAsJsonObject();
}
return value.toString();
return value.get(keys[keys.length - 1]).getAsString();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LingsHttpUtils 配置文件
#
# 配置文件版本 勿动
version: 1.2.3
version: '${project.version}'
#
# 每个模块名字随意
# 样例
Expand Down

0 comments on commit 3b4f1ea

Please sign in to comment.