Addition of Scripts.xml for easier scripts management.
Contributed by Sahar.
This commit is contained in:
29
L2J_Mobius_1.0_Ertheia/dist/game/config/Scripts.xml
vendored
Normal file
29
L2J_Mobius_1.0_Ertheia/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -48,10 +57,10 @@ public final class ScriptEngineManager
|
|||||||
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
|
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
|
||||||
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
|
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
|
||||||
public static final Path CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "ConditionMasterHandler.java");
|
public static final Path CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "ConditionMasterHandler.java");
|
||||||
public static final Path ONE_DAY_REWARD_MASTER_HANDLER = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "DailyMissionMasterHandler.java");
|
|
||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +71,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -172,11 +254,6 @@ public final class ScriptEngineManager
|
|||||||
executeScript(CONDITION_HANDLER_FILE);
|
executeScript(CONDITION_HANDLER_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeDailyMissionMasterHandler() throws Exception
|
|
||||||
{
|
|
||||||
executeScript(ONE_DAY_REWARD_MASTER_HANDLER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void executeScriptList() throws Exception
|
public void executeScriptList() throws Exception
|
||||||
{
|
{
|
||||||
if (Config.ALT_DEV_NO_QUESTS)
|
if (Config.ALT_DEV_NO_QUESTS)
|
||||||
@@ -222,17 +299,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
30
L2J_Mobius_2.5_Underground/dist/game/config/Scripts.xml
vendored
Normal file
30
L2J_Mobius_2.5_Underground/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
<exclude file="DailyMissionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_2.5_Underground/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_2.5_Underground/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -52,6 +61,7 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +72,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -222,17 +305,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
30
L2J_Mobius_3.0_Helios/dist/game/config/Scripts.xml
vendored
Normal file
30
L2J_Mobius_3.0_Helios/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
<exclude file="DailyMissionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_3.0_Helios/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_3.0_Helios/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -52,6 +61,7 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +72,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -222,17 +305,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
30
L2J_Mobius_4.0_GrandCrusade/dist/game/config/Scripts.xml
vendored
Normal file
30
L2J_Mobius_4.0_GrandCrusade/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
<exclude file="DailyMissionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -52,6 +61,7 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +72,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -222,17 +305,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
27
L2J_Mobius_CT_2.6_HighFive/dist/game/config/Scripts.xml
vendored
Normal file
27
L2J_Mobius_CT_2.6_HighFive/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_CT_2.6_HighFive/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_CT_2.6_HighFive/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,25 +39,26 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
|
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
|
||||||
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
|
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
|
||||||
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
|
|
||||||
public static final Path CONDITION_HANDLER_FILE = Paths.get(ScriptEngineManager.SCRIPT_FOLDER.toString(), "handlers", "ConditionMasterHandler.java");
|
|
||||||
public static final Path ONE_DAY_REWARD_MASTER_HANDLER = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "DailyMissionMasterHandler.java");
|
|
||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +69,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -162,21 +242,6 @@ public final class ScriptEngineManager
|
|||||||
executeScript(EFFECT_MASTER_HANDLER_FILE);
|
executeScript(EFFECT_MASTER_HANDLER_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeSkillConditionMasterHandler() throws Exception
|
|
||||||
{
|
|
||||||
executeScript(SKILL_CONDITION_HANDLER_FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void executeConditionMasterHandler() throws Exception
|
|
||||||
{
|
|
||||||
executeScript(CONDITION_HANDLER_FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void executeDailyMissionMasterHandler() throws Exception
|
|
||||||
{
|
|
||||||
executeScript(ONE_DAY_REWARD_MASTER_HANDLER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void executeScriptList() throws Exception
|
public void executeScriptList() throws Exception
|
||||||
{
|
{
|
||||||
if (Config.ALT_DEV_NO_QUESTS)
|
if (Config.ALT_DEV_NO_QUESTS)
|
||||||
@@ -222,17 +287,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
30
L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Scripts.xml
vendored
Normal file
30
L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
<exclude file="DailyMissionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -52,6 +61,7 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +72,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -222,17 +305,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
30
L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Scripts.xml
vendored
Normal file
30
L2J_Mobius_Classic_2.0_Zaken/dist/game/config/Scripts.xml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../data/xsd/Scripts.xsd">
|
||||||
|
<!-- Skip these filenames from script loading, because they are already loaded using a different way. -->
|
||||||
|
<exclude file="package-info.java" />
|
||||||
|
<exclude file="MasterHandler.java" />
|
||||||
|
<exclude file="EffectMasterHandler.java" />
|
||||||
|
<exclude file="SkillConditionMasterHandler.java" />
|
||||||
|
<exclude file="ConditionMasterHandler.java" />
|
||||||
|
<exclude file="DailyMissionMasterHandler.java" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
With this file you can exclude/include specific folders/files from within the scripts directory.
|
||||||
|
|
||||||
|
In order to exclude a folder/file simply add the following line:
|
||||||
|
<exclude file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
For example to exclude the quests directory, use:
|
||||||
|
<exclude file="quests" />
|
||||||
|
|
||||||
|
If you want to exclude all files within a directory except certain file(s), you can do it like so:
|
||||||
|
<exclude file="{FOLDER NAME HERE}">
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
<include file="{FOLDER/FILE NAME HERE}" />
|
||||||
|
...
|
||||||
|
</exclude>
|
||||||
|
For example to exclude ForgeOfTheGods folder except Valakas script, use:
|
||||||
|
<exclude file="ForgeOfTheGods">
|
||||||
|
<include file="Valakas.java" />
|
||||||
|
</exclude>
|
||||||
|
-->
|
||||||
|
</list>
|
21
L2J_Mobius_Classic_2.0_Zaken/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
21
L2J_Mobius_Classic_2.0_Zaken/dist/game/data/xsd/Scripts.xsd
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<xs:element name="list">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="exclude" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="include" minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="file" type="xs:string" use="required" />
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
@@ -18,10 +18,16 @@ package com.l2jmobius.gameserver.scripting;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,14 +39,17 @@ import java.util.ServiceLoader;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
|
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||||
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches script engines and provides functionality for executing and managing scripts.
|
* Caches script engines and provides functionality for executing and managing scripts.
|
||||||
* @author KenM, HorridoJoho
|
* @author KenM, HorridoJoho
|
||||||
*/
|
*/
|
||||||
public final class ScriptEngineManager
|
public final class ScriptEngineManager implements IGameXmlReader
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
|
||||||
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
|
||||||
@@ -52,6 +61,7 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
private final Map<String, IExecutionContext> _extEngines = new HashMap<>();
|
||||||
private IExecutionContext _currentExecutionContext = null;
|
private IExecutionContext _currentExecutionContext = null;
|
||||||
|
static final List<String> _exclusions = new ArrayList<>();
|
||||||
|
|
||||||
protected ScriptEngineManager()
|
protected ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@@ -62,6 +72,79 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
// Load external script engines
|
// Load external script engines
|
||||||
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
ServiceLoader.load(IScriptingEngine.class).forEach(engine -> registerEngine(engine, props));
|
||||||
|
|
||||||
|
// Load Scripts.xml
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
_exclusions.clear();
|
||||||
|
parseDatapackFile("config/Scripts.xml");
|
||||||
|
LOGGER.info("Loaded " + _exclusions.size() + " files to exclude.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parseDocument(Document doc, File f)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Map<String, List<String>> excludePaths = new HashMap<>();
|
||||||
|
forEach(doc, "list", listNode -> forEach(listNode, "exclude", excludeNode ->
|
||||||
|
{
|
||||||
|
final String excludeFile = parseString(excludeNode.getAttributes(), "file");
|
||||||
|
excludePaths.putIfAbsent(excludeFile, new ArrayList<>());
|
||||||
|
|
||||||
|
forEach(excludeNode, "include", includeNode -> excludePaths.get(excludeFile).add(parseString(includeNode.getAttributes(), "file")));
|
||||||
|
}));
|
||||||
|
|
||||||
|
final int nameCount = SCRIPT_FOLDER.getNameCount();
|
||||||
|
Files.walkFileTree(SCRIPT_FOLDER, new SimpleFileVisitor<Path>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
||||||
|
{
|
||||||
|
final String fileName = file.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".java"))
|
||||||
|
{
|
||||||
|
final Iterator<Path> relativePath = file.subpath(nameCount, file.getNameCount()).iterator();
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
final String nextPart = relativePath.next().toString();
|
||||||
|
if (excludePaths.containsKey(nextPart))
|
||||||
|
{
|
||||||
|
boolean excludeScript = true;
|
||||||
|
|
||||||
|
final List<String> includePath = excludePaths.get(nextPart);
|
||||||
|
if (includePath != null)
|
||||||
|
{
|
||||||
|
while (relativePath.hasNext())
|
||||||
|
{
|
||||||
|
if (includePath.contains(relativePath.next().toString()))
|
||||||
|
{
|
||||||
|
excludeScript = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (excludeScript)
|
||||||
|
{
|
||||||
|
_exclusions.add(fileName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (final IOException e)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, "Couldn't load script exclusions.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties loadProperties()
|
private Properties loadProperties()
|
||||||
@@ -222,17 +305,9 @@ public final class ScriptEngineManager
|
|||||||
|
|
||||||
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
private void processFile(File file, Map<IExecutionContext, List<Path>> files)
|
||||||
{
|
{
|
||||||
switch (file.getName())
|
if (_exclusions.contains(file.getName()))
|
||||||
{
|
{
|
||||||
case "package-info.java":
|
return;
|
||||||
case "MasterHandler.java":
|
|
||||||
case "EffectMasterHandler.java":
|
|
||||||
case "SkillConditionMasterHandler.java":
|
|
||||||
case "ConditionMasterHandler.java":
|
|
||||||
case "DailyMissionMasterHandler.java":
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path sourceFile = file.toPath();
|
Path sourceFile = file.toPath();
|
||||||
|
Reference in New Issue
Block a user