mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
More improvement on blockphysics and blockfromto chatter
This commit is contained in:
parent
888051d497
commit
35cf3ed8fa
@ -85,9 +85,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
private static class BlockToCheck {
|
||||
Location loc;
|
||||
int typeid;
|
||||
byte data;
|
||||
String trigger;
|
||||
};
|
||||
private LinkedList<BlockToCheck> blocks_to_check = new LinkedList<BlockToCheck>();
|
||||
private LinkedList<BlockToCheck> blocks_to_check = null;
|
||||
private LinkedList<BlockToCheck> blocks_to_check_accum = new LinkedList<BlockToCheck>();
|
||||
|
||||
public DynmapPlugin() {
|
||||
plugin = this;
|
||||
@ -630,26 +632,20 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
pm.registerEvents(pl, this);
|
||||
}
|
||||
|
||||
|
||||
private void checkBlock(Block b, String trigger) {
|
||||
BlockToCheck btt = new BlockToCheck();
|
||||
btt.loc = b.getLocation();
|
||||
btt.typeid = b.getTypeId();
|
||||
btt.trigger = trigger;
|
||||
if(blocks_to_check.isEmpty()) {
|
||||
blocks_to_check.add(btt);
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
private class BlockCheckHandler implements Runnable {
|
||||
public void run() {
|
||||
BlockToCheck btt;
|
||||
while(blocks_to_check.isEmpty() != true) {
|
||||
btt = blocks_to_check.pop();
|
||||
Location loc = btt.loc;
|
||||
World w = loc.getWorld();
|
||||
if(!w.isChunkLoaded(loc.getBlockX()>>4, loc.getBlockZ()>>4))
|
||||
continue;
|
||||
int bt = w.getBlockTypeIdAt(loc);
|
||||
/* Avoid stationary and moving water churn */
|
||||
if(bt == 9) bt = 8;
|
||||
if(btt.typeid == 9) btt.typeid = 8;
|
||||
if(bt != btt.typeid) {
|
||||
if((bt != btt.typeid) || (btt.data != w.getBlockAt(loc).getData())) {
|
||||
sscache.invalidateSnapshot(w.getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
if((onblockfromto && btt.trigger.equals("blockfromto")) ||
|
||||
(onblockphysics && btt.trigger.equals("blockphysics"))) {
|
||||
@ -658,13 +654,29 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
}
|
||||
}
|
||||
}
|
||||
blocks_to_check = null;
|
||||
/* Kick next run, if one is needed */
|
||||
startIfNeeded();
|
||||
}
|
||||
});
|
||||
public void startIfNeeded() {
|
||||
if((blocks_to_check == null) && (blocks_to_check_accum.isEmpty() == false)) { /* More pending? */
|
||||
blocks_to_check = blocks_to_check_accum;
|
||||
blocks_to_check_accum = new LinkedList<BlockToCheck>();
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(DynmapPlugin.this, this, 10);
|
||||
}
|
||||
else {
|
||||
blocks_to_check.add(btt);
|
||||
}
|
||||
}
|
||||
private BlockCheckHandler btth = new BlockCheckHandler();
|
||||
|
||||
private void checkBlock(Block b, String trigger) {
|
||||
BlockToCheck btt = new BlockToCheck();
|
||||
btt.loc = b.getLocation();
|
||||
btt.typeid = b.getTypeId();
|
||||
btt.data = b.getData();
|
||||
btt.trigger = trigger;
|
||||
blocks_to_check_accum.add(btt); /* Add to accumulator */
|
||||
btth.startIfNeeded();
|
||||
}
|
||||
|
||||
private boolean onplace;
|
||||
private boolean onbreak;
|
||||
@ -780,7 +792,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
Material m = event.getBlock().getType();
|
||||
if((m != Material.WOOD_PLATE) && (m != Material.STONE_PLATE))
|
||||
checkBlock(event.getBlock(), "blockfromto");
|
||||
m = event.getToBlock().getType();
|
||||
if((m != Material.WOOD_PLATE) && (m != Material.STONE_PLATE))
|
||||
checkBlock(event.getToBlock(), "blockfromto");
|
||||
}
|
||||
|
||||
@ -790,7 +806,17 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
Block b = event.getBlock();
|
||||
Material m = b.getType();
|
||||
switch(m) {
|
||||
case STATIONARY_WATER:
|
||||
case WATER:
|
||||
case STATIONARY_LAVA:
|
||||
case LAVA:
|
||||
case GRAVEL:
|
||||
case SAND:
|
||||
checkBlock(event.getBlock(), "blockphysics");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
Loading…
Reference in New Issue
Block a user