From 4496e0854f03dc13aa60f61d144b1170918c7073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BA=A1t=20Nh=C3=A2n=20Tr=C6=B0=C6=A1ng?= Date: Mon, 1 Aug 2022 14:25:32 +0700 Subject: [PATCH] Clean up formatting & Update NIO in some remaining files --- pom.xml | 2 +- src/main/java/provider/wz/XMLWZFile.java | 100 +++++----- .../server/SkillbookInformationProvider.java | 65 ++++--- .../tools/mapletools/BossHpBarFetcher.java | 14 +- .../mapletools/CashCosmeticsChecker.java | 6 +- .../tools/mapletools/CashDropFetcher.java | 146 +++++++-------- .../tools/mapletools/CashVegaChecker.java | 6 +- .../tools/mapletools/CodeCouponGenerator.java | 48 ++--- .../java/tools/mapletools/DojoUpdate.java | 2 - .../mapletools/EquipmentOmniLeveller.java | 52 +++--- .../mapletools/GachaponItemIdRetriever.java | 95 +++++----- .../java/tools/mapletools/IdRetriever.java | 12 +- .../tools/mapletools/MapInfoRetriever.java | 26 +-- .../java/tools/mapletools/MesoFetcher.java | 5 +- .../java/tools/mapletools/MobBookIndexer.java | 43 +++-- .../java/tools/mapletools/MobBookUpdate.java | 47 +++-- .../tools/mapletools/MonsterStatFetcher.java | 2 +- .../tools/mapletools/NoItemIdFetcher.java | 23 ++- .../tools/mapletools/NoItemNameFetcher.java | 58 +++--- .../mapletools/QuestItemCountFetcher.java | 36 ++-- .../tools/mapletools/QuestItemFetcher.java | 176 +++++++++--------- .../tools/mapletools/QuestMesoFetcher.java | 36 ++-- .../tools/mapletools/QuestlineFetcher.java | 42 ++--- .../tools/mapletools/ReactorDropFetcher.java | 32 ++-- .../tools/mapletools/SkillMakerFetcher.java | 40 ++-- .../mapletools/SkillMakerReagentIndexer.java | 41 ++-- .../mapletools/SkillbookChanceFetcher.java | 25 +-- .../mapletools/SkillbookStackUpdate.java | 34 ++-- .../tools/mapletools/WorldmapChecker.java | 2 +- 29 files changed, 603 insertions(+), 613 deletions(-) diff --git a/pom.xml b/pom.xml index a72823045b..bb3aac3675 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 1.0 2.11.0 5.0.1 - 8.0.29 + 8.0.30 diff --git a/src/main/java/provider/wz/XMLWZFile.java b/src/main/java/provider/wz/XMLWZFile.java index c9d95c8656..0644b95371 100644 --- a/src/main/java/provider/wz/XMLWZFile.java +++ b/src/main/java/provider/wz/XMLWZFile.java @@ -25,68 +25,66 @@ import provider.Data; import provider.DataDirectoryEntry; import provider.DataProvider; -import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class XMLWZFile implements DataProvider { - private final Path root; - private final WZDirectoryEntry rootForNavigation; + private static final Logger log = LoggerFactory.getLogger(DataProvider.class); + private final Path root; + private final WZDirectoryEntry rootForNavigation; - public XMLWZFile(Path fileIn) { - root = fileIn; - rootForNavigation = new WZDirectoryEntry(fileIn.getFileName().toString(), 0, 0, null); - fillMapleDataEntitys(root, rootForNavigation); - } + public XMLWZFile(Path fileIn) { + root = fileIn; + rootForNavigation = new WZDirectoryEntry(fileIn.getFileName().toString(), 0, 0, null); + fillMapleDataEntitys(root, rootForNavigation); + } - private void fillMapleDataEntitys(Path lroot, WZDirectoryEntry wzdir) { - - try (DirectoryStream stream = Files.newDirectoryStream(lroot)) { - for (Path path : stream) { - String fileName = path.getFileName().toString(); - if(Files.isDirectory(path) && !fileName.endsWith(".img") ) { - WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir); - wzdir.addDirectory(newDir); - fillMapleDataEntitys(path, newDir); - } else if (fileName.endsWith(".xml")) { - wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir)); - } - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + private void fillMapleDataEntitys(Path lroot, WZDirectoryEntry wzdir) { + + try (DirectoryStream stream = Files.newDirectoryStream(lroot)) { + for (Path path : stream) { + String fileName = path.getFileName().toString(); + if (Files.isDirectory(path) && !fileName.endsWith(".img")) { + WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir); + wzdir.addDirectory(newDir); + fillMapleDataEntitys(path, newDir); + } else if (fileName.endsWith(".xml")) { + wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir)); + } + } + } catch (IOException e) { + log.warn("Can not open file/directory at " + lroot); } - } + } - @Override - public synchronized Data getData(String path) { - Path dataFile = root.resolve(path + ".xml"); - //File(root, path + ".xml"); - Path imageDataDir = root.resolve(path); - //File imageDataDir = new File(root, path); - if (!Files.exists(dataFile)) { - return null;//bitches - } - final XMLDomMapleData domMapleData; - try(FileInputStream fis = new FileInputStream(dataFile.toString()) ) { - domMapleData = new XMLDomMapleData(fis, imageDataDir.getParent()); - }catch (FileNotFoundException e) { - throw new RuntimeException("Datafile " + path + " does not exist in " + root.toAbsolutePath()); - }catch (IOException e) { - throw new RuntimeException(e); - } - - - return domMapleData; - } + @Override + public synchronized Data getData(String path) { + Path dataFile = root.resolve(path + ".xml"); + Path imageDataDir = root.resolve(path); + if (!Files.exists(dataFile)) { + return null;// bitches + } + final XMLDomMapleData domMapleData; + try (FileInputStream fis = new FileInputStream(dataFile.toString())) { + domMapleData = new XMLDomMapleData(fis, imageDataDir.getParent()); + } catch (FileNotFoundException e) { + throw new RuntimeException("Datafile " + path + " does not exist in " + root.toAbsolutePath()); + } catch (IOException e) { + throw new RuntimeException(e); + } - @Override - public DataDirectoryEntry getRoot() { - return rootForNavigation; - } + return domMapleData; + } + + @Override + public DataDirectoryEntry getRoot() { + return rootForNavigation; + } } \ No newline at end of file diff --git a/src/main/java/server/SkillbookInformationProvider.java b/src/main/java/server/SkillbookInformationProvider.java index 62f63b0a37..a28e54838d 100644 --- a/src/main/java/server/SkillbookInformationProvider.java +++ b/src/main/java/server/SkillbookInformationProvider.java @@ -26,11 +26,17 @@ import provider.Data; import provider.DataProvider; import provider.DataProviderFactory; import provider.DataTool; +import provider.wz.WZDirectoryEntry; +import provider.wz.WZFileEntry; import provider.wz.WZFiles; import tools.DatabaseConnection; import java.io.File; import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -185,26 +191,31 @@ public class SkillbookInformationProvider { return loadedSkillbooks; } - private static void listFiles(String directoryName, ArrayList files) { - File directory = new File(directoryName); + private static void listFiles(String directoryName, ArrayList files) { + Path directory = Paths.get(directoryName); - // get all the files from a directory - File[] fList = directory.listFiles(); - for (File file : fList) { - if (file.isFile()) { - files.add(file); - } else if (file.isDirectory()) { - listFiles(file.getAbsolutePath(), files); - } - } - } + // get all the files from a directory + try (DirectoryStream stream = Files.newDirectoryStream(directory)) { + for (Path path : stream) { - private static List listFilesFromDirectoryRecursively(String directory) { - ArrayList files = new ArrayList<>(); - listFiles(directory, files); + if (Files.isRegularFile(path)) { + files.add(path); + } else if (Files.isDirectory(path)) { + listFiles(path.toAbsolutePath().toString(), files); + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - return files; - } + private static List listFilesFromDirectoryRecursively(String directory) { + ArrayList files = new ArrayList<>(); + listFiles(directory, files); + + return files; + } private static Set findMatchingSkillbookIdsOnFile(String fileContent) { Set skillbookIds = new HashSet<>(4); @@ -219,22 +230,20 @@ public class SkillbookInformationProvider { return skillbookIds; } - private static String readFileToString(File file, String encoding) throws IOException { + private static String readFileToString(Path file, String encoding) throws IOException { Scanner scanner = new Scanner(file, encoding); String text = ""; - try { - try { - text = scanner.useDelimiter("\\A").next(); - } finally { - scanner.close(); - } + try(scanner) { + + text = scanner.useDelimiter("\\A").next(); + } catch (NoSuchElementException e) { } return text; } - private static Map fileSearchMatchingData(File file) { + private static Map fileSearchMatchingData(Path file) { Map scriptFileSkillbooks = new HashMap<>(); try { @@ -245,7 +254,7 @@ public class SkillbookInformationProvider { scriptFileSkillbooks.put(skillbookId, SkillBookEntry.SCRIPT); } } catch (IOException ioe) { - log.error("Failed to read file:{}", file.getName(), ioe); + log.error("Failed to read file:{}", file.getFileName(), ioe); } return scriptFileSkillbooks; @@ -254,8 +263,8 @@ public class SkillbookInformationProvider { private static Map fetchSkillbooksFromScripts() { Map scriptSkillbooks = new HashMap<>(); - for (File file : listFilesFromDirectoryRecursively("./scripts")) { - if (file.getName().endsWith(".js")) { + for (Path file : listFilesFromDirectoryRecursively("./scripts")) { + if (file.getFileName().endsWith(".js")) { scriptSkillbooks.putAll(fileSearchMatchingData(file)); } } diff --git a/src/main/java/tools/mapletools/BossHpBarFetcher.java b/src/main/java/tools/mapletools/BossHpBarFetcher.java index 51dca74fea..e313f39e37 100644 --- a/src/main/java/tools/mapletools/BossHpBarFetcher.java +++ b/src/main/java/tools/mapletools/BossHpBarFetcher.java @@ -134,18 +134,16 @@ public class BossHpBarFetcher { } private static void readBossHpBarData() throws IOException { - - - final Path mobDirectory = WZFiles.MOB.getFile(); + final Path mobDirectory = WZFiles.MOB.getFile(); try (DirectoryStream stream = Files.newDirectoryStream(mobDirectory)) { for (Path path : stream) { - if(Files.isRegularFile(path)) { - try(BufferedReader br = Files.newBufferedReader(path)) { + if (Files.isRegularFile(path)) { + try (BufferedReader br = Files.newBufferedReader(path)) { bufferedReader = br; String line; while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } + translateToken(line); + } } } } @@ -167,7 +165,7 @@ public class BossHpBarFetcher { private static void reportBossHpBarData() { // This will reference one line at a time - try(final PrintWriter printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)))) { + try (PrintWriter printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)))) { System.out.println("Reading WZs..."); readBossHpBarData(); diff --git a/src/main/java/tools/mapletools/CashCosmeticsChecker.java b/src/main/java/tools/mapletools/CashCosmeticsChecker.java index 4ba2d5c3d6..349afff565 100644 --- a/src/main/java/tools/mapletools/CashCosmeticsChecker.java +++ b/src/main/java/tools/mapletools/CashCosmeticsChecker.java @@ -616,9 +616,9 @@ public class CashCosmeticsChecker { private static void reportCosmeticResults() throws IOException { System.out.println("Reporting results ..."); - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { - printWriter = pw; - printReportFileHeader(); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { + printWriter = pw; + printReportFileHeader(); if (!missingCosmeticsNpcTypes.isEmpty()) { printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries."); diff --git a/src/main/java/tools/mapletools/CashDropFetcher.java b/src/main/java/tools/mapletools/CashDropFetcher.java index 04504085f7..f567a4fc2c 100644 --- a/src/main/java/tools/mapletools/CashDropFetcher.java +++ b/src/main/java/tools/mapletools/CashDropFetcher.java @@ -1,10 +1,13 @@ package tools.mapletools; +import provider.wz.WZDirectoryEntry; +import provider.wz.WZFileEntry; import provider.wz.WZFiles; import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -177,18 +180,20 @@ public class CashDropFetcher { printWriter.println(); } - private static void listFiles(String directoryName, ArrayList files) { - File directory = new File(directoryName); - + private static void listFiles(Path directoryName, ArrayList files) { // get all the files from a directory - File[] fList = directory.listFiles(); - for (File file : fList) { - if (file.isFile()) { - files.add(file); - } else if (file.isDirectory()) { - listFiles(file.getAbsolutePath(), files); - } - } + try (DirectoryStream stream = Files.newDirectoryStream(directoryName)) { + for (Path path : stream) { + if (Files.isRegularFile(path)) { + files.add(path); + } else if (Files.isDirectory(path)) { + listFiles(path, files); + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } private static int getItemIdFromFilename(String name) { @@ -263,82 +268,75 @@ public class CashDropFetcher { private static void reportNxDropData() { //NEED FUTURE UPDATE - try { - System.out.println("Reading Character.wz ..."); - ArrayList files = new ArrayList<>(); - listFiles(WZFiles.CHARACTER.getFilePath(), files); + try (con; PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Reading Character.wz ..."); + ArrayList files = new ArrayList<>(); + listFiles(WZFiles.CHARACTER.getFile(), files); - InputStreamReader fileReader = null; - for (File f : files) { - //System.out.println("Parsing " + f.getAbsolutePath()); - int itemid = getItemIdFromFilename(f.getName()); - if (itemid < 0) { - continue; - } + for (Path path : files) { + // System.out.println("Parsing " + f.getAbsolutePath()); + int itemid = getItemIdFromFilename(path.getFileName().toString()); + if (itemid < 0) { + continue; + } - fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + bufferedReader = Files.newBufferedReader(path); - currentItemid = itemid; - inspectEquipWzEntry(); + currentItemid = itemid; + inspectEquipWzEntry(); - bufferedReader.close(); - fileReader.close(); - } + bufferedReader.close(); + } - System.out.println("Reading Item.wz ..."); - files = new ArrayList<>(); - listFiles(WZFiles.ITEM.getFilePath(), files); + System.out.println("Reading Item.wz ..."); + files = new ArrayList<>(); + listFiles(WZFiles.ITEM.getFile(), files); - for (File f : files) { - //System.out.println("Parsing " + f.getAbsolutePath()); - fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + for (Path path : files) { + // System.out.println("Parsing " + f.getAbsolutePath()); + bufferedReader = Files.newBufferedReader(path); - if (f.getName().length() <= ITEM_FILE_NAME_SIZE) { - inspectItemWzEntry(); - } else { // pet file structure is similar to equips, maybe there are other item-types following this behaviour? - int itemid = getItemIdFromFilename(f.getName()); - if (itemid < 0) { - continue; - } + if (path.getFileName().toString().length() <= ITEM_FILE_NAME_SIZE) { + inspectItemWzEntry(); + } else { // pet file structure is similar to equips, maybe there are other item-types + // following this behaviour? + int itemid = getItemIdFromFilename(path.getFileName().toString()); + if (itemid < 0) { + continue; + } - currentItemid = itemid; - inspectEquipWzEntry(); - } + currentItemid = itemid; + inspectEquipWzEntry(); + } - bufferedReader.close(); - fileReader.close(); - } + bufferedReader.close(); + } - System.out.println("Reporting results..."); + System.out.println("Reporting results..."); - // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); - printReportFileHeader(); + // report suspects of missing quest drop data, as well as those drop data that + // may have incorrect questids. + printWriter = pw; + printReportFileHeader(); - reportNxDropResults(true); - reportNxDropResults(false); + reportNxDropResults(true); + reportNxDropResults(false); - /* - printWriter.println("NX LIST"); // list of all cash items found - for(Integer nx : nxItems) { - printWriter.println(nx); - } - */ + /* + * printWriter.println("NX LIST"); // list of all cash items found for(Integer + * nx : nxItems) { printWriter.println(nx); } + */ - con.close(); - printWriter.close(); - System.out.println("Done!"); - } catch (SQLException e) { - System.out.println("Warning: Could not establish connection to database to report quest data."); - System.out.println(e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } - } + System.out.println("Done!"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to report quest data."); + System.out.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } - public static void main(String[] args) { - reportNxDropData(); - } + public static void main(String[] args) { + reportNxDropData(); + } } diff --git a/src/main/java/tools/mapletools/CashVegaChecker.java b/src/main/java/tools/mapletools/CashVegaChecker.java index 2c375723ba..6886be533f 100644 --- a/src/main/java/tools/mapletools/CashVegaChecker.java +++ b/src/main/java/tools/mapletools/CashVegaChecker.java @@ -156,18 +156,16 @@ public class CashVegaChecker { } private static void reportMissingVegaItems() { - //NEED FUTURE UPDATE System.out.println("Reporting results ..."); - try { - printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; printReportFileHeader(); for (Integer itemid : vegaItems) { printWriter.println(" " + itemid); } - printWriter.close(); } catch (IOException ioe) { ioe.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/CodeCouponGenerator.java b/src/main/java/tools/mapletools/CodeCouponGenerator.java index 3231172524..6d0b69b791 100644 --- a/src/main/java/tools/mapletools/CodeCouponGenerator.java +++ b/src/main/java/tools/mapletools/CodeCouponGenerator.java @@ -315,34 +315,34 @@ public class CodeCouponGenerator { } private static void generateCodeCoupons(Path file) throws IOException { - try(BufferedReader br = Files.newBufferedReader(file); con;) { - bufferedReader = br; - resetCouponPackage(); - status = 0; + try (BufferedReader br = Files.newBufferedReader(file); con;) { + bufferedReader = br; + resetCouponPackage(); + status = 0; - System.out.println("Reading XML coupon information..."); - String line; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - System.out.println(); + System.out.println("Reading XML coupon information..."); + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + System.out.println(); - System.out.println("Loading DB coupon codes..."); - loadUsedCouponCodes(); - System.out.println(); + System.out.println("Loading DB coupon codes..."); + loadUsedCouponCodes(); + System.out.println(); - System.out.println("Saving generated coupons..."); - currentTime = System.currentTimeMillis(); - for (CodeCouponDescriptor ccd : activeCoupons) { - commitCodeCouponDescription(ccd); - } - System.out.println(); - System.out.println("Done."); + System.out.println("Saving generated coupons..."); + currentTime = System.currentTimeMillis(); + for (CodeCouponDescriptor ccd : activeCoupons) { + commitCodeCouponDescription(ccd); + } + System.out.println(); + System.out.println("Done."); - } catch (SQLException e) { - e.printStackTrace(); - } - } + } catch (SQLException e) { + e.printStackTrace(); + } + } public static void main(String[] args) { try { diff --git a/src/main/java/tools/mapletools/DojoUpdate.java b/src/main/java/tools/mapletools/DojoUpdate.java index 9ad06668fa..0accbaff2d 100644 --- a/src/main/java/tools/mapletools/DojoUpdate.java +++ b/src/main/java/tools/mapletools/DojoUpdate.java @@ -3,7 +3,6 @@ package tools.mapletools; import provider.wz.WZFiles; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -22,7 +21,6 @@ import java.time.Instant; * Estimated parse time: 10 seconds */ public class DojoUpdate { - //private static final Path INPUT_DIRECTORY = WZFiles.MAP.getFile().resolve("/Map/Map9"); private static final Path INPUT_DIRECTORY = WZFiles.MAP.getFile().resolve("Map").resolve("Map9"); private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps"); private static final Path WORKING_DIRECTORY = Paths.get("").toAbsolutePath(); diff --git a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java index 6047cdf981..964c1f462f 100644 --- a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java +++ b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java @@ -403,41 +403,41 @@ public class EquipmentOmniLeveller { } private static void parseDirectoryEquipData(String curPath) { - Path folder = OUTPUT_DIRECTORY.resolve(curPath); - if (!Files.exists(folder)) { - try { + Path folder = OUTPUT_DIRECTORY.resolve(curPath); + if (!Files.exists(folder)) { + try { Files.createDirectory(folder); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("Unable to create folder " + folder.toAbsolutePath() + "."); e.printStackTrace(); } - } + } - System.out.println("Parsing directory '" + curPath + "'"); - folder = INPUT_DIRECTORY.resolve(curPath); - try (DirectoryStream stream = Files.newDirectoryStream(folder)) { - for (Path path : stream) { - if(Files.isRegularFile(path)) { - try { - parseEquipData(path, curPath); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open dojo file " + path.toAbsolutePath() + "."); - } catch (IOException ex) { - System.out.println("Error reading dojo file " + path.toAbsolutePath() + "."); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - parseDirectoryEquipData(curPath + path.getFileName() + "/"); - } - } - } catch (IOException e1) { - System.out.println("Unable to read folder " + folder.toAbsolutePath() + "."); - // TODO Auto-generated catch block + System.out.println("Parsing directory '" + curPath + "'"); + folder = INPUT_DIRECTORY.resolve(curPath); + try (DirectoryStream stream = Files.newDirectoryStream(folder)) { + for (Path path : stream) { + if (Files.isRegularFile(path)) { + try { + parseEquipData(path, curPath); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open dojo file " + path.toAbsolutePath() + "."); + } catch (IOException ex) { + System.out.println("Error reading dojo file " + path.toAbsolutePath() + "."); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + parseDirectoryEquipData(curPath + path.getFileName() + "/"); + } + } + } catch (IOException e1) { + System.out.println("Unable to read folder " + folder.toAbsolutePath() + "."); + // TODO Auto-generated catch block e1.printStackTrace(); } - } + } public static void main(String[] args) { Instant instantStarted = Instant.now(); diff --git a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java index efffff4e74..cd884bc8ce 100644 --- a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java +++ b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java @@ -248,61 +248,58 @@ public class GachaponItemIdRetriever { } private static void fetchDataOnMapleHandbook() throws SQLException { - String line; - try(BufferedReader bufferedReader = Files.newBufferedReader(INPUT_FILE)) { - int skip = 0; - boolean lineHeader = false; - while ((line = bufferedReader.readLine()) != null) { - if (skip > 0) { - skip--; + String line; + try (BufferedReader bufferedReader = Files.newBufferedReader(INPUT_FILE)) { + int skip = 0; + boolean lineHeader = false; + while ((line = bufferedReader.readLine()) != null) { + if (skip > 0) { + skip--; - if (lineHeader) { - if (!line.isEmpty()) { - lineHeader = false; - printWriter.println(); - printWriter.println(line + ":"); - } - } - } else if (line.isEmpty()) { - printWriter.println(""); + if (lineHeader) { + if (!line.isEmpty()) { + lineHeader = false; + printWriter.println(); + printWriter.println(line + ":"); + } + } + } else if (line.isEmpty()) { + printWriter.println(""); } else if (line.startsWith("Gachapon ")) { - String[] s = line.split("� "); - String gachaponName = s[s.length - 1]; - gachaponName = gachaponName.replace(" ", "_"); - gachaponName = gachaponName.toLowerCase(); + String[] s = line.split("� "); + String gachaponName = s[s.length - 1]; + gachaponName = gachaponName.replace(" ", "_"); + gachaponName = gachaponName.toLowerCase(); - if (printWriter != null) { - printWriter.close(); - } - Path outputFile = OUTPUT_DIRECTORY.resolve(gachaponName + ".txt"); - setupDirectories(outputFile); + if (printWriter != null) { + printWriter.close(); + } + Path outputFile = OUTPUT_DIRECTORY.resolve(gachaponName + ".txt"); + setupDirectories(outputFile); - printWriter = new PrintWriter(Files.newOutputStream(outputFile)); + printWriter = new PrintWriter(Files.newOutputStream(outputFile)); - skip = 2; - lineHeader = true; - } else if (line.startsWith(".")) { - skip = 1; - lineHeader = true; - } else { - line = line.replace("�", "'"); + skip = 2; + lineHeader = true; + } else if (line.startsWith(".")) { + skip = 1; + lineHeader = true; + } else { + line = line.replace("�", "'"); for (String item : line.split("\\s\\|\\s")) { - item = item.trim(); - if (!item.contentEquals("n/a")) { - String[] itemInfo = item.split(" - "); - fetchLineOnMapleHandbook(itemInfo[0], itemInfo.length > 1 ? itemInfo[1] : null); - } - } - } - } - } catch (IOException ex) { - System.out.println(ex.getMessage()); - ex.printStackTrace(); - } - - - - } + item = item.trim(); + if (!item.contentEquals("n/a")) { + String[] itemInfo = item.split(" - "); + fetchLineOnMapleHandbook(itemInfo[0], itemInfo.length > 1 ? itemInfo[1] : null); + } + } + } + } + } catch (IOException ex) { + System.out.println(ex.getMessage()); + ex.printStackTrace(); + } + } private static void setupDirectories(Path file) { if(!Files.exists(file.getParent())) { diff --git a/src/main/java/tools/mapletools/IdRetriever.java b/src/main/java/tools/mapletools/IdRetriever.java index a41806e70b..150d740f30 100644 --- a/src/main/java/tools/mapletools/IdRetriever.java +++ b/src/main/java/tools/mapletools/IdRetriever.java @@ -136,10 +136,10 @@ public class IdRetriever { } private static void fetchDataOnMapleHandbook() throws SQLException { - try(BufferedReader br = Files.newBufferedReader(INPUT_FILE); - PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { - bufferedReader = br; - String line; + try (BufferedReader br = Files.newBufferedReader(INPUT_FILE); + PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) { + bufferedReader = br; + String line; while ((line = bufferedReader.readLine()) != null) { if (line.isEmpty()) { printWriter.println(""); @@ -171,14 +171,12 @@ public class IdRetriever { public static void main(String[] args) { Instant instantStarted = Instant.now(); - try { + try (con) { if (INSTALL_SQLTABLE) { parseMapleHandbook(); } else { fetchDataOnMapleHandbook(); } - - con.close(); } catch (SQLException e) { System.out.println("Error: invalid SQL syntax"); e.printStackTrace(); diff --git a/src/main/java/tools/mapletools/MapInfoRetriever.java b/src/main/java/tools/mapletools/MapInfoRetriever.java index ade7693d24..6e884d1007 100644 --- a/src/main/java/tools/mapletools/MapInfoRetriever.java +++ b/src/main/java/tools/mapletools/MapInfoRetriever.java @@ -130,19 +130,19 @@ public class MapInfoRetriever { } } - private static void writeReport() { - try(PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - if (!missingInfo.isEmpty()) { - for (Integer i : missingInfo) { - printWriter.println(i); - } - } else { - printWriter.println("All map files contain 'info' node."); - } - } catch (IOException e) { - e.printStackTrace(); - } - } + private static void writeReport() { + try (PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + if (!missingInfo.isEmpty()) { + for (Integer i : missingInfo) { + printWriter.println(i); + } + } else { + printWriter.println("All map files contain 'info' node."); + } + } catch (IOException e) { + e.printStackTrace(); + } + } public static void main(String[] args) { for (int i = 0; i <= 9; i++) { diff --git a/src/main/java/tools/mapletools/MesoFetcher.java b/src/main/java/tools/mapletools/MesoFetcher.java index c843c4e7f8..908e22f929 100644 --- a/src/main/java/tools/mapletools/MesoFetcher.java +++ b/src/main/java/tools/mapletools/MesoFetcher.java @@ -123,7 +123,7 @@ public class MesoFetcher { private static void generateMissingMobsMesoRange() { System.out.print("Generating missing ranges... "); - try(Connection con = SimpleDatabaseConnection.getConnection(); + try (Connection con = SimpleDatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE dropperid NOT IN (SELECT DISTINCT dropperid FROM drop_data WHERE itemid = 0) GROUP BY dropperid HAVING count(*) >= " + MIN_ITEMS + ";"); ResultSet rs = ps.executeQuery();) { @@ -139,7 +139,7 @@ public class MesoFetcher { } if (!existingMobs.isEmpty()) { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { printWriter = pw; printSqlHeader(); @@ -169,7 +169,6 @@ public class MesoFetcher { e.printStackTrace(); } } - } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/MobBookIndexer.java b/src/main/java/tools/mapletools/MobBookIndexer.java index 3dbb168588..56d566fae3 100644 --- a/src/main/java/tools/mapletools/MobBookIndexer.java +++ b/src/main/java/tools/mapletools/MobBookIndexer.java @@ -125,14 +125,13 @@ public class MobBookIndexer { } private static void indexFromDropData() { - - try(con; - BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { - bufferedReader = br; - String line = null; - - PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;"); - ps.execute(); + + try (con; BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + bufferedReader = br; + String line = null; + + PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;"); + ps.execute(); ps = con.prepareStatement("CREATE TABLE `monstercardwz` (" + "`id` int(10) unsigned NOT NULL AUTO_INCREMENT," @@ -142,20 +141,20 @@ public class MobBookIndexer { + ");"); ps.execute(); - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + INPUT_FILE + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + INPUT_FILE + "'"); - } catch (SQLException e) { - System.out.println("Warning: Could not establish connection to database to change card chance rate."); - System.out.println(e.getMessage()); - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + INPUT_FILE + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + INPUT_FILE + "'"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to change card chance rate."); + System.out.println(e.getMessage()); + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/MobBookUpdate.java b/src/main/java/tools/mapletools/MobBookUpdate.java index efe91373f3..be17c5b66e 100644 --- a/src/main/java/tools/mapletools/MobBookUpdate.java +++ b/src/main/java/tools/mapletools/MobBookUpdate.java @@ -144,30 +144,29 @@ public class MobBookUpdate { } - private static void updateFromDropData() { - try(con; - PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); - BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { - printWriter = pw; - bufferedReader = br; - - String line = null; - - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + INPUT_FILE + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + INPUT_FILE + "'"); - } catch (SQLException e) { - System.out.println("Warning: Could not establish connection to database to change card chance rate."); - System.out.println(e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } - - } + private static void updateFromDropData() { + try (con; + PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + printWriter = pw; + bufferedReader = br; + + String line = null; + + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + INPUT_FILE + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + INPUT_FILE + "'"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to change card chance rate."); + System.out.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void main(String[] args) { updateFromDropData(); diff --git a/src/main/java/tools/mapletools/MonsterStatFetcher.java b/src/main/java/tools/mapletools/MonsterStatFetcher.java index db855bfff8..508e6d0815 100644 --- a/src/main/java/tools/mapletools/MonsterStatFetcher.java +++ b/src/main/java/tools/mapletools/MonsterStatFetcher.java @@ -145,7 +145,7 @@ public class MonsterStatFetcher { public static void main(String[] args) { Instant instantStarted = Instant.now(); // load mob stats from WZ - Map mobStats = MonsterStatFetcher.getAllMonsterStats(); + Map mobStats = MonsterStatFetcher.getAllMonsterStats(); Instant instantStopped = Instant.now(); Duration durationBetween = Duration.between(instantStarted, instantStopped); System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); diff --git a/src/main/java/tools/mapletools/NoItemIdFetcher.java b/src/main/java/tools/mapletools/NoItemIdFetcher.java index d055bb2816..83c60ad14a 100644 --- a/src/main/java/tools/mapletools/NoItemIdFetcher.java +++ b/src/main/java/tools/mapletools/NoItemIdFetcher.java @@ -176,7 +176,7 @@ public class NoItemIdFetcher { } private static void evaluateDropsFromDb() { - try { + try (con) { System.out.println("Evaluating item data on DB..."); evaluateDropsFromTable("drop_data"); @@ -194,22 +194,21 @@ public class NoItemIdFetcher { System.out.println("Inexistent itemid count: " + nonExistingIds.size()); System.out.println("Total itemid count: " + existingIds.size()); - con.close(); } catch (Exception e) { e.printStackTrace(); } } - public static void main(String[] args) { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - printWriter = pw; - existingIds.add(0); // meso itemid - readEquipDataDirectory(WZFiles.CHARACTER.getFilePath()); - readItemDataDirectory(WZFiles.ITEM.getFilePath()); + public static void main(String[] args) { + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + existingIds.add(0); // meso itemid + readEquipDataDirectory(WZFiles.CHARACTER.getFilePath()); + readItemDataDirectory(WZFiles.ITEM.getFilePath()); - evaluateDropsFromDb(); - } catch (Exception e) { - e.printStackTrace(); - } + evaluateDropsFromDb(); + } catch (Exception e) { + e.printStackTrace(); + } } } \ No newline at end of file diff --git a/src/main/java/tools/mapletools/NoItemNameFetcher.java b/src/main/java/tools/mapletools/NoItemNameFetcher.java index 161fccfd7e..e3b011a9ca 100644 --- a/src/main/java/tools/mapletools/NoItemNameFetcher.java +++ b/src/main/java/tools/mapletools/NoItemNameFetcher.java @@ -435,41 +435,41 @@ public class NoItemNameFetcher { } } - private static void writeMissingStringWZNames(Map> missingNames) throws Exception { - System.out.println("Writing remaining 'String.wz' names..."); - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_XML_FILE))) { - printWriter = pw; - - printOutputFileHeader(); + private static void writeMissingStringWZNames(Map> missingNames) throws Exception { + System.out.println("Writing remaining 'String.wz' names..."); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_XML_FILE))) { + printWriter = pw; - String[] nodePaths = {"Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img"}; - for (int i = 0; i < nodePaths.length; i++) { - writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2); - } + printOutputFileHeader(); - } - } + String[] nodePaths = { "Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img" }; + for (int i = 0; i < nodePaths.length; i++) { + writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2); + } - public static void main(String[] args) { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - printWriter = pw; - curType = ItemType.EQP; - readEquipWZData(); + } + } - curType = ItemType.UNDEF; - readItemWZData(); - readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ + public static void main(String[] args) { + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + curType = ItemType.EQP; + readEquipWZData(); - System.out.println("Reporting results..."); - printReportFileHeader(); - printReportFileResults(); + curType = ItemType.UNDEF; + readItemWZData(); + readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ - Map> missingNames = filterMissingItemNames(); - writeMissingStringWZNames(missingNames); + System.out.println("Reporting results..."); + printReportFileHeader(); + printReportFileResults(); - System.out.println("Done!"); - } catch (Exception e) { - e.printStackTrace(); - } + Map> missingNames = filterMissingItemNames(); + writeMissingStringWZNames(missingNames); + + System.out.println("Done!"); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/tools/mapletools/QuestItemCountFetcher.java b/src/main/java/tools/mapletools/QuestItemCountFetcher.java index c19f0adda5..211ee211c5 100644 --- a/src/main/java/tools/mapletools/QuestItemCountFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemCountFetcher.java @@ -240,28 +240,28 @@ public class QuestItemCountFetcher { } } - private static void reportQuestItemCountData() { - // This will reference one line at a time + private static void reportQuestItemCountData() { + // This will reference one line at a time - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - System.out.println("Reading WZs..."); - readQuestItemCountData(); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Reading WZs..."); + readQuestItemCountData(); - System.out.println("Reporting results..."); - printWriter = pw; + System.out.println("Reporting results..."); + printWriter = pw; - printReportFileHeader(); - printReportFileResults(); + printReportFileHeader(); + printReportFileResults(); - System.out.println("Done!"); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open quest file."); - } catch (IOException ex) { - System.out.println("Error reading quest file."); - } catch (Exception e) { - e.printStackTrace(); - } - } + System.out.println("Done!"); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open quest file."); + } catch (IOException ex) { + System.out.println("Error reading quest file."); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void main(String[] args) { reportQuestItemCountData(); diff --git a/src/main/java/tools/mapletools/QuestItemFetcher.java b/src/main/java/tools/mapletools/QuestItemFetcher.java index 56b4ef1e97..50570ad38e 100644 --- a/src/main/java/tools/mapletools/QuestItemFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemFetcher.java @@ -408,113 +408,113 @@ public class QuestItemFetcher { return (!limitedQuestids.contains(questid) ? "" : " EXPIRED"); } - private static void reportQuestItemData() { - // This will reference one line at a time - String line = null; - Path file = null; + private static void reportQuestItemData() { + // This will reference one line at a time + String line = null; + Path file = null; - try{ - System.out.println("Reading WZs..."); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Reading WZs..."); - file = WZFiles.QUEST.getFile().resolve("Check.img.xml"); - bufferedReader = Files.newBufferedReader(file); + file = WZFiles.QUEST.getFile().resolve("Check.img.xml"); + bufferedReader = Files.newBufferedReader(file); - while ((line = bufferedReader.readLine()) != null) { - translateCheckToken(line); // fetch expired quests through here as well - } + while ((line = bufferedReader.readLine()) != null) { + translateCheckToken(line); // fetch expired quests through here as well + } - bufferedReader.close(); + bufferedReader.close(); - file = WZFiles.QUEST.getFile().resolve("Act.img.xml"); - bufferedReader = Files.newBufferedReader(file); + file = WZFiles.QUEST.getFile().resolve("Act.img.xml"); + bufferedReader = Files.newBufferedReader(file); - while ((line = bufferedReader.readLine()) != null) { - translateActToken(line); - } + while ((line = bufferedReader.readLine()) != null) { + translateActToken(line); + } - bufferedReader.close(); + bufferedReader.close(); - System.out.println("Calculating table diffs..."); - calculateQuestItemDiff(); + System.out.println("Calculating table diffs..."); + calculateQuestItemDiff(); - System.out.println("Filtering drops on DB..."); - List> itemsWithQuest = getPairsQuestItem(); + System.out.println("Filtering drops on DB..."); + List> itemsWithQuest = getPairsQuestItem(); - filterQuestDropsOnDB(itemsWithQuest); - con.close(); + filterQuestDropsOnDB(itemsWithQuest); + con.close(); - System.out.println("Filtering drops on project files..."); - // finally, filter whether this item is mentioned on the source code or not. - filterDirectorySearchMatchingData("scripts", itemsWithQuest); - filterDirectorySearchMatchingData("sql", itemsWithQuest); - filterDirectorySearchMatchingData("src", itemsWithQuest); + System.out.println("Filtering drops on project files..."); + // finally, filter whether this item is mentioned on the source code or not. + filterDirectorySearchMatchingData("scripts", itemsWithQuest); + filterDirectorySearchMatchingData("sql", itemsWithQuest); + filterDirectorySearchMatchingData("src", itemsWithQuest); - System.out.println("Reporting results..."); - // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + System.out.println("Reporting results..."); + // report suspects of missing quest drop data, as well as those drop data that + // may have incorrect questids. + printWriter = pw; - printReportFileHeader(); + printReportFileHeader(); - if (!mixedQuestidItems.isEmpty()) { - printWriter.println("INCORRECT QUESTIDS ON DB"); - for (Map.Entry emqi : getSortedMapEntries1(mixedQuestidItems)) { - int[] mqi = emqi.getValue(); - printWriter.println(mqi[0] + " : " + mqi[1] + " -> " + mqi[2] + getExpiredStringLabel(mqi[2])); - } - printWriter.println("\n\n\n\n\n"); - } + if (!mixedQuestidItems.isEmpty()) { + printWriter.println("INCORRECT QUESTIDS ON DB"); + for (Map.Entry emqi : getSortedMapEntries1(mixedQuestidItems)) { + int[] mqi = emqi.getValue(); + printWriter.println(mqi[0] + " : " + mqi[1] + " -> " + mqi[2] + getExpiredStringLabel(mqi[2])); + } + printWriter.println("\n\n\n\n\n"); + } - if (!itemsWithQuest.isEmpty()) { - Map mapIwq = new HashMap<>(itemsWithQuest.size()); - for (Pair iwq : itemsWithQuest) { - mapIwq.put(iwq.getLeft(), iwq.getRight()); - } + if (!itemsWithQuest.isEmpty()) { + Map mapIwq = new HashMap<>(itemsWithQuest.size()); + for (Pair iwq : itemsWithQuest) { + mapIwq.put(iwq.getLeft(), iwq.getRight()); + } - printWriter.println("ITEMS WITH NO QUEST DROP DATA ON DB"); - for (Map.Entry iwq : getSortedMapEntries0(mapIwq)) { - printWriter.println(iwq.getKey() + " - " + iwq.getValue() + getExpiredStringLabel(iwq.getValue())); - } - printWriter.println("\n\n\n\n\n"); - } + printWriter.println("ITEMS WITH NO QUEST DROP DATA ON DB"); + for (Map.Entry iwq : getSortedMapEntries0(mapIwq)) { + printWriter.println(iwq.getKey() + " - " + iwq.getValue() + getExpiredStringLabel(iwq.getValue())); + } + printWriter.println("\n\n\n\n\n"); + } - if (DISPLAY_EXTRA_INFO) { - if (!zeroedStartQuestItems.isEmpty()) { - printWriter.println("START QUEST ITEMS WITH ZERO QUANTITY"); - for (Pair> iwq : getSortedMapEntries2(zeroedStartQuestItems)) { - printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":"); - for (Integer i : iwq.getRight()) { - printWriter.println(" " + i); - } - printWriter.println(); - } - printWriter.println("\n\n\n\n\n"); - } + if (DISPLAY_EXTRA_INFO) { + if (!zeroedStartQuestItems.isEmpty()) { + printWriter.println("START QUEST ITEMS WITH ZERO QUANTITY"); + for (Pair> iwq : getSortedMapEntries2(zeroedStartQuestItems)) { + printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":"); + for (Integer i : iwq.getRight()) { + printWriter.println(" " + i); + } + printWriter.println(); + } + printWriter.println("\n\n\n\n\n"); + } - if (!zeroedCompleteQuestItems.isEmpty()) { - printWriter.println("COMPLETE QUEST ITEMS WITH ZERO QUANTITY"); - for (Pair> iwq : getSortedMapEntries2(zeroedCompleteQuestItems)) { - printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":"); - for (Integer i : iwq.getRight()) { - printWriter.println(" " + i); - } - printWriter.println(); - } - printWriter.println("\n\n\n\n\n"); - } - } + if (!zeroedCompleteQuestItems.isEmpty()) { + printWriter.println("COMPLETE QUEST ITEMS WITH ZERO QUANTITY"); + for (Pair> iwq : getSortedMapEntries2(zeroedCompleteQuestItems)) { + printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":"); + for (Integer i : iwq.getRight()) { + printWriter.println(" " + i); + } + printWriter.println(); + } + printWriter.println("\n\n\n\n\n"); + } + } - printWriter.close(); - System.out.println("Done!"); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + file + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + file + "'"); - } catch (SQLException e) { - System.out.println("Warning: Could not establish connection to database to report quest data."); - System.out.println(e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println("Done!"); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + file + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + file + "'"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to report quest data."); + System.out.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/QuestMesoFetcher.java b/src/main/java/tools/mapletools/QuestMesoFetcher.java index 5623911a54..25c72149b3 100644 --- a/src/main/java/tools/mapletools/QuestMesoFetcher.java +++ b/src/main/java/tools/mapletools/QuestMesoFetcher.java @@ -228,29 +228,29 @@ public class QuestMesoFetcher { } private static void reportQuestMesoData() { - // This will reference one line at a time + // This will reference one line at a time - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - System.out.println("Reading WZs..."); - readQuestMesoData(); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Reading WZs..."); + readQuestMesoData(); - System.out.println("Reporting results..."); - // report missing meso checks on quest completes - printWriter = pw; + System.out.println("Reporting results..."); + // report missing meso checks on quest completes + printWriter = pw; - printReportFileHeader(); + printReportFileHeader(); - printReportFileResults(checkedMesoQuests, appliedMesoQuests, true); - printReportFileResults(appliedMesoQuests, checkedMesoQuests, false); + printReportFileResults(checkedMesoQuests, appliedMesoQuests, true); + printReportFileResults(appliedMesoQuests, checkedMesoQuests, false); - System.out.println("Done!"); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open quest file."); - } catch (IOException ex) { - System.out.println("Error reading quest file."); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println("Done!"); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open quest file."); + } catch (IOException ex) { + System.out.println("Error reading quest file."); + } catch (Exception e) { + e.printStackTrace(); + } } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/QuestlineFetcher.java b/src/main/java/tools/mapletools/QuestlineFetcher.java index 0e8188fb10..ef102506b5 100644 --- a/src/main/java/tools/mapletools/QuestlineFetcher.java +++ b/src/main/java/tools/mapletools/QuestlineFetcher.java @@ -291,33 +291,33 @@ public class QuestlineFetcher { } private static void reportQuestlineData() { - // This will reference one line at a time + // This will reference one line at a time - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - System.out.println("Reading quest scripts..."); - instantiateQuestScriptFiles(ToolConstants.SCRIPTS_PATH + "/quest"); + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Reading quest scripts..."); + instantiateQuestScriptFiles(ToolConstants.SCRIPTS_PATH + "/quest"); - System.out.println("Reading WZs..."); - readQuestsWithSkillReward(); - readQuestsWithMissingScripts(); + System.out.println("Reading WZs..."); + readQuestsWithSkillReward(); + readQuestsWithMissingScripts(); - System.out.println("Calculating skill related quests..."); - calculateSkillRelatedMissingQuestScripts(); + System.out.println("Calculating skill related quests..."); + calculateSkillRelatedMissingQuestScripts(); - System.out.println("Reporting results..."); - printWriter = pw; + System.out.println("Reporting results..."); + printWriter = pw; - printReportFileHeader(); - printReportFileResults(); + printReportFileHeader(); + printReportFileResults(); - System.out.println("Done!"); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open quest file."); - } catch (IOException ex) { - System.out.println("Error reading quest file."); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println("Done!"); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open quest file."); + } catch (IOException ex) { + System.out.println("Error reading quest file."); + } catch (Exception e) { + e.printStackTrace(); + } } /* diff --git a/src/main/java/tools/mapletools/ReactorDropFetcher.java b/src/main/java/tools/mapletools/ReactorDropFetcher.java index 32879069fd..8999acd199 100644 --- a/src/main/java/tools/mapletools/ReactorDropFetcher.java +++ b/src/main/java/tools/mapletools/ReactorDropFetcher.java @@ -86,25 +86,25 @@ public class ReactorDropFetcher { } private static void reportMissingReactors() { - try(con; - PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - System.out.println("Fetching reactors from DB..."); - fetchMissingReactorDrops(); + try (con; PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + System.out.println("Fetching reactors from DB..."); + fetchMissingReactorDrops(); - printWriter = pw; + printWriter = pw; - // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - System.out.println("Reporting results..."); - printReportFileHeader(); - reportMissingReactorDrops(); + // report suspects of missing quest drop data, as well as those drop data that + // may have incorrect questids. + System.out.println("Reporting results..."); + printReportFileHeader(); + reportMissingReactorDrops(); - System.out.println("Done!"); - } catch (SQLException e) { - System.out.println("Warning: Could not establish connection to database to report quest data."); - System.out.println(e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println("Done!"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to report quest data."); + System.out.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/SkillMakerFetcher.java b/src/main/java/tools/mapletools/SkillMakerFetcher.java index e8960be230..dd9eee54cf 100644 --- a/src/main/java/tools/mapletools/SkillMakerFetcher.java +++ b/src/main/java/tools/mapletools/SkillMakerFetcher.java @@ -301,31 +301,31 @@ public class SkillMakerFetcher { printWriter.println(sb_reward); } - private static void writeMakerTableData() { - // This will reference one line at a time - String line = null; + private static void writeMakerTableData() { + // This will reference one line at a time + String line = null; - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); - BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { - printWriter = pw; - bufferedReader = br; + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + printWriter = pw; + bufferedReader = br; - resetMakerDataFields(); + resetMakerDataFields(); - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } - WriteMakerTableFile(); + WriteMakerTableFile(); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + INPUT_FILE + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + INPUT_FILE + "'"); - } catch (Exception e) { - e.printStackTrace(); - } - } + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + INPUT_FILE + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + INPUT_FILE + "'"); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void main(String[] args) { DatabaseConnection.initializeConnectionPool(); // Using ItemInformationProvider which loads som unrelated things from the db diff --git a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java index 08b3153e8a..e2f1d3e0af 100644 --- a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java +++ b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java @@ -149,31 +149,30 @@ public class SkillMakerReagentIndexer { printWriter.println(sb); } - private static void writeMakerReagentTableData() { - // This will reference one line at a time - String line = null; + private static void writeMakerReagentTableData() { + // This will reference one line at a time + String line = null; - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); - BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { - bufferedReader = br; + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + bufferedReader = br; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + SortReagentList(); - SortReagentList(); - - printWriter = pw; - WriteMakerReagentTableFile(); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + OUTPUT_FILE + "'"); - } catch (IOException ex) { - System.out.println("Error reading file '" + OUTPUT_FILE + "'"); - } catch (Exception e) { - e.printStackTrace(); - } - } + printWriter = pw; + WriteMakerReagentTableFile(); + } catch (FileNotFoundException ex) { + System.out.println("Unable to open file '" + OUTPUT_FILE + "'"); + } catch (IOException ex) { + System.out.println("Error reading file '" + OUTPUT_FILE + "'"); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void main(String[] args) { writeMakerReagentTableData(); diff --git a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java index 39a0f19465..7afba7ed2d 100644 --- a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java +++ b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java @@ -103,21 +103,22 @@ public class SkillbookChanceFetcher { printWriter.println(" REPLACE INTO drop_data (`dropperid`, `itemid`, `minimum_quantity`, `maximum_quantity`, `questid`, `chance`) VALUES"); } - private static void generateSkillbookChanceUpdateFile() { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - printWriter = pw; + private static void generateSkillbookChanceUpdateFile() { + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; - printSkillbookChanceUpdateSqlHeader(); + printSkillbookChanceUpdateSqlHeader(); - List, Integer>> skillbookChancesList = sortedSkillbookChances(); - for (Map.Entry, Integer> e : skillbookChancesList) { - printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, " + e.getValue() + "),"); - } + List, Integer>> skillbookChancesList = sortedSkillbookChances(); + for (Map.Entry, Integer> e : skillbookChancesList) { + printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, " + + e.getValue() + "),"); + } - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } public static void main(String[] args) { // load mob stats from WZ diff --git a/src/main/java/tools/mapletools/SkillbookStackUpdate.java b/src/main/java/tools/mapletools/SkillbookStackUpdate.java index d540331a24..7b7cb84f43 100644 --- a/src/main/java/tools/mapletools/SkillbookStackUpdate.java +++ b/src/main/java/tools/mapletools/SkillbookStackUpdate.java @@ -116,26 +116,26 @@ public class SkillbookStackUpdate { } private static void parseItemFile(Path file, Path outputFile) { - setupDirectories(outputFile); - - try(BufferedReader br = Files.newBufferedReader(file); - PrintWriter pw = new PrintWriter(Files.newOutputStream(outputFile))) { - bufferedReader = br; - printWriter = pw; - String line; - while ((line = bufferedReader.readLine()) != null) { - translateItemToken(line); - } - } catch (IOException ex) { - System.out.println("Error reading file '" + file.getFileName() + "'"); - ex.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } + setupDirectories(outputFile); + + try (BufferedReader br = Files.newBufferedReader(file); + PrintWriter pw = new PrintWriter(Files.newOutputStream(outputFile))) { + bufferedReader = br; + printWriter = pw; + String line; + while ((line = bufferedReader.readLine()) != null) { + translateItemToken(line); + } + } catch (IOException ex) { + System.out.println("Error reading file '" + file.getFileName() + "'"); + ex.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } } private static void setupDirectories(Path file) { - if(!Files.exists(file.getParent())) { + if (!Files.exists(file.getParent())) { try { Files.createDirectories(file.getParent()); } catch (IOException e) { diff --git a/src/main/java/tools/mapletools/WorldmapChecker.java b/src/main/java/tools/mapletools/WorldmapChecker.java index 8c47254752..a05c2b97a5 100644 --- a/src/main/java/tools/mapletools/WorldmapChecker.java +++ b/src/main/java/tools/mapletools/WorldmapChecker.java @@ -188,7 +188,7 @@ public class WorldmapChecker { } private static void verifyWorldmapTreeMapids() { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { printWriter = pw; printReportFileHeader();