mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-03 22:12:18 +01:00
Added a warning about modifying region database files manually.
This commit is contained in:
parent
fb39261dc7
commit
0fa43ee287
@ -225,6 +225,17 @@ public void save() throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
config.setHeader("#\r\n" +
|
||||
"# WorldGuard regions file\r\n" +
|
||||
"#\r\n" +
|
||||
"# WARNING: THIS FILE IS AUTOMATICALLY GENERATED. If you modify this file by\r\n" +
|
||||
"# hand, be aware that A SINGLE MISTYPED CHARACTER CAN CORRUPT THE FILE. If\r\n" +
|
||||
"# WorldGuard is unable to parse the file, your regions will FAIL TO LOAD and\r\n" +
|
||||
"# the contents of this file will reset. Please use a YAML validator such as\r\n" +
|
||||
"# http://yaml-online-parser.appspot.com (for smaller files).\r\n" +
|
||||
"#\r\n" +
|
||||
"# REMEMBER TO KEEP PERIODICAL BACKUPS.\r\n" +
|
||||
"#");
|
||||
config.save();
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@
|
||||
public class Configuration extends ConfigurationNode {
|
||||
private Yaml yaml;
|
||||
private File file;
|
||||
private String header = null;
|
||||
|
||||
public Configuration(File file) {
|
||||
super(new HashMap<String, Object>());
|
||||
@ -105,31 +106,79 @@ public void load() throws IOException {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the configuration to disk.
|
||||
*
|
||||
* @throws IOException
|
||||
* Set the header for the file as a series of lines that are terminated
|
||||
* by a new line sequence.
|
||||
*
|
||||
* @param headerLines header lines to prepend
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
public void setHeader(String... headerLines) {
|
||||
StringBuilder header = new StringBuilder();
|
||||
|
||||
for (String line : headerLines) {
|
||||
if (header.length() > 0) {
|
||||
header.append("\r\n");
|
||||
}
|
||||
header.append(line);
|
||||
}
|
||||
|
||||
setHeader(header.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the header for the file. A header can be provided to prepend the
|
||||
* YAML data output on configuration save. The header is
|
||||
* printed raw and so must be manually commented if used. A new line will
|
||||
* be appended after the header, however, if a header is provided.
|
||||
*
|
||||
* @param header header to prepend
|
||||
*/
|
||||
public void setHeader(String header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the set header.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the configuration to disk. All errors are clobbered.
|
||||
*
|
||||
* @return true if it was successful
|
||||
*/
|
||||
public boolean save() {
|
||||
FileOutputStream stream = null;
|
||||
|
||||
|
||||
File parent = file.getParentFile();
|
||||
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
stream = new FileOutputStream(file);
|
||||
yaml.dump(root, new OutputStreamWriter(stream, "UTF-8"));
|
||||
} finally {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
|
||||
if (header != null) {
|
||||
writer.append(header);
|
||||
writer.append("\r\n");
|
||||
}
|
||||
yaml.dump(root, writer);
|
||||
return true;
|
||||
} catch (IOException e) {} finally {
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
Loading…
Reference in New Issue
Block a user