mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-13 19:21:48 +01:00
Try to reduce excessive firing of blockfromto and blockphysics triggers
This commit is contained in:
parent
559bc0ef55
commit
888051d497
@ -3,6 +3,7 @@ package org.dynmap.bukkit;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@ -11,6 +12,7 @@ import java.util.concurrent.Future;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -80,6 +82,13 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||||||
public SpoutPluginBlocks spb;
|
public SpoutPluginBlocks spb;
|
||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
|
|
||||||
|
private static class BlockToCheck {
|
||||||
|
Location loc;
|
||||||
|
int typeid;
|
||||||
|
String trigger;
|
||||||
|
};
|
||||||
|
private LinkedList<BlockToCheck> blocks_to_check = new LinkedList<BlockToCheck>();
|
||||||
|
|
||||||
public DynmapPlugin() {
|
public DynmapPlugin() {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
}
|
}
|
||||||
@ -621,6 +630,42 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||||||
pm.registerEvents(pl, this);
|
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() {
|
||||||
|
public void run() {
|
||||||
|
BlockToCheck btt;
|
||||||
|
while(blocks_to_check.isEmpty() != true) {
|
||||||
|
btt = blocks_to_check.pop();
|
||||||
|
Location loc = btt.loc;
|
||||||
|
World w = loc.getWorld();
|
||||||
|
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) {
|
||||||
|
sscache.invalidateSnapshot(w.getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||||
|
if((onblockfromto && btt.trigger.equals("blockfromto")) ||
|
||||||
|
(onblockphysics && btt.trigger.equals("blockphysics"))) {
|
||||||
|
mapManager.touch(w.getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), btt.trigger);
|
||||||
|
//Log.info("trigger=" + btt.trigger + " before=" + btt.typeid + ", after=" + bt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
blocks_to_check.add(btt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean onplace;
|
private boolean onplace;
|
||||||
private boolean onbreak;
|
private boolean onbreak;
|
||||||
private boolean onblockform;
|
private boolean onblockform;
|
||||||
@ -735,16 +780,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||||||
public void onBlockFromTo(BlockFromToEvent event) {
|
public void onBlockFromTo(BlockFromToEvent event) {
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
return;
|
return;
|
||||||
Location loc = event.getToBlock().getLocation();
|
checkBlock(event.getBlock(), "blockfromto");
|
||||||
String wn = loc.getWorld().getName();
|
checkBlock(event.getToBlock(), "blockfromto");
|
||||||
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
|
||||||
if(onblockfromto)
|
|
||||||
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfromto");
|
|
||||||
loc = event.getBlock().getLocation();
|
|
||||||
wn = loc.getWorld().getName();
|
|
||||||
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
|
||||||
if(onblockfromto)
|
|
||||||
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfromto");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -752,12 +789,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
if(event.isCancelled())
|
if(event.isCancelled())
|
||||||
return;
|
return;
|
||||||
Location loc = event.getBlock().getLocation();
|
Block b = event.getBlock();
|
||||||
String wn = loc.getWorld().getName();
|
checkBlock(event.getBlock(), "blockphysics");
|
||||||
sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
|
||||||
if(onblockphysics) {
|
|
||||||
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockphysics");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
Loading…
Reference in New Issue
Block a user