Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.YamlConfiguration


      data = YamlConfiguration.loadConfiguration(dataFile);
  
      // Look for defaults in the jar
      InputStream defConfigStream = getResource("data.yml");
      if (defConfigStream != null) {
          YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
          data.setDefaults(defConfig);
      }
  }
View Full Code Here


      language = YamlConfiguration.loadConfiguration(languageFile);
  
      // Look for defaults in the jar
      InputStream defConfigStream = getResource(lang);
      if (defConfigStream != null) {
          YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
          language.setDefaults(defConfig);
      }
  }
View Full Code Here

      data = YamlConfiguration.loadConfiguration(dataFile);
  
      // Look for defaults in the jar
      InputStream defConfigStream = getResource("data.yml");
      if (defConfigStream != null) {
          YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
          data.setDefaults(defConfig);
      }
  }
View Full Code Here

      language = YamlConfiguration.loadConfiguration(languageFile);
  
      // Look for defaults in the jar
      InputStream defConfigStream = getResource(lang);
      if (defConfigStream != null) {
          YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
          language.setDefaults(defConfig);
      }
  }
View Full Code Here

      newWar = true;
      WarYmlMapper.save();
      War.war.log("war.yml settings file created.", Level.INFO);
    }
   
    YamlConfiguration warYmlConfig = YamlConfiguration.loadConfiguration(warYmlFile);
    ConfigurationSection warRootSection = warYmlConfig.getConfigurationSection("set");
   
    // warzones
    List<String> warzones = warRootSection.getStringList("war.info.warzones");
    RestoreYmlWarzonesJob restoreWarzones = new RestoreYmlWarzonesJob(warzones)// during conversion, this should execute just after the RestoreTxtWarzonesJob
    if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones) == -1) {
View Full Code Here

      War.war.setMysqlConfig(new MySQLConfig(warRootSection.getConfigurationSection("war.mysql")));
    }
  }
 
  public static void save() {
    YamlConfiguration warYmlConfig = new YamlConfiguration();
    ConfigurationSection warRootSection = warYmlConfig.createSection("set");
    (new File(War.war.getDataFolder().getPath())).mkdir();
    (new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();

    // War settings
    ConfigurationSection warConfigSection = warRootSection.createSection("war.config");
    War.war.getWarConfig().saveTo(warConfigSection);
   
    // Warzone default settings
    ConfigurationSection warzoneConfigSection = warRootSection.createSection("warzone.default.config");
    War.war.getWarzoneDefaultConfig().saveTo(warzoneConfigSection);
   
    // Team default settings
    ConfigurationSection teamDefault = warRootSection.createSection("team.default");
    ConfigurationSection teamConfigSection = teamDefault.createSection("config");
    War.war.getTeamDefaultConfig().saveTo(teamConfigSection);
   
    // defaultLoadouts
    ConfigurationSection loadoutSection = teamDefault.createSection("loadout");
    LoadoutYmlMapper.fromLoadoutsToConfig(War.war.getDefaultInventories().getNewLoadouts(), loadoutSection);
       
    // defaultReward
    ConfigurationSection rewardsSection = teamDefault.createSection("reward");
    LoadoutYmlMapper.fromLoadoutToConfig("default", War.war.getDefaultInventories().getReward(), rewardsSection);

    ConfigurationSection warInfoSection = warRootSection.createSection("war.info");
   
    // warzones
    List<String> warzones = new ArrayList<String>();
    for (Warzone zone : War.war.getWarzones()) {
      warzones.add(zone.getName());
    }   
    warInfoSection.set("warzones", warzones);
   
    // zone makers
    warInfoSection.set("zonemakers", War.war.getZoneMakerNames());
   
    // whitelisted commands during a game
    warInfoSection.set("commandwhitelist", War.war.getCommandWhitelist());
   
    // warhub
    WarHub hub = War.war.getWarHub();
    if (hub != null) {
      String orientationStr = "";
      switch (hub.getOrientation()) {
        case SOUTH:
          if (Direction.isLegacy) orientationStr = "south";
          else orientationStr = "west"// temp fix for rotating warhub
          break;
        case EAST:
          if (Direction.isLegacy) orientationStr = "east";
          else orientationStr = "south";
          break;
        case NORTH:
          if (Direction.isLegacy) orientationStr = "north";
          else orientationStr = "east";
          break;
        case WEST:
        default:
          if (Direction.isLegacy) orientationStr = "west";
          else orientationStr = "north";
          break;
      }
     
      ConfigurationSection hubConfigSection = warInfoSection.createSection("warhub");
      hubConfigSection.set("x", hub.getLocation().getBlockX());
      hubConfigSection.set("y", hub.getLocation().getBlockY());
      hubConfigSection.set("z", hub.getLocation().getBlockZ());
      hubConfigSection.set("world", hub.getLocation().getWorld().getName());
      hubConfigSection.set("orientation", orientationStr);
     
      hubConfigSection.set("materials.floor", War.war.getWarhubMaterials().getFloorBlock());
      hubConfigSection.set("materials.outline", War.war.getWarhubMaterials().getOutlineBlock());
      hubConfigSection.set("materials.gate", War.war.getWarhubMaterials().getGateBlock());
      hubConfigSection.set("materials.light", War.war.getWarhubMaterials().getLightBlock());

      try {
        VolumeMapper.save(hub.getVolume(), "");
      } catch (SQLException e) {
        // who really even cares
        War.war.getLogger().log(Level.WARNING, "Failed to save warhub volume blocks", e);
      }
    }

    ConfigurationSection killstreakSection = warRootSection.createSection("war.killstreak");
    War.war.getKillstreakReward().saveTo(killstreakSection);

    ConfigurationSection mysqlSection = warRootSection.createSection("war.mysql");
    War.war.getMysqlConfig().saveTo(mysqlSection);

    // Save to disk
    File warConfigFile = new File(War.war.getDataFolder().getPath() + "/war.yml");
    try {
      warYmlConfig.save(warConfigFile);
    } catch (IOException e) {
      War.war.log("Failed to save war.yml", Level.WARNING);
      e.printStackTrace();
    }
  }
View Full Code Here

          modify.update(true, false);
        }
       
        // Containers
        if (modify instanceof InventoryHolder) {
          YamlConfiguration config = new YamlConfiguration();
          config.loadFromString(query.getString("metadata"));
          ((InventoryHolder) modify).getInventory().clear();
          for (Object obj : config.getList("items")) {
            if (obj instanceof ItemStack) {
              ((InventoryHolder) modify).getInventory().addItem((ItemStack) obj);
            }
          }
          modify.update(true, false);
View Full Code Here

          if (state instanceof Sign) {
            final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n");
            dataStmt.setString(6, signText);
          } else if (state instanceof InventoryHolder) {
            List<ItemStack> items = Arrays.asList(((InventoryHolder) block.getState()).getInventory().getContents());
            YamlConfiguration config = new YamlConfiguration();
            // Serialize to config, then store config in database
            config.set("items", items);
            dataStmt.setString(6, config.saveToString());
          } else if (state instanceof NoteBlock) {
            Note note = ((NoteBlock) block.getState()).getNote();
            dataStmt.setString(6, note.getTone().toString() + '\n' + note.getOctave() + '\n' + note.isSharped());
          } else if (state instanceof Jukebox) {
            dataStmt.setString(6, ((Jukebox) block.getState()).getPlaying().toString());
View Full Code Here

    }
   
    if (!warzoneYmlFile.exists()) {
      War.war.log("File warzone-" + name + ".yml not found", Level.WARNING);
    } else {
      YamlConfiguration warzoneYmlConfig = YamlConfiguration.loadConfiguration(warzoneYmlFile);
      ConfigurationSection warzoneRootSection = warzoneYmlConfig.getConfigurationSection("set");
     
      // Bukkit config API forces all Yml nodes to lowercase, now, it seems, sigh...
      // We need to keep this original (non-lowercase) implementation because old warzone.yml
      // files are not lowercased yet if they haven't been saved since the API change.
      String zoneInfoPrefix = "warzone." + name + ".info.";
View Full Code Here

   
    return null;
  }
 
  public static void save(Warzone warzone) {
    YamlConfiguration warzoneYmlConfig = new YamlConfiguration();
    ConfigurationSection warzoneRootSection = warzoneYmlConfig.createSection("set");
    (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir()// create folder
   
    ConfigurationSection warzoneSection = warzoneRootSection.createSection("warzone." + warzone.getName());
   
    // Warzone settings
    if (!warzone.getWarzoneConfig().isEmpty()) {
      ConfigurationSection warzoneConfigSection = warzoneSection.createSection("config");
      warzone.getWarzoneConfig().saveTo(warzoneConfigSection);
    }
       
    ConfigurationSection warzoneInfoSection = warzoneSection.createSection("info");
   
    // authors
    warzoneInfoSection.set("authors", warzone.getAuthors());
   
    // teleport
    ConfigurationSection teleSection = warzoneInfoSection.createSection("teleport");
    teleSection.set("x", warzone.getTeleport().getBlockX());
    teleSection.set("y", warzone.getTeleport().getBlockY());
    teleSection.set("z", warzone.getTeleport().getBlockZ());
    teleSection.set("yaw", toIntYaw(warzone.getTeleport().getYaw()));
 
    // world
    warzoneInfoSection.set("world", warzone.getWorld().getName())
   
    // lobby
    if (warzone.getLobby() != null) {
      String lobbyOrientation = "";
      if (Direction.SOUTH() == warzone.getLobby().getWall()) {
        lobbyOrientation = "south";
      } else if (Direction.EAST() == warzone.getLobby().getWall()) {
        lobbyOrientation = "east";
      } else if (Direction.NORTH() == warzone.getLobby().getWall()) {
        lobbyOrientation = "north";
      } else if (Direction.WEST() == warzone.getLobby().getWall()) {
        lobbyOrientation = "west";
      }
     
      ConfigurationSection lobbySection = warzoneInfoSection.createSection("lobby");
      lobbySection.set("orientation", lobbyOrientation);
      lobbySection.set("world", warzone.getLobby().getVolume().getWorld().getName());
     
      lobbySection.set("materials.floor", warzone.getLobbyMaterials().getFloorBlock());
      lobbySection.set("materials.outline", warzone.getLobbyMaterials().getOutlineBlock());
      lobbySection.set("materials.gate", warzone.getLobbyMaterials().getGateBlock());
      lobbySection.set("materials.light", warzone.getLobbyMaterials().getLightBlock());
    }
   
    // materials
    if (warzone.getLobby() != null) {
      warzoneInfoSection.set("materials.main", warzone.getWarzoneMaterials().getMainBlock());
      warzoneInfoSection.set("materials.stand", warzone.getWarzoneMaterials().getStandBlock());
      warzoneInfoSection.set("materials.light", warzone.getWarzoneMaterials().getLightBlock());
    }

    // rallyPoint
    if (warzone.getRallyPoint() != null) {
      ConfigurationSection rpSection = warzoneInfoSection.createSection("rallypoint");
      rpSection.set("x", warzone.getRallyPoint().getBlockX());
      rpSection.set("y", warzone.getRallyPoint().getBlockY());
      rpSection.set("z", warzone.getRallyPoint().getBlockZ());
      rpSection.set("yaw", toIntYaw(warzone.getRallyPoint().getYaw()));
    }
   
    // monuments
    if (warzone.getMonuments().size() > 0) {
      ConfigurationSection monumentsSection = warzoneInfoSection.createSection("monument");
     
      List<String> monumentNames = new ArrayList<String>();
      for (Monument monument : warzone.getMonuments()) {
        monumentNames.add(monument.getName());
      }
      monumentsSection.set("names", monumentNames);
     
      for (Monument monument : warzone.getMonuments()) {
       
        ConfigurationSection monumentSection = monumentsSection.createSection(monument.getName());
        monumentSection.set("x", monument.getLocation().getBlockX());
        monumentSection.set("y", monument.getLocation().getBlockY());
        monumentSection.set("z", monument.getLocation().getBlockZ());
        monumentSection.set("yaw", toIntYaw(monument.getLocation().getYaw()));
      }
    }
   
    // bombs
    if (warzone.getBombs().size() > 0) {
      ConfigurationSection bombsSection = warzoneInfoSection.createSection("bomb");
     
      List<String> bombNames = new ArrayList<String>();
      for (Bomb bomb : warzone.getBombs()) {
        bombNames.add(bomb.getName());
      }
      bombsSection.set("names", bombNames);
     
      for (Bomb bomb : warzone.getBombs()) {
       
        ConfigurationSection bombSection = bombsSection.createSection(bomb.getName());
        bombSection.set("x", bomb.getLocation().getBlockX());
        bombSection.set("y", bomb.getLocation().getBlockY());
        bombSection.set("z", bomb.getLocation().getBlockZ());
        bombSection.set("yaw", toIntYaw(bomb.getLocation().getYaw()));
      }
    }
   
    // cakes
    if (warzone.getCakes().size() > 0) {
      ConfigurationSection cakesSection = warzoneInfoSection.createSection("cake");
     
      List<String> cakeNames = new ArrayList<String>();
      for (Cake cake : warzone.getCakes()) {
        cakeNames.add(cake.getName());
      }
      cakesSection.set("names", cakeNames);
     
      for (Cake cake : warzone.getCakes()) {
       
        ConfigurationSection cakeSection = cakesSection.createSection(cake.getName());
        cakeSection.set("x", cake.getLocation().getBlockX());
        cakeSection.set("y", cake.getLocation().getBlockY());
        cakeSection.set("z", cake.getLocation().getBlockZ());
        cakeSection.set("yaw", toIntYaw(cake.getLocation().getYaw()));
      }
    }
   
    ConfigurationSection teamsSection = warzoneRootSection.createSection("team");
   
    // teams
    List<Team> teams = warzone.getTeams();
   
    List<String> teamNames = new ArrayList<String>();
    for (Team team : teams) {
      teamNames.add(team.getName());
    }
    if (teamNames.size() > 0) {
      teamsSection.set("names", teamNames);
    }

    // Team default settings
    if (!warzone.getTeamDefaultConfig().isEmpty()) {
      ConfigurationSection teamConfigSection = teamsSection.createSection("default.config");
      warzone.getTeamDefaultConfig().saveTo(teamConfigSection);
    }   
   
    // defaultLoadouts
    if (warzone.getDefaultInventories().hasLoadouts()) {
      ConfigurationSection loadoutsSection = teamsSection.createSection("default.loadout");
      LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getNewLoadouts(), loadoutsSection);
    }
   
    // defaultReward
    if (warzone.getDefaultInventories().hasReward()) {
      ConfigurationSection rewardsSection = teamsSection.createSection("default.reward");
      LoadoutYmlMapper.fromLoadoutToConfig("default", warzone.getDefaultInventories().getReward(), rewardsSection);
   
   
    for (Team team : teams) {
      if (!team.getTeamConfig().isEmpty()) {
        // team specific config
        ConfigurationSection teamConfigSection = teamsSection.createSection(team.getName() + ".config");
        team.getTeamConfig().saveTo(teamConfigSection);
      }
     
      if (team.getInventories().hasLoadouts()) {
        // team specific loadouts
        ConfigurationSection loadoutsSection = teamsSection.createSection(team.getName() + ".loadout");
        LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getNewLoadouts(), loadoutsSection);
      }
     
      if (team.getInventories().hasReward()) {
        // team specific reward
        ConfigurationSection rewardsSection = teamsSection.createSection(team.getName() + ".reward");
        LoadoutYmlMapper.fromLoadoutToConfig("default", team.getInventories().getReward(), rewardsSection);
      }

      ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info");
     
      List<Map<String, Object>> spawnSerilization = new ArrayList<Map<String, Object>>();
      for (Location spawn : team.getTeamSpawns()) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("x", spawn.getBlockX());
        map.put("y", spawn.getBlockY());
        map.put("z", spawn.getBlockZ());
        map.put("yaw", toIntYaw(spawn.getYaw()));
        spawnSerilization.add(map);
      }
      teamInfoSection.set("spawns", spawnSerilization);
     
      if (team.getTeamFlag() != null) {
        ConfigurationSection flagSection = teamInfoSection.createSection("flag");
        Location teamFlag = team.getTeamFlag();
        flagSection.set("x", teamFlag.getBlockX());
        flagSection.set("y", teamFlag.getBlockY());
        flagSection.set("z", teamFlag.getBlockZ());
        flagSection.set("yaw", toIntYaw(teamFlag.getYaw()));
      }
    }
    Connection connection = null;
    try {
      connection = ZoneVolumeMapper.getZoneConnection(warzone.getVolume(), warzone.getName(), warzone.getWorld());
    } catch (SQLException e) {
      War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
    }
    // monument blocks
    for (Monument monument : warzone.getMonuments()) {
      try {
        ZoneVolumeMapper.saveStructure(monument.getVolume(), connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
      }
    }
   
    // bomb blocks
    for (Bomb bomb : warzone.getBombs()) {
      try {
        ZoneVolumeMapper.saveStructure(bomb.getVolume(), connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
      }
    }
   
    // cake blocks
    for (Cake cake : warzone.getCakes()) {
      try {
        ZoneVolumeMapper.saveStructure(cake.getVolume(), connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
      }
    }

    // team spawn & flag blocks
    for (Team team : teams) {
      for (Volume volume : team.getSpawnVolumes().values()) {
        try {
          ZoneVolumeMapper.saveStructure(volume, connection);
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
        }
      }
      if (team.getFlagVolume() != null) {
        try {
          ZoneVolumeMapper.saveStructure(team.getFlagVolume(), connection);
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
        }
      }
    }

    if (warzone.getLobby() != null) {
      try {
        ZoneVolumeMapper.saveStructure(warzone.getLobby().getVolume(), connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
      }
    }
    try {
      connection.close();
    } catch (SQLException ignored) {
    }

    // Save to disk
    try {
      File warzoneConfigFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".yml");
      warzoneYmlConfig.save(warzoneConfigFile);
    } catch (IOException e) {
      War.war.log("Failed to save warzone-" + warzone.getName() + ".yml", Level.WARNING);
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.file.YamlConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.