Skip to content

Commit 1888109

Browse files
authored
Merge pull request #3 from PonderFox0643/main
修复了配置文件创建失败问题
2 parents d195fac + 2e7f755 commit 1888109

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.hitech0926</groupId>
88
<artifactId>HubCommand</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>

src/main/java/com/hitech0926/hubcommand/HubCommand.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@Plugin(
2828
id = "hubcommand",
2929
name = "HubCommand",
30-
version = "1.0.0",
30+
version = "1.0.3",
3131
authors = {"Hitech0926"}
3232
)
3333
public class HubCommand {
@@ -75,11 +75,26 @@ public ProxyServer getServer() {
7575
}
7676

7777
private void loadConfig() {
78+
if (!Files.exists(dataDirectory)) {
79+
try {
80+
Files.createDirectories(dataDirectory);
81+
} catch (IOException e) {
82+
logger.error("无法创建插件目录", e);
83+
return;
84+
}
85+
}
86+
7887
File file = dataDirectory.resolve("config.yml").toFile();
7988
Yaml yaml = new Yaml();
8089
if (!file.exists()) {
8190
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("config.yml")) {
82-
Files.copy(inputStream, file.toPath());
91+
if (inputStream != null) {
92+
Files.copy(inputStream, file.toPath());
93+
logger.info("配置文件已创建!");
94+
} else {
95+
logger.error("无法找到默认配置文件");
96+
return;
97+
}
8398
} catch (IOException e) {
8499
logger.error("无法创建配置文件", e);
85100
return;
@@ -92,6 +107,8 @@ private void loadConfig() {
92107
sendSuccessful = (String) config.getOrDefault("send-successful", "<green>你已被传送到大厅!");
93108
noPermission = (String) config.getOrDefault("no-permission", "<red>你没有权限执行此命令!");
94109
noConsole = (String) config.getOrDefault("no-console", "<red>只有玩家可以执行此命令!");
110+
111+
logger.info("配置文件加载成功!");
95112
} catch (IOException e) {
96113
logger.error("无法加载配置文件", e);
97114
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"id":"hubcommand","name":"HubCommand","version":"1.0.2","authors":["HitTech0926"],"dependencies":[],"main":"com.hitech0926.hubcommand.HubCommand"}
1+
{"id":"hubcommand","name":"HubCommand","version":"1.0.3","authors":["HitTech0926"],"dependencies":[],"main":"com.hitech0926.hubcommand.HubCommand"}

0 commit comments

Comments
 (0)