Skip to content

Commit

Permalink
Merge pull request #180 from TheLegionCrazy/patch-14
Browse files Browse the repository at this point in the history
fixes #179
  • Loading branch information
YourCoal authored Feb 1, 2019
2 parents 1717ada + 9b6a082 commit 7cca81c
Showing 1 changed file with 28 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,50 +49,33 @@ public SyncGetChestInventory() {
lock = new ReentrantLock();
}

@Override
public void run() {
if (lock.tryLock()) {
try {
for (int i = 0; i < UPDATE_LIMIT; i++) {
GetChestRequest request = requestQueue.poll();
if (request == null) {
continue;
}

Chest chest = null;

int chunkX = request.block_x >> 4;
int chunkZ = request.block_z >> 4;
net.minecraft.server.v1_11_R1.Chunk chunk =
((CraftWorld) Bukkit.getWorld(request.worldName))
.getHandle()
.getChunkIfLoaded(chunkX, chunkZ);
@Override
public void run() {
for (int i = 0; i < UPDATE_LIMIT; i++) {
GetChestRequest request = requestQueue.poll();
if (request == null) {
continue;
}

if (chunk != null) {
Block b =
chunk.bukkitChunk.getBlock(
request.block_x, request.block_y, request.block_z);

try {
chest = (Chest)b.getState();
} catch (ClassCastException e) {
ItemManager.setTypeId(b, CivData.CHEST);
ItemManager.setTypeId(b.getState(), CivData.CHEST);
b.getState().update();
chest = (Chest)b.getState();
}
}


/* Set the result and signal all threads we're complete. */
request.result = chest.getBlockInventory();
request.finished = true;
request.condition.signalAll();

}
} finally {
lock.unlock();
}
}
}
Chest chest = null;

if (((CraftWorld) Bukkit.getWorld(request.worldName)).isChunkLoaded(request.block_x >> 4, request.block_z >> 4)) {
Block b = Bukkit.getWorld(request.worldName).getBlockAt(request.block_x, request.block_y, request.block_z);

try {
chest = (Chest) b.getState();
} catch (ClassCastException e) {
ItemManager.setTypeId(b, CivData.CHEST);
ItemManager.setTypeId(b.getState(), CivData.CHEST);
b.getState().update();
chest = (Chest) b.getState();
}
}


request.result = chest.getBlockInventory();
request.finished = true;
request.condition.signalAll();
}
}
}

0 comments on commit 7cca81c

Please sign in to comment.