Code improvements.

This commit is contained in:
MobiusDev
2016-04-24 16:30:15 +00:00
parent 8bd51aba1c
commit 2dd14bef9b
860 changed files with 8865 additions and 17041 deletions

View File

@ -321,170 +321,77 @@ public class AugmentationData
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
final File aFile = new File(Config.DATAPACK_ROOT + "/stats/augmentation/retailchances.xml");
if (aFile.exists())
{
Document aDoc = null;
try
{
aDoc = factory.newDocumentBuilder().parse(aFile);
}
catch (Exception e)
{
e.printStackTrace();
return;
}
String aWeaponType = null;
int aStoneId = 0;
int aVariationId = 0;
int aCategoryChance = 0;
int aAugmentId = 0;
float aAugmentChance = 0;
for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
{
if (l.getNodeName().equals("list"))
{
NamedNodeMap aNodeAttributes = null;
for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
{
if (n.getNodeName().equals("weapon"))
{
aNodeAttributes = n.getAttributes();
aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
{
if (c.getNodeName().equals("stone"))
{
aNodeAttributes = c.getAttributes();
aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
{
if (v.getNodeName().equals("variation"))
{
aNodeAttributes = v.getAttributes();
aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
{
if (j.getNodeName().equals("category"))
{
aNodeAttributes = j.getAttributes();
aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
{
if (e.getNodeName().equals("augment"))
{
aNodeAttributes = e.getAttributes();
aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
_augmentationChances.add(new AugmentationChance(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
}
}
}
}
}
}
}
}
}
}
}
}
}
else
if (!aFile.exists())
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The retailchances.xml data file is missing.");
return;
}
}
if (Config.RETAIL_LIKE_AUGMENTATION_ACCESSORY)
{
final DocumentBuilderFactory factory3 = DocumentBuilderFactory.newInstance();
factory3.setValidating(false);
factory3.setIgnoringComments(true);
final File aFile3 = new File(Config.DATAPACK_ROOT + "/stats/augmentation/retailchances_accessory.xml");
if (aFile3.exists())
Document aDoc = null;
try
{
Document aDoc = null;
try
aDoc = factory.newDocumentBuilder().parse(aFile);
}
catch (Exception e)
{
e.printStackTrace();
return;
}
String aWeaponType = null;
int aStoneId = 0;
int aVariationId = 0;
int aCategoryChance = 0;
int aAugmentId = 0;
float aAugmentChance = 0;
for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
{
if (l.getNodeName().equals("list"))
{
aDoc = factory3.newDocumentBuilder().parse(aFile3);
}
catch (Exception e)
{
e.printStackTrace();
return;
}
String aWeaponType = null;
int aStoneId = 0;
int aVariationId = 0;
int aCategoryChance = 0;
int aAugmentId = 0;
float aAugmentChance = 0;
for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
{
if (l.getNodeName().equals("list"))
NamedNodeMap aNodeAttributes = null;
for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
{
NamedNodeMap aNodeAttributes = null;
for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
if (n.getNodeName().equals("weapon"))
{
if (n.getNodeName().equals("weapon"))
aNodeAttributes = n.getAttributes();
aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
{
aNodeAttributes = n.getAttributes();
aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
if (c.getNodeName().equals("stone"))
{
if (c.getNodeName().equals("stone"))
aNodeAttributes = c.getAttributes();
aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
{
aNodeAttributes = c.getAttributes();
aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
if (v.getNodeName().equals("variation"))
{
if (v.getNodeName().equals("variation"))
aNodeAttributes = v.getAttributes();
aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
{
aNodeAttributes = v.getAttributes();
aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
if (j.getNodeName().equals("category"))
{
if (j.getNodeName().equals("category"))
aNodeAttributes = j.getAttributes();
aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
{
aNodeAttributes = j.getAttributes();
aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
if (e.getNodeName().equals("augment"))
{
if (e.getNodeName().equals("augment"))
{
aNodeAttributes = e.getAttributes();
aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
_augmentationChancesAcc.add(new augmentationChanceAcc(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
}
aNodeAttributes = e.getAttributes();
aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
_augmentationChances.add(new AugmentationChance(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
}
}
}
@ -497,10 +404,94 @@ public class AugmentationData
}
}
}
else
}
if (!Config.RETAIL_LIKE_AUGMENTATION_ACCESSORY)
{
return;
}
final DocumentBuilderFactory factory3 = DocumentBuilderFactory.newInstance();
factory3.setValidating(false);
factory3.setIgnoringComments(true);
final File aFile3 = new File(Config.DATAPACK_ROOT + "/stats/augmentation/retailchances_accessory.xml");
if (!aFile3.exists())
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The retailchances_accessory.xml data file is missing.");
return;
}
Document aDoc = null;
try
{
aDoc = factory3.newDocumentBuilder().parse(aFile3);
}
catch (Exception e)
{
e.printStackTrace();
return;
}
String aWeaponType = null;
int aStoneId = 0;
int aVariationId = 0;
int aCategoryChance = 0;
int aAugmentId = 0;
float aAugmentChance = 0;
for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
{
if (l.getNodeName().equals("list"))
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The retailchances_accessory.xml data file is missing.");
return;
NamedNodeMap aNodeAttributes = null;
for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
{
if (n.getNodeName().equals("weapon"))
{
aNodeAttributes = n.getAttributes();
aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
{
if (c.getNodeName().equals("stone"))
{
aNodeAttributes = c.getAttributes();
aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
{
if (v.getNodeName().equals("variation"))
{
aNodeAttributes = v.getAttributes();
aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
{
if (j.getNodeName().equals("category"))
{
aNodeAttributes = j.getAttributes();
aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
{
if (e.getNodeName().equals("augment"))
{
aNodeAttributes = e.getAttributes();
aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
_augmentationChancesAcc.add(new augmentationChanceAcc(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
}
}
}
}
}
}
}
}
}
}
}
}
}

View File

@ -29,7 +29,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
@ -75,32 +74,33 @@ public final class BotReportTable
BotReportTable()
{
if (Config.BOTREPORT_ENABLE)
if (!Config.BOTREPORT_ENABLE)
{
_ipRegistry = new HashMap<>();
_charRegistry = new ConcurrentHashMap<>();
_reports = new ConcurrentHashMap<>();
_punishments = new ConcurrentHashMap<>();
try
{
final File punishments = new File("./config/BotReportPunishments.xml");
if (!punishments.exists())
{
throw new FileNotFoundException(punishments.getName());
}
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(punishments, new PunishmentsLoader());
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "BotReportTable: Could not load punishments from /config/BotReportPunishments.xml", e);
}
loadReportedCharData();
scheduleResetPointTask();
return;
}
_ipRegistry = new HashMap<>();
_charRegistry = new ConcurrentHashMap<>();
_reports = new ConcurrentHashMap<>();
_punishments = new ConcurrentHashMap<>();
try
{
final File punishments = new File("./config/BotReportPunishments.xml");
if (!punishments.exists())
{
throw new FileNotFoundException(punishments.getName());
}
SAXParserFactory.newInstance().newSAXParser().parse(punishments, new PunishmentsLoader());
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "BotReportTable: Could not load punishments from /config/BotReportPunishments.xml", e);
}
loadReportedCharData();
scheduleResetPointTask();
}
/**
@ -186,12 +186,11 @@ public final class BotReportTable
for (Map.Entry<Integer, ReportedCharData> entrySet : _reports.entrySet())
{
final Map<Integer, Long> reportTable = entrySet.getValue()._reporters;
for (int reporterId : reportTable.keySet())
for (int reporterId : entrySet.getValue()._reporters.keySet())
{
ps.setInt(1, entrySet.getKey());
ps.setInt(2, reporterId);
ps.setLong(3, reportTable.get(reporterId));
ps.setLong(3, entrySet.getValue()._reporters.get(reporterId));
ps.execute();
}
}
@ -360,17 +359,19 @@ public final class BotReportTable
*/
private void punishBot(L2PcInstance bot, PunishHolder ph)
{
if (ph != null)
if (ph == null)
{
ph._punish.applyEffects(bot, bot);
if (ph._systemMessageId > -1)
{
final SystemMessageId id = SystemMessageId.getSystemMessageId(ph._systemMessageId);
if (id != null)
{
bot.sendPacket(id);
}
}
return;
}
ph._punish.applyEffects(bot, bot);
if (ph._systemMessageId <= -1)
{
return;
}
final SystemMessageId id = SystemMessageId.getSystemMessageId(ph._systemMessageId);
if (id != null)
{
bot.sendPacket(id);
}
}
@ -461,11 +462,7 @@ public final class BotReportTable
*/
private static boolean timeHasPassed(Map<Integer, Long> map, int objectId)
{
if (map.containsKey(objectId))
{
return (System.currentTimeMillis() - map.get(objectId)) > Config.BOTREPORT_REPORT_DELAY;
}
return true;
return !map.containsKey(objectId) || ((System.currentTimeMillis() - map.get(objectId)) > Config.BOTREPORT_REPORT_DELAY);
}
/**
@ -562,32 +559,33 @@ public final class BotReportTable
@Override
public void startElement(String uri, String localName, String qName, Attributes attr)
{
if (qName.equals("punishment"))
if (!qName.equals("punishment"))
{
int reportCount = -1, skillId = -1, skillLevel = 1, sysMessage = -1;
try
return;
}
int reportCount = -1, skillId = -1, skillLevel = 1, sysMessage = -1;
try
{
reportCount = Integer.parseInt(attr.getValue("neededReportCount"));
skillId = Integer.parseInt(attr.getValue("skillId"));
final String level = attr.getValue("skillLevel");
final String systemMessageId = attr.getValue("sysMessageId");
if (level != null)
{
reportCount = Integer.parseInt(attr.getValue("neededReportCount"));
skillId = Integer.parseInt(attr.getValue("skillId"));
final String level = attr.getValue("skillLevel");
final String systemMessageId = attr.getValue("sysMessageId");
if (level != null)
{
skillLevel = Integer.parseInt(level);
}
if (systemMessageId != null)
{
sysMessage = Integer.parseInt(systemMessageId);
}
}
catch (Exception e)
{
e.printStackTrace();
skillLevel = Integer.parseInt(level);
}
addPunishment(reportCount, skillId, skillLevel, sysMessage);
if (systemMessageId != null)
{
sysMessage = Integer.parseInt(systemMessageId);
}
}
catch (Exception e)
{
e.printStackTrace();
}
addPunishment(reportCount, skillId, skillLevel, sysMessage);
}
}

View File

@ -188,12 +188,7 @@ public class ItemTable
*/
public L2Item getTemplate(int id)
{
if ((id >= _allTemplates.length) || (id < 0))
{
return null;
}
return _allTemplates[id];
return (id >= _allTemplates.length) || (id < 0) ? null : _allTemplates[id];
}
/**
@ -218,11 +213,9 @@ public class ItemTable
ScheduledFuture<?> itemLootShedule;
if ((reference instanceof L2Attackable) && ((L2Attackable) reference).isRaid()) // loot privilege for raids
{
final L2Attackable raid = (L2Attackable) reference;
// if in CommandChannel and was killing a World/RaidBoss
if ((raid.getFirstCommandChannelAttacked() != null) && !Config.AUTO_LOOT_RAIDS)
if ((((L2Attackable) reference).getFirstCommandChannelAttacked() != null) && !Config.AUTO_LOOT_RAIDS)
{
item.setOwnerId(raid.getFirstCommandChannelAttacked().getLeaderObjectId());
item.setOwnerId(((L2Attackable) reference).getFirstCommandChannelAttacked().getLeaderObjectId());
itemLootShedule = ThreadPoolManager.getInstance().scheduleGeneral(new ResetOwner(item), Config.LOOT_RAIDS_PRIVILEGE_INTERVAL);
item.setItemLootShedule(itemLootShedule);
}
@ -249,40 +242,33 @@ public class ItemTable
item.setCount(count);
}
if (Config.LOG_ITEMS && !process.equals("Reset"))
if (Config.LOG_ITEMS && !process.equals("Reset") && (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || (item.getId() == ADENA_ID)))))
{
if (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || (item.getId() == ADENA_ID))))
final LogRecord record = new LogRecord(Level.INFO, "CREATE:" + process);
record.setLoggerName("item");
record.setParameters(new Object[]
{
final LogRecord record = new LogRecord(Level.INFO, "CREATE:" + process);
record.setLoggerName("item");
record.setParameters(new Object[]
{
item,
actor,
reference
});
LOGGER_ITEMS.log(record);
}
item,
actor,
reference
});
LOGGER_ITEMS.log(record);
}
if (actor != null)
if ((actor != null) && actor.isGM())
{
if (actor.isGM())
String referenceName = "no-reference";
if (reference instanceof L2Object)
{
String referenceName = "no-reference";
if (reference instanceof L2Object)
{
referenceName = (((L2Object) reference).getName() != null ? ((L2Object) reference).getName() : "no-name");
}
else if (reference instanceof String)
{
referenceName = (String) reference;
}
final String targetName = (actor.getTarget() != null ? actor.getTarget().getName() : "no-target");
if (Config.GMAUDIT)
{
GMAudit.auditGMAction(actor.getName() + " [" + actor.getObjectId() + "]", process + "(id: " + itemId + " count: " + count + " name: " + item.getItemName() + " objId: " + item.getObjectId() + ")", targetName, "L2Object referencing this action is: " + referenceName);
}
referenceName = (((L2Object) reference).getName() != null ? ((L2Object) reference).getName() : "no-name");
}
else if (reference instanceof String)
{
referenceName = (String) reference;
}
if (Config.GMAUDIT)
{
GMAudit.auditGMAction(actor.getName() + " [" + actor.getObjectId() + "]", process + "(id: " + itemId + " count: " + count + " name: " + item.getItemName() + " objId: " + item.getObjectId() + ")", (actor.getTarget() != null ? actor.getTarget().getName() : "no-target"), "L2Object referencing this action is: " + referenceName);
}
}
@ -322,41 +308,34 @@ public class ItemTable
L2World.getInstance().removeObject(item);
IdFactory.getInstance().releaseId(item.getObjectId());
if (Config.LOG_ITEMS)
if (Config.LOG_ITEMS && (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || (item.getId() == ADENA_ID)))))
{
if (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || (item.getId() == ADENA_ID))))
final LogRecord record = new LogRecord(Level.INFO, "DELETE:" + process);
record.setLoggerName("item");
record.setParameters(new Object[]
{
final LogRecord record = new LogRecord(Level.INFO, "DELETE:" + process);
record.setLoggerName("item");
record.setParameters(new Object[]
{
item,
"PrevCount(" + old + ")",
actor,
reference
});
LOGGER_ITEMS.log(record);
}
item,
"PrevCount(" + old + ")",
actor,
reference
});
LOGGER_ITEMS.log(record);
}
if (actor != null)
if ((actor != null) && actor.isGM())
{
if (actor.isGM())
String referenceName = "no-reference";
if (reference instanceof L2Object)
{
String referenceName = "no-reference";
if (reference instanceof L2Object)
{
referenceName = (((L2Object) reference).getName() != null ? ((L2Object) reference).getName() : "no-name");
}
else if (reference instanceof String)
{
referenceName = (String) reference;
}
final String targetName = (actor.getTarget() != null ? actor.getTarget().getName() : "no-target");
if (Config.GMAUDIT)
{
GMAudit.auditGMAction(actor.getName() + " [" + actor.getObjectId() + "]", process + "(id: " + item.getId() + " count: " + item.getCount() + " itemObjId: " + item.getObjectId() + ")", targetName, "L2Object referencing this action is: " + referenceName);
}
referenceName = (((L2Object) reference).getName() != null ? ((L2Object) reference).getName() : "no-name");
}
else if (reference instanceof String)
{
referenceName = (String) reference;
}
if (Config.GMAUDIT)
{
GMAudit.auditGMAction(actor.getName() + " [" + actor.getObjectId() + "]", process + "(id: " + item.getId() + " count: " + item.getCount() + " itemObjId: " + item.getObjectId() + ")", (actor.getTarget() != null ? actor.getTarget().getName() : "no-target"), "L2Object referencing this action is: " + referenceName);
}
}

View File

@ -77,84 +77,87 @@ public class MerchantPriceConfigTable implements InstanceListManager
factory.setValidating(false);
factory.setIgnoringComments(true);
final File file = new File(Config.DATAPACK_ROOT + "/" + MPCS_FILE);
if (file.exists())
if (!file.exists())
{
int defaultPriceConfigId;
final Document doc = factory.newDocumentBuilder().parse(file);
Node n = doc.getDocumentElement();
final Node dpcNode = n.getAttributes().getNamedItem("defaultPriceConfig");
if (dpcNode == null)
{
throw new IllegalStateException("merchantPriceConfig must define an 'defaultPriceConfig'");
}
defaultPriceConfigId = Integer.parseInt(dpcNode.getNodeValue());
MerchantPriceConfig mpc;
for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
{
mpc = parseMerchantPriceConfig(n);
if (mpc != null)
{
_mpcs.put(mpc.getId(), mpc);
}
}
final MerchantPriceConfig defaultMpc = this.getMerchantPriceConfig(defaultPriceConfigId);
if (defaultMpc == null)
{
throw new IllegalStateException("'defaultPriceConfig' points to an non-loaded priceConfig");
}
_defaultMpc = defaultMpc;
return;
}
int defaultPriceConfigId;
final Document doc = factory.newDocumentBuilder().parse(file);
Node n = doc.getDocumentElement();
final Node dpcNode = n.getAttributes().getNamedItem("defaultPriceConfig");
if (dpcNode == null)
{
throw new IllegalStateException("merchantPriceConfig must define an 'defaultPriceConfig'");
}
defaultPriceConfigId = Integer.parseInt(dpcNode.getNodeValue());
MerchantPriceConfig mpc;
for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
{
mpc = parseMerchantPriceConfig(n);
if (mpc != null)
{
_mpcs.put(mpc.getId(), mpc);
}
}
final MerchantPriceConfig defaultMpc = this.getMerchantPriceConfig(defaultPriceConfigId);
if (defaultMpc == null)
{
throw new IllegalStateException("'defaultPriceConfig' points to an non-loaded priceConfig");
}
_defaultMpc = defaultMpc;
}
private MerchantPriceConfig parseMerchantPriceConfig(Node n)
{
if (n.getNodeName().equals("priceConfig"))
if (!n.getNodeName().equals("priceConfig"))
{
final int id;
final int baseTax;
int castleId = -1;
int zoneId = -1;
final String name;
Node node = n.getAttributes().getNamedItem("id");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'id'");
}
id = Integer.parseInt(node.getNodeValue());
node = n.getAttributes().getNamedItem("name");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'name'");
}
name = node.getNodeValue();
node = n.getAttributes().getNamedItem("baseTax");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'baseTax'");
}
baseTax = Integer.parseInt(node.getNodeValue());
node = n.getAttributes().getNamedItem("castleId");
if (node != null)
{
castleId = Integer.parseInt(node.getNodeValue());
}
node = n.getAttributes().getNamedItem("zoneId");
if (node != null)
{
zoneId = Integer.parseInt(node.getNodeValue());
}
return new MerchantPriceConfig(id, name, baseTax, castleId, zoneId);
return null;
}
return null;
final int id;
final int baseTax;
int castleId = -1;
int zoneId = -1;
final String name;
Node node = n.getAttributes().getNamedItem("id");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'id'");
}
id = Integer.parseInt(node.getNodeValue());
node = n.getAttributes().getNamedItem("name");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'name'");
}
name = node.getNodeValue();
node = n.getAttributes().getNamedItem("baseTax");
if (node == null)
{
throw new IllegalStateException("Must define the priceConfig 'baseTax'");
}
baseTax = Integer.parseInt(node.getNodeValue());
node = n.getAttributes().getNamedItem("castleId");
if (node != null)
{
castleId = Integer.parseInt(node.getNodeValue());
}
node = n.getAttributes().getNamedItem("zoneId");
if (node != null)
{
zoneId = Integer.parseInt(node.getNodeValue());
}
return new MerchantPriceConfig(id, name, baseTax, castleId, zoneId);
}
@Override

View File

@ -46,16 +46,17 @@ public class NpcPersonalAIData
*/
public void storeData(L2Spawn spawnDat, Map<String, Integer> data)
{
if ((data != null) && !data.isEmpty())
if ((data == null) || data.isEmpty())
{
// check for spawn name. Since spawn name is key for AI Data, generate random name, if spawn name isn't specified
if (spawnDat.getName() == null)
{
spawnDat.setName(Long.toString(Rnd.nextLong()));
}
_AIData.put(spawnDat.getName(), data);
return;
}
if (spawnDat.getName() == null)
{
spawnDat.setName(Long.toString(Rnd.nextLong()));
}
_AIData.put(spawnDat.getName(), data);
}
/**
@ -88,34 +89,36 @@ public class NpcPersonalAIData
*/
public void initializeNpcParameters(L2Npc npc, L2Spawn spawn, String spawnName)
{
if (_AIData.containsKey(spawnName))
if (!_AIData.containsKey(spawnName))
{
final Map<String, Integer> map = _AIData.get(spawnName);
try
return;
}
final Map<String, Integer> map = _AIData.get(spawnName);
try
{
for (String key : map.keySet())
{
for (String key : map.keySet())
switch (key)
{
switch (key)
case "disableRandomAnimation":
{
case "disableRandomAnimation":
{
npc.setRandomAnimationEnabled((map.get(key) == 0));
break;
}
case "disableRandomWalk":
{
npc.setIsNoRndWalk((map.get(key) == 1));
spawn.setIsNoRndWalk((map.get(key) == 1));
break;
}
npc.setRandomAnimationEnabled((map.get(key) == 0));
break;
}
case "disableRandomWalk":
{
npc.setIsNoRndWalk((map.get(key) == 1));
spawn.setIsNoRndWalk((map.get(key) == 1));
break;
}
}
}
catch (Exception e)
{
// Do nothing
}
}
catch (Exception e)
{
// Do nothing
}
}

View File

@ -78,8 +78,7 @@ public final class SkillData
}
// only non-enchanted skills
final int maxLvl = getMaxLevel(skillId);
if (skillLvl > maxLvl)
if (skillLvl > getMaxLevel(skillId))
{
_skillMaxLevel.put(skillId, skillLvl);
}

View File

@ -64,21 +64,23 @@ public final class SpawnTable implements IXmlReader
@Override
public void load()
{
if (!Config.ALT_DEV_NO_SPAWNS)
if (Config.ALT_DEV_NO_SPAWNS)
{
fillSpawnTable(false);
final int spawnCount = _spawnTable.size();
LOGGER.info(getClass().getSimpleName() + ": Loaded " + spawnCount + " npc spawns.");
if (Config.CUSTOM_SPAWNLIST_TABLE)
{
fillSpawnTable(true);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + (_spawnTable.size() - spawnCount) + " custom npc spawns.");
}
// Load XML list
parseDatapackDirectory("spawnlist", false);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _xmlSpawnCount + " npc spawns from XML.");
return;
}
fillSpawnTable(false);
final int spawnCount = _spawnTable.size();
LOGGER.info(getClass().getSimpleName() + ": Loaded " + spawnCount + " npc spawns.");
if (Config.CUSTOM_SPAWNLIST_TABLE)
{
fillSpawnTable(true);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + (_spawnTable.size() - spawnCount) + " custom npc spawns.");
}
// Load XML list
parseDatapackDirectory("spawnlist", false);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _xmlSpawnCount + " npc spawns from XML.");
}
/**
@ -89,19 +91,13 @@ public final class SpawnTable implements IXmlReader
private boolean checkTemplate(int npcId)
{
final L2NpcTemplate npcTemplate = NpcData.getInstance().getTemplate(npcId);
if (npcTemplate == null)
if (npcTemplate != null)
{
LOGGER.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + npcId + ".");
return false;
return !npcTemplate.isType("L2SiegeGuard") && !npcTemplate.isType("L2RaidBoss") && (Config.ALLOW_CLASS_MASTERS || !npcTemplate.isType("L2ClassMaster"));
}
if (npcTemplate.isType("L2SiegeGuard") || npcTemplate.isType("L2RaidBoss") || (!Config.ALLOW_CLASS_MASTERS && npcTemplate.isType("L2ClassMaster")))
{
// Don't spawn
return false;
}
return true;
LOGGER.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + npcId + ".");
// Don't spawn
return false;
}
@Override
@ -413,27 +409,28 @@ public final class SpawnTable implements IXmlReader
{
addSpawn(spawn);
if (storeInDb)
if (!storeInDb)
{
final String spawnTable = spawn.isCustom() && Config.CUSTOM_SPAWNLIST_TABLE ? "custom_spawnlist" : "spawnlist";
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement insert = con.prepareStatement("INSERT INTO " + spawnTable + "(count,npc_templateid,locx,locy,locz,heading,respawn_delay,respawn_random,loc_id) values(?,?,?,?,?,?,?,?,?)"))
{
insert.setInt(1, spawn.getAmount());
insert.setInt(2, spawn.getId());
insert.setInt(3, spawn.getX());
insert.setInt(4, spawn.getY());
insert.setInt(5, spawn.getZ());
insert.setInt(6, spawn.getHeading());
insert.setInt(7, spawn.getRespawnDelay() / 1000);
insert.setInt(8, spawn.getRespawnMaxDelay() - spawn.getRespawnMinDelay());
insert.setInt(9, spawn.getLocationId());
insert.execute();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Could not store spawn in the DB:" + e.getMessage(), e);
}
return;
}
final String spawnTable = spawn.isCustom() && Config.CUSTOM_SPAWNLIST_TABLE ? "custom_spawnlist" : "spawnlist";
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement insert = con.prepareStatement("INSERT INTO " + spawnTable + "(count,npc_templateid,locx,locy,locz,heading,respawn_delay,respawn_random,loc_id) values(?,?,?,?,?,?,?,?,?)"))
{
insert.setInt(1, spawn.getAmount());
insert.setInt(2, spawn.getId());
insert.setInt(3, spawn.getX());
insert.setInt(4, spawn.getY());
insert.setInt(5, spawn.getZ());
insert.setInt(6, spawn.getHeading());
insert.setInt(7, spawn.getRespawnDelay() / 1000);
insert.setInt(8, spawn.getRespawnMaxDelay() - spawn.getRespawnMinDelay());
insert.setInt(9, spawn.getLocationId());
insert.execute();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Could not store spawn in the DB:" + e.getMessage(), e);
}
}
@ -485,16 +482,17 @@ public final class SpawnTable implements IXmlReader
private boolean removeSpawn(L2Spawn spawn)
{
final Set<L2Spawn> set = _spawnTable.get(spawn.getId());
if (set != null)
if (set == null)
{
final boolean removed = set.remove(spawn);
if (set.isEmpty())
{
_spawnTable.remove(spawn.getId());
}
return removed;
return false;
}
return false;
final boolean removed = set.remove(spawn);
if (set.isEmpty())
{
_spawnTable.remove(spawn.getId());
}
return removed;
}
/**