Access zone character list only by getter method.

This commit is contained in:
MobiusDevelopment
2020-02-04 05:21:24 +00:00
parent 232a3bb69b
commit 407ff24524
74 changed files with 126 additions and 224 deletions

View File

@ -40,7 +40,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.WorldRegion;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneType;
import org.l2jmobius.gameserver.model.zone.form.ZoneCuboid;
import org.l2jmobius.gameserver.model.zone.form.ZoneCylinder;
@ -445,7 +445,7 @@ public class ZoneData
temp.setParameter(name, val);
}
else if ("spawn".equalsIgnoreCase(cd.getNodeName()) && (temp instanceof SpawnZone))
else if ("spawn".equalsIgnoreCase(cd.getNodeName()) && (temp instanceof ZoneRespawn))
{
attrs = cd.getAttributes();
int spawnX = Integer.parseInt(attrs.getNamedItem("X").getNodeValue());
@ -455,11 +455,11 @@ public class ZoneData
Node val = attrs.getNamedItem("isChaotic");
if ((val != null) && Boolean.parseBoolean(val.getNodeValue()))
{
((SpawnZone) temp).addChaoticSpawn(spawnX, spawnY, spawnZ);
((ZoneRespawn) temp).addChaoticSpawn(spawnX, spawnY, spawnZ);
}
else
{
((SpawnZone) temp).addSpawn(spawnX, spawnY, spawnZ);
((ZoneRespawn) temp).addSpawn(spawnX, spawnY, spawnZ);
}
}
}

View File

