From 59c4cf27381d14c5718e954213849e3c851b491f Mon Sep 17 00:00:00 2001 From: ElgarL Date: Sat, 1 Oct 2011 13:54:28 +0100 Subject: Attempt to stop GM wiping groups/users yml's on a bad shut down. --- EssentialsGroupManager/src/Changelog.txt | 3 +- .../groupmanager/dataholder/WorldDataHolder.java | 33 +++++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'EssentialsGroupManager/src') diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 8a2d92c1d..371f935f9 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -30,4 +30,5 @@ v 1.2: If present and set to false, op's will not get overriding permissions in GroupManager. (one op will not be able to alter another op's settings) - GM will now create all relevant world data files for non mirrored worlds. - (for all worlds named in config.yml) \ No newline at end of file + (for all worlds named in config.yml) + - Attempt to stop GM wiping groups/users yml's on a bad shut down. \ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 77d933fa0..4a9f806d8 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -767,13 +767,15 @@ public class WorldDataHolder { aGroupMap.put("permissions", group.getPermissionList()); } - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - yaml.dump(root, new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8")); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + yaml.dump(root, new OutputStreamWriter(new FileOutputStream(groupsFile), "UTF-8")); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } } /*FileWriter tx = null; @@ -829,13 +831,16 @@ public class WorldDataHolder { aUserMap.put("subgroups", user.subGroupListStringCopy()); //END SUBGROUPS NODE - BETA } - DumperOptions opt = new DumperOptions(); - opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - final Yaml yaml = new Yaml(opt); - try { - yaml.dump(root, new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8")); - } catch (UnsupportedEncodingException ex) { - } catch (FileNotFoundException ex) { + + if (!root.isEmpty()) { + DumperOptions opt = new DumperOptions(); + opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + final Yaml yaml = new Yaml(opt); + try { + yaml.dump(root, new OutputStreamWriter(new FileOutputStream(usersFile), "UTF-8")); + } catch (UnsupportedEncodingException ex) { + } catch (FileNotFoundException ex) { + } } /*FileWriter tx = null; try { -- cgit v1.2.3