Skip to content

Commit

Permalink
Ensure pending BlockStore updates aren't cancelled upon plugin disable
Browse files Browse the repository at this point in the history
  • Loading branch information
bermudalocket committed Jan 21, 2019
1 parent 7543e8e commit 912d88f
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/nu/nerd/SafeBuckets/SafeBuckets.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ public void onEnable() {
/**
* @see JavaPlugin#onDisable().
*/
/*
@Override
public void onDisable() {
getServer().getScheduler().cancelTasks(this);
for (Location location : CACHE) {
Block block = location.getBlock();
if (block.getType() == Material.WATER || block.getType() == Material.LAVA) {
Object meta = BlockStoreApi.getBlockMeta(block, this, METADATA_KEY);
if (meta == null || !((boolean) meta)) {
BlockStoreApi.setBlockMeta(block, this, METADATA_KEY, true);
}
}
}
}

*/
// ------------------------------------------------------------------------
/**
* If true, the given block is safe. Consults cache before calling the BlockStore API.
Expand Down Expand Up @@ -109,24 +118,26 @@ static boolean isSafe(Block block) {
* @param state the safety status (true = safe).
*/
static void setSafe(Block block, boolean state) {
if (state) {
sendDebugMessage("Safety change: " + Util.formatCoords(block.getLocation()) + " has been made §aSAFE");
CACHE.add(block.getLocation());
} else {
sendDebugMessage("Safety change: " + Util.formatCoords(block.getLocation()) + " has been made §cUNSAFE");
CACHE.remove(block.getLocation());
}
Bukkit.getScheduler().runTaskLater(PLUGIN, () -> {
if (state) {
sendDebugMessage("Safety change: " + Util.formatCoords(block.getLocation()) + " has been made §aSAFE");
CACHE.add(block.getLocation());
} else {
sendDebugMessage("Safety change: " + Util.formatCoords(block.getLocation()) + " has been made §cUNSAFE");
CACHE.remove(block.getLocation());
}

// check if there's an entry before spawning particles
if (Configuration.SHOW_PARTICLES && BlockStoreApi.getBlockMeta(block, PLUGIN, METADATA_KEY) != null) {
Bukkit.getScheduler().runTaskLaterAsynchronously(PLUGIN, () -> Util.showParticles(block, state), 1);
}
// check if there's an entry before spawning particles
if (Configuration.SHOW_PARTICLES && BlockStoreApi.getBlockMeta(block, PLUGIN, METADATA_KEY) != null) {
Bukkit.getScheduler().runTaskLaterAsynchronously(PLUGIN, () -> Util.showParticles(block, state), 1);
}

BlockStoreApi.setBlockMeta(block, PLUGIN, METADATA_KEY, state);
BlockStoreApi.setBlockMeta(block, PLUGIN, METADATA_KEY, state);

if (!state) {
Util.forceBlockUpdate(block);
}
if (!state) {
Util.forceBlockUpdate(block);
}
}, 1);
}

// ------------------------------------------------------------------------
Expand Down

0 comments on commit 912d88f

Please sign in to comment.