This commit is contained in:
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public class DateRange
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(DateRange.class.getName());
|
||||
private final Date _startDate, _endDate;
|
||||
|
||||
public DateRange(Date from, Date to)
|
||||
{
|
||||
_startDate = from;
|
||||
_endDate = to;
|
||||
}
|
||||
|
||||
public static DateRange parse(String dateRange, DateFormat format)
|
||||
{
|
||||
final String[] date = dateRange.split("-");
|
||||
if (date.length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new DateRange(format.parse(date[0]), format.parse(date[1]));
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Invalid Date Format.", e);
|
||||
}
|
||||
}
|
||||
return new DateRange(null, null);
|
||||
}
|
||||
|
||||
public boolean isValid()
|
||||
{
|
||||
return (_startDate != null) && (_endDate != null) && _startDate.before(_endDate);
|
||||
}
|
||||
|
||||
public boolean isWithinRange(Date date)
|
||||
{
|
||||
return (date.equals(_startDate) || date.after(_startDate)) //
|
||||
&& (date.equals(_endDate) || date.before(_endDate));
|
||||
}
|
||||
|
||||
public Date getEndDate()
|
||||
{
|
||||
return _endDate;
|
||||
}
|
||||
|
||||
public Date getStartDate()
|
||||
{
|
||||
return _startDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "DateRange: From: " + getStartDate() + " To: " + getEndDate();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public interface EngineInterface
|
||||
{
|
||||
void addEventDrop(int[] items, int[] count, double chance, DateRange range);
|
||||
|
||||
void onPlayerLogin(String message, DateRange range);
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
/**
|
||||
* @author Zoey76
|
||||
*/
|
||||
public class EventDrop
|
||||
{
|
||||
private final int[] _itemIdList;
|
||||
private final long _minCount;
|
||||
private final long _maxCount;
|
||||
private final int _dropChance;
|
||||
|
||||
public EventDrop(int[] itemIdList, long min, long max, int dropChance)
|
||||
{
|
||||
_itemIdList = itemIdList;
|
||||
_minCount = min;
|
||||
_maxCount = max;
|
||||
_dropChance = dropChance;
|
||||
}
|
||||
|
||||
public EventDrop(int itemId, long minCount, long maxCount, int dropChance)
|
||||
{
|
||||
_itemIdList = new int[]
|
||||
{
|
||||
itemId
|
||||
};
|
||||
_minCount = minCount;
|
||||
_maxCount = maxCount;
|
||||
_dropChance = dropChance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _itemId
|
||||
*/
|
||||
public int[] getItemIdList()
|
||||
{
|
||||
return _itemIdList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _minCount
|
||||
*/
|
||||
public long getMinCount()
|
||||
{
|
||||
return _minCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _maxCount
|
||||
*/
|
||||
public long getMaxCount()
|
||||
{
|
||||
return _maxCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _dropChance
|
||||
*/
|
||||
public int getDropChance()
|
||||
{
|
||||
return _dropChance;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
|
||||
public class Expression
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(Expression.class.getName());
|
||||
private final ScriptContext _context;
|
||||
@SuppressWarnings("unused")
|
||||
private final String _lang;
|
||||
@SuppressWarnings("unused")
|
||||
private final String _code;
|
||||
|
||||
public static Expression create(ScriptContext context, String lang, String code)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Expression(context, lang, code);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Expression(ScriptContext pContext, String pLang, String pCode)
|
||||
{
|
||||
_context = pContext;
|
||||
_lang = pLang;
|
||||
_code = pCode;
|
||||
}
|
||||
|
||||
public <T> void addDynamicVariable(String name, T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.setAttribute(name, value, ScriptContext.ENGINE_SCOPE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDynamicVariable(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.removeAttribute(name, ScriptContext.ENGINE_SCOPE);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public class IntList
|
||||
{
|
||||
public static int[] parse(String range)
|
||||
{
|
||||
if (range.contains("-"))
|
||||
{
|
||||
return getIntegerRange(range.split("-"));
|
||||
}
|
||||
else if (range.contains(","))
|
||||
{
|
||||
return getIntegerList(range.split(","));
|
||||
}
|
||||
|
||||
final int[] list =
|
||||
{
|
||||
getInt(range)
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
private static int getInt(String number)
|
||||
{
|
||||
return Integer.parseInt(number);
|
||||
}
|
||||
|
||||
private static int[] getIntegerList(String[] numbers)
|
||||
{
|
||||
final int[] list = new int[numbers.length];
|
||||
for (int i = 0; i < list.length; i++)
|
||||
{
|
||||
list[i] = getInt(numbers[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static int[] getIntegerRange(String[] numbers)
|
||||
{
|
||||
final int min = getInt(numbers[0]);
|
||||
final int max = getInt(numbers[1]);
|
||||
final int[] list = new int[(max - min) + 1];
|
||||
for (int i = 0; i < list.length; i++)
|
||||
{
|
||||
list[i] = min + i;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public abstract class Parser
|
||||
{
|
||||
public abstract void parseScript(Node node, ScriptContext context);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
public abstract class ParserFactory
|
||||
{
|
||||
public abstract Parser create();
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
public class ParserNotCreatedException extends Exception
|
||||
{
|
||||
public ParserNotCreatedException()
|
||||
{
|
||||
super("Parser could not be created!");
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ScriptDocument
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(ScriptDocument.class.getName());
|
||||
|
||||
private Document _document;
|
||||
private final String _name;
|
||||
|
||||
public ScriptDocument(String name, InputStream input)
|
||||
{
|
||||
_name = name;
|
||||
|
||||
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
try
|
||||
{
|
||||
_document = factory.newDocumentBuilder().parse(input);
|
||||
}
|
||||
catch (SAXException sxe)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + (sxe.getException() != null ? sxe.getException() : sxe).getMessage());
|
||||
}
|
||||
catch (ParserConfigurationException pce)
|
||||
{
|
||||
// Parser with specified options can't be built
|
||||
_log.log(Level.WARNING, "", pce);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
// I/O error
|
||||
_log.log(Level.WARNING, "", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public Document getDocument()
|
||||
{
|
||||
return _document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the _name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public class ScriptEngine
|
||||
{
|
||||
public static final Hashtable<String, ParserFactory> parserFactories = new Hashtable<>();
|
||||
|
||||
protected static Parser createParser(String name) throws ParserNotCreatedException
|
||||
{
|
||||
ParserFactory s = parserFactories.get(name);
|
||||
if (s == null) // shape not found
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("com.l2jmobius.gameserver.script." + name);
|
||||
// By now the static block with no function would
|
||||
// have been executed if the shape was found.
|
||||
// the shape is expected to have put its factory
|
||||
// in the hashtable.
|
||||
|
||||
s = parserFactories.get(name);
|
||||
if (s == null) // if the shape factory is not there even now
|
||||
{
|
||||
throw new ParserNotCreatedException();
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
// We'll throw an exception to indicate that
|
||||
// the shape could not be created
|
||||
throw new ParserNotCreatedException();
|
||||
}
|
||||
}
|
||||
return s.create();
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
|
||||
/**
|
||||
* @author Luis Arias
|
||||
*/
|
||||
public class ScriptPackage
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(ScriptPackage.class.getName());
|
||||
|
||||
private final List<ScriptDocument> _scriptFiles = new ArrayList<>();
|
||||
private final List<String> _otherFiles = new ArrayList<>();
|
||||
private final String _name;
|
||||
|
||||
public ScriptPackage(ZipFile pack)
|
||||
{
|
||||
_name = pack.getName();
|
||||
addFiles(pack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the otherFiles.
|
||||
*/
|
||||
public List<String> getOtherFiles()
|
||||
{
|
||||
return _otherFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the scriptFiles.
|
||||
*/
|
||||
public List<ScriptDocument> getScriptFiles()
|
||||
{
|
||||
return _scriptFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pack
|
||||
*/
|
||||
private void addFiles(ZipFile pack)
|
||||
{
|
||||
for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
|
||||
{
|
||||
final ZipEntry entry = e.nextElement();
|
||||
if (entry.getName().endsWith(".xml"))
|
||||
{
|
||||
try
|
||||
{
|
||||
_scriptFiles.add(new ScriptDocument(entry.getName(), pack.getInputStream(entry)));
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": " + io.getMessage());
|
||||
}
|
||||
}
|
||||
else if (!entry.isDirectory())
|
||||
{
|
||||
_otherFiles.add(entry.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (getScriptFiles().isEmpty() && getOtherFiles().isEmpty())
|
||||
{
|
||||
return "Empty Package.";
|
||||
}
|
||||
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("Package Name: ");
|
||||
out.append(getName());
|
||||
out.append(Config.EOL);
|
||||
|
||||
if (!getScriptFiles().isEmpty())
|
||||
{
|
||||
out.append("Xml Script Files..." + Config.EOL);
|
||||
for (ScriptDocument script : getScriptFiles())
|
||||
{
|
||||
out.append(script.getName());
|
||||
out.append(Config.EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!getOtherFiles().isEmpty())
|
||||
{
|
||||
out.append("Other Files..." + Config.EOL);
|
||||
for (String fileName : getOtherFiles())
|
||||
{
|
||||
out.append(fileName);
|
||||
out.append(Config.EOL);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.script;
|
||||
|
||||
/**
|
||||
* @author -Nemesiss-
|
||||
*/
|
||||
public class ShortList
|
||||
{
|
||||
public static short[] parse(String range)
|
||||
{
|
||||
if (range.contains("-"))
|
||||
{
|
||||
return getShortList(range.split("-"));
|
||||
}
|
||||
else if (range.contains(","))
|
||||
{
|
||||
return getShortList(range.split(","));
|
||||
}
|
||||
|
||||
final short[] list =
|
||||
{
|
||||
getShort(range)
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
private static short getShort(String number)
|
||||
{
|
||||
return Short.parseShort(number);
|
||||
}
|
||||
|
||||
private static short[] getShortList(String[] numbers)
|
||||
{
|
||||
final short[] list = new short[numbers.length];
|
||||
for (int i = 0; i < list.length; i++)
|
||||
{
|
||||
list[i] = getShort(numbers[i]);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user