Package org.bukkit.configuration

Examples of org.bukkit.configuration.ConfigurationSection


    // load groups information from config and check if our player belongs to any of them, then change his group
    Player p = (Player) e.getEntity();
    if (Permissions.checkPermEx(p, "cex.deathgroup.ignore")) return;
   
    FileConfiguration f = CommandsEX.getConf();
    ConfigurationSection configGroups = f.getConfigurationSection("deathGroupChanges");
    if (configGroups == null){ return; }
    Set<String> groups = configGroups.getKeys(false);
    String pName = p.getName();
    String toGroup = null;
    String command = null;
    List<String> removedGroups = new ArrayList<String>();
    final CommanderCommandSender ccs = new CommanderCommandSender();
View Full Code Here


    final Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    final Team playerTeam = Team.getTeamByPlayerName(player.getName());
    Validate.notNull(zone, "Cannot reward player if they are not in a warzone");
    Validate.notNull(playerTeam, "Cannot reward player if they are not in a team");
    if (section.contains(Integer.toString(kills))) {
      ConfigurationSection killSection = section.getConfigurationSection(Integer.toString(kills));
      if (killSection.contains("message")) {
        final String playerName = playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE;
        final String message = ChatColor.translateAlternateColorCodes('&', MessageFormat.format(killSection.getString("message"), playerName));
        for (Team team : zone.getTeams()) {
          team.teamcast(message);
        }
      }
      if (killSection.contains("privmsg")) {
        War.war.msg(player, ChatColor.translateAlternateColorCodes('&', killSection.getString("privmsg")));
      }
      if (killSection.contains("reward.health")) {
        double health = player.getHealth() + killSection.getInt("reward.health");
        player.setHealth(health > 20 ? 20 : health); // Grant up to full health only
      }
      if (killSection.contains("reward.items")) {
        for (Object obj : killSection.getList("reward.items")) {
          if (obj instanceof ItemStack) {
            player.getInventory().addItem((ItemStack) obj);
          }
        }
      }
      if (killSection.contains("reward.xp") && !playerTeam.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
        // Will not work if XPKILLMETER is enabled
        player.setLevel(player.getLevel() + killSection.getInt("reward.xp"));
      }
      if (killSection.contains("reward.points")) {
        for (int i = 0; i < killSection.getInt("reward.points"); i++) {
          playerTeam.addPoint();
        }
        // Detect win conditions
        if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
          player.getServer().getScheduler().runTaskLater(War.war, new Runnable() {
            public void run() {
              zone.handleScoreCapReached(playerTeam.getName());
            }
          }, 1L);
        } else {
          // just added a point
          playerTeam.resetSign();
          zone.getLobby().resetTeamGateSign(playerTeam);
        }
      }
      if (killSection.getBoolean("reward.airstrike")) {
        this.airstrikePlayers.add(player.getName());
      }
      if (killSection.contains("reward.effect")) {
        Effect effect = Effect.valueOf(killSection.getString("reward.effect"));
        player.getWorld().playEffect(player.getLocation(), effect, null);
      }
    }
  }
View Full Code Here

    // materials
    if (warhubConfig.isItemStack("materials.floor")) {
      War.war.getWarhubMaterials().setFloorBlock(
          warhubConfig.getItemStack("materials.floor"));
    } else {
      ConfigurationSection floorMaterialSection = warhubConfig
          .getConfigurationSection("materials.floor");
      if (floorMaterialSection != null) {
        War.war.getWarhubMaterials().setFloorBlock(
          new ItemStack(floorMaterialSection.getInt("id"), 1,
            (short) floorMaterialSection.getInt("data")));
      }
    }
    if (warhubConfig.isItemStack("materials.outline")) {
      War.war.getWarhubMaterials().setOutlineBlock(
          warhubConfig.getItemStack("materials.outline"));
    } else {
      ConfigurationSection floorMaterialSection = warhubConfig
          .getConfigurationSection("materials.outline");
      if (floorMaterialSection != null) {
        War.war.getWarhubMaterials().setOutlineBlock(
          new ItemStack(floorMaterialSection.getInt("id"), 1,
            (short) floorMaterialSection.getInt("data")));
      }
    }
    if (warhubConfig.isItemStack("materials.gate")) {
      War.war.getWarhubMaterials().setGateBlock(
          warhubConfig.getItemStack("materials.gate"));
    } else {
      ConfigurationSection floorMaterialSection = warhubConfig
          .getConfigurationSection("materials.gate");
      if (floorMaterialSection != null) {
        War.war.getWarhubMaterials().setGateBlock(
          new ItemStack(floorMaterialSection.getInt("id"), 1,
            (short) floorMaterialSection.getInt("data")));
      }
    }
    if (warhubConfig.isItemStack("materials.light")) {
      War.war.getWarhubMaterials().setLightBlock(
          warhubConfig.getItemStack("materials.light"));
    } else {
      ConfigurationSection floorMaterialSection = warhubConfig
          .getConfigurationSection("materials.light");
      if (floorMaterialSection != null) {
        War.war.getWarhubMaterials().setLightBlock(
          new ItemStack(floorMaterialSection.getInt("id"), 1,
            (short) floorMaterialSection.getInt("data")));
      }
    }
    World world = War.war.getServer().getWorld(worldName);
    if (world != null) {
      Location hubLocation = new Location(world, hubX, hubY, hubZ);
View Full Code Here

      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) {
      War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
    }

    // zone makers
    List<String> makers = warRootSection.getStringList("war.info.zonemakers");
    War.war.getZoneMakerNames().clear();
    for (String makerName : makers) {
      if (makerName != null && !makerName.equals("")) {
        War.war.getZoneMakerNames().add(makerName);
      }
    }

    // command whitelist
    List<String> whitelist = warRootSection.getStringList("war.info.commandwhitelist");
    War.war.getCommandWhitelist().clear();
    for (String command : whitelist) {
      if (command != null && !command.equals("")) {
        War.war.getCommandWhitelist().add(command);
      }
    }
   
    // defaultLoadouts
    ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout");
    War.war.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));

    // defaultReward
    ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");
    HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
    LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
    War.war.getDefaultInventories().setReward(reward);
   
    // War settings
    ConfigurationSection warConfigSection = warRootSection.getConfigurationSection("war.config");
    War.war.getWarConfig().loadFrom(warConfigSection);
   
    // Warzone default settings
    ConfigurationSection warzoneConfigSection = warRootSection.getConfigurationSection("warzone.default.config");
    War.war.getWarzoneDefaultConfig().loadFrom(warzoneConfigSection);
   
    // Team default settings
    ConfigurationSection teamConfigSection = warRootSection.getConfigurationSection("team.default.config");
    War.war.getTeamDefaultConfig().loadFrom(teamConfigSection);

    // warhub
    ConfigurationSection hubConfigSection = warRootSection.getConfigurationSection("war.info.warhub");
    if (hubConfigSection != null) {
      RestoreYmlWarhubJob restoreWarhub = new RestoreYmlWarhubJob(hubConfigSection);
      if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub, 20) == -1) {
        War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
      }
