mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 04:35:35 +01:00
Added a configuration converter
This commit is contained in:
parent
a18e7f75ef
commit
7f17d6cb29
@ -8,6 +8,9 @@
|
|||||||
<classpathentry combineaccessrules="false" kind="src" path="/craftbukkit"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/craftbukkit"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
<classpathentry kind="lib" path="C:/dev/war/war/lib/mockito-all-1.8.5.jar"/>
|
<classpathentry kind="lib" path="C:/dev/war/war/lib/mockito-all-1.8.5.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/Users/Shared/bukkit-1.0.1-R1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/Users/Shared/craftbukkit-1.0.1-R1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/Users/Shared/Permissions.jar"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Permissions"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Permissions"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -55,7 +55,7 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
|
|||||||
War.war.getWarzones().remove(zone);
|
War.war.getWarzones().remove(zone);
|
||||||
|
|
||||||
// rename zone file
|
// rename zone file
|
||||||
(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".txt")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".txt"));
|
(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml"));
|
||||||
// rename zone folder
|
// rename zone folder
|
||||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0]));
|
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0]));
|
||||||
|
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
package com.tommytony.war.mappers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
public class PropertiesConverter {
|
||||||
|
File properties;
|
||||||
|
File yaml;
|
||||||
|
public PropertiesConverter (File properties, File yaml) {
|
||||||
|
this.properties = properties;
|
||||||
|
this.yaml = yaml;
|
||||||
|
}
|
||||||
|
public void ConvertWarCfg() throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||||
|
PropertiesFile propertiesUtil = new PropertiesFile(properties.getAbsolutePath());
|
||||||
|
YamlConfiguration yamlUtil = new YamlConfiguration();
|
||||||
|
if (!yaml.exists()) {
|
||||||
|
yaml.createNewFile();
|
||||||
|
}
|
||||||
|
propertiesUtil.load();
|
||||||
|
yamlUtil.load(yaml);
|
||||||
|
yamlUtil.set("warzones", propertiesUtil.getString("warzones"));
|
||||||
|
yamlUtil.set("zoneMakers", propertiesUtil.getString("zoneMakers"));
|
||||||
|
yamlUtil.set("commandWhitelist", propertiesUtil.getString("commandWhitelist"));
|
||||||
|
yamlUtil.set("defaultLoadout", propertiesUtil.getString("defaultLoadout"));
|
||||||
|
yamlUtil.set("defaultExtraLoadouts", propertiesUtil.getString("defaultExtraLoadouts"));
|
||||||
|
yamlUtil.set("maxZones", propertiesUtil.getInt("maxZones"));
|
||||||
|
yamlUtil.set("defaultLifePool", propertiesUtil.getInt("defaultLifePool"));
|
||||||
|
yamlUtil.set("defaultMonumentHeal", propertiesUtil.getInt("defaultMonumentHeal"));
|
||||||
|
yamlUtil.set("defaultFriendlyFire", propertiesUtil.getBoolean("defaultFriendlyFire"));
|
||||||
|
yamlUtil.set("defaultAutoAssignOnly", propertiesUtil.getBoolean("defaultAutoAssignOnly"));
|
||||||
|
yamlUtil.set("defaultFlagPointsOnly", propertiesUtil.getBoolean("defaultFlagPointsOnly"));
|
||||||
|
yamlUtil.set("defaultTeamCap", propertiesUtil.getInt("defaultTeamCap"));
|
||||||
|
yamlUtil.set("defaultScoreCap", propertiesUtil.getInt("defaultScoreCap"));
|
||||||
|
yamlUtil.set("pvpInZonesOnly", propertiesUtil.getBoolean("pvpInZonesOnly"));
|
||||||
|
yamlUtil.set("defaultBlockHeads", propertiesUtil.getBoolean("defaultBlockHeads"));
|
||||||
|
yamlUtil.set("buildInZonesOnly", propertiesUtil.getBoolean("buildInZonesOnly"));
|
||||||
|
yamlUtil.set("disablePvpMessage", propertiesUtil.getBoolean("disablePvpMessage"));
|
||||||
|
yamlUtil.set("tntInZonesOnly", propertiesUtil.getBoolean("tntInZonesOnly"));
|
||||||
|
yamlUtil.set("spawnStyle", propertiesUtil.getString("spawnStyle"));
|
||||||
|
yamlUtil.set("flagReturn", propertiesUtil.getString("flagReturn"));
|
||||||
|
yamlUtil.set("defaultReward", propertiesUtil.getString("defaultReward"));
|
||||||
|
yamlUtil.set("defaultUnbreakableZoneBlocks", propertiesUtil.getBoolean("defaultUnbreakableZoneBlocks"));
|
||||||
|
yamlUtil.set("defaultNoCreatures", propertiesUtil.getBoolean("defaultNoCreatures"));
|
||||||
|
yamlUtil.set("defaultGlassWalls", propertiesUtil.getBoolean("defaultGlassWalls"));
|
||||||
|
yamlUtil.set("defaultPvpInZone", propertiesUtil.getBoolean("defaultPvpInZone"));
|
||||||
|
yamlUtil.set("defaultInstaBreak", propertiesUtil.getBoolean("defaultInstaBreak"));
|
||||||
|
yamlUtil.set("defaultNoDrops", propertiesUtil.getBoolean("defaultNoDrops"));
|
||||||
|
yamlUtil.set("defaultNoHunger", propertiesUtil.getBoolean("defaultNoHunger"));
|
||||||
|
yamlUtil.set("defaultSaturation", propertiesUtil.getInt("defaultSaturation"));
|
||||||
|
yamlUtil.set("defaultMinPlayers", propertiesUtil.getInt("defaultMinPlayers"));
|
||||||
|
yamlUtil.set("defaultMinTeams", propertiesUtil.getInt("defaultMinTeams"));
|
||||||
|
yamlUtil.set("defaultResetOnEmpty", propertiesUtil.getBoolean("defaultResetOnEmpty"));
|
||||||
|
yamlUtil.set("defaultResetOnLoad", propertiesUtil.getBoolean("defaultResetOnLoad"));
|
||||||
|
yamlUtil.set("defaultResetOnUnload", propertiesUtil.getBoolean("defaultResetOnUnload"));
|
||||||
|
yamlUtil.set("warhub", propertiesUtil.getString("warhub"));
|
||||||
|
yamlUtil.save(yaml);
|
||||||
|
propertiesUtil.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void ConvertZoneCfg() throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||||
|
PropertiesFile propertiesUtil = new PropertiesFile(properties.getAbsolutePath());
|
||||||
|
YamlConfiguration yamlUtil = new YamlConfiguration();
|
||||||
|
if (!yaml.exists()) {
|
||||||
|
yaml.createNewFile();
|
||||||
|
}
|
||||||
|
propertiesUtil.load();
|
||||||
|
yamlUtil.load(yaml);
|
||||||
|
yamlUtil.set("name", propertiesUtil.getString("name"));
|
||||||
|
yamlUtil.set("world", propertiesUtil.getString("world"));
|
||||||
|
yamlUtil.set("teleport", propertiesUtil.getString("teleport"));
|
||||||
|
yamlUtil.set("teams", propertiesUtil.getString("teams"));
|
||||||
|
yamlUtil.set("teamFlags", propertiesUtil.getString("teamFlags"));
|
||||||
|
yamlUtil.set("friendlyFire", propertiesUtil.getString("friendlyFire"));
|
||||||
|
yamlUtil.set("loadout", propertiesUtil.getString("loadout"));
|
||||||
|
yamlUtil.set("extraLoadouts", propertiesUtil.getString("extraLoadouts"));
|
||||||
|
yamlUtil.set("author", propertiesUtil.getString("author"));
|
||||||
|
yamlUtil.set("lifePool", propertiesUtil.getString("lifePool"));
|
||||||
|
yamlUtil.set("monumentHeal", propertiesUtil.getString("monumentHeal"));
|
||||||
|
yamlUtil.set("autoAssignOnly", propertiesUtil.getString("autoAssignOnly"));
|
||||||
|
yamlUtil.set("flagPointsOnly", propertiesUtil.getString("flagPointsOnly"));
|
||||||
|
yamlUtil.set("teamCap", propertiesUtil.getString("teamCap"));
|
||||||
|
yamlUtil.set("scoreCap", propertiesUtil.getString("scoreCap"));
|
||||||
|
yamlUtil.set("blockHeads", propertiesUtil.getString("blockHeads"));
|
||||||
|
yamlUtil.set("spawnStyle", propertiesUtil.getString("spawnStyle"));
|
||||||
|
yamlUtil.set("flagReturn", propertiesUtil.getString("flagReturn"));
|
||||||
|
yamlUtil.set("reward", propertiesUtil.getString("reward"));
|
||||||
|
yamlUtil.set("unbreakableZoneBlocks", propertiesUtil.getString("unbreakableZoneBlocks"));
|
||||||
|
yamlUtil.set("disabled", propertiesUtil.getString("disabled"));
|
||||||
|
yamlUtil.set("noCreatures", propertiesUtil.getString("noCreatures"));
|
||||||
|
yamlUtil.set("glassWalls", propertiesUtil.getString("glassWalls"));
|
||||||
|
yamlUtil.set("pvpInZone", propertiesUtil.getString("pvpInZone"));
|
||||||
|
yamlUtil.set("instaBreak", propertiesUtil.getString("instaBreak"));
|
||||||
|
yamlUtil.set("noDrops", propertiesUtil.getString("noDrops"));
|
||||||
|
yamlUtil.set("noHunger", propertiesUtil.getString("noHunger"));
|
||||||
|
yamlUtil.set("saturation", propertiesUtil.getString("saturation"));
|
||||||
|
yamlUtil.set("minPlayers", propertiesUtil.getString("minPlayers"));
|
||||||
|
yamlUtil.set("minTeams", propertiesUtil.getString("minTeams"));
|
||||||
|
yamlUtil.set("resetOnEmpty", propertiesUtil.getString("resetOnEmpty"));
|
||||||
|
yamlUtil.set("resetOnLoad", propertiesUtil.getString("resetOnLoad"));
|
||||||
|
yamlUtil.set("resetOnUnload", propertiesUtil.getString("resetOnUnload"));
|
||||||
|
yamlUtil.set("rallyPoint", propertiesUtil.getString("rallyPoint"));
|
||||||
|
yamlUtil.set("monuments", propertiesUtil.getString("monuments"));
|
||||||
|
yamlUtil.set("lobby", propertiesUtil.getString("lobby"));
|
||||||
|
yamlUtil.save(yaml);
|
||||||
|
propertiesUtil.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -29,11 +29,25 @@ public class WarMapper {
|
|||||||
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
||||||
YamlConfiguration warConfig = new YamlConfiguration();
|
YamlConfiguration warConfig = new YamlConfiguration();
|
||||||
File config = new File(War.war.getDataFolder().getPath() + "/war.yml");
|
File config = new File(War.war.getDataFolder().getPath() + "/war.yml");
|
||||||
|
File oldconfig = new File(War.war.getDataFolder().getPath() + "/war.txt");
|
||||||
|
if (oldconfig.exists()) {
|
||||||
|
War.war.log("Old config file found. Converting to YAML...", Level.INFO);
|
||||||
|
try {
|
||||||
|
new PropertiesConverter(oldconfig, config).ConvertWarCfg();
|
||||||
|
oldconfig.delete();
|
||||||
|
War.war.log("Converted successfully!", Level.INFO);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
oldconfig.renameTo(new File(War.war.getDataFolder().getPath() + "/war.txt.bad"));
|
||||||
|
War.war.log("Error in conversion, old war.txt has been renamed to war.txt.bad. Default config will be generated.", Level.INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oldconfig = null;
|
||||||
try {
|
try {
|
||||||
warConfig.load(config);
|
warConfig.load(config);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
War.war.log("Failed to load war.txt file.", Level.WARNING);
|
War.war.log("Failed to load war.yml file.", Level.WARNING);
|
||||||
e.printStackTrace();
|
e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create file if need be
|
// Create file if need be
|
||||||
@ -58,7 +72,13 @@ public class WarMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// zone makers
|
// zone makers
|
||||||
String[] makers = warConfig.getString("zoneMakers").split(",");
|
String[] makers = null;
|
||||||
|
try {
|
||||||
|
makers = warConfig.getString("zoneMakers").split(",");
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
warConfig.set("zoneMakers", "");
|
||||||
|
makers = warConfig.getString("zoneMakers").split(",");
|
||||||
|
}
|
||||||
War.war.getZoneMakerNames().clear();
|
War.war.getZoneMakerNames().clear();
|
||||||
for (String makerName : makers) {
|
for (String makerName : makers) {
|
||||||
if (makerName != null && !makerName.equals("")) {
|
if (makerName != null && !makerName.equals("")) {
|
||||||
|
@ -34,10 +34,29 @@ public class WarzoneMapper {
|
|||||||
public static Warzone load(String name, boolean createNewVolume) {
|
public static Warzone load(String name, boolean createNewVolume) {
|
||||||
// war.getLogger().info("Loading warzone " + name + " config and blocks...");
|
// war.getLogger().info("Loading warzone " + name + " config and blocks...");
|
||||||
YamlConfiguration warzoneConfig = new YamlConfiguration();
|
YamlConfiguration warzoneConfig = new YamlConfiguration();
|
||||||
File config = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");try {
|
File config = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
|
||||||
|
File oldconfig = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||||
|
File dataFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
|
||||||
|
if (oldconfig.exists()) {
|
||||||
|
War.war.log("Old zone file found. Converting to YAML...", Level.INFO);
|
||||||
|
try {
|
||||||
|
new PropertiesConverter(oldconfig, config).ConvertZoneCfg();
|
||||||
|
oldconfig.delete();
|
||||||
|
War.war.log("Converted successfully!", Level.INFO);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
oldconfig.renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt.bad"));
|
||||||
|
dataFolder.renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "-bad"));
|
||||||
|
War.war.getWarzones().remove(Warzone.getZoneByName(name));
|
||||||
|
WarMapper.save();
|
||||||
|
War.war.log("Error in conversion, old warzone-" + name + ".txt has been renamed to warzone-" + name + ".txt.bad and old data folder /dat/warzone-" + name + " has been renamed to /dat/warzone-" + name + "-bad. Zone has been removed.", Level.INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oldconfig = null;
|
||||||
|
try {
|
||||||
warzoneConfig.load(config);
|
warzoneConfig.load(config);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
War.war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
|
War.war.getLogger().info("Failed to load warzone-" + name + ".yml file.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,7 +610,7 @@ public class WarzoneMapper {
|
|||||||
if (!deletedData) {
|
if (!deletedData) {
|
||||||
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
||||||
}
|
}
|
||||||
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
|
||||||
deletedData = zoneFile.delete();
|
deletedData = zoneFile.delete();
|
||||||
if (!deletedData) {
|
if (!deletedData) {
|
||||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||||
|
Loading…
Reference in New Issue
Block a user