From 3a306429697983064dfb6d75894482b0f7eac7b7 Mon Sep 17 00:00:00 2001 From: truongdatnhan Date: Thu, 21 Jul 2022 14:48:52 +0700 Subject: [PATCH 1/5] Update .gitignore --- .gitignore | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 96502955e0..580bdf21a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/logs/** +/logs/** .idea/ *.iml /target @@ -7,6 +7,12 @@ /build/ /dist/ /nbproject/ - +/.settings /out *.onetoc2 + +# Eclipse m2e generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath From d42a57ef7902f98542bf9fd598f6aedc24385ecf 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: Thu, 21 Jul 2022 15:00:30 +0700 Subject: [PATCH 2/5] Update dependencies ! --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 2d53675e85..a72823045b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,15 +25,15 @@ 1.7.36 - 2.17.1 - 21.1.0 - 4.1.74.Final + 2.18.0 + 22.2.0 + 4.1.79.Final 5.8.2 1.15 1.0 2.11.0 5.0.1 - 8.0.28 + 8.0.29 From a44744c05b10e389cafde72074df9cac5cb2072d 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: Sat, 30 Jul 2022 16:10:46 +0700 Subject: [PATCH 3/5] Upgrade to Java NIO --- handbook/Use.txt | 2 +- src/main/java/client/Stat.java | 42 +------ .../java/provider/DataProviderFactory.java | 3 +- src/main/java/provider/wz/WZFiles.java | 8 +- .../java/provider/wz/XMLDomMapleData.java | 15 +-- src/main/java/provider/wz/XMLWZFile.java | 68 +++++----- .../java/tools/mapletools/ArrowFetcher.java | 10 +- .../tools/mapletools/BossHpBarFetcher.java | 43 ++++--- .../mapletools/CashCosmeticsChecker.java | 93 +++++++------- .../tools/mapletools/CashDropFetcher.java | 9 +- .../tools/mapletools/CashVegaChecker.java | 10 +- .../tools/mapletools/CodeCouponGenerator.java | 38 +++--- .../java/tools/mapletools/DojoUpdate.java | 99 +++++++++------ .../tools/mapletools/EmptyItemWzChecker.java | 17 +-- .../mapletools/EquipmentOmniLeveller.java | 119 +++++++++--------- .../mapletools/GachaponItemIdRetriever.java | 46 ++++--- .../java/tools/mapletools/IdRetriever.java | 34 ++--- .../tools/mapletools/MapInfoRetriever.java | 12 +- .../java/tools/mapletools/MesoFetcher.java | 58 +++++---- .../java/tools/mapletools/MobBookIndexer.java | 26 ++-- .../java/tools/mapletools/MobBookUpdate.java | 31 +++-- .../tools/mapletools/MonsterStatFetcher.java | 13 ++ .../tools/mapletools/NoItemIdFetcher.java | 13 +- .../tools/mapletools/NoItemNameFetcher.java | 26 ++-- .../mapletools/QuestItemCountFetcher.java | 9 +- .../tools/mapletools/QuestItemFetcher.java | 26 ++-- .../tools/mapletools/QuestMesoFetcher.java | 17 ++- .../tools/mapletools/QuestlineFetcher.java | 17 ++- .../tools/mapletools/ReactorDropFetcher.java | 11 +- .../tools/mapletools/SkillMakerFetcher.java | 17 ++- .../mapletools/SkillMakerReagentIndexer.java | 17 ++- .../mapletools/SkillbookChanceFetcher.java | 9 +- .../mapletools/SkillbookStackUpdate.java | 71 ++++++----- .../java/tools/mapletools/ToolConstants.java | 15 +-- .../tools/mapletools/WorldmapChecker.java | 9 +- 35 files changed, 553 insertions(+), 500 deletions(-) diff --git a/handbook/Use.txt b/handbook/Use.txt index 37f96fee60..3cc5d46e54 100644 --- a/handbook/Use.txt +++ b/handbook/Use.txt @@ -1,4 +1,4 @@ -2000000 - Red Potion - A potion made out of red herbs.\nRecovers 50 HP. +2000000 - Red Potion - A potion made out of red herbs.\nRecovers 50 HP. 2000001 - Orange Potion - A concentrated potion made out of red herbs.\nRecovers 150 HP. 2000002 - White Potion - A highly-concentrated potion made out of red herbs.\nRecovers 300 HP. 2000003 - Blue Potion - A potion made out of blue herbs.\nRecovers 100 MP. diff --git a/src/main/java/client/Stat.java b/src/main/java/client/Stat.java index 940d5b139b..cd0ee18e42 100644 --- a/src/main/java/client/Stat.java +++ b/src/main/java/client/Stat.java @@ -76,44 +76,10 @@ public enum Stat { } public static Stat getByString(String type) { - if (type.equals("SKIN")) { - return SKIN; - } else if (type.equals("FACE")) { - return FACE; - } else if (type.equals("HAIR")) { - return HAIR; - } else if (type.equals("LEVEL")) { - return LEVEL; - } else if (type.equals("JOB")) { - return JOB; - } else if (type.equals("STR")) { - return STR; - } else if (type.equals("DEX")) { - return DEX; - } else if (type.equals("INT")) { - return INT; - } else if (type.equals("LUK")) { - return LUK; - } else if (type.equals("HP")) { - return HP; - } else if (type.equals("MAXHP")) { - return MAXHP; - } else if (type.equals("MP")) { - return MP; - } else if (type.equals("MAXMP")) { - return MAXMP; - } else if (type.equals("AVAILABLEAP")) { - return AVAILABLEAP; - } else if (type.equals("AVAILABLESP")) { - return AVAILABLESP; - } else if (type.equals("EXP")) { - return EXP; - } else if (type.equals("FAME")) { - return FAME; - } else if (type.equals("MESO")) { - return MESO; - } else if (type.equals("PET")) { - return PET; + for (Stat stat : Stat.values()) { + if (stat.name().equals(type)) { + return stat; + } } return null; } diff --git a/src/main/java/provider/DataProviderFactory.java b/src/main/java/provider/DataProviderFactory.java index dc15004cb0..a90751a83d 100644 --- a/src/main/java/provider/DataProviderFactory.java +++ b/src/main/java/provider/DataProviderFactory.java @@ -25,9 +25,10 @@ import provider.wz.WZFiles; import provider.wz.XMLWZFile; import java.io.File; +import java.nio.file.Path; public class DataProviderFactory { - private static DataProvider getWZ(File in) { + private static DataProvider getWZ(Path in) { return new XMLWZFile(in); } diff --git a/src/main/java/provider/wz/WZFiles.java b/src/main/java/provider/wz/WZFiles.java index f563941118..3fe8dae892 100644 --- a/src/main/java/provider/wz/WZFiles.java +++ b/src/main/java/provider/wz/WZFiles.java @@ -1,6 +1,8 @@ package provider.wz; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; public enum WZFiles { QUEST("Quest"), @@ -25,12 +27,12 @@ public enum WZFiles { this.fileName = name + ".wz"; } - public File getFile() { - return new File(DIRECTORY, fileName); + public Path getFile() { + return Paths.get(DIRECTORY).resolve(fileName); } public String getFilePath() { - return getFile().getPath(); + return getFile().toString(); } private static String getWzDirectory() { diff --git a/src/main/java/provider/wz/XMLDomMapleData.java b/src/main/java/provider/wz/XMLDomMapleData.java index 0962b2734b..4ea8461c37 100644 --- a/src/main/java/provider/wz/XMLDomMapleData.java +++ b/src/main/java/provider/wz/XMLDomMapleData.java @@ -37,15 +37,16 @@ import java.awt.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class XMLDomMapleData implements Data { private final Node node; - private File imageDataDir; + private Path imageDataDir; - public XMLDomMapleData(FileInputStream fis, File imageDataDir) { + public XMLDomMapleData(FileInputStream fis, Path imageDataDir) { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); @@ -91,7 +92,7 @@ public class XMLDomMapleData implements Data { } XMLDomMapleData ret = new XMLDomMapleData(myNode); - ret.imageDataDir = new File(imageDataDir, getName() + "/" + path).getParentFile(); + ret.imageDataDir = imageDataDir.resolve(getName().trim()).resolve(path).getParent(); return ret; } @@ -103,12 +104,12 @@ public class XMLDomMapleData implements Data { for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { - XMLDomMapleData child = new XMLDomMapleData(childNode); - child.imageDataDir = new File(imageDataDir, getName()); + XMLDomMapleData child = new XMLDomMapleData(childNode); + child.imageDataDir = imageDataDir.resolve(getName().trim()); ret.add(child); } } - + return ret; } @@ -193,7 +194,7 @@ public class XMLDomMapleData implements Data { return null; } XMLDomMapleData parentData = new XMLDomMapleData(parentNode); - parentData.imageDataDir = imageDataDir.getParentFile(); + parentData.imageDataDir = imageDataDir.getParent(); return parentData; } diff --git a/src/main/java/provider/wz/XMLWZFile.java b/src/main/java/provider/wz/XMLWZFile.java index 6b1f62b129..c9d95c8656 100644 --- a/src/main/java/provider/wz/XMLWZFile.java +++ b/src/main/java/provider/wz/XMLWZFile.java @@ -29,53 +29,59 @@ 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; public class XMLWZFile implements DataProvider { - private final File root; + private final Path root; private final WZDirectoryEntry rootForNavigation; - public XMLWZFile(File fileIn) { + public XMLWZFile(Path fileIn) { root = fileIn; - rootForNavigation = new WZDirectoryEntry(fileIn.getName(), 0, 0, null); + rootForNavigation = new WZDirectoryEntry(fileIn.getFileName().toString(), 0, 0, null); fillMapleDataEntitys(root, rootForNavigation); } - private void fillMapleDataEntitys(File lroot, WZDirectoryEntry wzdir) { - for (File file : lroot.listFiles()) { - String fileName = file.getName(); - if (file.isDirectory() && !fileName.endsWith(".img")) { - WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir); - wzdir.addDirectory(newDir); - fillMapleDataEntitys(file, newDir); - } else if (fileName.endsWith(".xml")) { - wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir)); + 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(); + } } @Override public synchronized Data getData(String path) { - File dataFile = new File(root, path + ".xml"); - File imageDataDir = new File(root, path); - if (!dataFile.exists()) { + 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 } - FileInputStream fis; - try { - fis = new FileInputStream(dataFile); - } catch (FileNotFoundException e) { - throw new RuntimeException("Datafile " + path + " does not exist in " + root.getAbsolutePath()); - } final XMLDomMapleData domMapleData; - try { - domMapleData = new XMLDomMapleData(fis, imageDataDir.getParentFile()); - } finally { - try { - fis.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } + 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; } @@ -83,4 +89,4 @@ public class XMLWZFile implements DataProvider { public DataDirectoryEntry getRoot() { return rootForNavigation; } -} +} \ No newline at end of file diff --git a/src/main/java/tools/mapletools/ArrowFetcher.java b/src/main/java/tools/mapletools/ArrowFetcher.java index f2d4344e5f..996f8e3bd7 100644 --- a/src/main/java/tools/mapletools/ArrowFetcher.java +++ b/src/main/java/tools/mapletools/ArrowFetcher.java @@ -24,9 +24,12 @@ import tools.Pair; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -171,7 +174,7 @@ public class ArrowFetcher { if (!existingEntries.isEmpty()) { List entryValues = getArrowEntryValues(existingEntries); - printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME))); printSqlHeader(); for (int[] arrowEntry : entryValues) { @@ -211,10 +214,15 @@ public class ArrowFetcher { } public static void main(String[] args) { + Instant instantStarted = Instant.now(); // load mob stats from WZ mobStats = MonsterStatFetcher.getAllMonsterStats(); calcAllMobsArrowRange(); updateMobsArrowRange(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/BossHpBarFetcher.java b/src/main/java/tools/mapletools/BossHpBarFetcher.java index a08d0cfdcb..51dca74fea 100644 --- a/src/main/java/tools/mapletools/BossHpBarFetcher.java +++ b/src/main/java/tools/mapletools/BossHpBarFetcher.java @@ -4,6 +4,11 @@ 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; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -129,21 +134,21 @@ public class BossHpBarFetcher { } private static void readBossHpBarData() throws IOException { - String line; + - final File mobDirectory = WZFiles.MOB.getFile(); - for (File file : mobDirectory.listFiles()) { - if (file.isFile()) { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - - bufferedReader.close(); - fileReader.close(); - } + 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)) { + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + } + } + } } } @@ -162,17 +167,16 @@ public class BossHpBarFetcher { private static void reportBossHpBarData() { // This will reference one line at a time - try { + try(final PrintWriter printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)))) { System.out.println("Reading WZs..."); readBossHpBarData(); System.out.println("Reporting results..."); - final PrintWriter printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8); + printReportFileHeader(printWriter); printReportFileResults(printWriter); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open mob file."); @@ -184,7 +188,12 @@ public class BossHpBarFetcher { } public static void main(String[] args) { + Instant instantStarted = Instant.now(); reportBossHpBarData(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/CashCosmeticsChecker.java b/src/main/java/tools/mapletools/CashCosmeticsChecker.java index 696f3218b1..4ba2d5c3d6 100644 --- a/src/main/java/tools/mapletools/CashCosmeticsChecker.java +++ b/src/main/java/tools/mapletools/CashCosmeticsChecker.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -21,8 +23,8 @@ import java.util.*; * Estimated parse time: 1 minute */ public class CashCosmeticsChecker { - private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").getPath(); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt"); + private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").toString(); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt"); private static final boolean IGNORE_CURRENT_SCRIPT_COSMETICS = false; // Toggle to preference private static final int INITIAL_STRING_LENGTH = 50; @@ -613,51 +615,50 @@ public class CashCosmeticsChecker { private static void reportCosmeticResults() throws IOException { System.out.println("Reporting results ..."); - - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - printReportFileHeader(); - - if (!missingCosmeticsNpcTypes.isEmpty()) { - printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries."); - - for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { - printWriter.println(" NPC " + mcn.getLeft()); - - Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); - reportNpcCosmetics(genderItemids.getLeft()); - reportNpcCosmetics(genderItemids.getRight()); - printWriter.println(); - } + + 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."); + + for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { + printWriter.println(" NPC " + mcn.getLeft()); + + Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); + reportNpcCosmetics(genderItemids.getLeft()); + reportNpcCosmetics(genderItemids.getRight()); + printWriter.println(); + } + } + + if (!unusedCosmetics.isEmpty()) { + printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); + + List list = new ArrayList<>(unusedCosmetics); + Collections.sort(list); + + for (Integer i : list) { + printWriter.println(i + " " + cosmeticIdNames.get(i)); + } + + printWriter.println(); + } + + if (!missingCosmeticNames.isEmpty()) { + printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); + + List listString = new ArrayList<>(missingCosmeticNames); + Collections.sort(listString); + + for (String c : listString) { + printWriter.println(c); + } + + printWriter.println(); + } } - - if (!unusedCosmetics.isEmpty()) { - printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); - - List list = new ArrayList<>(unusedCosmetics); - Collections.sort(list); - - for (Integer i : list) { - printWriter.println(i + " " + cosmeticIdNames.get(i)); - } - - printWriter.println(); - } - - if (!missingCosmeticNames.isEmpty()) { - printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); - - List listString = new ArrayList<>(missingCosmeticNames); - Collections.sort(listString); - - for (String c : listString) { - printWriter.println(c); - } - - printWriter.println(); - } - - printWriter.close(); } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/CashDropFetcher.java b/src/main/java/tools/mapletools/CashDropFetcher.java index 75176c4a81..04504085f7 100644 --- a/src/main/java/tools/mapletools/CashDropFetcher.java +++ b/src/main/java/tools/mapletools/CashDropFetcher.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -20,7 +22,7 @@ import java.util.*; * Estimated parse time: 2 minutes */ public class CashDropFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final int INITIAL_STRING_LENGTH = 50; private static final int ITEM_FILE_NAME_SIZE = 13; @@ -260,7 +262,8 @@ public class CashDropFetcher { } private static void reportNxDropData() { - try { + //NEED FUTURE UPDATE + try { System.out.println("Reading Character.wz ..."); ArrayList files = new ArrayList<>(); listFiles(WZFiles.CHARACTER.getFilePath(), files); @@ -311,7 +314,7 @@ public class CashDropFetcher { 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(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); reportNxDropResults(true); diff --git a/src/main/java/tools/mapletools/CashVegaChecker.java b/src/main/java/tools/mapletools/CashVegaChecker.java index 230c0814d7..2c375723ba 100644 --- a/src/main/java/tools/mapletools/CashVegaChecker.java +++ b/src/main/java/tools/mapletools/CashVegaChecker.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashSet; import java.util.Set; @@ -16,7 +18,7 @@ import java.util.Set; * Estimated parse time: 10 seconds */ public class CashVegaChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt"); private static final int INITIAL_STRING_LENGTH = 1000; private static final Set vegaItems = new HashSet<>(); @@ -154,11 +156,11 @@ public class CashVegaChecker { } private static void reportMissingVegaItems() { - System.out.println("Reporting results ..."); + //NEED FUTURE UPDATE + System.out.println("Reporting results ..."); try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); for (Integer itemid : vegaItems) { diff --git a/src/main/java/tools/mapletools/CodeCouponGenerator.java b/src/main/java/tools/mapletools/CodeCouponGenerator.java index ddf9b94805..3231172524 100644 --- a/src/main/java/tools/mapletools/CodeCouponGenerator.java +++ b/src/main/java/tools/mapletools/CodeCouponGenerator.java @@ -4,6 +4,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.*; import java.util.ArrayList; import java.util.HashSet; @@ -22,7 +24,7 @@ import static java.util.concurrent.TimeUnit.HOURS; * Estimated parse time: 2 minutes (for 100 code entries) */ public class CodeCouponGenerator { - private static final File INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml"); private static final int INITIAL_STRING_LENGTH = 250; private static final Connection con = SimpleDatabaseConnection.getConnection(); @@ -312,24 +314,19 @@ public class CodeCouponGenerator { ps.close(); } - private static void generateCodeCoupons(File file) throws IOException { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + private static void generateCodeCoupons(Path file) throws IOException { + try(BufferedReader br = Files.newBufferedReader(file); con;) { + bufferedReader = br; + resetCouponPackage(); + status = 0; - 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); - } - - bufferedReader.close(); - fileReader.close(); - System.out.println(); - - try { System.out.println("Loading DB coupon codes..."); loadUsedCouponCodes(); System.out.println(); @@ -340,10 +337,9 @@ public class CodeCouponGenerator { commitCodeCouponDescription(ccd); } System.out.println(); - - con.close(); System.out.println("Done."); - } catch (SQLException e) { + + } catch (SQLException e) { e.printStackTrace(); } } @@ -352,7 +348,7 @@ public class CodeCouponGenerator { try { generateCodeCoupons(INPUT_FILE); } catch (IOException ex) { - System.out.println("Error reading file '" + INPUT_FILE.getAbsolutePath() + "'"); + System.out.println("Error reading file '" + INPUT_FILE.toAbsolutePath() + "'"); } } } diff --git a/src/main/java/tools/mapletools/DojoUpdate.java b/src/main/java/tools/mapletools/DojoUpdate.java index dbacb0ac18..9ad06668fa 100644 --- a/src/main/java/tools/mapletools/DojoUpdate.java +++ b/src/main/java/tools/mapletools/DojoUpdate.java @@ -4,6 +4,12 @@ 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; +import java.nio.file.Paths; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -16,8 +22,10 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 10 seconds */ public class DojoUpdate { - private static final File INPUT_DIRECTORY = new File(WZFiles.MAP.getFile(), "/Map/Map9"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps"); + //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(); private static final int DOJO_MIN_MAP_ID = 925_020_100; private static final int DOJO_MAX_MAP_ID = 925_033_804; private static final int INITIAL_STRING_LENGTH = 250; @@ -114,30 +122,25 @@ public class DojoUpdate { return Integer.parseInt(fileName.substring(0, 9)); } - private static void parseDojoData(File file, String curPath) throws IOException { - int mapId = getMapId(file.getName()); + private static void parseDojoData(Path file, String curPath) throws IOException { + int mapId = getMapId(file.getFileName().toString()); isDojoMapid = isDojoMapId(mapId); if (!isDojoMapid) { return; } + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + status = 0; - printWriter = new PrintWriter(OUTPUT_DIRECTORY.getPath() + "/" + curPath + file.getName(), StandardCharsets.UTF_8); - - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - status = 0; - - String line; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + + printFileFooter(); } - - bufferedReader.close(); - fileReader.close(); - - printFileFooter(); - printWriter.close(); } private static boolean isDojoMapId(int mapId) { @@ -152,31 +155,49 @@ public class DojoUpdate { } private static void parseDirectoryDojoData(String curPath) { - File folder = new File(OUTPUT_DIRECTORY, curPath); - if (!folder.exists()) { - folder.mkdir(); + 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 = new File(INPUT_DIRECTORY, curPath); - for (File file : folder.listFiles()) { - if (file.isFile()) { - try { - parseDojoData(file, curPath); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open dojo file " + file.getAbsolutePath() + "."); - } catch (IOException ex) { - System.out.println("Error reading dojo file " + file.getAbsolutePath() + "."); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - parseDirectoryDojoData(curPath + file.getName() + "/"); - } - } + folder = INPUT_DIRECTORY.resolve(curPath); + try (DirectoryStream stream = Files.newDirectoryStream(folder)) { + for (Path path : stream) { + if(Files.isRegularFile(path)) { + try { + parseDojoData(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 { + parseDirectoryDojoData(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(); parseDirectoryDojoData(""); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/EmptyItemWzChecker.java b/src/main/java/tools/mapletools/EmptyItemWzChecker.java index f696d319a1..3ac5c7ddf0 100644 --- a/src/main/java/tools/mapletools/EmptyItemWzChecker.java +++ b/src/main/java/tools/mapletools/EmptyItemWzChecker.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -14,8 +16,8 @@ import java.util.*; * And it removes from the String.wz XMLs all entries which misses properties on Item.wz. */ public class EmptyItemWzChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt"); - private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.getPath(); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt"); + private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.toString(); private static final int INITIAL_STRING_LENGTH = 50; private static final int ITEM_FILE_NAME_SIZE = 13; @@ -338,12 +340,11 @@ public class EmptyItemWzChecker { private static void reportItemNameDiff(Set emptyItemNames, Set emptyNameItems) throws IOException { System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - printReportFileHeader(); - printReportFileResults(emptyItemNames, emptyNameItems); - - printWriter.close(); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + printReportFileHeader(); + printReportFileResults(emptyItemNames, emptyNameItems); + } } private static void locateItemStringWzDiff() throws IOException { diff --git a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java index b10caeb260..6047cdf981 100644 --- a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java +++ b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java @@ -4,6 +4,11 @@ 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; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -16,14 +21,13 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 7 minutes */ public class EquipmentOmniLeveller { - private static final File INPUT_DIRECTORY = WZFiles.CHARACTER.getFile(); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels"); + private static final Path INPUT_DIRECTORY = WZFiles.CHARACTER.getFile(); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels"); private static final int INITIAL_STRING_LENGTH = 250; private static final int FIXED_EXP = 10000; private static final int MAX_EQP_LEVEL = 30; private static PrintWriter printWriter = null; - private static InputStreamReader fileReader = null; private static BufferedReader bufferedReader = null; private static int infoTagState = -1; @@ -353,31 +357,25 @@ public class EquipmentOmniLeveller { return accessInfoTag; } - private static void copyCashItemData(File file, String curPath) throws IOException { - printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8); - - fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - String line; - while ((line = bufferedReader.readLine()) != null) { - printWriter.println(line); - } - - bufferedReader.close(); - fileReader.close(); - - printWriter.close(); + private static void copyCashItemData(Path file, String curPath) throws IOException { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { + printWriter.println(line); + } + } } - private static void parseEquipData(File file, String curPath) throws IOException { - printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8); - - fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - try { - status = 0; + private static void parseEquipData(Path file, String curPath) throws IOException { + + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + status = 0; upgradeable = false; cash = false; @@ -389,20 +387,12 @@ public class EquipmentOmniLeveller { infoTagState = -1; } } - - bufferedReader.close(); - fileReader.close(); - printFileFooter(); - printWriter.close(); - } catch (RuntimeException e) { - bufferedReader.close(); - fileReader.close(); - - printWriter.close(); - + } catch (RuntimeException e) { copyCashItemData(file, curPath); } + + } private static void printFileFooter() { @@ -413,31 +403,48 @@ public class EquipmentOmniLeveller { } private static void parseDirectoryEquipData(String curPath) { - File folder = new File(OUTPUT_DIRECTORY, curPath); - if (!folder.exists()) { - folder.mkdir(); + 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 = new File(INPUT_DIRECTORY, curPath); - for (File file : folder.listFiles()) { - if (file.isFile()) { - try { - parseEquipData(file, curPath); - } catch (FileNotFoundException ex) { - System.out.println("Unable to open equip file " + file.getAbsolutePath() + "."); - } catch (IOException ex) { - System.out.println("Error reading equip file " + file.getAbsolutePath() + "."); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - parseDirectoryEquipData(curPath + file.getName() + "/"); - } - } + 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(); parseDirectoryEquipData(""); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java index 0761d804a1..efffff4e74 100644 --- a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java +++ b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java @@ -2,6 +2,8 @@ package tools.mapletools; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -22,8 +24,8 @@ import java.util.regex.Pattern; * Estimated parse time: 1 minute */ public class GachaponItemIdRetriever { - private static final File INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt"); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final Pattern pattern = Pattern.compile("(\\d*)%"); private static final int[] scrollsChances = new int[]{10, 15, 30, 60, 65, 70, 100}; @@ -247,12 +249,8 @@ public class GachaponItemIdRetriever { private static void fetchDataOnMapleHandbook() throws SQLException { String line; - - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(fileReader); - - int skip = 0; + try(BufferedReader bufferedReader = Files.newBufferedReader(INPUT_FILE)) { + int skip = 0; boolean lineHeader = false; while ((line = bufferedReader.readLine()) != null) { if (skip > 0) { @@ -276,10 +274,10 @@ public class GachaponItemIdRetriever { if (printWriter != null) { printWriter.close(); } - File outputFile = new File(OUTPUT_DIRECTORY, gachaponName + ".txt"); + Path outputFile = OUTPUT_DIRECTORY.resolve(gachaponName + ".txt"); setupDirectories(outputFile); - printWriter = new PrintWriter(outputFile, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(outputFile)); skip = 2; lineHeader = true; @@ -297,30 +295,30 @@ public class GachaponItemIdRetriever { } } } - - if (printWriter != null) { - printWriter.close(); - } - bufferedReader.close(); - fileReader.close(); } catch (IOException ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } + + + } - private static void setupDirectories(File file) { - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } + private static void setupDirectories(Path file) { + if(!Files.exists(file.getParent())) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } public static void main(String[] args) { - try { - loadHandbookUseNames(); + try(con) { + loadHandbookUseNames(); fetchDataOnMapleHandbook(); - - con.close(); } catch (SQLException e) { System.out.println("Error: invalid SQL syntax"); System.out.println(e.getMessage()); diff --git a/src/main/java/tools/mapletools/IdRetriever.java b/src/main/java/tools/mapletools/IdRetriever.java index 58039bc0dc..a41806e70b 100644 --- a/src/main/java/tools/mapletools/IdRetriever.java +++ b/src/main/java/tools/mapletools/IdRetriever.java @@ -2,10 +2,14 @@ package tools.mapletools; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; /** @@ -26,8 +30,8 @@ import java.util.ArrayList; */ public class IdRetriever { private static final boolean INSTALL_SQLTABLE = true; - private static final File INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt"); + private static final Path INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static InputStreamReader fileReader = null; @@ -132,15 +136,11 @@ public class IdRetriever { } private static void fetchDataOnMapleHandbook() throws SQLException { - String line; - - try { - fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - while ((line = bufferedReader.readLine()) != null) { + 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(""); continue; @@ -164,17 +164,13 @@ public class IdRetriever { printWriter.println(str); } - - printWriter.close(); - bufferedReader.close(); - fileReader.close(); - } catch (IOException ex) { + } catch (IOException ex) { System.out.println(ex.getMessage()); } } public static void main(String[] args) { - + Instant instantStarted = Instant.now(); try { if (INSTALL_SQLTABLE) { parseMapleHandbook(); @@ -187,6 +183,10 @@ public class IdRetriever { System.out.println("Error: invalid SQL syntax"); e.printStackTrace(); } + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/MapInfoRetriever.java b/src/main/java/tools/mapletools/MapInfoRetriever.java index 6c35a62a06..ade7693d24 100644 --- a/src/main/java/tools/mapletools/MapInfoRetriever.java +++ b/src/main/java/tools/mapletools/MapInfoRetriever.java @@ -5,6 +5,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -16,7 +18,7 @@ import java.util.List; * the "info" node in their WZ node tree. */ public class MapInfoRetriever { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt"); private static final List missingInfo = new ArrayList<>(); private static BufferedReader bufferedReader = null; @@ -129,18 +131,14 @@ public class MapInfoRetriever { } private static void writeReport() { - try { - PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - if (!missingInfo.isEmpty()) { + 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."); } - - printWriter.close(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/MesoFetcher.java b/src/main/java/tools/mapletools/MesoFetcher.java index 7f777664c9..c843c4e7f8 100644 --- a/src/main/java/tools/mapletools/MesoFetcher.java +++ b/src/main/java/tools/mapletools/MesoFetcher.java @@ -6,9 +6,13 @@ import tools.Pair; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -27,7 +31,7 @@ import java.util.Map; */ public class MesoFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql"); private static final boolean PERMIT_MESOS_ON_DOJO_BOSSES = false; private static final int MESO_ID = 0; private static final int MIN_ITEMS = 4; @@ -119,14 +123,12 @@ public class MesoFetcher { private static void generateMissingMobsMesoRange() { System.out.print("Generating missing ranges... "); - Connection con = SimpleDatabaseConnection.getConnection(); - List existingMobs = new ArrayList<>(200); - - try { - // select all mobs which doesn't drop mesos and have a fair amount of items dropping (meaning they are not an event mob) - 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(); - + 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();) { + + List existingMobs = new ArrayList<>(200); + if (rs.isBeforeFirst()) { while (rs.next()) { int mobid = rs.getInt(1); @@ -137,18 +139,19 @@ public class MesoFetcher { } if (!existingMobs.isEmpty()) { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - printSqlHeader(); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; + + printSqlHeader(); - for (int i = 0; i < existingMobs.size() - 1; i++) { - printSqlMobMesoRange(existingMobs.get(i)); + for (int i = 0; i < existingMobs.size() - 1; i++) { + printSqlMobMesoRange(existingMobs.get(i)); + } + + printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1)); + + printSqlExceptions(); } - - printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1)); - - printSqlExceptions(); - - printWriter.close(); } else { throw new Exception("ALREADY UPDATED"); } @@ -156,13 +159,9 @@ public class MesoFetcher { } else { throw new Exception("ALREADY UPDATED"); } - - rs.close(); - ps.close(); - con.close(); - + System.out.println("done!"); - + } catch (Exception e) { if (e.getMessage() != null && e.getMessage().equals("ALREADY UPDATED")) { System.out.println("done! The DB is already up-to-date, no file generated."); @@ -170,14 +169,21 @@ public class MesoFetcher { e.printStackTrace(); } } + } public static void main(String[] args) { - // load mob stats from WZ + Instant instantStarted = Instant.now(); + // load mob stats from WZ mobStats = MonsterStatFetcher.getAllMonsterStats(); calcAllMobsMesoRange(); generateMissingMobsMesoRange(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/MobBookIndexer.java b/src/main/java/tools/mapletools/MobBookIndexer.java index 403b470430..3dbb168588 100644 --- a/src/main/java/tools/mapletools/MobBookIndexer.java +++ b/src/main/java/tools/mapletools/MobBookIndexer.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -16,7 +18,7 @@ import java.sql.SQLException; * puts them on a SQL table with the correspondent mob cardid. */ public class MobBookIndexer { - private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml"); + private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static BufferedReader bufferedReader = null; @@ -123,14 +125,13 @@ public class MobBookIndexer { } private static void indexFromDropData() { - // This will reference one line at a time - String line = null; - - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;"); + + 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` (" @@ -144,12 +145,7 @@ public class MobBookIndexer { while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - - bufferedReader.close(); - fileReader.close(); - - con.close(); - } catch (FileNotFoundException ex) { + } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { System.out.println("Error reading file '" + INPUT_FILE + "'"); diff --git a/src/main/java/tools/mapletools/MobBookUpdate.java b/src/main/java/tools/mapletools/MobBookUpdate.java index fe5e28743b..efe91373f3 100644 --- a/src/main/java/tools/mapletools/MobBookUpdate.java +++ b/src/main/java/tools/mapletools/MobBookUpdate.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -26,8 +28,8 @@ import java.sql.SQLException; * remove the property 'MonsterBook.img' inside 'string.wz' and choose to import the xml generated with this software. */ public class MobBookUpdate { - private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml"); + private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static PrintWriter printWriter = null; @@ -143,23 +145,17 @@ public class MobBookUpdate { } private static void updateFromDropData() { - // This will reference one line at a time - String line = null; - - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { + 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); } - - printWriter.close(); - bufferedReader.close(); - fileReader.close(); - - con.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { @@ -170,6 +166,7 @@ public class MobBookUpdate { } catch (Exception e) { e.printStackTrace(); } + } public static void main(String[] args) { diff --git a/src/main/java/tools/mapletools/MonsterStatFetcher.java b/src/main/java/tools/mapletools/MonsterStatFetcher.java index e28d6506d0..db855bfff8 100644 --- a/src/main/java/tools/mapletools/MonsterStatFetcher.java +++ b/src/main/java/tools/mapletools/MonsterStatFetcher.java @@ -11,6 +11,8 @@ import server.life.LifeFactory.selfDestruction; import server.life.MonsterStats; import tools.Pair; +import java.time.Duration; +import java.time.Instant; import java.util.*; public class MonsterStatFetcher { @@ -140,4 +142,15 @@ public class MonsterStatFetcher { } } + public static void main(String[] args) { + Instant instantStarted = Instant.now(); + // load mob stats from WZ + Map mobStats = MonsterStatFetcher.getAllMonsterStats(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + + } + } diff --git a/src/main/java/tools/mapletools/NoItemIdFetcher.java b/src/main/java/tools/mapletools/NoItemIdFetcher.java index 602d5420c2..d055bb2816 100644 --- a/src/main/java/tools/mapletools/NoItemIdFetcher.java +++ b/src/main/java/tools/mapletools/NoItemIdFetcher.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -20,7 +22,7 @@ import java.util.*; * A file is generated listing all the inexistent ids. */ public class NoItemIdFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static final Set existingIds = new HashSet<>(); @@ -199,16 +201,13 @@ public class NoItemIdFetcher { } public static void main(String[] args) { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - - existingIds.add(0); // meso itemid + 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(); - - printWriter.close(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/NoItemNameFetcher.java b/src/main/java/tools/mapletools/NoItemNameFetcher.java index 3e7e3989cb..161fccfd7e 100644 --- a/src/main/java/tools/mapletools/NoItemNameFetcher.java +++ b/src/main/java/tools/mapletools/NoItemNameFetcher.java @@ -6,6 +6,8 @@ import provider.wz.WZFiles; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -19,8 +21,8 @@ import java.util.*; * Estimated parse time: 2 minutes */ public class NoItemNameFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt"); - private static final File OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt"); + private static final Path OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt"); private static final Map itemsWzPath = new HashMap<>(); private static final Map equipTypes = new HashMap<>(); @@ -435,20 +437,22 @@ 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(); - printWriter = new PrintWriter(OUTPUT_XML_FILE, StandardCharsets.UTF_8); - 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); + } - 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); } - - printWriter.close(); } public static void main(String[] args) { - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; curType = ItemType.EQP; readEquipWZData(); @@ -457,10 +461,8 @@ public class NoItemNameFetcher { readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); printReportFileHeader(); printReportFileResults(); - printWriter.close(); Map> missingNames = filterMissingItemNames(); writeMissingStringWZNames(missingNames); diff --git a/src/main/java/tools/mapletools/QuestItemCountFetcher.java b/src/main/java/tools/mapletools/QuestItemCountFetcher.java index fb0a453a92..c19f0adda5 100644 --- a/src/main/java/tools/mapletools/QuestItemCountFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemCountFetcher.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -17,7 +19,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestItemCountFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt"); private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; private static final int INITIAL_STRING_LENGTH = 50; @@ -241,17 +243,16 @@ public class QuestItemCountFetcher { private static void reportQuestItemCountData() { // This will reference one line at a time - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Reading WZs..."); readQuestItemCountData(); System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); diff --git a/src/main/java/tools/mapletools/QuestItemFetcher.java b/src/main/java/tools/mapletools/QuestItemFetcher.java index 3c3f6becca..56b4ef1e97 100644 --- a/src/main/java/tools/mapletools/QuestItemFetcher.java +++ b/src/main/java/tools/mapletools/QuestItemFetcher.java @@ -8,6 +8,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -25,7 +27,7 @@ import java.util.*; * Estimated parse time: 1 minute */ public class QuestItemFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt"); private static final int INITIAL_STRING_LENGTH = 50; private static final int INITIAL_LENGTH = 200; private static final boolean DISPLAY_EXTRA_INFO = true; // display items with zero quantity over the quest act WZ @@ -409,32 +411,28 @@ public class QuestItemFetcher { private static void reportQuestItemData() { // This will reference one line at a time String line = null; - String fileName = null; + Path file = null; - try { + try{ System.out.println("Reading WZs..."); - fileName = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + 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 } bufferedReader.close(); - fileReader.close(); - fileName = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; - fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + file = WZFiles.QUEST.getFile().resolve("Act.img.xml"); + bufferedReader = Files.newBufferedReader(file); while ((line = bufferedReader.readLine()) != null) { translateActToken(line); } bufferedReader.close(); - fileReader.close(); System.out.println("Calculating table diffs..."); calculateQuestItemDiff(); @@ -453,7 +451,7 @@ public class QuestItemFetcher { 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(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); printReportFileHeader(); @@ -508,9 +506,9 @@ public class QuestItemFetcher { printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { - System.out.println("Unable to open file '" + fileName + "'"); + System.out.println("Unable to open file '" + file + "'"); } catch (IOException ex) { - System.out.println("Error reading file '" + fileName + "'"); + 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()); diff --git a/src/main/java/tools/mapletools/QuestMesoFetcher.java b/src/main/java/tools/mapletools/QuestMesoFetcher.java index 4bf1a8da95..5623911a54 100644 --- a/src/main/java/tools/mapletools/QuestMesoFetcher.java +++ b/src/main/java/tools/mapletools/QuestMesoFetcher.java @@ -4,6 +4,8 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -16,7 +18,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestMesoFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt"); private static final boolean PRINT_FEES = true; // print missing values as additional info report private static final int INITIAL_STRING_LENGTH = 50; @@ -147,25 +149,21 @@ public class QuestMesoFetcher { private static void readQuestMesoData() throws IOException { String line; - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Act.img.xml"), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Act.img.xml")); while ((line = bufferedReader.readLine()) != null) { translateTokenAct(line); } bufferedReader.close(); - fileReader.close(); - fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Check.img.xml"), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Check.img.xml")); while ((line = bufferedReader.readLine()) != null) { translateTokenCheck(line); } bufferedReader.close(); - fileReader.close(); } private static void printReportFileHeader() { @@ -232,20 +230,19 @@ public class QuestMesoFetcher { private static void reportQuestMesoData() { // This will reference one line at a time - try { + 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 = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(checkedMesoQuests, appliedMesoQuests, true); printReportFileResults(appliedMesoQuests, checkedMesoQuests, false); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); diff --git a/src/main/java/tools/mapletools/QuestlineFetcher.java b/src/main/java/tools/mapletools/QuestlineFetcher.java index cd40f6c83b..0e8188fb10 100644 --- a/src/main/java/tools/mapletools/QuestlineFetcher.java +++ b/src/main/java/tools/mapletools/QuestlineFetcher.java @@ -4,6 +4,10 @@ import provider.wz.WZFiles; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; import java.util.*; /** @@ -18,7 +22,7 @@ import java.util.*; * Running it should generate a report file under "output" folder with the search results. */ public class QuestlineFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt"); private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml"; private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml"; private static final int INITIAL_STRING_LENGTH = 50; @@ -289,7 +293,7 @@ public class QuestlineFetcher { private static void reportQuestlineData() { // This will reference one line at a time - try { + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Reading quest scripts..."); instantiateQuestScriptFiles(ToolConstants.SCRIPTS_PATH + "/quest"); @@ -301,12 +305,11 @@ public class QuestlineFetcher { calculateSkillRelatedMissingQuestScripts(); System.out.println("Reporting results..."); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; printReportFileHeader(); printReportFileResults(); - printWriter.close(); System.out.println("Done!"); } catch (FileNotFoundException ex) { System.out.println("Unable to open quest file."); @@ -356,7 +359,13 @@ public class QuestlineFetcher { */ public static void main(String[] args) { + Instant instantStarted = Instant.now(); reportQuestlineData(); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + } } diff --git a/src/main/java/tools/mapletools/ReactorDropFetcher.java b/src/main/java/tools/mapletools/ReactorDropFetcher.java index c8c5497c5f..32879069fd 100644 --- a/src/main/java/tools/mapletools/ReactorDropFetcher.java +++ b/src/main/java/tools/mapletools/ReactorDropFetcher.java @@ -3,6 +3,8 @@ package tools.mapletools; import java.io.File; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -16,7 +18,7 @@ import java.util.*; * not yet coded. */ public class ReactorDropFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt"); private static final String REACTOR_SCRIPT_PATH = ToolConstants.SCRIPTS_PATH + "/reactor"; private static final Connection con = SimpleDatabaseConnection.getConnection(); @@ -84,19 +86,18 @@ public class ReactorDropFetcher { } private static void reportMissingReactors() { - try { + try(con; + PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { System.out.println("Fetching reactors from DB..."); fetchMissingReactorDrops(); - con.close(); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + 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(); - printWriter.close(); System.out.println("Done!"); } catch (SQLException e) { System.out.println("Warning: Could not establish connection to database to report quest data."); diff --git a/src/main/java/tools/mapletools/SkillMakerFetcher.java b/src/main/java/tools/mapletools/SkillMakerFetcher.java index 08dcf7f885..e8960be230 100644 --- a/src/main/java/tools/mapletools/SkillMakerFetcher.java +++ b/src/main/java/tools/mapletools/SkillMakerFetcher.java @@ -6,6 +6,8 @@ import tools.DatabaseConnection; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -20,8 +22,8 @@ import java.util.Map; */ public class SkillMakerFetcher { - private static final File INPUT_FILE = new File(WZFiles.ETC.getFile(), "ItemMake.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql"); + private static final Path INPUT_FILE = WZFiles.ETC.getFile().resolve("ItemMake.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql"); private static final int INITIAL_STRING_LENGTH = 50; private static PrintWriter printWriter = null; @@ -303,10 +305,10 @@ public class SkillMakerFetcher { // This will reference one line at a time String line = null; - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + printWriter = pw; + bufferedReader = br; resetMakerDataFields(); @@ -316,9 +318,6 @@ public class SkillMakerFetcher { WriteMakerTableFile(); - printWriter.close(); - bufferedReader.close(); - fileReader.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + INPUT_FILE + "'"); } catch (IOException ex) { diff --git a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java index 798bebb3e7..08b3153e8a 100644 --- a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java +++ b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -16,8 +18,8 @@ import java.util.List; * by the server source. */ public class SkillMakerReagentIndexer { - private static final File INPUT_FILE = new File(WZFiles.ITEM.getFile(), "Etc/0425.img.xml"); - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql"); + private static final Path INPUT_FILE = WZFiles.ITEM.getFile().resolve("Etc/0425.img.xml"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql"); private static final int INITIAL_STRING_LENGTH = 50; private static final List>> reagentList = new ArrayList<>(); @@ -151,22 +153,19 @@ public class SkillMakerReagentIndexer { // This will reference one line at a time String line = null; - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE)); + BufferedReader br = Files.newBufferedReader(INPUT_FILE);) { + bufferedReader = br; while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - bufferedReader.close(); - fileReader.close(); SortReagentList(); - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + printWriter = pw; WriteMakerReagentTableFile(); - printWriter.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + OUTPUT_FILE + "'"); } catch (IOException ex) { diff --git a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java index 411c7626f2..39a0f19465 100644 --- a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java +++ b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java @@ -7,6 +7,8 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -27,7 +29,7 @@ import java.util.Map; * drops. */ public class SkillbookChanceFetcher { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql"); private static final Map, Integer> skillbookChances = new HashMap<>(); private static PrintWriter printWriter; @@ -102,8 +104,8 @@ public class SkillbookChanceFetcher { } private static void generateSkillbookChanceUpdateFile() { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; printSkillbookChanceUpdateSqlHeader(); @@ -112,7 +114,6 @@ public class SkillbookChanceFetcher { printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, " + e.getValue() + "),"); } - printWriter.close(); } catch (IOException ioe) { ioe.printStackTrace(); } diff --git a/src/main/java/tools/mapletools/SkillbookStackUpdate.java b/src/main/java/tools/mapletools/SkillbookStackUpdate.java index c25609be87..d540331a24 100644 --- a/src/main/java/tools/mapletools/SkillbookStackUpdate.java +++ b/src/main/java/tools/mapletools/SkillbookStackUpdate.java @@ -3,7 +3,12 @@ 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; +import java.nio.file.StandardOpenOption; +import java.time.Duration; +import java.time.Instant; /** * @author RonanLana @@ -15,8 +20,8 @@ import java.nio.charset.StandardCharsets; * Estimated parse time: 10 seconds */ public class SkillbookStackUpdate { - private static final File INPUT_DIRECTORY = new File(WZFiles.ITEM.getFile(), "Consume"); - private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update"); + private static final Path INPUT_DIRECTORY = WZFiles.ITEM.getFile().resolve("Consume"); + private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update"); private static final int INITIAL_STRING_LENGTH = 50; private static PrintWriter printWriter = null; @@ -65,7 +70,6 @@ public class SkillbookStackUpdate { private static void forwardCursor(int st) { String line = null; - try { while (status >= st && (line = bufferedReader.readLine()) != null) { simpleToken(line); @@ -111,47 +115,56 @@ public class SkillbookStackUpdate { printWriter.println(token); } - private static void parseItemFile(File file, File outputFile) { + private static void parseItemFile(Path file, Path outputFile) { setupDirectories(outputFile); - // This will reference one line at a time - String line = null; - - try { - printWriter = new PrintWriter(outputFile); - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); - - while ((line = bufferedReader.readLine()) != null) { - translateItemToken(line); - } - - bufferedReader.close(); - fileReader.close(); - printWriter.close(); + + 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.getName() + "'"); + System.out.println("Error reading file '" + file.getFileName() + "'"); ex.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } - private static void setupDirectories(File file) { - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } + private static void setupDirectories(Path file) { + if(!Files.exists(file.getParent())) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + System.out.println("Error creating folder '" + file.getParent() + "'"); + e.printStackTrace(); + } + } } - private static void parseItemDirectory(File inputDirectory, File outputDirectory) { - for (File f : inputDirectory.listFiles()) { - parseItemFile(f, new File(outputDirectory, f.getName())); - } + private static void parseItemDirectory(Path inputDirectory, Path outputDirectory) { + try (DirectoryStream stream = Files.newDirectoryStream(inputDirectory)) { + for (Path path : stream) { + parseItemFile(path, outputDirectory.resolve(path.getFileName())); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } public static void main(String[] args) { + Instant instantStarted = Instant.now(); System.out.println("Reading item files..."); parseItemDirectory(INPUT_DIRECTORY, OUTPUT_DIRECTORY); System.out.println("Done!"); + Instant instantStopped = Instant.now(); + Duration durationBetween = Duration.between(instantStarted, instantStopped); + System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/ToolConstants.java b/src/main/java/tools/mapletools/ToolConstants.java index 641d8a7d69..b14a896d4f 100644 --- a/src/main/java/tools/mapletools/ToolConstants.java +++ b/src/main/java/tools/mapletools/ToolConstants.java @@ -1,18 +1,19 @@ package tools.mapletools; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; class ToolConstants { - static final File INPUT_DIRECTORY = new File("tools/input"); - static final File OUTPUT_DIRECTORY = new File("tools/output"); + static final Path INPUT_DIRECTORY = Paths.get("tools/input"); + static final Path OUTPUT_DIRECTORY = Paths.get("tools/output"); static final String SCRIPTS_PATH = "scripts"; static final String HANDBOOK_PATH = "handbook"; - static File getInputFile(String fileName) { - return new File(INPUT_DIRECTORY, fileName); + static Path getInputFile(String fileName) { + return INPUT_DIRECTORY.resolve(fileName); } - static File getOutputFile(String fileName) { - return new File(OUTPUT_DIRECTORY, fileName); + static Path getOutputFile(String fileName) { + return OUTPUT_DIRECTORY.resolve(fileName); } } diff --git a/src/main/java/tools/mapletools/WorldmapChecker.java b/src/main/java/tools/mapletools/WorldmapChecker.java index 5fda287730..8c47254752 100644 --- a/src/main/java/tools/mapletools/WorldmapChecker.java +++ b/src/main/java/tools/mapletools/WorldmapChecker.java @@ -5,6 +5,8 @@ import tools.Pair; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; /** @@ -14,7 +16,7 @@ import java.util.*; * throughout the map tree (area map -> continent map -> world map) but are currently missing. */ public class WorldmapChecker { - private static final File OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt"); + private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt"); private static final int INITIAL_STRING_LENGTH = 50; private static final Map> worldMapids = new HashMap<>(); private static final Map parentWorldmaps = new HashMap<>(); @@ -186,8 +188,8 @@ public class WorldmapChecker { } private static void verifyWorldmapTreeMapids() { - try { - printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { + printWriter = pw; printReportFileHeader(); if (rootWorldmaps.size() > 1) { @@ -242,7 +244,6 @@ public class WorldmapChecker { printReportFileResults(unreferencedEntries); } - printWriter.close(); } catch (Exception e) { e.printStackTrace(); } 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 4/5] 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(); From d9a86d6d756ec45a663173052dcc24f1124a1c11 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: Tue, 2 Aug 2022 23:14:17 +0700 Subject: [PATCH 5/5] Fixing indents ! --- src/main/java/net/server/channel/Channel.java | 16 +- src/main/java/provider/wz/WZFiles.java | 5 +- .../java/provider/wz/XMLDomMapleData.java | 7 +- src/main/java/provider/wz/XMLWZFile.java | 78 ++++---- .../server/SkillbookInformationProvider.java | 34 ++-- .../java/tools/mapletools/ArrowFetcher.java | 3 +- .../tools/mapletools/BossHpBarFetcher.java | 28 ++- .../mapletools/CashCosmeticsChecker.java | 87 ++++----- .../tools/mapletools/CashDropFetcher.java | 140 +++++++------- .../tools/mapletools/CashVegaChecker.java | 2 +- .../tools/mapletools/CodeCouponGenerator.java | 49 +++-- .../tools/mapletools/CouponInstaller.java | 16 +- .../java/tools/mapletools/DojoUpdate.java | 46 ++--- .../tools/mapletools/EmptyItemWzChecker.java | 2 +- .../mapletools/EquipmentOmniLeveller.java | 104 +++++------ .../mapletools/GachaponItemIdRetriever.java | 113 ++++++----- .../java/tools/mapletools/IdRetriever.java | 16 +- .../mapletools/MapFieldLimitChecker.java | 41 ++-- .../tools/mapletools/MapInfoRetriever.java | 26 +-- .../java/tools/mapletools/MesoFetcher.java | 14 +- .../java/tools/mapletools/MobBookUpdate.java | 43 +++-- .../tools/mapletools/NoItemIdFetcher.java | 20 +- .../tools/mapletools/NoItemNameFetcher.java | 58 +++--- .../mapletools/QuestItemCountFetcher.java | 36 ++-- .../tools/mapletools/QuestItemFetcher.java | 176 +++++++++--------- .../tools/mapletools/QuestMesoFetcher.java | 37 ++-- .../tools/mapletools/QuestlineFetcher.java | 42 ++--- .../tools/mapletools/ReactorDropFetcher.java | 51 ++--- .../tools/mapletools/SkillMakerFetcher.java | 35 ++-- .../mapletools/SkillMakerReagentIndexer.java | 39 ++-- .../mapletools/SkillbookChanceFetcher.java | 28 ++- .../mapletools/SkillbookStackUpdate.java | 2 - 32 files changed, 691 insertions(+), 703 deletions(-) diff --git a/src/main/java/net/server/channel/Channel.java b/src/main/java/net/server/channel/Channel.java index 0343dc5da7..feb22becb8 100644 --- a/src/main/java/net/server/channel/Channel.java +++ b/src/main/java/net/server/channel/Channel.java @@ -50,7 +50,11 @@ import server.maps.*; import tools.PacketCreator; import tools.Pair; -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.util.*; import java.util.Map.Entry; import java.util.concurrent.ScheduledFuture; @@ -448,8 +452,14 @@ public final class Channel { private static String[] getEvents() { List events = new ArrayList<>(); - for (File file : new File("scripts/event").listFiles()) { - events.add(file.getName().substring(0, file.getName().length() - 3)); + try (DirectoryStream stream = Files.newDirectoryStream(Paths.get("scripts/event"))) { + for (Path path : stream) { + String fileName = path.getFileName().toString(); + events.add(fileName.substring(0, fileName.length() - 3)); + } + } catch (IOException e) { + log.warn("Unable to load events !"); + e.printStackTrace(); } return events.toArray(new String[0]); } diff --git a/src/main/java/provider/wz/WZFiles.java b/src/main/java/provider/wz/WZFiles.java index 3fe8dae892..783785e85e 100644 --- a/src/main/java/provider/wz/WZFiles.java +++ b/src/main/java/provider/wz/WZFiles.java @@ -28,7 +28,7 @@ public enum WZFiles { } public Path getFile() { - return Paths.get(DIRECTORY).resolve(fileName); + return Paths.get(DIRECTORY).resolve(fileName); } public String getFilePath() { @@ -36,8 +36,7 @@ public enum WZFiles { } private static String getWzDirectory() { - // Either provide a custom directory path through the "wz-path" property when launching the .jar, - // or don't provide one to use the default "wz" directory + // Either provide a custom directory path through the "wz-path" property when launching the .jar, or don't provide one to use the default "wz" directory String propertyPath = System.getProperty("wz-path"); if (propertyPath != null && new File(propertyPath).isDirectory()) { return propertyPath; diff --git a/src/main/java/provider/wz/XMLDomMapleData.java b/src/main/java/provider/wz/XMLDomMapleData.java index 4ea8461c37..da37b46880 100644 --- a/src/main/java/provider/wz/XMLDomMapleData.java +++ b/src/main/java/provider/wz/XMLDomMapleData.java @@ -80,7 +80,8 @@ public class XMLDomMapleData implements Data { boolean foundChild = false; for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) { + if (childNode.getNodeType() == Node.ELEMENT_NODE + && childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) { myNode = childNode; foundChild = true; break; @@ -104,12 +105,12 @@ public class XMLDomMapleData implements Data { for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE) { - XMLDomMapleData child = new XMLDomMapleData(childNode); + XMLDomMapleData child = new XMLDomMapleData(childNode); child.imageDataDir = imageDataDir.resolve(getName().trim()); ret.add(child); } } - + return ret; } diff --git a/src/main/java/provider/wz/XMLWZFile.java b/src/main/java/provider/wz/XMLWZFile.java index 0644b95371..b493658bd4 100644 --- a/src/main/java/provider/wz/XMLWZFile.java +++ b/src/main/java/provider/wz/XMLWZFile.java @@ -38,50 +38,50 @@ import org.slf4j.LoggerFactory; public class XMLWZFile implements DataProvider { private static final Logger log = LoggerFactory.getLogger(DataProvider.class); private final Path root; - private final WZDirectoryEntry rootForNavigation; + 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) { + 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); - } - } + 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"); - 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 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); + } - return domMapleData; - } + return domMapleData; + } @Override public DataDirectoryEntry getRoot() { diff --git a/src/main/java/server/SkillbookInformationProvider.java b/src/main/java/server/SkillbookInformationProvider.java index a28e54838d..1661f80732 100644 --- a/src/main/java/server/SkillbookInformationProvider.java +++ b/src/main/java/server/SkillbookInformationProvider.java @@ -191,24 +191,24 @@ public class SkillbookInformationProvider { return loadedSkillbooks; } - private static void listFiles(String directoryName, ArrayList files) { - Path directory = Paths.get(directoryName); + private static void listFiles(String directoryName, ArrayList files) { + Path directory = Paths.get(directoryName); - // get all the files from a directory - try (DirectoryStream stream = Files.newDirectoryStream(directory)) { - for (Path path : stream) { + // get all the files from a directory + try (DirectoryStream stream = Files.newDirectoryStream(directory)) { + for (Path path : stream) { - 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(); - } - } + 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(); + } + } private static List listFilesFromDirectoryRecursively(String directory) { ArrayList files = new ArrayList<>(); @@ -233,7 +233,7 @@ public class SkillbookInformationProvider { private static String readFileToString(Path file, String encoding) throws IOException { Scanner scanner = new Scanner(file, encoding); String text = ""; - try(scanner) { + try (scanner) { text = scanner.useDelimiter("\\A").next(); diff --git a/src/main/java/tools/mapletools/ArrowFetcher.java b/src/main/java/tools/mapletools/ArrowFetcher.java index 996f8e3bd7..d049fa0869 100644 --- a/src/main/java/tools/mapletools/ArrowFetcher.java +++ b/src/main/java/tools/mapletools/ArrowFetcher.java @@ -23,7 +23,6 @@ import server.life.MonsterStats; import tools.Pair; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.sql.Connection; import java.sql.PreparedStatement; @@ -214,7 +213,7 @@ public class ArrowFetcher { } public static void main(String[] args) { - Instant instantStarted = Instant.now(); + Instant instantStarted = Instant.now(); // load mob stats from WZ mobStats = MonsterStatFetcher.getAllMonsterStats(); diff --git a/src/main/java/tools/mapletools/BossHpBarFetcher.java b/src/main/java/tools/mapletools/BossHpBarFetcher.java index e313f39e37..e7634f09bb 100644 --- a/src/main/java/tools/mapletools/BossHpBarFetcher.java +++ b/src/main/java/tools/mapletools/BossHpBarFetcher.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; @@ -134,19 +133,19 @@ public class BossHpBarFetcher { } private static void readBossHpBarData() throws IOException { - 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)) { - bufferedReader = br; - String line; - while ((line = bufferedReader.readLine()) != null) { - translateToken(line); - } - } - } - } + 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)) { + bufferedReader = br; + String line; + while ((line = bufferedReader.readLine()) != null) { + translateToken(line); + } + } + } + } } } @@ -170,7 +169,6 @@ public class BossHpBarFetcher { readBossHpBarData(); System.out.println("Reporting results..."); - printReportFileHeader(printWriter); printReportFileResults(printWriter); diff --git a/src/main/java/tools/mapletools/CashCosmeticsChecker.java b/src/main/java/tools/mapletools/CashCosmeticsChecker.java index 349afff565..261cf555b1 100644 --- a/src/main/java/tools/mapletools/CashCosmeticsChecker.java +++ b/src/main/java/tools/mapletools/CashCosmeticsChecker.java @@ -615,49 +615,50 @@ 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(); - - if (!missingCosmeticsNpcTypes.isEmpty()) { - printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries."); - - for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { - printWriter.println(" NPC " + mcn.getLeft()); - - Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); - reportNpcCosmetics(genderItemids.getLeft()); - reportNpcCosmetics(genderItemids.getRight()); - printWriter.println(); - } - } - - if (!unusedCosmetics.isEmpty()) { - printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); - - List list = new ArrayList<>(unusedCosmetics); - Collections.sort(list); - - for (Integer i : list) { - printWriter.println(i + " " + cosmeticIdNames.get(i)); - } - - printWriter.println(); - } - - if (!missingCosmeticNames.isEmpty()) { - printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); - - List listString = new ArrayList<>(missingCosmeticNames); - Collections.sort(listString); - - for (String c : listString) { - printWriter.println(c); - } - - printWriter.println(); - } + + 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."); + + for (Pair, List> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) { + printWriter.println(" NPC " + mcn.getLeft()); + + Pair, List> genderItemids = getCosmeticReport(mcn.getRight()); + reportNpcCosmetics(genderItemids.getLeft()); + reportNpcCosmetics(genderItemids.getRight()); + printWriter.println(); + } + } + + if (!unusedCosmetics.isEmpty()) { + printWriter.println("Unused cosmetics: " + unusedCosmetics.size()); + + List list = new ArrayList<>(unusedCosmetics); + Collections.sort(list); + + for (Integer i : list) { + printWriter.println(i + " " + cosmeticIdNames.get(i)); + } + + printWriter.println(); + } + + if (!missingCosmeticNames.isEmpty()) { + printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size()); + + List listString = new ArrayList<>(missingCosmeticNames); + Collections.sort(listString); + + for (String c : listString) { + printWriter.println(c); + } + + printWriter.println(); + } } } diff --git a/src/main/java/tools/mapletools/CashDropFetcher.java b/src/main/java/tools/mapletools/CashDropFetcher.java index f567a4fc2c..91282fa6d7 100644 --- a/src/main/java/tools/mapletools/CashDropFetcher.java +++ b/src/main/java/tools/mapletools/CashDropFetcher.java @@ -1,12 +1,9 @@ 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; @@ -182,18 +179,18 @@ public class CashDropFetcher { private static void listFiles(Path directoryName, ArrayList files) { // get all the files from a directory - 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(); - } + 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) { @@ -267,76 +264,75 @@ public class CashDropFetcher { } private static void reportNxDropData() { - //NEED FUTURE UPDATE - 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); + 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); - for (Path path : files) { - // System.out.println("Parsing " + f.getAbsolutePath()); - int itemid = getItemIdFromFilename(path.getFileName().toString()); - if (itemid < 0) { - continue; - } + for (Path path : files) { + // System.out.println("Parsing " + f.getAbsolutePath()); + int itemid = getItemIdFromFilename(path.getFileName().toString()); + if (itemid < 0) { + continue; + } - bufferedReader = Files.newBufferedReader(path); + bufferedReader = Files.newBufferedReader(path); - currentItemid = itemid; - inspectEquipWzEntry(); + currentItemid = itemid; + inspectEquipWzEntry(); - bufferedReader.close(); - } + bufferedReader.close(); + } - System.out.println("Reading Item.wz ..."); - files = new ArrayList<>(); - listFiles(WZFiles.ITEM.getFile(), files); + System.out.println("Reading Item.wz ..."); + files = new ArrayList<>(); + listFiles(WZFiles.ITEM.getFile(), files); - for (Path path : files) { - // System.out.println("Parsing " + f.getAbsolutePath()); - bufferedReader = Files.newBufferedReader(path); + for (Path path : files) { + // System.out.println("Parsing " + f.getAbsolutePath()); + bufferedReader = Files.newBufferedReader(path); - 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; - } + 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(); - } + 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 = pw; - 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); } + */ - 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 6886be533f..1cbea1b5aa 100644 --- a/src/main/java/tools/mapletools/CashVegaChecker.java +++ b/src/main/java/tools/mapletools/CashVegaChecker.java @@ -156,7 +156,7 @@ public class CashVegaChecker { } private static void reportMissingVegaItems() { - System.out.println("Reporting results ..."); + System.out.println("Reporting results ..."); try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { printWriter = pw; diff --git a/src/main/java/tools/mapletools/CodeCouponGenerator.java b/src/main/java/tools/mapletools/CodeCouponGenerator.java index 6d0b69b791..62e35c6e09 100644 --- a/src/main/java/tools/mapletools/CodeCouponGenerator.java +++ b/src/main/java/tools/mapletools/CodeCouponGenerator.java @@ -3,7 +3,6 @@ package tools.mapletools; import tools.Pair; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.sql.*; @@ -315,34 +314,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/CouponInstaller.java b/src/main/java/tools/mapletools/CouponInstaller.java index aba16b58dd..2532458370 100644 --- a/src/main/java/tools/mapletools/CouponInstaller.java +++ b/src/main/java/tools/mapletools/CouponInstaller.java @@ -3,7 +3,8 @@ package tools.mapletools; import provider.wz.WZFiles; import java.io.*; -import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -16,8 +17,8 @@ import java.sql.SQLException; * a SQL table that the server will make use. */ public class CouponInstaller { - private static final File COUPON_INPUT_FILE_1 = new File(WZFiles.ITEM.getFilePath(), "/Cash/0521.img.xml"); - private static final File COUPON_INPUT_FILE_2 = new File(WZFiles.ITEM.getFilePath(), "/Cash/0536.img.xml"); + private static final Path COUPON_INPUT_FILE_1 = WZFiles.ITEM.getFile().resolve("Cash/0521.img.xml"); + private static final Path COUPON_INPUT_FILE_2 = WZFiles.ITEM.getFile().resolve("Cash/0536.img.xml"); private static final Connection con = SimpleDatabaseConnection.getConnection(); private static BufferedReader bufferedReader = null; private static byte status = 0; @@ -192,20 +193,17 @@ public class CouponInstaller { } } - private static void installRateCoupons(File file) { + private static void installRateCoupons(Path file) { // This will reference one line at a time String line = null; - try { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + try (BufferedReader br = Files.newBufferedReader(file)) { + bufferedReader = br; while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - bufferedReader.close(); - fileReader.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + file + "'"); } catch (IOException ex) { diff --git a/src/main/java/tools/mapletools/DojoUpdate.java b/src/main/java/tools/mapletools/DojoUpdate.java index 0accbaff2d..584682cc75 100644 --- a/src/main/java/tools/mapletools/DojoUpdate.java +++ b/src/main/java/tools/mapletools/DojoUpdate.java @@ -126,8 +126,9 @@ public class DojoUpdate { if (!isDojoMapid) { return; } - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); - BufferedReader br = Files.newBufferedReader(file);) { + try (PrintWriter pw = new PrintWriter( + Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { printWriter = pw; bufferedReader = br; status = 0; @@ -136,7 +137,7 @@ public class DojoUpdate { while ((line = bufferedReader.readLine()) != null) { translateToken(line); } - + printFileFooter(); } } @@ -156,20 +157,20 @@ public class DojoUpdate { 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(); - } + 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 { + try (DirectoryStream stream = Files.newDirectoryStream(folder)) { + for (Path path : stream) { + if (Files.isRegularFile(path)) { + try { parseDojoData(path, curPath); } catch (FileNotFoundException ex) { System.out.println("Unable to open dojo file " + path.toAbsolutePath() + "."); @@ -178,24 +179,23 @@ public class DojoUpdate { } catch (Exception e) { e.printStackTrace(); } - } else { - parseDirectoryDojoData(curPath + path.getFileName() + "/"); - } - } + } else { + parseDirectoryDojoData(curPath + path.getFileName() + "/"); + } + } } catch (IOException e1) { - System.out.println("Unable to read folder " + folder.toAbsolutePath() + "."); - // TODO Auto-generated catch block - e1.printStackTrace(); - } + 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(); + Instant instantStarted = Instant.now(); parseDirectoryDojoData(""); Instant instantStopped = Instant.now(); Duration durationBetween = Duration.between(instantStarted, instantStopped); System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); - } } diff --git a/src/main/java/tools/mapletools/EmptyItemWzChecker.java b/src/main/java/tools/mapletools/EmptyItemWzChecker.java index 3ac5c7ddf0..4ac3face4f 100644 --- a/src/main/java/tools/mapletools/EmptyItemWzChecker.java +++ b/src/main/java/tools/mapletools/EmptyItemWzChecker.java @@ -409,7 +409,7 @@ public class EmptyItemWzChecker { private static void generateStringWz() throws IOException { System.out.println("Generating clean String.wz ..."); - String[][] stringWzFiles = {{"Cash", "Consume", "Ins", "Pet"}, {"Etc"}, {"Eqp"}}; + String[][] stringWzFiles = { { "Cash", "Consume", "Ins", "Pet" }, { "Etc" }, { "Eqp" } }; String stringWzPath = "/String.wz/"; File folder = new File(OUTPUT_PATH + "/String.wz/"); diff --git a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java b/src/main/java/tools/mapletools/EquipmentOmniLeveller.java index 964c1f462f..71e3635b31 100644 --- a/src/main/java/tools/mapletools/EquipmentOmniLeveller.java +++ b/src/main/java/tools/mapletools/EquipmentOmniLeveller.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; @@ -358,41 +357,40 @@ public class EquipmentOmniLeveller { } private static void copyCashItemData(Path file, String curPath) throws IOException { - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); - BufferedReader br = Files.newBufferedReader(file);) { - printWriter = pw; - bufferedReader = br; - String line; + try (PrintWriter pw = new PrintWriter( + Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + String line; while ((line = bufferedReader.readLine()) != null) { printWriter.println(line); } - } + } } private static void parseEquipData(Path file, String curPath) throws IOException { - - try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); - BufferedReader br = Files.newBufferedReader(file);) { - printWriter = pw; - bufferedReader = br; - status = 0; + try (PrintWriter pw = new PrintWriter( + Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName()))); + BufferedReader br = Files.newBufferedReader(file);) { + printWriter = pw; + bufferedReader = br; + status = 0; upgradeable = false; cash = false; String line; while ((line = bufferedReader.readLine()) != null) { if (translateToken(line)) { - infoTagState = status; // status: 2 + infoTagState = status; // status: 2 translateInfoTag(status); infoTagState = -1; } } printFileFooter(); - } catch (RuntimeException e) { + } catch (RuntimeException e) { copyCashItemData(file, curPath); } - - } private static void printFileFooter() { @@ -403,48 +401,48 @@ public class EquipmentOmniLeveller { } private static void parseDirectoryEquipData(String curPath) { - 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(); - } - } + 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 - e1.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 + e1.printStackTrace(); + } + } public static void main(String[] args) { - Instant instantStarted = Instant.now(); + Instant instantStarted = Instant.now(); parseDirectoryEquipData(""); Instant instantStopped = Instant.now(); Duration durationBetween = Duration.between(instantStarted, instantStopped); System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); - System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java index cd884bc8ce..f39fb0f918 100644 --- a/src/main/java/tools/mapletools/GachaponItemIdRetriever.java +++ b/src/main/java/tools/mapletools/GachaponItemIdRetriever.java @@ -1,7 +1,6 @@ package tools.mapletools; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -248,73 +247,73 @@ 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())) { - try { - Files.createDirectories(file.getParent()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + if (!Files.exists(file.getParent())) { + try { + Files.createDirectories(file.getParent()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } public static void main(String[] args) { - try(con) { - loadHandbookUseNames(); + try (con) { + loadHandbookUseNames(); fetchDataOnMapleHandbook(); } catch (SQLException e) { System.out.println("Error: invalid SQL syntax"); diff --git a/src/main/java/tools/mapletools/IdRetriever.java b/src/main/java/tools/mapletools/IdRetriever.java index 150d740f30..b511499f96 100644 --- a/src/main/java/tools/mapletools/IdRetriever.java +++ b/src/main/java/tools/mapletools/IdRetriever.java @@ -136,11 +136,11 @@ 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; - while ((line = bufferedReader.readLine()) != null) { + 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(""); continue; @@ -164,13 +164,13 @@ public class IdRetriever { printWriter.println(str); } - } catch (IOException ex) { + } catch (IOException ex) { System.out.println(ex.getMessage()); } } public static void main(String[] args) { - Instant instantStarted = Instant.now(); + Instant instantStarted = Instant.now(); try (con) { if (INSTALL_SQLTABLE) { parseMapleHandbook(); @@ -184,7 +184,7 @@ public class IdRetriever { Instant instantStopped = Instant.now(); Duration durationBetween = Duration.between(instantStarted, instantStopped); System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis()); - System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); + System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds()); } } diff --git a/src/main/java/tools/mapletools/MapFieldLimitChecker.java b/src/main/java/tools/mapletools/MapFieldLimitChecker.java index da54249d97..92909399bc 100644 --- a/src/main/java/tools/mapletools/MapFieldLimitChecker.java +++ b/src/main/java/tools/mapletools/MapFieldLimitChecker.java @@ -3,7 +3,9 @@ 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; import java.util.ArrayList; /** @@ -72,17 +74,17 @@ public class MapFieldLimitChecker { } } - private static void listFiles(String directoryName, ArrayList files) { - File directory = new File(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); + private static void listFiles(Path directory, ArrayList files) { + try (DirectoryStream stream = Files.newDirectoryStream(directory)) { + for (Path path : stream) { + if (Files.isRegularFile(path)) { + files.add(path); + } else if (Files.isDirectory(path)) { + listFiles(path, files); + } } + } catch (IOException e) { + e.printStackTrace(); } } @@ -134,18 +136,17 @@ public class MapFieldLimitChecker { private static void loadMapWz() throws IOException { System.out.println("Reading Map.wz ..."); - ArrayList files = new ArrayList<>(); - listFiles(WZFiles.MAP.getFilePath() + "/Map", files); + ArrayList files = new ArrayList<>(); + listFiles(WZFiles.MAP.getFile().resolve("Map"), files); - for (File f : files) { - InputStreamReader fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8); - bufferedReader = new BufferedReader(fileReader); + for (Path f : files) { + try (BufferedReader br = Files.newBufferedReader(f)) { + bufferedReader = br; - mapid = getMapIdFromFilename(f.getName()); - inspectMapEntry(); + mapid = getMapIdFromFilename(f.getFileName().toString()); + inspectMapEntry(); - bufferedReader.close(); - fileReader.close(); + } } } diff --git a/src/main/java/tools/mapletools/MapInfoRetriever.java b/src/main/java/tools/mapletools/MapInfoRetriever.java index 6e884d1007..86019e8a5d 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 908e22f929..44384fcb12 100644 --- a/src/main/java/tools/mapletools/MesoFetcher.java +++ b/src/main/java/tools/mapletools/MesoFetcher.java @@ -3,9 +3,7 @@ package tools.mapletools; import server.life.MonsterStats; import tools.Pair; -import java.io.File; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -128,7 +126,7 @@ public class MesoFetcher { ResultSet rs = ps.executeQuery();) { List existingMobs = new ArrayList<>(200); - + if (rs.isBeforeFirst()) { while (rs.next()) { int mobid = rs.getInt(1); @@ -140,9 +138,9 @@ public class MesoFetcher { if (!existingMobs.isEmpty()) { try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - printWriter = pw; - - printSqlHeader(); + printWriter = pw; + + printSqlHeader(); for (int i = 0; i < existingMobs.size() - 1; i++) { printSqlMobMesoRange(existingMobs.get(i)); @@ -159,9 +157,9 @@ public class MesoFetcher { } else { throw new Exception("ALREADY UPDATED"); } - + System.out.println("done!"); - + } catch (Exception e) { if (e.getMessage() != null && e.getMessage().equals("ALREADY UPDATED")) { System.out.println("done! The DB is already up-to-date, no file generated."); diff --git a/src/main/java/tools/mapletools/MobBookUpdate.java b/src/main/java/tools/mapletools/MobBookUpdate.java index be17c5b66e..a83af1c0e0 100644 --- a/src/main/java/tools/mapletools/MobBookUpdate.java +++ b/src/main/java/tools/mapletools/MobBookUpdate.java @@ -3,7 +3,6 @@ package tools.mapletools; import provider.wz.WZFiles; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -144,29 +143,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; + 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; + 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(); - } - } + 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/NoItemIdFetcher.java b/src/main/java/tools/mapletools/NoItemIdFetcher.java index 83c60ad14a..7e55e11fff 100644 --- a/src/main/java/tools/mapletools/NoItemIdFetcher.java +++ b/src/main/java/tools/mapletools/NoItemIdFetcher.java @@ -199,16 +199,16 @@ public class NoItemIdFetcher { } } - 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 e3b011a9ca..c5e463b769 100644 --- a/src/main/java/tools/mapletools/NoItemNameFetcher.java +++ b/src/main/java/tools/mapletools/NoItemNameFetcher.java @@ -3,9 +3,7 @@ package tools.mapletools; import provider.*; import provider.wz.WZFiles; -import java.io.File; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -435,41 +433,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; + 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(); + 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); - } + 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(); + 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 + curType = ItemType.UNDEF; + readItemWZData(); + readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ - System.out.println("Reporting results..."); - printReportFileHeader(); - printReportFileResults(); + System.out.println("Reporting results..."); + printReportFileHeader(); + printReportFileResults(); - Map> missingNames = filterMissingItemNames(); - writeMissingStringWZNames(missingNames); + Map> missingNames = filterMissingItemNames(); + writeMissingStringWZNames(missingNames); - System.out.println("Done!"); - } catch (Exception e) { - e.printStackTrace(); - } + 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 211ee211c5..1881438f48 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 50570ad38e..440e96fd26 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 (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) { - 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 = pw; + 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"); + } + } - 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 25c72149b3..c2aae9e4d5 100644 --- a/src/main/java/tools/mapletools/QuestMesoFetcher.java +++ b/src/main/java/tools/mapletools/QuestMesoFetcher.java @@ -3,7 +3,6 @@ package tools.mapletools; import provider.wz.WZFiles; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -228,29 +227,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 ef102506b5..25c8e256a0 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 8999acd199..3c88abcc06 100644 --- a/src/main/java/tools/mapletools/ReactorDropFetcher.java +++ b/src/main/java/tools/mapletools/ReactorDropFetcher.java @@ -1,10 +1,11 @@ package tools.mapletools; -import java.io.File; +import java.io.IOException; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; +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; @@ -40,14 +41,14 @@ public class ReactorDropFetcher { } private static void removeScriptedReactorids(String directoryName) { - File directory = new File(directoryName); - - // get all the files from a directory - File[] fList = directory.listFiles(); - for (File file : fList) { - if (file.isFile()) { - reactors.remove(getReactorIdFromFilename(file.getName())); + try (DirectoryStream stream = Files.newDirectoryStream(Paths.get(directoryName))) { + for (Path path : stream) { + if (Files.isRegularFile(path)) { + reactors.remove(getReactorIdFromFilename(path.getFileName().toString())); + } } + } catch (IOException e) { + e.printStackTrace(); } } @@ -86,25 +87,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 dd9eee54cf..38a52ad07e 100644 --- a/src/main/java/tools/mapletools/SkillMakerFetcher.java +++ b/src/main/java/tools/mapletools/SkillMakerFetcher.java @@ -5,7 +5,6 @@ import server.ItemInformationProvider; import tools.DatabaseConnection; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -303,28 +302,28 @@ public class SkillMakerFetcher { private static void writeMakerTableData() { // This will reference one line at a time - String line = null; + 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) { diff --git a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java index e2f1d3e0af..77708d225a 100644 --- a/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java +++ b/src/main/java/tools/mapletools/SkillMakerReagentIndexer.java @@ -4,7 +4,6 @@ import provider.wz.WZFiles; import tools.Pair; import java.io.*; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -150,29 +149,29 @@ public class SkillMakerReagentIndexer { } private static void writeMakerReagentTableData() { - // This will reference one line at a time - String line = null; + // 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 7afba7ed2d..9d9d065f68 100644 --- a/src/main/java/tools/mapletools/SkillbookChanceFetcher.java +++ b/src/main/java/tools/mapletools/SkillbookChanceFetcher.java @@ -3,10 +3,8 @@ package tools.mapletools; import server.life.MonsterStats; import tools.Pair; -import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -103,22 +101,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 7b7cb84f43..cedd89a2b9 100644 --- a/src/main/java/tools/mapletools/SkillbookStackUpdate.java +++ b/src/main/java/tools/mapletools/SkillbookStackUpdate.java @@ -6,7 +6,6 @@ import java.io.*; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardOpenOption; import java.time.Duration; import java.time.Instant; @@ -151,7 +150,6 @@ public class SkillbookStackUpdate { parseItemFile(path, outputDirectory.resolve(path.getFileName())); } } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } }