From 26e98d012fcaa877440ca133093998072b6b73a1 Mon Sep 17 00:00:00 2001 From: P0nk Date: Sat, 10 Jul 2021 23:35:43 +0200 Subject: [PATCH] Move MapleEventMethodFiller to main module --- pom.xml | 5 + .../tools/mapletools/EventMethodFiller.java | 102 ++++++++++++++ .../MapleEventMethodFiller.java | 126 ------------------ 3 files changed, 107 insertions(+), 126 deletions(-) create mode 100644 src/main/java/tools/mapletools/EventMethodFiller.java delete mode 100644 tools/MapleEventMethodFiller/src/mapleeventmethodfiller/MapleEventMethodFiller.java diff --git a/pom.xml b/pom.xml index 7df287a87f..cb56cd7ae4 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,11 @@ jcip-annotations 1.0 + + commons-io + commons-io + 2.10.0 + diff --git a/src/main/java/tools/mapletools/EventMethodFiller.java b/src/main/java/tools/mapletools/EventMethodFiller.java new file mode 100644 index 0000000000..473fbbde75 --- /dev/null +++ b/src/main/java/tools/mapletools/EventMethodFiller.java @@ -0,0 +1,102 @@ +package tools.mapletools; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author RonanLana + *

+ * This application objective is to read all scripts from the event folder + * and fill empty functions for every function name not yet present in the + * script. + *

+ * Estimated parse time: 10 seconds + */ +public class EventMethodFiller { + private static boolean foundMatchingDataOnFile(String fileContent, Pattern pattern) { + Matcher matcher = pattern.matcher(fileContent); + return matcher.find(); + } + + private static void fileSearchMatchingData(File file, Map functions) { + try { + String fileContent = FileUtils.readFileToString(file, "UTF-8"); + List fillFunctions = new LinkedList<>(); + + for (Map.Entry f : functions.entrySet()) { + if (!foundMatchingDataOnFile(fileContent, f.getKey())) { + fillFunctions.add(f.getValue()); + } + } + + if (!fillFunctions.isEmpty()) { + System.out.println("Filling out " + file.getName() + "..."); + + FileWriter fileWriter = new FileWriter(file, true); + PrintWriter printWriter = new PrintWriter(fileWriter); + + printWriter.println(); + printWriter.println(); + printWriter.println("// ---------- FILLER FUNCTIONS ----------"); + printWriter.println(); + + for (String s : fillFunctions) { + printWriter.println(s); + printWriter.println(); + } + + printWriter.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void filterDirectorySearchMatchingData(String directoryPath, Map functions) { + Iterator iter = FileUtils.iterateFiles(new File(directoryPath), new String[]{"sql", "js", "txt", "java"}, true); + + while (iter.hasNext()) { + File file = (File) iter.next(); + fileSearchMatchingData(file, functions); + } + } + + private static Pattern compileJsFunctionPattern(String function) { + String jsFunction = "function(\\s)+"; + return Pattern.compile(jsFunction + function); + } + + private static Map getFunctions() { + Map functions = new HashMap<>(); + functions.put(compileJsFunctionPattern("playerEntry"), "function playerEntry(eim, player) {}"); + functions.put(compileJsFunctionPattern("playerExit"), "function playerExit(eim, player) {}"); + functions.put(compileJsFunctionPattern("scheduledTimeout"), "function scheduledTimeout(eim) {}"); + functions.put(compileJsFunctionPattern("playerUnregistered"), "function playerUnregistered(eim, player) {}"); + functions.put(compileJsFunctionPattern("changedLeader"), "function changedLeader(eim, leader) {}"); + functions.put(compileJsFunctionPattern("monsterKilled"), "function monsterKilled(mob, eim) {}"); + functions.put(compileJsFunctionPattern("allMonstersDead"), "function allMonstersDead(eim) {}"); + functions.put(compileJsFunctionPattern("playerDisconnected"), "function playerDisconnected(eim, player) {}"); + functions.put(compileJsFunctionPattern("monsterValue"), "function monsterValue(eim, mobid) {return 0;}"); + functions.put(compileJsFunctionPattern("dispose"), "function dispose() {}"); + functions.put(compileJsFunctionPattern("leftParty"), "function leftParty(eim, player) {}"); + functions.put(compileJsFunctionPattern("disbandParty"), "function disbandParty(eim, player) {}"); + functions.put(compileJsFunctionPattern("clearPQ"), "function clearPQ(eim) {}"); + functions.put(compileJsFunctionPattern("afterSetup"), "function afterSetup(eim) {}"); + functions.put(compileJsFunctionPattern("cancelSchedule"), "function cancelSchedule() {}"); + functions.put(compileJsFunctionPattern("setup"), "function setup(eim, leaderid) {}"); + //put(compileJsFunctionPattern("getEligibleParty"), "function getEligibleParty(party) {}"); not really needed + return functions; + } + + public static void main(String[] args) { + filterDirectorySearchMatchingData(ToolConstants.SCRIPTS_PATH + "/event", getFunctions()); + } + +} diff --git a/tools/MapleEventMethodFiller/src/mapleeventmethodfiller/MapleEventMethodFiller.java b/tools/MapleEventMethodFiller/src/mapleeventmethodfiller/MapleEventMethodFiller.java deleted file mode 100644 index d051511efc..0000000000 --- a/tools/MapleEventMethodFiller/src/mapleeventmethodfiller/MapleEventMethodFiller.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ -package mapleeventmethodfiller; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.commons.io.FileUtils; - -/** - * - * @author RonanLana - * - This application objective is to read all scripts from the event folder - and fill empty functions for every function name not yet present in the - script. - - Estimated parse time: 10 seconds - */ -public class MapleEventMethodFiller { - - private static boolean foundMatchingDataOnFile(String fileContent, Pattern pattern) { - Matcher matcher = pattern.matcher(fileContent); - return matcher.find(); - } - - private static void fileSearchMatchingData(File file, Map functions) { - try { - String fileContent = FileUtils.readFileToString(file, "UTF-8"); - List fillFunctions = new LinkedList<>(); - - for(Entry f : functions.entrySet()) { - if(!foundMatchingDataOnFile(fileContent, f.getKey())) { - fillFunctions.add(f.getValue()); - } - } - - if (!fillFunctions.isEmpty()) { - System.out.println("Filling out " + file.getName() + "..."); - - FileWriter fileWriter = new FileWriter(file, true); - PrintWriter printWriter = new PrintWriter(fileWriter); - - printWriter.println(); - printWriter.println(); - printWriter.println("// ---------- FILLER FUNCTIONS ----------"); - printWriter.println(); - - for (String s : fillFunctions) { - printWriter.println(s); - printWriter.println(); - } - - printWriter.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static void filterDirectorySearchMatchingData(String directoryPath, Map functions) { - Iterator iter = FileUtils.iterateFiles(new File(directoryPath), new String[]{"sql", "js", "txt","java"}, true); - - while(iter.hasNext()) { - File file = (File) iter.next(); - fileSearchMatchingData(file, functions); - } - } - - private static String jsFunction = "function(\\s)+"; - - private static Pattern compileJsFunctionPattern(String function) { - return Pattern.compile(jsFunction + function); - } - - public static final Map functions = new HashMap(17) {{ - put(compileJsFunctionPattern("playerEntry"), "function playerEntry(eim, player) {}"); - put(compileJsFunctionPattern("playerExit"), "function playerExit(eim, player) {}"); - put(compileJsFunctionPattern("scheduledTimeout"), "function scheduledTimeout(eim) {}"); - put(compileJsFunctionPattern("playerUnregistered"), "function playerUnregistered(eim, player) {}"); - put(compileJsFunctionPattern("changedLeader"), "function changedLeader(eim, leader) {}"); - put(compileJsFunctionPattern("monsterKilled"), "function monsterKilled(mob, eim) {}"); - put(compileJsFunctionPattern("allMonstersDead"), "function allMonstersDead(eim) {}"); - put(compileJsFunctionPattern("playerDisconnected"), "function playerDisconnected(eim, player) {}"); - put(compileJsFunctionPattern("monsterValue"), "function monsterValue(eim, mobid) {return 0;}"); - put(compileJsFunctionPattern("dispose"), "function dispose() {}"); - put(compileJsFunctionPattern("leftParty"), "function leftParty(eim, player) {}"); - put(compileJsFunctionPattern("disbandParty"), "function disbandParty(eim, player) {}"); - put(compileJsFunctionPattern("clearPQ"), "function clearPQ(eim) {}"); - put(compileJsFunctionPattern("afterSetup"), "function afterSetup(eim) {}"); - put(compileJsFunctionPattern("cancelSchedule"), "function cancelSchedule() {}"); - put(compileJsFunctionPattern("setup"), "function setup(eim, leaderid) {}"); - //put(compileJsFunctionPattern("getEligibleParty"), "function getEligibleParty(party) {}"); not really needed - }}; - - public static void main(String[] args) { - filterDirectorySearchMatchingData("../../scripts/event", functions); - } - -}