View Full Code Here

    }
  }
 
  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 {
View Full Code Here

    if (loadout.requiresPermission()) {
      section.set(loadout.getName() + ".permission", loadout.getPermission());
    }
  }
  public static void fromLoadoutToConfig(String loadoutName, HashMap<Integer, ItemStack> loadout, ConfigurationSection section) {
    ConfigurationSection loadoutSection = section.createSection(loadoutName);
   
    if (loadoutSection != null) {
      loadoutSection.set("slots", toIntList(loadout.keySet()));
      for (Integer slot : loadout.keySet()) {
        ItemStack stack = loadout.get(slot);
        loadoutSection.set(slot.toString(), stack);
      }
    }
  }
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.";
     
      // world of the warzone
      String worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world");
      if (worldStr == null) {
        // Ah! Seems that the new (post 1.2.3-ish) Bukkit config API has lowercased our map name on the previous save.
        // Retry with lowercase warzone name.
        zoneInfoPrefix = "warzone." + name.toLowerCase() + ".info.";
        worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world");
      }
      World world = War.war.getServer().getWorld(worldStr);
     
      // Create the zone
      Warzone warzone = new Warzone(world, name);

      // teleport
      int teleX = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.x");
      int teleY = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.y");
      int teleZ = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.z");
      int teleYaw = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.yaw");
      warzone.setTeleport(new Location(world, teleX, teleY, teleZ, teleYaw, 0));
     
      // defaultLoadouts
      if (warzoneRootSection.contains("team.default.loadout")) {
        ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout");
        warzone.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
      }

      // defaultReward
      if (warzoneRootSection.contains("team.default.reward")) {
        ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection("team.default.reward");
        HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
        LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
        warzone.getDefaultInventories().setReward(reward);
      }
     
      // Team default settings
      if (warzoneRootSection.contains("team.default.config")) {
        ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection("team.default.config");
        warzone.getTeamDefaultConfig().loadFrom(teamConfigSection);
      }
     
      // Warzone settings
      if (warzoneRootSection.contains("warzone." + warzone.getName() + ".config")) {
        ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName() + ".config");
        warzone.getWarzoneConfig().loadFrom(warzoneConfigSection);
      } else if (warzoneRootSection.contains("warzone." + warzone.getName().toLowerCase() + ".config")) {
        // Workaround for broken Bukkit backward-compatibility for non-lowercase Yml nodes
        ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName().toLowerCase() + ".config");
        warzone.getWarzoneConfig().loadFrom(warzoneConfigSection);
      }

      // authors
      if (warzoneRootSection.contains(zoneInfoPrefix + "authors")) {
        for(String authorStr : warzoneRootSection.getStringList(zoneInfoPrefix + "authors")) {
          if (!authorStr.equals("")) {
            warzone.addAuthor(authorStr);
          }
        }
      }

      // rallyPoint
      if (warzoneRootSection.contains(zoneInfoPrefix + "rallypoint")) {
        int rpX = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.x");
        int rpY = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.y");
        int rpZ = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.z");
        int rpYaw = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.yaw");
        Location rallyPoint = new Location(world, rpX, rpY, rpZ, rpYaw, 0);
        warzone.setRallyPoint(rallyPoint);
      }

      // monuments
      if (warzoneRootSection.contains(zoneInfoPrefix + "monument")) {
        List<String> monunmentNames = warzoneRootSection.getStringList(zoneInfoPrefix + "monument.names");
        for (String monumentName : monunmentNames) {
          if (monumentName != null && !monumentName.equals("")) {
            String monumentPrefix = zoneInfoPrefix + "monument." + monumentName + ".";
            if (!warzoneRootSection.contains(monumentPrefix + "x")) {
              // try lowercase instead
              monumentPrefix = zoneInfoPrefix + "monument." + monumentName.toLowerCase() + ".";
            }
            int monumentX = warzoneRootSection.getInt(monumentPrefix + "x");
            int monumentY = warzoneRootSection.getInt(monumentPrefix + "y");
            int monumentZ = warzoneRootSection.getInt(monumentPrefix + "z");
            int monumentYaw = warzoneRootSection.getInt(monumentPrefix + "yaw");
            Monument monument = new Monument(monumentName, warzone, new Location(world, monumentX, monumentY, monumentZ, monumentYaw, 0));
            warzone.getMonuments().add(monument);
          }
        }
      }
     
      // bombs
      if (warzoneRootSection.contains(zoneInfoPrefix + "bomb")) {
        List<String> bombNames = warzoneRootSection.getStringList(zoneInfoPrefix + "bomb.names");
        for (String bombName : bombNames) {
          if (bombName != null && !bombName.equals("")) {
            String bombPrefix = zoneInfoPrefix + "bomb." + bombName + ".";
            if (!warzoneRootSection.contains(bombPrefix + "x")) {
              // try lowercase instead
              bombPrefix = zoneInfoPrefix + "bomb." + bombName.toLowerCase() + ".";
            }
            int bombX = warzoneRootSection.getInt(bombPrefix + "x");
            int bombY = warzoneRootSection.getInt(bombPrefix + "y");
            int bombZ = warzoneRootSection.getInt(bombPrefix + "z");
            int bombYaw = warzoneRootSection.getInt(bombPrefix + "yaw");
            Bomb bomb = new Bomb(bombName, warzone, new Location(world, bombX, bombY, bombZ, bombYaw, 0));
            warzone.getBombs().add(bomb);
          }
        }
      }
     
      // cakes
      if (warzoneRootSection.contains(zoneInfoPrefix + "cake")) {
        List<String> cakeNames = warzoneRootSection.getStringList(zoneInfoPrefix + "cake.names");
        for (String cakeName : cakeNames) {
          if (cakeName != null && !cakeName.equals("")) {
            String cakePrefix = zoneInfoPrefix + "cake." + cakeName + ".";
            if (!warzoneRootSection.contains(cakePrefix + "x")) {
              // try lowercase instead
              cakePrefix = zoneInfoPrefix + "cake." + cakeName + ".";
            }
            int cakeX = warzoneRootSection.getInt(cakePrefix + "x");
            int cakeY = warzoneRootSection.getInt(cakePrefix + "y");
            int cakeZ = warzoneRootSection.getInt(cakePrefix + "z");
            int cakeYaw = warzoneRootSection.getInt(cakePrefix + "yaw");
            Cake cake = new Cake(cakeName, warzone, new Location(world, cakeX, cakeY, cakeZ, cakeYaw, 0));
            warzone.getCakes().add(cake);
          }
        }
      }
     
      // teams (maybe no teams)
      if (warzoneRootSection.contains("team.names")) {
        List<String> teamsNames = warzoneRootSection.getStringList("team.names");
        for (String teamName : teamsNames) {
          // team info
          String teamInfoPrefix = "team." + teamName + ".info.";
          if (!warzoneRootSection.contains(teamInfoPrefix + "spawn.x")) {
            // try lowercase instead - supports custom team names
            teamInfoPrefix = "team." + teamName.toLowerCase() + ".info.";
          }
          List<Location> teamSpawns = new ArrayList<Location>();
          if (warzoneRootSection.contains(teamInfoPrefix + "spawn")) {
            int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
            int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
            int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z");
            int teamYaw = warzoneRootSection.getInt(teamInfoPrefix + "spawn.yaw");
            Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0);
            teamSpawns.add(teamLocation);
            File original = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + ".dat");
            File modified = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + teamSpawns.indexOf(teamLocation) + ".dat");
            File originalSql = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + ".sl3");
            File modifiedSql = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + teamSpawns.indexOf(teamLocation) + ".sl3");
            try {
              original.renameTo(modified);
            } catch (Exception ignored) {
            }
            try {
              originalSql.renameTo(modifiedSql);
            } catch (Exception ignored) {
            }
          }
          if (warzoneRootSection.contains(teamInfoPrefix + "spawns")) {
            for (Map<?, ?> map : warzoneRootSection.getMapList(teamInfoPrefix + "spawns")) {
              int teamX = (Integer) map.get("x");
              int teamY = (Integer) map.get("y");
              int teamZ = (Integer) map.get("z");
              int teamYaw = (Integer) map.get("yaw");
              Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0);
              teamSpawns.add(teamLocation);
            }
          }
 
          Team team = new Team(teamName, TeamKind.teamKindFromString(teamName), teamSpawns, warzone);
          warzone.getTeams().add(team);
         
          if (warzoneRootSection.contains(teamInfoPrefix + "flag")) {
            int flagX = warzoneRootSection.getInt(teamInfoPrefix + "flag.x");
            int flagY = warzoneRootSection.getInt(teamInfoPrefix + "flag.y");
            int flagZ = warzoneRootSection.getInt(teamInfoPrefix + "flag.z");
            int flagYaw = warzoneRootSection.getInt(teamInfoPrefix + "flag.yaw");
            Location flagLocation = new Location(world, flagX, flagY, flagZ, flagYaw, 0);
            team.setTeamFlag(flagLocation);
          }
         
          String teamConfigPrefix = "team." + teamName + ".config";
          if (warzoneRootSection.contains(teamConfigPrefix)) {
            // team specific config
            ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix);
            team.getTeamConfig().loadFrom(teamConfigSection);
          } else if (warzoneRootSection.contains(teamConfigPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix.toLowerCase());
            team.getTeamConfig().loadFrom(teamConfigSection);
          }
         
          // LIFEPOOL INITIALIZATION HERE
          team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
         
          String teamLoadoutPrefix = "team." + teamName + ".loadout";
          if (warzoneRootSection.contains(teamLoadoutPrefix)) {
            // team specific loadouts
            ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix);
            team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
          } else if (warzoneRootSection.contains(teamLoadoutPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix.toLowerCase());
            team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
          }
         
          String teamRewardPrefix = "team." + teamName + ".reward";
          if (warzoneRootSection.contains(teamRewardPrefix)) {
            // team specific reward
            ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix);
            HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
            LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
            warzone.getDefaultInventories().setReward(reward);
          } else if (warzoneRootSection.contains(teamRewardPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix.toLowerCase());
            HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
            LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
            warzone.getDefaultInventories().setReward(reward);
          }
        }
      }
      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 {
          monument.setVolume(warzone.loadStructure(monument.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // bomb blocks
      for (Bomb bomb : warzone.getBombs()) {
        try {
          bomb.setVolume(warzone.loadStructure("bomb-" + bomb.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // cake blocks
      for (Cake cake : warzone.getCakes()) {
        try {
          cake.setVolume(warzone.loadStructure("cake-" + cake.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // team spawn blocks
      for (Team team : warzone.getTeams()) {
        for (Location teamSpawn : team.getTeamSpawns()) {
          try {
            team.setSpawnVolume(teamSpawn, warzone.loadStructure(team.getName() + team.getTeamSpawns().indexOf(teamSpawn), connection));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
          }
        }
        if (team.getTeamFlag() != null) {
          try {
            team.setFlagVolume(warzone.loadStructure(team.getName() + "flag", connection));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
          }
        }
      }

      // lobby
      String lobbyPrefix = zoneInfoPrefix + "lobby.";
     
      // lobby orientation
      String lobbyOrientation = warzoneRootSection.getString(lobbyPrefix + "orientation");
      BlockFace lobbyFace = null;
      if (lobbyOrientation.equals("south")) {
        lobbyFace = Direction.SOUTH();
      } else if (lobbyOrientation.equals("east")) {
        lobbyFace = Direction.EAST();
      } else if (lobbyOrientation.equals("north")) {
        lobbyFace = Direction.NORTH();
      } else if (lobbyOrientation.equals("west")) {
        lobbyFace = Direction.WEST();
      }
     
      // lobby materials
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.floor")) {
        warzone.getLobbyMaterials().setFloorBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.floor"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.floor");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setFloorBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.outline")) {
        warzone.getLobbyMaterials().setOutlineBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.outline"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.outline");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setOutlineBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.gate")) {
        warzone.getLobbyMaterials().setGateBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.gate"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.gate");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setGateBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.light")) {
        warzone.getLobbyMaterials().setLightBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
     
      // lobby world
      String lobbyWorldName = warzoneRootSection.getString(lobbyPrefix + "world");
      World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
           
      // create the lobby
      Volume lobbyVolume = null;
      try {
        lobbyVolume = warzone.loadStructure("lobby", lobbyWorld, connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to load warzone lobby", e);
      }
      ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
      warzone.setLobby(lobby);
     
      // warzone materials
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.main")) {
        warzone.getWarzoneMaterials().setMainBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.main"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.main");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setMainBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.stand")) {
        warzone.getWarzoneMaterials().setStandBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.stand"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.stand");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setStandBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.light")) {
        warzone.getWarzoneMaterials().setLightBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      try {
        connection.close();
      } catch (SQLException ignored) {
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());
View Full Code Here

         * TODO: Figure out if this is really a good idea + It saves needing all
         * those methods in Arena.java + It is relatively simple + It would be
         * fairly easy to implement an observer pattern - More private fields -
         * Uglier code
         */
        ConfigurationSection s = arena.getSettings();
        this.softRestore      = s.getBoolean("soft-restore",         false);
        this.softRestoreDrops = s.getBoolean("soft-restore-drops",   false);
        this.protect          = s.getBoolean("protect",              true);
        this.monsterExp       = s.getBoolean("monster-exp",          false);
        this.monsterInfight   = s.getBoolean("monster-infight",      false);
        this.pvpOn            = s.getBoolean("pvp-enabled",          false);
        this.foodRegen        = s.getBoolean("food-regen",           false);
        this.lockFoodLevel    = s.getBoolean("lock-food-level",      true);
        this.allowTeleport    = s.getBoolean("allow-teleporting",    false);
        this.canShare         = s.getBoolean("share-items-in-arena", true);
        this.autoIgniteTNT    = s.getBoolean("auto-ignite-tnt",      false);
        this.useClassChests   = s.getBoolean("use-class-chests",     false);
       
        this.classLimits = arena.getClassLimitManager();

        this.allowMonsters = arena.getWorld().getAllowMonsters();

View Full Code Here

        wave = 0;
        singleWavesInstance = new TreeSet<Wave>(singleWaves);
    }
   
    public void reloadWaves() {
        ConfigurationSection rConfig = section.getConfigurationSection("recurrent");
        ConfigurationSection sConfig = section.getConfigurationSection("single");
       
        recurrentWaves = WaveParser.parseWaves(arena, rConfig, WaveBranch.RECURRENT);
        singleWaves    = WaveParser.parseWaves(arena, sConfig, WaveBranch.SINGLE);

        // getParent() => go back to the arena-node to access settings
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.ConfigurationSection

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.