From 9061e18db9ac2379ec3decca735057b94d994c10 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 30 Sep 2013 19:35:43 +0200 Subject: [PATCH] Fixed: blockbreak in threaded mode requires cached value... --- .../minecraft/limitedcreative/ModBlockStates.java | 5 +++-- .../limitedcreative/blockstate/ThreadedModel.java | 5 ----- .../blockstate/thread/ThreadLink.java | 13 +++++++++++++ .../regions/worldguard/CustomRegionManager.java | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index 9a72994..cedb08b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -90,9 +90,10 @@ public class ModBlockStates extends CoreModule { } @Override public void onDisable() { - model.onDisable(); + if (model != null) + model.onDisable(); super.onDisable(); - if (model instanceof Listener) + if (model != null && model instanceof Listener) listeners.removeListener((Listener) model); model = null; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java index 8cf2766..b94484d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java @@ -132,11 +132,6 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { } @Override public boolean isRestricted(Block block) { - HasBlockState has = getMetaBlock(block); - if (!has.set) { - BlockState state = threads.callUpdate(block); - return state != null ? state.isRestricted() : false; - } return getMetaBlock(block).restricted; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java index dc37a19..abfcddc 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java @@ -19,6 +19,9 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; public class ThreadLink { private static final int BATCH_ACTION_LENGTH = 10; + private static final int QUEUE_ACCESS_WARNING_DURATION = 5; + private static final int COUNT_WARNING_QUEUE = 5; + private static final int COUNT_ERROR_QUEUE = 20; private Stack updateQueue = new Stack(); private boolean shutdown = false; @@ -59,6 +62,11 @@ public class ThreadLink { synchronized (updateQueue) { while (updateQueue.isEmpty() && !shutdown) updateQueue.wait(); + if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_ERROR_QUEUE)) { + getLog().severe("Extrem large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + } else if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_WARNING_QUEUE)) { + getLog().warn("Large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + } for (int i = 0; i < BATCH_ACTION_LENGTH && !updateQueue.isEmpty(); i++) { acts.add(updateQueue.pop()); } @@ -95,10 +103,15 @@ public class ThreadLink { public void queueUpdate(Block block) { + long l = System.currentTimeMillis(); synchronized (updateQueue) { updateQueue.add(new UpdateBlockStateAction(block)); updateQueue.notify(); } + long l2 = System.currentTimeMillis(); + if (l2 - l > QUEUE_ACCESS_WARNING_DURATION) { + getLog().warn("queueUpdate-action took to long: " + (l - 2) + "ms"); + } } public BlockState callUpdate(Block block) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java index 34be3a0..227481e 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/worldguard/CustomRegionManager.java @@ -170,7 +170,7 @@ public class CustomRegionManager { public String getRegionsHash(Location loc) { StringBuilder hash = new StringBuilder(loc.getWorld().getName()); - List idlist = getWGGlobalManager().get(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc)); + List idlist = getWGManager(loc.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(loc)); if (idlist.size() > 0) { hash.append("#"); String[] ids = idlist.toArray(new String[idlist.size()]);