Implemented admin delete_group command.
This commit is contained in:
@@ -22,6 +22,7 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -33,6 +34,9 @@ import org.l2jmobius.gameserver.data.xml.NpcData;
|
||||
import org.l2jmobius.gameserver.model.Spawn;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.spawns.SpawnGroup;
|
||||
import org.l2jmobius.gameserver.model.spawns.SpawnTemplate;
|
||||
import org.l2jmobius.gameserver.model.zone.type.SpawnTerritory;
|
||||
|
||||
/**
|
||||
* Spawn data retriever.
|
||||
@@ -202,50 +206,104 @@ public class SpawnTable
|
||||
{
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(spawnFile));
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
|
||||
final String spawnId = String.valueOf(spawn.getId());
|
||||
final String spawnX = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getX() : spawn.getX());
|
||||
final String spawnY = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getY() : spawn.getY());
|
||||
final String spawnZ = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getZ() : spawn.getZ());
|
||||
|
||||
boolean found = false; // in XML you can have more than one spawn with same coords
|
||||
boolean isMultiLine = false; // in case spawn has more stats
|
||||
boolean lastLineFound = false; // used to check for empty file
|
||||
int lineCount = 0;
|
||||
String currentLine;
|
||||
while ((currentLine = reader.readLine()) != null)
|
||||
|
||||
final SpawnGroup group = npcSpawnTemplate != null ? npcSpawnTemplate.getGroup() : null;
|
||||
List<SpawnTerritory> territories = group != null ? group.getTerritories() : Collections.emptyList();
|
||||
boolean simpleTerritory = false;
|
||||
if (territories.isEmpty())
|
||||
{
|
||||
if (!found)
|
||||
final SpawnTemplate spawnTemplate = npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnTemplate() : null;
|
||||
if (spawnTemplate != null)
|
||||
{
|
||||
if (isMultiLine)
|
||||
{
|
||||
if (currentLine.contains("</npc>"))
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (currentLine.contains(spawnId) && currentLine.contains(spawnX) && currentLine.contains(spawnY) && currentLine.contains(spawnZ))
|
||||
{
|
||||
if (!currentLine.contains("/>") && !currentLine.contains("</npc>"))
|
||||
{
|
||||
isMultiLine = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
writer.write(currentLine + Config.EOL);
|
||||
if (currentLine.contains("</list>"))
|
||||
{
|
||||
lastLineFound = true;
|
||||
}
|
||||
if (!lastLineFound)
|
||||
{
|
||||
lineCount++;
|
||||
territories = spawnTemplate.getTerritories();
|
||||
simpleTerritory = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (territories.isEmpty())
|
||||
{
|
||||
final String spawnId = String.valueOf(spawn.getId());
|
||||
final String spawnX = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getX() : spawn.getX());
|
||||
final String spawnY = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getY() : spawn.getY());
|
||||
final String spawnZ = String.valueOf(npcSpawnTemplate != null ? npcSpawnTemplate.getSpawnLocation().getZ() : spawn.getZ());
|
||||
|
||||
while ((currentLine = reader.readLine()) != null)
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
if (isMultiLine)
|
||||
{
|
||||
if (currentLine.contains("</npc>"))
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (currentLine.contains(spawnId) && currentLine.contains(spawnX) && currentLine.contains(spawnY) && currentLine.contains(spawnZ))
|
||||
{
|
||||
if (!currentLine.contains("/>") && !currentLine.contains("</npc>"))
|
||||
{
|
||||
isMultiLine = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
writer.write(currentLine + Config.EOL);
|
||||
if (currentLine.contains("</list>"))
|
||||
{
|
||||
lastLineFound = true;
|
||||
}
|
||||
if (!lastLineFound)
|
||||
{
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SEARCH: while ((currentLine = reader.readLine()) != null)
|
||||
{
|
||||
if (!found)
|
||||
{
|
||||
if (isMultiLine)
|
||||
{
|
||||
if (currentLine.contains("</group>") || (simpleTerritory && currentLine.contains("<territories>")))
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (SpawnTerritory territory : territories)
|
||||
{
|
||||
if (currentLine.contains('"' + territory.getName() + '"'))
|
||||
{
|
||||
isMultiLine = true;
|
||||
continue SEARCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.write(currentLine + Config.EOL);
|
||||
if (currentLine.contains("</list>"))
|
||||
{
|
||||
lastLineFound = true;
|
||||
}
|
||||
if (!lastLineFound)
|
||||
{
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer.close();
|
||||
reader.close();
|
||||
spawnFile.delete();
|
||||
|
Reference in New Issue
Block a user