Package com.palmergames.util

Examples of com.palmergames.util.KeyValueFile


    String[] tokens;
    String path = rootFolder + dataFolder + "/nations/" + nation.getName() + ".txt";
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);

        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Town town = getTown(token);
            if (town != null)
              nation.addTown(town);
          }
        }

        line = kvFile.get("capital");
        nation.setCapital(getTown(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident assistant = getResident(token);
            if (assistant != null)
              nation.addAssistant(assistant);
          }
        }

        line = kvFile.get("allies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Nation friend = getNation(token);
            if (friend != null)
              nation.setAliegeance("ally", friend);
          }
        }

        line = kvFile.get("enemies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Nation enemy = getNation(token);
            if (enemy != null)
              nation.setAliegeance("enemy", enemy);
          }
        }

        line = kvFile.get("taxes");
        if (line != null)
          try {
            nation.setTaxes(Integer.parseInt(line));
          } catch (Exception e) {
            nation.setTaxes(0);
          }
         
        line = kvFile.get("neutral");
        if (line != null)
          try {
            nation.setNeutral(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
View Full Code Here


    String line;
    String path = rootFolder + dataFolder + "/residents/" + resident.getName() + ".txt";
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);
        resident.setLastOnline(Long.parseLong(kvFile.get("lastLogin")));
       
        line = kvFile.get("registered");
        if (line != null)
          resident.setRegistered(Long.parseLong(line));
        else
          resident.setRegistered(resident.getLastOnline());
       
       
        line = kvFile.get("town");
        if (line != null)
          resident.setTown(getTown(line));

        line = kvFile.get("friends");
        if (line != null) {
          String[] tokens = line.split(",");
          for (String token : tokens) {
            Resident friend = getResident(token);
            if (friend != null)
View Full Code Here

    String[] tokens;
    String path = rootFolder + dataFolder + "/towns/" + town.getName() + ".txt";
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);

        line = kvFile.get("residents");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident resident = getResident(token);
            if (resident != null)
              town.addResident(resident);
          }
        }

        line = kvFile.get("mayor");
        if (line != null)
          town.setMayor(getResident(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident assistant = getResident(token);
            if (assistant != null)
              town.addAssistant(assistant);
          }
        }

        town.setTownBoard(kvFile.get("townBoard"));

        line = kvFile.get("bonusBlocks");
        if (line != null)
          try {
            town.setBonusBlocks(Integer.parseInt(line));
          } catch (Exception e) {
            town.setBonusBlocks(0);
          }
       
        line = kvFile.get("purchasedBlocks");
        if (line != null)
          try {
            town.setPurchasedBlocks(Integer.parseInt(line));
          } catch (Exception e) {
            town.setPurchasedBlocks(0);
          }

        line = kvFile.get("plotPrice");
        if (line != null)
          try {
            town.setPlotPrice(Integer.parseInt(line));
          } catch (Exception e) {
            town.setPlotPrice(0);
          }

        line = kvFile.get("taxes");
        if (line != null)
          try {
            town.setTaxes(Integer.parseInt(line));
          } catch (Exception e) {
            town.setTaxes(0);
          }
       
        line = kvFile.get("plotTax");
        if (line != null)
          try {
            town.setPlotTax(Integer.parseInt(line));
          } catch (Exception e) {
            town.setPlotTax(0);
          }

        line = kvFile.get("pvp");
        if (line != null)
          try {
            town.setPVP(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
         
        line = kvFile.get("explosion");
        if (line != null)
          try {
            town.setBANG(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }

                line = kvFile.get("taxpercent");
        if (line != null)
          try {
            town.setTaxPercentage(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
       
        line = kvFile.get("fire");
        if (line != null)
          try {
            town.setFire(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
View Full Code Here

    String[] tokens;
    String path = getTownFilename(town);
    File fileTown = new File(path);
    if (fileTown.exists() && fileTown.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);

        line = kvFile.get("residents");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident resident = getResident(token);
              if (resident != null)
                town.addResident(resident);
            }
          }
        }

        line = kvFile.get("mayor");
        if (line != null)
          town.setMayor(getResident(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident assistant = getResident(token);
              if ((assistant != null) && (town.hasResident(assistant)))
                town.addAssistant(assistant);
            }
          }
        }

        town.setTownBoard(kvFile.get("townBoard"));
       
        line = kvFile.get("tag");
        if (line != null)
          try {
            town.setTag(line);
          } catch(TownyException e) {
            town.setTag("");
          }

        line = kvFile.get("protectionStatus");
        if (line != null)
          town.setPermissions(line);

        line = kvFile.get("bonusBlocks");
        if (line != null)
          try {
            town.setBonusBlocks(Integer.parseInt(line));
          } catch (Exception e) {
            town.setBonusBlocks(0);
          }
         
        line = kvFile.get("purchasedBlocks");
        if (line != null)
          try {
            town.setPurchasedBlocks(Integer.parseInt(line));
          } catch (Exception e) {
            town.setPurchasedBlocks(0);
          }

        line = kvFile.get("plotPrice");
        if (line != null)
          try {
            town.setPlotPrice(Double.parseDouble(line));
          } catch (Exception e) {
            town.setPlotPrice(0);
          }
       
        line = kvFile.get("hasUpkeep");
        if (line != null)
          try {
            town.setHasUpkeep(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }

        line = kvFile.get("taxpercent");
        if (line != null)
          try {
            town.setTaxPercentage(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
       
        line = kvFile.get("taxes");
        if (line != null)
          try {
            town.setTaxes(Double.parseDouble(line));
          } catch (Exception e) {
            town.setTaxes(0);
          }
       
        line = kvFile.get("plotTax");
        if (line != null)
          try {
            town.setPlotTax(Double.parseDouble(line));
          } catch (Exception e) {
            town.setPlotTax(0);
          }

                line = kvFile.get("commercialPlotPrice");
        if (line != null)
          try {
            town.setCommercialPlotPrice(Double.parseDouble(line));
          } catch (Exception e) {
            town.setCommercialPlotPrice(0);
          }

                line = kvFile.get("commercialPlotTax");
        if (line != null)
          try {
            town.setCommercialPlotTax(Double.parseDouble(line));
          } catch (Exception e) {
            town.setCommercialPlotTax(0);
          }
       
        line = kvFile.get("embassyPlotPrice");
        if (line != null)
          try {
            town.setEmbassyPlotPrice(Double.parseDouble(line));
          } catch (Exception e) {
            town.setEmbassyPlotPrice(0);
          }

                line = kvFile.get("embassyPlotTax");
        if (line != null)
          try {
            town.setEmbassyPlotTax(Double.parseDouble(line));
          } catch (Exception e) {
            town.setEmbassyPlotTax(0);
          }
        /*
        line = kvFile.get("pvp");
        if (line != null)
          try {
            town.setPVP(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }

        line = kvFile.get("mobs");
        if (line != null)
          try {
            town.setHasMobs(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
        */
        line = kvFile.get("open");
        if (line != null)
          try {
            town.setOpen(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
        line = kvFile.get("public");
        if (line != null)
          try {
            town.setPublic(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
        /*
        line = kvFile.get("explosion");
        if (line != null)
          try {
            town.setBANG(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
       
        line = kvFile.get("fire");
        if (line != null)
          try {
            town.setFire(Boolean.parseBoolean(line));
          } catch (NumberFormatException nfe) {
          } catch (Exception e) {
          }
         */
        line = kvFile.get("townBlocks");
        if (line != null)
          utilLoadTownBlocks(line, town, null);

        line = kvFile.get("homeBlock");
        if (line != null) {
          tokens = line.split(",");
          if (tokens.length == 3)
            try {
              TownyWorld world = getWorld(tokens[0]);
             
              try {
                int x = Integer.parseInt(tokens[1]);
                int z = Integer.parseInt(tokens[2]);
                TownBlock homeBlock = world.getTownBlock(x, z);
                town.setHomeBlock(homeBlock);
              } catch (NumberFormatException e) {
                System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid location.");
              } catch (NotRegisteredException e) {
                System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid TownBlock.");
              } catch (TownyException e) {
                System.out.println("[Towny] [Warning] " + town.getName() + " does not have a home block.");
              }
             
            } catch (NotRegisteredException e) {
              System.out.println("[Towny] [Warning] " + town.getName() + " homeBlock tried to load invalid world.");
            }
        }

        line = kvFile.get("spawn");
        if (line != null) {
          tokens = line.split(",");
          if (tokens.length >= 4)
            try {
              World world = plugin.getServerWorld(tokens[0]);
View Full Code Here

    String[] tokens;
    String path = getNationFilename(nation);
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);

        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Town town = getTown(token);
              if (town != null)
                nation.addTown(town);
            }
          }
        }

        line = kvFile.get("capital");
        if (line != null)
          nation.setCapital(getTown(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident assistant = getResident(token);
              if (assistant != null)
                nation.addAssistant(assistant);
            }
          }
        }
       
        line = kvFile.get("tag");
        if (line != null)
          try {
            nation.setTag(line);
          } catch(TownyException e) {
            nation.setTag("");
          }

        line = kvFile.get("allies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
            Nation friend = getNation(token);
              if (friend != null)
                nation.addAlly(friend); //("ally", friend);
            }
          }
        }

        line = kvFile.get("enemies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Nation enemy = getNation(token);
              if (enemy != null)
                nation.addEnemy(enemy); //("enemy", enemy);
            }
          }
        }

        line = kvFile.get("taxes");
        if (line != null)
          try {
            nation.setTaxes(Double.parseDouble(line));
          } catch (Exception e) {
            nation.setTaxes(0.0);
          }
         
        line = kvFile.get("neutral");
        if (line != null)
          try {
            nation.setNeutral(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
View Full Code Here

    }
   
    File fileWorld = new File(path);
    if (fileWorld.exists() && fileWorld.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);
       
        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Town town = getTown(token);
              if (town != null) {
                town.setWorld(world);
                //world.addTown(town); not needed as it's handled in the Town object
              }
            }
          }
        }
       
        line = kvFile.get("claimable");
        if (line != null)
          try {
            world.setClaimable(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
         
        line = kvFile.get("pvp");
        if (line != null)
          try {
            world.setPVP(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("forcepvp");
        if (line != null)
          try {
            world.setForcePVP(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("forcetownmobs");
        if (line != null)
          try {
            world.setForceTownMobs(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("worldmobs");
        if (line != null)
          try {
            world.setWorldMobs(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
         
        line = kvFile.get("firespread");
        if (line != null)
          try {
            world.setFire(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("forcefirespread");
        if (line != null)
          try {
            world.setForceFire(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("explosions");
        if (line != null)
          try {
            world.setExpl(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("forceexplosions");
        if (line != null)
          try {
            world.setForceExpl(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("endermanprotect");
        if (line != null)
          try {
            world.setEndermanProtect(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("disableplayertrample");
        if (line != null)
          try {
            world.setDisablePlayerTrample(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("disablecreaturetrample");
        if (line != null)
          try {
            world.setDisableCreatureTrample(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
       
        line = kvFile.get("unclaimedZoneBuild");
        if (line != null)
          try {
            world.setUnclaimedZoneBuild(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("unclaimedZoneDestroy");
        if (line != null)
          try {
            world.setUnclaimedZoneDestroy(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("unclaimedZoneSwitch");
        if (line != null)
          try {
            world.setUnclaimedZoneSwitch(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("unclaimedZoneItemUse");
        if (line != null)
          try {
            world.setUnclaimedZoneItemUse(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("unclaimedZoneName");
        if (line != null)
          try {
            world.setUnclaimedZoneName(line);
          } catch (Exception e) {
          }
        line = kvFile.get("unclaimedZoneIgnoreIds");
        if (line != null)
          try {
            List<Integer> nums = new ArrayList<Integer>();
            for (String s: line.split(","))
              if (!s.isEmpty())
              try {
                nums.add(Integer.parseInt(s));
              } catch (NumberFormatException e) {
              }
            world.setUnclaimedZoneIgnore(nums);
          } catch (Exception e) {
          }
       
        line = kvFile.get("usingPlotManagementDelete");
        if (line != null)
          try {
            world.setUsingPlotManagementDelete(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("plotManagementDeleteIds");
        if (line != null)
          try {
            List<Integer> nums = new ArrayList<Integer>();
            for (String s: line.split(","))
              if (!s.isEmpty())
              try {
                nums.add(Integer.parseInt(s));
              } catch (NumberFormatException e) {
              }
            world.setPlotManagementDeleteIds(nums);
          } catch (Exception e) {
          }
       
        line = kvFile.get("usingPlotManagementMayorDelete");
        if (line != null)
          try {
            world.setUsingPlotManagementMayorDelete(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("plotManagementMayorDelete");
        if (line != null)
          try {
            List<String> materials = new ArrayList<String>();
            for (String s: line.split(","))
              if (!s.isEmpty())
              try {
                materials.add(s.toUpperCase().trim());
              } catch (NumberFormatException e) {
              }
            world.setPlotManagementMayorDelete(materials);
          } catch (Exception e) {
          }
       
        line = kvFile.get("usingPlotManagementRevert");
        if (line != null)
          try {
            world.setUsingPlotManagementRevert(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("usingPlotManagementRevertSpeed");
        if (line != null)
          try {
            world.setPlotManagementRevertSpeed(Long.parseLong(line));
          } catch (Exception e) {
          }
        line = kvFile.get("plotManagementIgnoreIds");
        if (line != null)
          try {
            List<Integer> nums = new ArrayList<Integer>();
            for (String s: line.split(","))
              if (!s.isEmpty())
              try {
                nums.add(Integer.parseInt(s));
              } catch (NumberFormatException e) {
              }
            world.setPlotManagementIgnoreIds(nums);
          } catch (Exception e) {
          }
       
        line = kvFile.get("usingPlotManagementWildRegen");
        if (line != null)
          try {
            world.setUsingPlotManagementWildRevert(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
        line = kvFile.get("usingPlotManagementWildRegenDelay");
        if (line != null)
          try {
            world.setPlotManagementWildRevertDelay(Long.parseLong(line));
          } catch (Exception e) {
          }
       
        // Chat channel format
       
        line = kvFile.get("GlobalChatChannelFormat");
        if (line != null)
          try {
            world.setChatGlobalChannelFormat(line);
          } catch (Exception e) {
          }
       
        line = kvFile.get("TownChatChannelFormat");
        if (line != null)
          try {
            world.setChatTownChannelFormat(line);
          } catch (Exception e) {
          }
       
        line = kvFile.get("NationChatChannelFormat");
        if (line != null)
          try {
            world.setChatNationChannelFormat(line);
          } catch (Exception e) {
          }
       
        line = kvFile.get("DefaultChatChannelFormat");
        if (line != null)
          try {
            world.setChatDefaultChannelFormat(line);
          } catch (Exception e) {
          }
       
       
        line = kvFile.get("usingTowny");
        if (line != null)
          try {
            world.setUsingTowny(Boolean.parseBoolean(line));
          } catch (Exception e) {
          }
View Full Code Here

      boolean set = false;
     
      File fileTownBlock = new File(path);
      if (fileTownBlock.exists() && fileTownBlock.isFile()) {
        try {
          KeyValueFile kvFile = new KeyValueFile(path);
         
          line = kvFile.get("permissions");
          if (line != null)
            try {
              townBlock.setPermissions(line.trim());
              set = true;
            } catch (Exception e) {
            } 
         
          line = kvFile.get("changed");
          if (line != null)
            try {
              townBlock.setChanged(Boolean.parseBoolean(line.trim()));
            } catch (Exception e) {
            }
         
          line = kvFile.get("locked");
          if (line != null)
            try {
              townBlock.setLocked(Boolean.parseBoolean(line.trim()));
            } catch (Exception e) {
            }
View Full Code Here

    String line;
    String path = getResidentFilename(resident);
    File fileResident = new File(path);
    if (fileResident.exists() && fileResident.isFile()) {
      try {
        KeyValueFile kvFile = new KeyValueFile(path);
        resident.setLastOnline(Long.parseLong(kvFile.get("lastOnline")));
       
        line = kvFile.get("registered");
        if (line != null)
          resident.setRegistered(Long.parseLong(line));
        else
          resident.setRegistered(resident.getLastOnline());
       
        line = kvFile.get("isNPC");
        if (line != null)
          resident.setNPC(Boolean.parseBoolean(line));
       
        line = kvFile.get("title");
        if (line != null)
          resident.setTitle(line);
       
        line = kvFile.get("surname");
        if (line != null)
          resident.setSurname(line);
       
        line = kvFile.get("town");
        if (line != null)
          resident.setTown(getTown(line));

        line = kvFile.get("friends");
        if (line != null) {
          String[] tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident friend = getResident(token);
              if (friend != null)
                resident.addFriend(friend);
            }
          }
        }
       
        line = kvFile.get("protectionStatus");
        if (line != null)
          resident.setPermissions(line);

        line = kvFile.get("townBlocks");
        if (line != null)
          utilLoadTownBlocks(line, null, resident);

      } catch (Exception e) {
        System.out.println("[Towny] Loading Error: Exception while reading resident file " + resident.getName());
View Full Code Here

TOP

Related Classes of com.palmergames.util.KeyValueFile

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.