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.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class GameRulePlugin extends JavaPlugin {
|
public class GameRulePlugin extends JavaPlugin {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
}
|
}
|
||||||
@@ -18,15 +20,18 @@ public class GameRulePlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
Logger logger = getLogger();
|
||||||
FileConfiguration pluginConfig = getConfig();
|
FileConfiguration pluginConfig = getConfig();
|
||||||
ConfigurationSection allWorldsConfig = pluginConfig.getConfigurationSection("all-worlds");
|
ConfigurationSection allWorldsConfig = pluginConfig.getConfigurationSection("all-worlds");
|
||||||
if (allWorldsConfig != null) {
|
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, "");
|
String value = allWorldsConfig.getString(key, "");
|
||||||
//noinspection deprecation
|
if (world.setGameRuleValue(key, value)) {
|
||||||
world.setGameRuleValue(key, value);
|
logger.info("已设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
||||||
getLogger().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)) {
|
for (String worldName : specialWorldConfig.getKeys(false)) {
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
getLogger().warning("未找到世界: " + worldName);
|
logger.warning("未找到世界: " + worldName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ConfigurationSection gameRuleConfig = specialWorldConfig.getConfigurationSection(worldName);
|
ConfigurationSection gameRuleConfig = specialWorldConfig.getConfigurationSection(worldName);
|
||||||
if (gameRuleConfig != null) {
|
if (gameRuleConfig == null) {
|
||||||
for (String key : gameRuleConfig.getKeys(false)) {
|
continue;
|
||||||
String value = gameRuleConfig.getString(key, "");
|
}
|
||||||
//noinspection deprecation
|
for (String key : gameRuleConfig.getKeys(false)) {
|
||||||
world.setGameRuleValue(key, value);
|
String value = gameRuleConfig.getString(key, "");
|
||||||
getLogger().info("已单独设置世界 " + world.getName() + " 的游戏规则 " + key + " 值为: " + value);
|
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