|
@@ -1,6 +1,5 @@
|
|
|
package com.gmail.nossr50.util.blockmeta;
|
|
|
|
|
|
-import com.gmail.nossr50.mcMMO;
|
|
|
import org.bukkit.Bukkit;
|
|
|
import org.bukkit.World;
|
|
|
import org.bukkit.block.Block;
|
|
@@ -8,13 +7,16 @@ import org.bukkit.block.BlockState;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.DataInputStream;
|
|
|
+import java.io.DataOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class HashChunkManager implements ChunkManager {
|
|
|
- private final @NotNull HashMap<CoordinateKey, McMMOSimpleRegionFile> regionMap = new HashMap<>(); // Tracks active regions
|
|
|
- private final @NotNull HashMap<CoordinateKey, HashSet<CoordinateKey>> chunkUsageMap = new HashMap<>(); // Tracks active chunks by region
|
|
|
- private final @NotNull HashMap<CoordinateKey, ChunkStore> chunkMap = new HashMap<>(); // Tracks active chunks
|
|
|
+ private final HashMap<CoordinateKey, McMMOSimpleRegionFile> regionMap = new HashMap<>(); // Tracks active regions
|
|
|
+ private final HashMap<CoordinateKey, HashSet<CoordinateKey>> chunkUsageMap = new HashMap<>(); // Tracks active chunks by region
|
|
|
+ private final HashMap<CoordinateKey, ChunkStore> chunkMap = new HashMap<>(); // Tracks active chunks
|
|
|
|
|
|
@Override
|
|
|
public synchronized void closeAll() {
|
|
@@ -23,7 +25,10 @@ public class HashChunkManager implements ChunkManager {
|
|
|
{
|
|
|
if (!chunkStore.isDirty())
|
|
|
continue;
|
|
|
- writeChunkStore(Bukkit.getWorld(chunkStore.getWorldId()), chunkStore);
|
|
|
+ World world = Bukkit.getWorld(chunkStore.getWorldId());
|
|
|
+ if (world == null)
|
|
|
+ continue; // Oh well
|
|
|
+ writeChunkStore(world, chunkStore);
|
|
|
}
|
|
|
// Clear in memory chunks
|
|
|
chunkMap.clear();
|
|
@@ -104,56 +109,12 @@ public class HashChunkManager implements ChunkManager {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void saveChunk(int cx, int cz, @Nullable World world) {
|
|
|
- if (world == null)
|
|
|
- return;
|
|
|
-
|
|
|
- CoordinateKey chunkKey = toChunkKey(world.getUID(), cx, cz);
|
|
|
-
|
|
|
- ChunkStore out = chunkMap.get(chunkKey);
|
|
|
-
|
|
|
- if (out == null)
|
|
|
- return;
|
|
|
-
|
|
|
- if (!out.isDirty())
|
|
|
- return;
|
|
|
-
|
|
|
- writeChunkStore(world, out);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public synchronized void chunkUnloaded(int cx, int cz, @Nullable World world) {
|
|
|
- if (world == null)
|
|
|
- return;
|
|
|
-
|
|
|
+ public synchronized void chunkUnloaded(int cx, int cz, @NotNull World world) {
|
|
|
unloadChunk(cx, cz, world);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void saveWorld(@Nullable World world) {
|
|
|
- if (world == null)
|
|
|
- return;
|
|
|
-
|
|
|
- UUID wID = world.getUID();
|
|
|
-
|
|
|
- // Save all teh chunks
|
|
|
- for (ChunkStore chunkStore : chunkMap.values()) {
|
|
|
- if (!chunkStore.isDirty())
|
|
|
- continue;
|
|
|
- if (!wID.equals(chunkStore.getWorldId()))
|
|
|
- continue;
|
|
|
- try {
|
|
|
- writeChunkStore(world, chunkStore);
|
|
|
- }
|
|
|
- catch (Exception ignore) { }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public synchronized void unloadWorld(@Nullable World world) {
|
|
|
- if (world == null)
|
|
|
- return;
|
|
|
-
|
|
|
+ public synchronized void unloadWorld(@NotNull World world) {
|
|
|
UUID wID = world.getUID();
|
|
|
|
|
|
// Save and remove all the chunks
|
|
@@ -179,18 +140,7 @@ public class HashChunkManager implements ChunkManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public synchronized void saveAll() {
|
|
|
- for (World world : mcMMO.p.getServer().getWorlds()) {
|
|
|
- saveWorld(world);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public synchronized boolean isTrue(int x, int y, int z, @Nullable World world) {
|
|
|
- if (world == null)
|
|
|
- return false;
|
|
|
-
|
|
|
+ private synchronized boolean isTrue(int x, int y, int z, @NotNull World world) {
|
|
|
CoordinateKey chunkKey = blockCoordinateToChunkKey(world.getUID(), x, y, z);
|
|
|
|
|
|
// Get chunk, load from file if necessary
|
|
@@ -216,67 +166,36 @@ public class HashChunkManager implements ChunkManager {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized boolean isTrue(@Nullable Block block) {
|
|
|
- if (block == null)
|
|
|
- return false;
|
|
|
-
|
|
|
+ public synchronized boolean isTrue(@NotNull Block block) {
|
|
|
return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized boolean isTrue(@Nullable BlockState blockState) {
|
|
|
- if (blockState == null)
|
|
|
- return false;
|
|
|
-
|
|
|
+ public synchronized boolean isTrue(@NotNull BlockState blockState) {
|
|
|
return isTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void setTrue(int x, int y, int z, @Nullable World world) {
|
|
|
- set(x, y, z, world, true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public synchronized void setTrue(@Nullable Block block) {
|
|
|
- if (block == null)
|
|
|
- return;
|
|
|
-
|
|
|
- setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
|
|
|
+ public synchronized void setTrue(@NotNull Block block) {
|
|
|
+ set(block.getX(), block.getY(), block.getZ(), block.getWorld(), true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void setTrue(@Nullable BlockState blockState) {
|
|
|
- if (blockState == null)
|
|
|
- return;
|
|
|
-
|
|
|
- setTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
|
|
|
+ public synchronized void setTrue(@NotNull BlockState blockState) {
|
|
|
+ set(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld(), true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void setFalse(int x, int y, int z, @Nullable World world) {
|
|
|
- set(x, y, z, world, false);
|
|
|
+ public synchronized void setFalse(@NotNull Block block) {
|
|
|
+ set(block.getX(), block.getY(), block.getZ(), block.getWorld(), false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void setFalse(@Nullable Block block) {
|
|
|
- if (block == null)
|
|
|
- return;
|
|
|
-
|
|
|
- setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld());
|
|
|
+ public synchronized void setFalse(@NotNull BlockState blockState) {
|
|
|
+ set(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld(), false);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public synchronized void setFalse(@Nullable BlockState blockState) {
|
|
|
- if (blockState == null)
|
|
|
- return;
|
|
|
-
|
|
|
- setFalse(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
|
|
|
- }
|
|
|
-
|
|
|
- public synchronized void set(int x, int y, int z, @Nullable World world, boolean value){
|
|
|
- if (world == null)
|
|
|
- return;
|
|
|
-
|
|
|
+ private synchronized void set(int x, int y, int z, @NotNull World world, boolean value){
|
|
|
CoordinateKey chunkKey = blockCoordinateToChunkKey(world.getUID(), x, y, z);
|
|
|
|
|
|
// Get/Load/Create chunkstore
|
|
@@ -350,7 +269,4 @@ public class HashChunkManager implements ChunkManager {
|
|
|
return Objects.hash(worldID, x, z);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public synchronized void cleanUp() {}
|
|
|
}
|