Make showBlock(s) thread-safe.

This commit is contained in:
garbagemule 2013-09-09 09:05:54 +02:00
parent acd441dd2e
commit 349172b3b6

View File

@ -644,46 +644,55 @@ public class ArenaRegion
showBlocks(p, map.values()); showBlocks(p, map.values());
} }
public void showBlock(final Player p, final Location loc, int id, byte data) { public void showBlock(final Player p, final Location loc, final int id, final byte data) {
p.sendBlockChange(loc, id, data);
arena.scheduleTask(new Runnable() { arena.scheduleTask(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!p.isOnline()) return; p.sendBlockChange(loc, id, data);
arena.scheduleTask(new Runnable() {
@Override
public void run() {
if (!p.isOnline()) return;
Block b = loc.getBlock(); Block b = loc.getBlock();
p.sendBlockChange(loc, b.getTypeId(), b.getData()); p.sendBlockChange(loc, b.getTypeId(), b.getData());
}
}, 100);
} }
}, 100); }, 0);
} }
private void showBlocks(final Player p, Collection<Location> points) { private void showBlocks(final Player p, final Collection<Location> points) {
// Grab all the blocks, and send block change events.
final Map<Location,BlockState> blocks = new HashMap<Location,BlockState>();
for (Location l : points) {
Block b = l.getBlock();
blocks.put(l, b.getState());
p.sendBlockChange(l, 35, (byte) 14);
}
arena.scheduleTask(new Runnable() { arena.scheduleTask(new Runnable() {
@Override
public void run() { public void run() {
// If the player isn't online, just forget it. // Grab all the blocks, and send block change events.
if (!p.isOnline()) { final Map<Location,BlockState> blocks = new HashMap<Location,BlockState>();
return; for (Location l : points) {
Block b = l.getBlock();
blocks.put(l, b.getState());
p.sendBlockChange(l, 35, (byte) 14);
} }
arena.scheduleTask(new Runnable() {
public void run() {
// If the player isn't online, just forget it.
if (!p.isOnline()) {
return;
}
// Send block "restore" events. // Send block "restore" events.
for (Map.Entry<Location,BlockState> entry : blocks.entrySet()) { for (Map.Entry<Location,BlockState> entry : blocks.entrySet()) {
Location l = entry.getKey(); Location l = entry.getKey();
BlockState b = entry.getValue(); BlockState b = entry.getValue();
int id = b.getTypeId(); int id = b.getTypeId();
byte data = b.getRawData(); byte data = b.getRawData();
p.sendBlockChange(l, id, data); p.sendBlockChange(l, id, data);
} }
}
}, 100);
} }
}, 100); }, 0);
} }
private List<Location> getFramePoints(Location loc1, Location loc2) { private List<Location> getFramePoints(Location loc1, Location loc2) {