Added some checks for null values to the GatesManager class.
This commit is contained in:
parent
00573c2763
commit
232305a871
@ -35,7 +35,7 @@ public class GatesManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<Gate> getGatesInsideChunk(Chunk chunk)
|
public Set<Gate> getNearbyGates(Chunk chunk)
|
||||||
{
|
{
|
||||||
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
SimpleChunk simpleChunk = new SimpleChunk(chunk);
|
||||||
return gatesByChunk.get(simpleChunk);
|
return gatesByChunk.get(simpleChunk);
|
||||||
@ -71,8 +71,8 @@ public class GatesManager
|
|||||||
|
|
||||||
if(!this.gatesConfigFile.exists()) {
|
if(!this.gatesConfigFile.exists()) {
|
||||||
try {
|
try {
|
||||||
this.gatesConfigFile.createNewFile();
|
this.gatesConfigFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Plugin.log(Level.SEVERE, "Cannot create gate config file! No gates will be persisted.");
|
Plugin.log(Level.SEVERE, "Cannot create gate config file! No gates will be persisted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +111,10 @@ public class GatesManager
|
|||||||
HashSet<Chunk> chunksUsedByGates = new HashSet<Chunk>();
|
HashSet<Chunk> chunksUsedByGates = new HashSet<Chunk>();
|
||||||
|
|
||||||
for (Gate g : gates) {
|
for (Gate g : gates) {
|
||||||
chunksUsedByGates.add(g.getLocation().getChunk());
|
|
||||||
|
if (g.getLocation() != null) {
|
||||||
|
chunksUsedByGates.add(g.getLocation().getChunk());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gatesByChunk = new HashMap<SimpleChunk, Set<Gate>>((int)(chunksUsedByGates.size() * 1.25));
|
gatesByChunk = new HashMap<SimpleChunk, Set<Gate>>((int)(chunksUsedByGates.size() * 1.25));
|
||||||
@ -170,23 +173,29 @@ public class GatesManager
|
|||||||
|
|
||||||
private void removeGateFromChunk(Gate g, Location l)
|
private void removeGateFromChunk(Gate g, Location l)
|
||||||
{
|
{
|
||||||
SimpleChunk sc = new SimpleChunk(l.getChunk());
|
if (l != null) {
|
||||||
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
SimpleChunk sc = new SimpleChunk(l.getChunk());
|
||||||
gatesInChunk.remove(g);
|
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
|
||||||
|
gatesInChunk.remove(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addGateByChunk(Gate g)
|
private void addGateByChunk(Gate g)
|
||||||
{
|
{
|
||||||
SimpleChunk c = new SimpleChunk(g.getLocation().getChunk());
|
Location gateLocation = g.getLocation();
|
||||||
Set<Gate> gatesForC = gatesByChunk.get(c);
|
|
||||||
|
if (gateLocation != null) {
|
||||||
if (gatesForC == null) {
|
SimpleChunk c = new SimpleChunk(gateLocation.getChunk());
|
||||||
gatesForC = new HashSet<Gate>(); // NOTE: not optimizing size here
|
Set<Gate> gatesForC = gatesByChunk.get(c);
|
||||||
gatesByChunk.put(c, gatesForC);
|
|
||||||
}
|
if (gatesForC == null) {
|
||||||
|
gatesForC = new HashSet<Gate>(); // NOTE: not optimizing size here
|
||||||
gatesForC.add(g);
|
gatesByChunk.put(c, gatesForC);
|
||||||
|
}
|
||||||
|
|
||||||
|
gatesForC.add(g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user