More distant portal blocks now get send to players.

This commit is contained in:
Tobias Ottenweller 2013-06-12 21:58:01 +02:00
parent 1968ccaaeb
commit cb0dec8b83
3 changed files with 66 additions and 17 deletions

View File

@ -41,6 +41,8 @@ public class GatesManager
private static final String storageVersionPath = "version";
private static final int storageVersion = 1;
private static final int chunkRadius = 4; // TODO: move search radius into a config file / get value from config class
private Map<String, Gate> gatesById;
private Map<SimpleChunk, Set<Gate>> gatesByChunk;
private Map<SimpleLocation, Gate> gatesByLocation;
@ -142,12 +144,24 @@ public class GatesManager
private void fillGatesByChunk()
{
HashSet<Chunk> chunksUsedByGates = new HashSet<Chunk>();
HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
for (Gate g : gates) {
if (g.getLocation() != null) {
chunksUsedByGates.add(g.getLocation().getChunk());
Chunk c = g.getLocation().getChunk();
int x = c.getX();
int z = c.getZ();
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
chunksUsedByGates.add(new SimpleChunk(i, j, c.getWorld()));
}
}
}
}
@ -208,10 +222,25 @@ public class GatesManager
private void removeGateFromChunk(Gate g, Location l)
{
if (l != null) {
SimpleChunk sc = new SimpleChunk(l.getChunk());
Chunk c = l.getChunk();
int x = c.getX();
int z = c.getZ();
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
Set<Gate> gatesInChunk = gatesByChunk.get(sc);
if (gatesInChunk != null) {
gatesInChunk.remove(g);
}
}
}
}
}
@ -220,17 +249,29 @@ public class GatesManager
Location gateLocation = g.getLocation();
if (gateLocation != null) {
SimpleChunk c = new SimpleChunk(gateLocation.getChunk());
Set<Gate> gatesForC = gatesByChunk.get(c);
Chunk c = g.getLocation().getChunk();
int x = c.getX();
int z = c.getZ();
for (int i = x-chunkRadius; i < x+chunkRadius; i++) {
for (int j = z-chunkRadius; j < z+chunkRadius; j++) {
SimpleChunk sc = new SimpleChunk(i, j, c.getWorld());
Set<Gate> gatesForC = gatesByChunk.get(sc);
if (gatesForC == null) {
gatesForC = new HashSet<Gate>(); // NOTE: not optimizing size here
gatesByChunk.put(c, gatesForC);
gatesByChunk.put(sc, gatesForC);
}
gatesForC.add(g);
}
}
}
}
public void storeInvalidGate(Map<String, Object> map)

View File

@ -24,13 +24,12 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class GateBlockChangeSender
{
protected static final int searchRadius = 16; // TODO: move search radius into a config file / get value from config class
protected static final int searchRadius = 64; // TODO: move search radius into a config file / get value from config class
public static void updateGateBlocks(final Player player)

View File

@ -17,6 +17,7 @@
package de.craftinc.gates.util;
import org.bukkit.Chunk;
import org.bukkit.World;
public class SimpleChunk
{
@ -32,6 +33,14 @@ public class SimpleChunk
}
public SimpleChunk(int x, int z, World w)
{
this.x = x;
this.z = z;
this.world = w.getName();
}
@Override
public boolean equals(Object o)
{