Code Cleanup Pt 2

This commit is contained in:
nossr50
2019-04-03 19:25:14 -07:00
parent 0e39656c88
commit 43037f8c13
118 changed files with 372 additions and 400 deletions

View File

@@ -12,7 +12,7 @@ public interface ChunkletManager {
* @param cz Chunklet Z coordinate that needs to be loaded
* @param world World that the chunklet needs to be loaded in
*/
public void loadChunklet(int cx, int cy, int cz, World world);
void loadChunklet(int cx, int cy, int cz, World world);
/**
* Unload a specific chunklet
@@ -22,7 +22,7 @@ public interface ChunkletManager {
* @param cz Chunklet Z coordinate that needs to be unloaded
* @param world World that the chunklet needs to be unloaded from
*/
public void unloadChunklet(int cx, int cy, int cz, World world);
void unloadChunklet(int cx, int cy, int cz, World world);
/**
* Load a given Chunk's Chunklet data
@@ -31,7 +31,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is to be loaded
* @param world World that the Chunk is in
*/
public void loadChunk(int cx, int cz, World world);
void loadChunk(int cx, int cz, World world);
/**
* Unload a given Chunk's Chunklet data
@@ -40,7 +40,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is to be unloaded
* @param world World that the Chunk is in
*/
public void unloadChunk(int cx, int cz, World world);
void unloadChunk(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is loaded
@@ -49,7 +49,7 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is loaded
* @param world World that the chunk was loaded in
*/
public void chunkLoaded(int cx, int cz, World world);
void chunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is unloaded
@@ -58,38 +58,38 @@ public interface ChunkletManager {
* @param cz Chunk Z coordinate that is unloaded
* @param world World that the chunk was unloaded in
*/
public void chunkUnloaded(int cx, int cz, World world);
void chunkUnloaded(int cx, int cz, World world);
/**
* Save all ChunkletStores related to the given world
*
* @param world World to save
*/
public void saveWorld(World world);
void saveWorld(World world);
/**
* Unload all ChunkletStores from memory related to the given world after saving them
*
* @param world World to unload
*/
public void unloadWorld(World world);
void unloadWorld(World world);
/**
* Load all ChunkletStores from all loaded chunks from this world into memory
*
* @param world World to load
*/
public void loadWorld(World world);
void loadWorld(World world);
/**
* Save all ChunkletStores
*/
public void saveAll();
void saveAll();
/**
* Unload all ChunkletStores after saving them
*/
public void unloadAll();
void unloadAll();
/**
* Check to see if a given location is set to true
@@ -100,7 +100,7 @@ public interface ChunkletManager {
* @param world World to check in
* @return true if the given location is set to true, false if otherwise
*/
public boolean isTrue(int x, int y, int z, World world);
boolean isTrue(int x, int y, int z, World world);
/**
* Check to see if a given block location is set to true
@@ -108,7 +108,7 @@ public interface ChunkletManager {
* @param block Block location to check
* @return true if the given block location is set to true, false if otherwise
*/
public boolean isTrue(Block block);
boolean isTrue(Block block);
/**
* Set a given location to true, should create stores as necessary if the location does not exist
@@ -118,14 +118,14 @@ public interface ChunkletManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setTrue(int x, int y, int z, World world);
void setTrue(int x, int y, int z, World world);
/**
* Set a given block location to true, should create stores as necessary if the location does not exist
*
* @param block Block location to set
*/
public void setTrue(Block block);
void setTrue(Block block);
/**
* Set a given location to false, should not create stores if one does not exist for the given location
@@ -135,17 +135,17 @@ public interface ChunkletManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setFalse(int x, int y, int z, World world);
void setFalse(int x, int y, int z, World world);
/**
* Set a given block location to false, should not create stores if one does not exist for the given location
*
* @param block Block location to set
*/
public void setFalse(Block block);
void setFalse(Block block);
/**
* Delete any ChunkletStores that are empty
*/
public void cleanUp();
void cleanUp();
}

View File

@@ -14,7 +14,7 @@ public interface ChunkletStore extends Serializable {
* @param z z coordinate in current chunklet
* @return true if the value is true at the given coordinates, false if otherwise
*/
public boolean isTrue(int x, int y, int z);
boolean isTrue(int x, int y, int z);
/**
* Set the value to true at the given coordinates
@@ -23,7 +23,7 @@ public interface ChunkletStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setTrue(int x, int y, int z);
void setTrue(int x, int y, int z);
/**
* Set the value to false at the given coordinates
@@ -32,17 +32,17 @@ public interface ChunkletStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setFalse(int x, int y, int z);
void setFalse(int x, int y, int z);
/**
* @return true if all values in the chunklet are false, false if otherwise
*/
public boolean isEmpty();
boolean isEmpty();
/**
* Set all values in this ChunkletStore to the values from another provided ChunkletStore
*
* @param otherStore Another ChunkletStore that this one should copy all data from
*/
public void copyFrom(ChunkletStore otherStore);
void copyFrom(ChunkletStore otherStore);
}

View File

@@ -8,7 +8,7 @@ import java.io.*;
import java.util.HashMap;
public class HashChunkletManager implements ChunkletManager {
public HashMap<String, ChunkletStore> store = new HashMap<String, ChunkletStore>();
public HashMap<String, ChunkletStore> store = new HashMap<>();
@Override
public void loadChunklet(int cx, int cy, int cz, World world) {

View File

@@ -8,13 +8,13 @@ import org.bukkit.entity.Entity;
import java.io.IOException;
public interface ChunkManager {
public void closeAll();
void closeAll();
public ChunkStore readChunkStore(World world, int x, int z) throws IOException;
ChunkStore readChunkStore(World world, int x, int z) throws IOException;
public void writeChunkStore(World world, int x, int z, ChunkStore data);
void writeChunkStore(World world, int x, int z, ChunkStore data);
public void closeChunkStore(World world, int x, int z);
void closeChunkStore(World world, int x, int z);
/**
* Loads a specific chunklet
@@ -24,7 +24,7 @@ public interface ChunkManager {
* @param cz Chunklet Z coordinate that needs to be loaded
* @param world World that the chunklet needs to be loaded in
*/
public void loadChunklet(int cx, int cy, int cz, World world);
void loadChunklet(int cx, int cy, int cz, World world);
/**
* Unload a specific chunklet
@@ -34,7 +34,7 @@ public interface ChunkManager {
* @param cz Chunklet Z coordinate that needs to be unloaded
* @param world World that the chunklet needs to be unloaded from
*/
public void unloadChunklet(int cx, int cy, int cz, World world);
void unloadChunklet(int cx, int cy, int cz, World world);
/**
* Load a given Chunk's Chunklet data
@@ -43,7 +43,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be loaded
* @param world World that the Chunk is in
*/
public void loadChunk(int cx, int cz, World world, Entity[] entities);
void loadChunk(int cx, int cz, World world, Entity[] entities);
/**
* Unload a given Chunk's Chunklet data
@@ -52,7 +52,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be unloaded
* @param world World that the Chunk is in
*/
public void unloadChunk(int cx, int cz, World world);
void unloadChunk(int cx, int cz, World world);
/**
* Saves a given Chunk's Chunklet data
@@ -61,9 +61,9 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is to be saved
* @param world World that the Chunk is in
*/
public void saveChunk(int cx, int cz, World world);
void saveChunk(int cx, int cz, World world);
public boolean isChunkLoaded(int cx, int cz, World world);
boolean isChunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is loaded
@@ -72,7 +72,7 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is loaded
* @param world World that the chunk was loaded in
*/
public void chunkLoaded(int cx, int cz, World world);
void chunkLoaded(int cx, int cz, World world);
/**
* Informs the ChunkletManager a chunk is unloaded
@@ -81,38 +81,38 @@ public interface ChunkManager {
* @param cz Chunk Z coordinate that is unloaded
* @param world World that the chunk was unloaded in
*/
public void chunkUnloaded(int cx, int cz, World world);
void chunkUnloaded(int cx, int cz, World world);
/**
* Save all ChunkletStores related to the given world
*
* @param world World to save
*/
public void saveWorld(World world);
void saveWorld(World world);
/**
* Unload all ChunkletStores from memory related to the given world after saving them
*
* @param world World to unload
*/
public void unloadWorld(World world);
void unloadWorld(World world);
/**
* Load all ChunkletStores from all loaded chunks from this world into memory
*
* @param world World to load
*/
public void loadWorld(World world);
void loadWorld(World world);
/**
* Save all ChunkletStores
*/
public void saveAll();
void saveAll();
/**
* Unload all ChunkletStores after saving them
*/
public void unloadAll();
void unloadAll();
/**
* Check to see if a given location is set to true
@@ -123,7 +123,7 @@ public interface ChunkManager {
* @param world World to check in
* @return true if the given location is set to true, false if otherwise
*/
public boolean isTrue(int x, int y, int z, World world);
boolean isTrue(int x, int y, int z, World world);
/**
* Check to see if a given block location is set to true
@@ -131,7 +131,7 @@ public interface ChunkManager {
* @param block Block location to check
* @return true if the given block location is set to true, false if otherwise
*/
public boolean isTrue(Block block);
boolean isTrue(Block block);
/**
* Check to see if a given BlockState location is set to true
@@ -139,7 +139,7 @@ public interface ChunkManager {
* @param blockState BlockState to check
* @return true if the given BlockState location is set to true, false if otherwise
*/
public boolean isTrue(BlockState blockState);
boolean isTrue(BlockState blockState);
/**
* Set a given location to true, should create stores as necessary if the location does not exist
@@ -149,21 +149,21 @@ public interface ChunkManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setTrue(int x, int y, int z, World world);
void setTrue(int x, int y, int z, World world);
/**
* Set a given block location to true, should create stores as necessary if the location does not exist
*
* @param block Block location to set
*/
public void setTrue(Block block);
void setTrue(Block block);
/**
* Set a given BlockState location to true, should create stores as necessary if the location does not exist
*
* @param blockState BlockState location to set
*/
public void setTrue(BlockState blockState);
void setTrue(BlockState blockState);
/**
* Set a given location to false, should not create stores if one does not exist for the given location
@@ -173,24 +173,24 @@ public interface ChunkManager {
* @param z Z coordinate to set
* @param world World to set in
*/
public void setFalse(int x, int y, int z, World world);
void setFalse(int x, int y, int z, World world);
/**
* Set a given block location to false, should not create stores if one does not exist for the given location
*
* @param block Block location to set
*/
public void setFalse(Block block);
void setFalse(Block block);
/**
* Set a given BlockState location to false, should not create stores if one does not exist for the given location
*
* @param blockState BlockState location to set
*/
public void setFalse(BlockState blockState);
void setFalse(BlockState blockState);
/**
* Delete any ChunkletStores that are empty
*/
public void cleanUp();
void cleanUp();
}

View File

@@ -13,28 +13,28 @@ public interface ChunkStore extends Serializable {
*
* @return true if the has been modified since it was last saved
*/
public boolean isDirty();
boolean isDirty();
/**
* Checks the chunk's save state
*
* @param dirty the save state of the current chunk
*/
public void setDirty(boolean dirty);
void setDirty(boolean dirty);
/**
* Checks the chunk's x coordinate
*
* @return the chunk's x coordinate.
*/
public int getChunkX();
int getChunkX();
/**
* Checks the chunk's z coordinate
*
* @return the chunk's z coordinate.
*/
public int getChunkZ();
int getChunkZ();
/**
* Checks the value at the given coordinates
@@ -44,7 +44,7 @@ public interface ChunkStore extends Serializable {
* @param z z coordinate in current chunklet
* @return true if the value is true at the given coordinates, false if otherwise
*/
public boolean isTrue(int x, int y, int z);
boolean isTrue(int x, int y, int z);
/**
* Set the value to true at the given coordinates
@@ -53,7 +53,7 @@ public interface ChunkStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setTrue(int x, int y, int z);
void setTrue(int x, int y, int z);
/**
* Set the value to false at the given coordinates
@@ -62,17 +62,17 @@ public interface ChunkStore extends Serializable {
* @param y y coordinate in current chunklet
* @param z z coordinate in current chunklet
*/
public void setFalse(int x, int y, int z);
void setFalse(int x, int y, int z);
/**
* @return true if all values in the chunklet are false, false if otherwise
*/
public boolean isEmpty();
boolean isEmpty();
/**
* Set all values in this ChunkletStore to the values from another provided ChunkletStore
*
* @param otherStore Another ChunkletStore that this one should copy all data from
*/
public void copyFrom(ChunkletStore otherStore);
void copyFrom(ChunkletStore otherStore);
}

View File

@@ -11,10 +11,10 @@ import java.io.*;
import java.util.*;
public class HashChunkManager implements ChunkManager {
private HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>> regionFiles = new HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>>();
public HashMap<String, ChunkStore> store = new HashMap<String, ChunkStore>();
public ArrayList<BlockStoreConversionZDirectory> converters = new ArrayList<BlockStoreConversionZDirectory>();
private HashMap<UUID, Boolean> oldData = new HashMap<UUID, Boolean>();
private HashMap<UUID, HashMap<Long, McMMOSimpleRegionFile>> regionFiles = new HashMap<>();
public HashMap<String, ChunkStore> store = new HashMap<>();
public ArrayList<BlockStoreConversionZDirectory> converters = new ArrayList<>();
private HashMap<UUID, Boolean> oldData = new HashMap<>();
@Override
public synchronized void closeAll() {
@@ -38,31 +38,19 @@ public class HashChunkManager implements ChunkManager {
if (in == null) {
return null;
}
ObjectInputStream objectStream = new ObjectInputStream(in);
try {
try (ObjectInputStream objectStream = new ObjectInputStream(in)) {
Object o = objectStream.readObject();
if (o instanceof ChunkStore) {
return (ChunkStore) o;
}
throw new RuntimeException("Wrong class type read for chunk meta data for " + x + ", " + z);
}
catch (IOException e) {
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
// Assume the format changed
return null;
//throw new RuntimeException("Unable to process chunk meta data for " + x + ", " + z, e);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
// Assume the format changed
//System.out.println("[SpoutPlugin] is Unable to find serialized class for " + x + ", " + z + ", " + e.getMessage());
return null;
//throw new RuntimeException("Unable to find serialized class for " + x + ", " + z, e);
}
finally {
objectStream.close();
}
}
@Override
@@ -101,7 +89,7 @@ public class HashChunkManager implements ChunkManager {
HashMap<Long, McMMOSimpleRegionFile> worldRegions = regionFiles.get(key);
if (worldRegions == null) {
worldRegions = new HashMap<Long, McMMOSimpleRegionFile>();
worldRegions = new HashMap<>();
regionFiles.put(key, worldRegions);
}
@@ -222,7 +210,7 @@ public class HashChunkManager implements ChunkManager {
closeAll();
String worldName = world.getName();
List<String> keys = new ArrayList<String>(store.keySet());
List<String> keys = new ArrayList<>(store.keySet());
for (String key : keys) {
String[] info = key.split(",");
if (worldName.equals(info[0])) {
@@ -245,7 +233,7 @@ public class HashChunkManager implements ChunkManager {
closeAll();
String worldName = world.getName();
List<String> keys = new ArrayList<String>(store.keySet());
List<String> keys = new ArrayList<>(store.keySet());
for (String key : keys) {
String[] info = key.split(",");
if (worldName.equals(info[0])) {

View File

@@ -29,7 +29,7 @@ public class McMMOSimpleRegionFile {
private final int[] dataStart = new int[1024];
private final int[] dataActualLength = new int[1024];
private final int[] dataLength = new int[1024];
private final ArrayList<Boolean> inuse = new ArrayList<Boolean>();
private final ArrayList<Boolean> inuse = new ArrayList<>();
private int segmentSize;
private int segmentMask;
private final int rx;