refactor(hamster-auto-game-rule): 优化日志
This commit is contained in:
@@ -6,6 +6,8 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class GameRulePlugin extends JavaPlugin {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
@@ -18,15 +20,18 @@ public class GameRulePlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Logger logger = getLogger();
|
||||
FileConfiguration pluginConfig = getConfig();
|
||||
ConfigurationSection allWorldsConfig = pluginConfig.getConfigurationSection("all-worlds");
|
||||
if (allWorldsConfig != null) {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (String key : allWorldsConfig.getKeys(false)) {
|
||||
for (String key : allWorldsConfig.getKeys(false)) {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
String value = allWorldsConfig.getString(key, "");
|
||||
//noinspection deprecation
|
||||
world.setGameRuleValue(key, value);
|
||||
getLogger().info("已设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
if (world.setGameRuleValue(key, value)) {
|
||||
logger.info("已设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
} else {
|
||||
logger.warning("设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value + " 失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,16 +40,20 @@ public class GameRulePlugin extends JavaPlugin {
|
||||
for (String worldName : specialWorldConfig.getKeys(false)) {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) {
|
||||
getLogger().warning("未找到世界: " + worldName);
|
||||
logger.warning("未找到世界: " + worldName);
|
||||
continue;
|
||||
}
|
||||
ConfigurationSection gameRuleConfig = specialWorldConfig.getConfigurationSection(worldName);
|
||||
if (gameRuleConfig != null) {
|
||||
for (String key : gameRuleConfig.getKeys(false)) {
|
||||
String value = gameRuleConfig.getString(key, "");
|
||||
//noinspection deprecation
|
||||
world.setGameRuleValue(key, value);
|
||||
getLogger().info("已单独设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
if (gameRuleConfig == null) {
|
||||
continue;
|
||||
}
|
||||
for (String key : gameRuleConfig.getKeys(false)) {
|
||||
String value = gameRuleConfig.getString(key, "");
|
||||
world.setGameRuleValue(key, value);
|
||||
if (world.setGameRuleValue(key, value)) {
|
||||
logger.info("已单独设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||
} else {
|
||||
logger.warning("单独设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value + " 失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user