Java Code Examples for org.bukkit.configuration.file.FileConfiguration#createSection()

The following examples show how to use org.bukkit.configuration.file.FileConfiguration#createSection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Configurator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void checkOrSet(AtomicBoolean modify, FileConfiguration config, String path, Object value) {
    if (!config.isSet(path)) {
        if (value instanceof Map) {
            config.createSection(path, (Map<?, ?>) value);
        } else {
            config.set(path, value);
        }
        modify.set(true);
    }
}
 
Example 2
Source File: Configurator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void checkOrSet(AtomicBoolean modify, FileConfiguration config, String path, Object value) {
    if (!config.isSet(path)) {
        if (value instanceof Map) {
            config.createSection(path, (Map<?, ?>) value);
        } else {
            config.set(path, value);
        }
        modify.set(true);
    }
}
 
Example 3
Source File: ChallengeCompletionLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void saveToConfiguration(FileConfiguration configuration, Map<String, ChallengeCompletion> map) {
    for (Map.Entry<String, ChallengeCompletion> entry : map.entrySet()) {
        String challengeName = entry.getKey();
        ChallengeCompletion completion = entry.getValue();
        ConfigurationSection section = configuration.createSection(challengeName);
        section.set("firstCompleted", completion.getCooldownUntil());
        section.set("timesCompleted", completion.getTimesCompleted());
        section.set("timesCompletedSinceTimer", completion.getTimesCompletedInCooldown());
    }
}
 
Example 4
Source File: PlayerInfo.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void setupPlayer() {
    FileConfiguration playerConfig = playerData;
    ConfigurationSection pSection = playerConfig.createSection("player");
    pSection.set("islandX", 0);
    pSection.set("islandY", 0);
    pSection.set("islandZ", 0);
    pSection.set("homeX", 0);
    pSection.set("homeY", 0);
    pSection.set("homeZ", 0);
    pSection.set("homeYaw", 0);
    pSection.set("homePitch", 0);
    pSection.set("perms", null);
}
 
Example 5
Source File: SExprYaml.java    From skUtilities with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
  File pth = new File(skUtilities.getDefaultPath(path.getSingle(e)));
  String ypth = ypath.getSingle(e);
  FileConfiguration con = YamlConfiguration.loadConfiguration(pth);
  try {
    if (mode == Changer.ChangeMode.DELETE) {
      con.set(ypth, null);
    } else {
      Object v = (delta[0] == null ? "" : delta[0]);
      switch (ty) {
        case 0: {
          if (mode == Changer.ChangeMode.SET) {
            con.set(ypth, delta[0]);
          }
          break;
        }
        case 1:
        case 2:
          if (mode == Changer.ChangeMode.ADD) {
            con.createSection(ypth);
          } else if (mode == Changer.ChangeMode.REMOVE) {
            con.set(ypth + "." + v, null);
          }
          break;
        case 3: {
          if (mode == Changer.ChangeMode.ADD) {
            List obj = con.getList(ypth);
            if (obj == null) {
              obj = new ArrayList<>();
              obj.add(delta[0]);
              con.set(ypth, obj);
            } else {
              obj.add(delta[0]);
            }
          } else if (mode == Changer.ChangeMode.REMOVE) {
            con.getList(ypth).remove(delta[0]);
          }
        }
      }
    }
  } finally {
    try {
      con.save(pth);
    } catch (IOException x) {
      skUtilities.prSysE("Failed to save: '" + pth + "'", getClass().getSimpleName(), x);
    }
  }
}