diff --git a/src/main/java/com/blockfantasy/LimboBackSpawn.java b/src/main/java/com/blockfantasy/LimboBackSpawn.java index 201a29e..0d0d85b 100644 --- a/src/main/java/com/blockfantasy/LimboBackSpawn.java +++ b/src/main/java/com/blockfantasy/LimboBackSpawn.java @@ -10,6 +10,12 @@ import com.loohp.limbo.location.Location; import com.loohp.limbo.player.Player; import com.loohp.limbo.plugins.LimboPlugin; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Properties; + public class LimboBackSpawn extends LimboPlugin implements Listener { public static LimboBackSpawn instance; public static Location spawn; @@ -21,9 +27,13 @@ public class LimboBackSpawn extends LimboPlugin implements Listener { @Override public void onEnable() { instance = this; + + loadConfig(); + spawn = instance.getServer().getServerProperties().getWorldSpawn(); - Limbo.getInstance().getEventsManager().registerEvents(this,new LimboBackSpawnListener()); - Limbo.getInstance().getPluginManager().registerCommands(this,new GetLocationCommand()); + + instance.getServer().getEventsManager().registerEvents(this,new LimboBackSpawnListener()); + instance.getServer().getPluginManager().registerCommands(this,new GetLocationCommand()); } @@ -78,4 +88,37 @@ public class LimboBackSpawn extends LimboPlugin implements Listener { } } } + + private void loadConfig() { + File configFile = new File(getDataFolder(), "config.properties"); + if (!configFile.exists()) { + saveDefaultConfig(configFile); + } + Properties props = new Properties(); + try { + props.load(Files.newInputStream(configFile.toPath())); + + maxX = Integer.parseInt(props.getProperty("maxX", "50")); + minY = Integer.parseInt(props.getProperty("minY", "-10")); + maxZ = Integer.parseInt(props.getProperty("maxZ", "50")); + + } catch (IOException | NumberFormatException e) { + instance.getServer().getConsole().sendMessage("无法加载配置文件,使用默认值"); + maxX = 50; + minY = -10; + maxZ = 50; + } + } + private void saveDefaultConfig(File configFile) { + try { + configFile.getParentFile().mkdirs(); + Properties props = new Properties(); + props.setProperty("maxX", "50"); + props.setProperty("minY", "-10"); + props.setProperty("maxZ", "50"); + props.store(Files.newOutputStream(configFile.toPath()), "LimboBackSpawn"); + } catch (IOException e) { + instance.getServer().getConsole().sendMessage("无法创建默认配置文件"); + } + } }