@ -196,7 +196,7 @@ public class BanditStrongholdSiege extends ClanHallSiege
public void teleportPlayers()
{
final ClanHallZone zone = clanhall.getZone();
for (Creature creature : zone.getCharactersInside().values())
for (Creature creature : zone.getCharactersInside())
{
if (creature instanceof PlayerInstance)
{

View File

@ -189,7 +189,7 @@ public class WildBeastFarmSiege extends ClanHallSiege
public void teleportPlayers()
{
final ClanHallZone zone = clanhall.getZone();
for (Creature creature : zone.getCharactersInside().values())
for (Creature creature : zone.getCharactersInside())
{
if (creature instanceof PlayerInstance)
{

View File

@ -23,20 +23,20 @@ import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.model.Location;
/**
* Abstract zone with spawn locations.<br>
* It inherits regular ZoneType behavior, with the possible addition of 2 Lists holding Locations.
* Abstract zone with spawn locations
* @author DS, Nyaran (rework 10/07/2011)
*/
public abstract class SpawnZone extends ZoneType
public abstract class ZoneRespawn extends ZoneType
{
private List<Location> _spawnLocs = null;
private List<Location> _chaoticSpawnLocs = null;
public SpawnZone(int id)
public ZoneRespawn(int id)
{
super(id);
}
public final void addSpawn(int x, int y, int z)
public void addSpawn(int x, int y, int z)
{
if (_spawnLocs == null)
{
@ -46,7 +46,7 @@ public abstract class SpawnZone extends ZoneType
_spawnLocs.add(new Location(x, y, z));
}
public final void addChaoticSpawn(int x, int y, int z)
public void addChaoticSpawn(int x, int y, int z)
{
if (_chaoticSpawnLocs == null)
{
@ -56,17 +56,17 @@ public abstract class SpawnZone extends ZoneType
_chaoticSpawnLocs.add(new Location(x, y, z));
}
public final List<Location> getSpawns()
public List<Location> getSpawns()
{
return _spawnLocs;
}
public final Location getSpawnLoc()
public Location getSpawnLoc()
{
return _spawnLocs.get(Rnd.get(_spawnLocs.size()));
}
public final Location getChaoticSpawnLoc()
public Location getChaoticSpawnLoc()
{
if (_chaoticSpawnLocs != null)
{

View File

@ -16,6 +16,7 @@
*/
package org.l2jmobius.gameserver.model.zone;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -32,7 +33,7 @@ public abstract class ZoneType
{
private final int _id;
protected ZoneForm _zone;
public Map<Integer, Creature> _characterList;
private final Map<Integer, Creature> _characterList = new ConcurrentHashMap<>();
/** Parameters to affect specific characters */
private boolean _checkAffected;
@ -46,7 +47,6 @@ public abstract class ZoneType
protected ZoneType(int id)
{
_id = id;
_characterList = new ConcurrentHashMap<>();
_checkAffected = false;
@ -354,9 +354,9 @@ public abstract class ZoneType
}
}
public Map<Integer, Creature> getCharactersInside()
public Collection<Creature> getCharactersInside()
{
return _characterList;
return _characterList.values();
}
public void visualizeZone(int z)

View File

@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.zone.type;
import org.l2jmobius.gameserver.enums.TeleportWhereType;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.network.SystemMessageId;
@ -27,7 +27,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
* An arena
* @author durgus
*/
public class ArenaZone extends SpawnZone
public class ArenaZone extends ZoneRespawn
{
public ArenaZone(int id)
{
@ -70,17 +70,7 @@ public class ArenaZone extends SpawnZone
public void oustAllPlayers()
{
if (_characterList == null)
{
return;
}
if (_characterList.isEmpty())
{
return;
}
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if (creature == null)
{

View File

@ -173,12 +173,7 @@ public class BossZone extends ZoneType
*/
public void movePlayersTo(int x, int y, int z)
{
if (_characterList.isEmpty())
{
return;
}
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if (creature instanceof PlayerInstance)
{
@ -277,17 +272,12 @@ public class BossZone extends ZoneType
*/
public void oustAllPlayers()
{
if (_characterList == null)
if (getCharactersInside().isEmpty())
{
return;
}
if (_characterList.isEmpty())
{
return;
}
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if (creature == null)
{
@ -336,13 +326,13 @@ public class BossZone extends ZoneType
public void updateKnownList(NpcInstance npc)
{
if ((_characterList == null) || _characterList.isEmpty())
if (getCharactersInside().isEmpty())
{
return;
}
final Map<Integer, PlayerInstance> npcKnownPlayers = npc.getKnownList().getKnownPlayers();
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if (creature == null)
{

View File

@ -107,7 +107,7 @@ public class CastleTeleportZone extends ZoneType
public List<Creature> getAllPlayers()
{
final List<Creature> players = new ArrayList<>();
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if (creature instanceof PlayerInstance)
{
@ -119,17 +119,7 @@ public class CastleTeleportZone extends ZoneType
public void oustAllPlayers()
{
if (_characterList == null)
{
return;
}
if (_characterList.isEmpty())
{
return;
}
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
if ((creature != null) && (creature instanceof PlayerInstance))
{

View File

@ -24,7 +24,7 @@ import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.actor.instance.SiegeSummonInstance;
import org.l2jmobius.gameserver.model.entity.siege.Castle;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.network.SystemMessageId;
@ -32,7 +32,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
* A castle zone
* @author durgus
*/
public class CastleZone extends SpawnZone
public class CastleZone extends ZoneRespawn
{
private Castle _castle;
@ -120,7 +120,7 @@ public class CastleZone extends SpawnZone
{
if (_castle.getSiege().isInProgress())
{
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
try
{
@ -133,7 +133,7 @@ public class CastleZone extends SpawnZone
}
else
{
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
try
{
@ -163,7 +163,7 @@ public class CastleZone extends SpawnZone
*/
public void banishForeigners(int owningClanId)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (!(temp instanceof PlayerInstance))
{
@ -185,7 +185,7 @@ public class CastleZone extends SpawnZone
*/
public void announceToPlayers(String message)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (temp instanceof PlayerInstance)
{
@ -201,15 +201,13 @@ public class CastleZone extends SpawnZone
public List<PlayerInstance> getAllPlayers()
{
final List<PlayerInstance> players = new ArrayList<>();
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (temp instanceof PlayerInstance)
{
players.add((PlayerInstance) temp);
}
}
return players;
}
@ -219,7 +217,6 @@ public class CastleZone extends SpawnZone
{
return _castle.isSiegeInProgress();
}
return false;
}
}

View File

@ -16,14 +16,12 @@
*/
package org.l2jmobius.gameserver.model.zone.type;
import java.util.Map;
import org.l2jmobius.gameserver.enums.TeleportWhereType;
import org.l2jmobius.gameserver.instancemanager.ClanHallManager;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.ClanHall;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.network.serverpackets.ClanHallDecoration;
@ -31,7 +29,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ClanHallDecoration;
* A clan hall zone
* @author durgus
*/
public class ClanHallZone extends SpawnZone
public class ClanHallZone extends ZoneRespawn
{
private int _clanHallId;
@ -118,7 +116,7 @@ public class ClanHallZone extends SpawnZone
*/
public void banishForeigners(int owningClanId)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (!(temp instanceof PlayerInstance))
{
@ -133,10 +131,4 @@ public class ClanHallZone extends SpawnZone
((PlayerInstance) temp).teleToLocation(TeleportWhereType.TOWN);
}
}
@Override
public Map<Integer, Creature> getCharactersInside()
{
return _characterList;
}
}

View File

@ -16,7 +16,6 @@
*/
package org.l2jmobius.gameserver.model.zone.type;
import java.util.Collection;
import java.util.concurrent.Future;
import org.l2jmobius.commons.concurrent.ThreadPool;
@ -66,18 +65,13 @@ public class DamageZone extends ZoneType
@Override
protected void onExit(Creature creature)
{
if (_characterList.isEmpty())
if (getCharactersInside().isEmpty())
{
_task.cancel(true);
_task = null;
}
}
protected Collection<Creature> getCharacterList()
{
return _characterList.values();
}
protected int getDamagePerSecond()
{
return _damagePerSec;
@ -95,7 +89,7 @@ public class DamageZone extends ZoneType
@Override
public void run()
{
for (Creature temp : _dmgZone.getCharacterList())
for (Creature temp : _dmgZone.getCharactersInside())
{
if ((temp != null) && !temp.isDead() && (temp instanceof PlayerInstance))
{

View File

@ -97,7 +97,7 @@ public class DynamicZone extends ZoneType
_region.removeZone(this);
for (Creature member : _characterList.values())
for (Creature member : getCharactersInside())
{
try
{

View File

@ -16,7 +16,6 @@
*/
package org.l2jmobius.gameserver.model.zone.type;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
@ -160,7 +159,7 @@ public class EffectZone extends ZoneType
}
}
if (_characterList.isEmpty() && (_task != null))
if (getCharactersInside().isEmpty() && (_task != null))
{
_task.cancel(true);
_task = null;
@ -233,11 +232,6 @@ public class EffectZone extends ZoneType
_enabled = value;
}
protected Collection<Creature> getCharacterList()
{
return _characterList.values();
}
class ApplySkill implements Runnable
{
ApplySkill()
@ -253,7 +247,7 @@ public class EffectZone extends ZoneType
{
if (_enabled)
{
for (Creature temp : getCharacterList())
for (Creature temp : getCharactersInside())
{
if ((temp != null) && !temp.isDead())
{

View File

@ -25,7 +25,7 @@ import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.actor.instance.SiegeSummonInstance;
import org.l2jmobius.gameserver.model.entity.siege.Fort;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.network.SystemMessageId;
@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
* A castle zone
* @author programmos
*/
public class FortZone extends SpawnZone
public class FortZone extends ZoneRespawn
{
private Fort _fort;
@ -117,7 +117,7 @@ public class FortZone extends SpawnZone
{
if (_fort.getSiege().isInProgress())
{
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
try
{
@ -130,7 +130,7 @@ public class FortZone extends SpawnZone
}
else
{
for (Creature creature : _characterList.values())
for (Creature creature : getCharactersInside())
{
try
{
@ -160,7 +160,7 @@ public class FortZone extends SpawnZone
*/
public void banishForeigners(int owningClanId)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (!(temp instanceof PlayerInstance))
{
@ -182,7 +182,7 @@ public class FortZone extends SpawnZone
*/
public void announceToPlayers(String message)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (temp instanceof PlayerInstance)
{
@ -198,7 +198,7 @@ public class FortZone extends SpawnZone
public List<PlayerInstance> getAllPlayers()
{
final List<PlayerInstance> players = new ArrayList<>();
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if (temp instanceof PlayerInstance)
{

View File

@ -113,7 +113,7 @@ public class PoisonZone extends ZoneType
@Override
protected void onExit(Creature creature)
{
if (_characterList.isEmpty() && (_task != null))
if (getCharactersInside().isEmpty() && (_task != null))
{
_task.cancel(true);
_task = null;
@ -152,7 +152,7 @@ public class PoisonZone extends ZoneType
{
if (_enabled)
{
for (Creature temp : _characterList.values())
for (Creature temp : getCharactersInside())
{
if ((temp != null) && !temp.isDead() && (((temp instanceof Playable) && _target.equalsIgnoreCase("pc")) || ((temp instanceof PlayerInstance) && _target.equalsIgnoreCase("pc_only")) || ((temp instanceof MonsterInstance) && _target.equalsIgnoreCase("npc"))) && (Rnd.get(100) < _chance))
{

View File

@ -19,14 +19,14 @@ package org.l2jmobius.gameserver.model.zone.type;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.SpawnZone;
import org.l2jmobius.gameserver.model.zone.ZoneRespawn;
import org.l2jmobius.gameserver.model.zone.ZoneId;
/**
* A Town zone
* @author durgus
*/
public class TownZone extends SpawnZone
public class TownZone extends ZoneRespawn
{
private String _townName;
private int _townId;

View File

@ -193,7 +193,7 @@ public class Broadcast
{
for (ZoneType zone : ZoneData.getInstance().getAllZones(zoneType))
{
for (Creature creature : zone.getCharactersInside().values())
for (Creature creature : zone.getCharactersInside())
{
if (creature == null)
{