Skip to content

Commit

Permalink
调整房间加载异常捕获
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Dec 19, 2023
1 parent d783d29 commit 6662509
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 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.lanink</groupId>
<artifactId>GunWar</artifactId>
<version>1.7.2<!-- -SNAPSHOT--></version>
<version>1.7.3-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/cn/lanink/gunwar/room/base/GunWarGameRoomManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,35 @@ public boolean loadGameRoom(String level) {
if (this.hasGameRoom(level)) {
return false;
}
Config config = this.gunWar.getRoomConfig(level);
if (config.getInt("waitTime", 0) == 0 ||
config.getInt("gameTime", 0) == 0 ||
"".equals(config.getString("waitSpawn", "").trim()) ||
/*"".equals(config.getString("redSpawn", "").trim()) ||
"".equals(config.getString("blueSpawn", "").trim()) ||*/
"".equals(config.getString("gameMode", "").trim())) {
this.gunWar.getLogger().warning("§c房间:" + level + " 配置不完整,加载失败!");
return false;
}
if (Server.getInstance().getLevelByName(level) == null && !Server.getInstance().loadLevel(level)) {
this.gunWar.getLogger().warning("§c房间:" + level + " 地图加载失败!");
return false;
}

String gameMode = config.getString("gameMode", "classic");
if (!ROOM_CLASS.containsKey(gameMode)) {
this.gunWar.getLogger().warning("§c房间:" + level + " 游戏模式设置错误!没有找到游戏模式: " + gameMode);
return false;
}
try {
Config config = this.gunWar.getRoomConfig(level);
if (config.getInt("waitTime", 0) == 0 ||
config.getInt("gameTime", 0) == 0 ||
"".equals(config.getString("waitSpawn", "").trim()) ||
/*"".equals(config.getString("redSpawn", "").trim()) ||
"".equals(config.getString("blueSpawn", "").trim()) ||*/
"".equals(config.getString("gameMode", "").trim())) {
this.gunWar.getLogger().warning("§c房间:" + level + " 配置不完整,加载失败!");
return false;
}
if (Server.getInstance().getLevelByName(level) == null && !Server.getInstance().loadLevel(level)) {
this.gunWar.getLogger().warning("§c房间:" + level + " 地图加载失败!");
return false;
}

String gameMode = config.getString("gameMode", "classic");
if (!ROOM_CLASS.containsKey(gameMode)) {
this.gunWar.getLogger().warning("§c房间:" + level + " 游戏模式设置错误!没有找到游戏模式: " + gameMode);
return false;
}

Constructor<? extends BaseRoom> constructor = ROOM_CLASS.get(gameMode).getConstructor(Level.class, Config.class);
BaseRoom baseRoom = constructor.newInstance(Server.getInstance().getLevelByName(level), config);
baseRoom.setGameMode(gameMode);
this.addGameRoom(level, baseRoom);
this.gunWar.getLogger().info("§a房间:" + level + " 已加载!");
return true;
} catch (Exception e) {
} catch (Throwable e) {
this.gunWar.getLogger().error("§c加载房间:" + level + " 时出错,请检查配置文件", e);
return false;
}
Expand Down

0 comments on commit 6662509

Please sign in to comment.