Minor SpawnTable improvements.
This commit is contained in:
parent
a3b568f97b
commit
afda308a02
@ -41,6 +41,7 @@ public final class SpawnTable
|
|||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(SpawnTable.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SpawnTable.class.getName());
|
||||||
private static final Map<Integer, Set<L2Spawn>> _spawnTable = new ConcurrentHashMap<>();
|
private static final Map<Integer, Set<L2Spawn>> _spawnTable = new ConcurrentHashMap<>();
|
||||||
|
private static final String OTHER_XML_FOLDER = "data/spawns/Others";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the spawn data.
|
* Gets the spawn data.
|
||||||
@ -93,7 +94,7 @@ public final class SpawnTable
|
|||||||
if (store)
|
if (store)
|
||||||
{
|
{
|
||||||
// Create output directory if it doesn't exist
|
// Create output directory if it doesn't exist
|
||||||
final File outputDirectory = new File("data/spawns/Others");
|
final File outputDirectory = new File(OTHER_XML_FOLDER);
|
||||||
if (!outputDirectory.exists())
|
if (!outputDirectory.exists())
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
@ -108,19 +109,14 @@ public final class SpawnTable
|
|||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
LOGGER.info(getClass().getSimpleName() + ": Created directory: data/spawns/Others");
|
LOGGER.info(getClass().getSimpleName() + ": Created directory: " + OTHER_XML_FOLDER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XML file for spawn
|
// XML file for spawn
|
||||||
final int x = ((spawn.getX() - L2World.MAP_MIN_X) >> 15) + L2World.TILE_X_MIN;
|
final int x = ((spawn.getX() - L2World.MAP_MIN_X) >> 15) + L2World.TILE_X_MIN;
|
||||||
final int y = ((spawn.getY() - L2World.MAP_MIN_Y) >> 15) + L2World.TILE_Y_MIN;
|
final int y = ((spawn.getY() - L2World.MAP_MIN_Y) >> 15) + L2World.TILE_Y_MIN;
|
||||||
final File spawnFile = new File("data/spawns/Others/" + x + "_" + y + ".xml");
|
final File spawnFile = new File(OTHER_XML_FOLDER + "/" + x + "_" + y + ".xml");
|
||||||
if (spawnFile.isDirectory())
|
|
||||||
{
|
|
||||||
LOGGER.warning(getClass().getSimpleName() + ": Could not save spawn. Target path seems to be a directory.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write info to XML
|
// Write info to XML
|
||||||
final String spawnId = String.valueOf(spawn.getId());
|
final String spawnId = String.valueOf(spawn.getId());
|
||||||
@ -130,8 +126,7 @@ public final class SpawnTable
|
|||||||
final String spawnZ = String.valueOf(spawn.getZ());
|
final String spawnZ = String.valueOf(spawn.getZ());
|
||||||
final String spawnHeading = String.valueOf(spawn.getHeading());
|
final String spawnHeading = String.valueOf(spawn.getHeading());
|
||||||
final String spawnDelay = String.valueOf(spawn.getRespawnDelay() / 1000);
|
final String spawnDelay = String.valueOf(spawn.getRespawnDelay() / 1000);
|
||||||
// Update
|
if (spawnFile.exists()) // update
|
||||||
if (spawnFile.exists())
|
|
||||||
{
|
{
|
||||||
final File tempFile = new File(spawnFile.getAbsolutePath().substring(Config.DATAPACK_ROOT.getAbsolutePath().length() + 1).replace('\\', '/') + ".tmp");
|
final File tempFile = new File(spawnFile.getAbsolutePath().substring(Config.DATAPACK_ROOT.getAbsolutePath().length() + 1).replace('\\', '/') + ".tmp");
|
||||||
try
|
try
|
||||||
@ -159,7 +154,7 @@ public final class SpawnTable
|
|||||||
LOGGER.warning(getClass().getSimpleName() + ": Could not store spawn in the spawn XML files: " + e);
|
LOGGER.warning(getClass().getSimpleName() + ": Could not store spawn in the spawn XML files: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // New file
|
else // new file
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -173,7 +168,7 @@ public final class SpawnTable
|
|||||||
writer.write(" </spawn>" + Config.EOL);
|
writer.write(" </spawn>" + Config.EOL);
|
||||||
writer.write("</list>" + Config.EOL);
|
writer.write("</list>" + Config.EOL);
|
||||||
writer.close();
|
writer.close();
|
||||||
LOGGER.info(getClass().getSimpleName() + ": Created file: data/spawns/Others/" + x + "_" + y + ".xml");
|
LOGGER.info(getClass().getSimpleName() + ": Created file: " + OTHER_XML_FOLDER + "/" + x + "_" + y + ".xml");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -199,7 +194,7 @@ public final class SpawnTable
|
|||||||
{
|
{
|
||||||
final int x = ((spawn.getX() - L2World.MAP_MIN_X) >> 15) + L2World.TILE_X_MIN;
|
final int x = ((spawn.getX() - L2World.MAP_MIN_X) >> 15) + L2World.TILE_X_MIN;
|
||||||
final int y = ((spawn.getY() - L2World.MAP_MIN_Y) >> 15) + L2World.TILE_Y_MIN;
|
final int y = ((spawn.getY() - L2World.MAP_MIN_Y) >> 15) + L2World.TILE_Y_MIN;
|
||||||
final File spawnFile = spawn.getNpcSpawnTemplate() != null ? spawn.getNpcSpawnTemplate().getSpawnTemplate().getFile() : new File("data/spawns/Others/" + x + "_" + y + ".xml");
|
final File spawnFile = spawn.getNpcSpawnTemplate() != null ? spawn.getNpcSpawnTemplate().getSpawnTemplate().getFile() : new File(OTHER_XML_FOLDER + "/" + x + "_" + y + ".xml");
|
||||||
final File tempFile = new File(spawnFile.getAbsolutePath().substring(Config.DATAPACK_ROOT.getAbsolutePath().length() + 1).replace('\\', '/') + ".tmp");
|
final File tempFile = new File(spawnFile.getAbsolutePath().substring(Config.DATAPACK_ROOT.getAbsolutePath().length() + 1).replace('\\', '/') + ".tmp");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -222,14 +217,13 @@ public final class SpawnTable
|
|||||||
{
|
{
|
||||||
if (currentLine.contains("</npc>"))
|
if (currentLine.contains("</npc>"))
|
||||||
{
|
{
|
||||||
isMultiLine = false;
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (currentLine.contains(spawnId) && currentLine.contains(spawnX) && currentLine.contains(spawnY) && currentLine.contains(spawnZ))
|
if (currentLine.contains(spawnId) && currentLine.contains(spawnX) && currentLine.contains(spawnY) && currentLine.contains(spawnZ))
|
||||||
{
|
{
|
||||||
if (!currentLine.contains("/>"))
|
if (!currentLine.contains("/>") && !currentLine.contains("</npc>"))
|
||||||
{
|
{
|
||||||
isMultiLine = true;
|
isMultiLine = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user