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

@ -40,6 +40,8 @@ public class GatesManager
private static final String gatesPath = "gates"; // path to gates inside the yaml file private static final String gatesPath = "gates"; // path to gates inside the yaml file
private static final String storageVersionPath = "version"; private static final String storageVersionPath = "version";
private static final int storageVersion = 1; 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<String, Gate> gatesById;
private Map<SimpleChunk, Set<Gate>> gatesByChunk; private Map<SimpleChunk, Set<Gate>> gatesByChunk;
@ -119,9 +121,9 @@ public class GatesManager
// migration // migration
int fileStorageVersion = gatesConfig.getInt(storageVersionPath); int fileStorageVersion = gatesConfig.getInt(storageVersionPath);
if (fileStorageVersion > storageVersion) { if (fileStorageVersion > storageVersion) {
throw new RuntimeException("Unsupported storage version detected! Make sure you have the latest version of Craft Inc. Gates installed."); throw new RuntimeException("Unsupported storage version detected! Make sure you have the latest version of Craft Inc. Gates installed.");
} }
if (fileStorageVersion < storageVersion) { if (fileStorageVersion < storageVersion) {
Plugin.log("Outdated storage version detected. Performing data migration..."); Plugin.log("Outdated storage version detected. Performing data migration...");
@ -142,12 +144,24 @@ public class GatesManager
private void fillGatesByChunk() private void fillGatesByChunk()
{ {
HashSet<Chunk> chunksUsedByGates = new HashSet<Chunk>(); HashSet<SimpleChunk> chunksUsedByGates = new HashSet<SimpleChunk>();
for (Gate g : gates) { for (Gate g : gates) {
if (g.getLocation() != null) { 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,9 +222,24 @@ public class GatesManager
private void removeGateFromChunk(Gate g, Location l) private void removeGateFromChunk(Gate g, Location l)
{ {
if (l != null) { if (l != null) {
SimpleChunk sc = new SimpleChunk(l.getChunk());
Set<Gate> gatesInChunk = gatesByChunk.get(sc); Chunk c = l.getChunk();
gatesInChunk.remove(g); 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,15 +249,27 @@ public class GatesManager
Location gateLocation = g.getLocation(); Location gateLocation = g.getLocation();
if (gateLocation != null) { if (gateLocation != null) {
SimpleChunk c = new SimpleChunk(gateLocation.getChunk());
Set<Gate> gatesForC = gatesByChunk.get(c);
if (gatesForC == null) { Chunk c = g.getLocation().getChunk();
gatesForC = new HashSet<Gate>(); // NOTE: not optimizing size here int x = c.getX();
gatesByChunk.put(c, gatesForC); 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(sc, gatesForC);
}
gatesForC.add(g);
}
} }
gatesForC.add(g);
} }
} }

View File

@ -24,13 +24,12 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
public class GateBlockChangeSender 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) public static void updateGateBlocks(final Player player)

View File

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