mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
More nullability in blockmeta classes
This commit is contained in:
parent
7ea3a2bf07
commit
eff016c0a6
@ -3,6 +3,7 @@ package com.gmail.nossr50.util.blockmeta;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@ -15,9 +16,9 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
private final int cx;
|
private final int cx;
|
||||||
private final int cz;
|
private final int cz;
|
||||||
private final int worldHeight;
|
private final int worldHeight;
|
||||||
private final UUID worldUid;
|
private final @NotNull UUID worldUid;
|
||||||
// Bitset store conforms to a "bottom-up" bit ordering consisting of a stack of {worldHeight} Y planes, each Y plane consists of 16 Z rows of 16 X bits.
|
// Bitset store conforms to a "bottom-up" bit ordering consisting of a stack of {worldHeight} Y planes, each Y plane consists of 16 Z rows of 16 X bits.
|
||||||
private final BitSet store;
|
private final @NotNull BitSet store;
|
||||||
|
|
||||||
private transient boolean dirty = false;
|
private transient boolean dirty = false;
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
return (z * 16 + x) + (256 * y);
|
return (z * 16 + x) + (256 * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getWorldHeight(UUID worldUid, int storedWorldHeight)
|
private static int getWorldHeight(@NotNull UUID worldUid, int storedWorldHeight)
|
||||||
{
|
{
|
||||||
World world = Bukkit.getWorld(worldUid);
|
World world = Bukkit.getWorld(worldUid);
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
return world.getMaxHeight();
|
return world.getMaxHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void serialize(DataOutputStream out) throws IOException {
|
private void serialize(@NotNull DataOutputStream out) throws IOException {
|
||||||
out.writeInt(MAGIC_NUMBER);
|
out.writeInt(MAGIC_NUMBER);
|
||||||
out.writeInt(CURRENT_VERSION);
|
out.writeInt(CURRENT_VERSION);
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BitSetChunkStore deserialize(@NotNull DataInputStream in) throws IOException {
|
private static @NotNull BitSetChunkStore deserialize(@NotNull DataInputStream in) throws IOException {
|
||||||
int magic = in.readInt();
|
int magic = in.readInt();
|
||||||
// Can be used to determine the format of the file
|
// Can be used to determine the format of the file
|
||||||
int fileVersionNumber = in.readInt();
|
int fileVersionNumber = in.readInt();
|
||||||
@ -187,7 +188,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
throw new IOException("Bad Data Format");
|
throw new IOException("Bad Data Format");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeChunkStore(DataOutputStream outputStream, ChunkStore chunkStore) throws IOException {
|
public static void writeChunkStore(@NotNull DataOutputStream outputStream, @NotNull ChunkStore chunkStore) throws IOException {
|
||||||
if (!(chunkStore instanceof BitSetChunkStore))
|
if (!(chunkStore instanceof BitSetChunkStore))
|
||||||
throw new InvalidClassException("ChunkStore must be instance of BitSetChunkStore");
|
throw new InvalidClassException("ChunkStore must be instance of BitSetChunkStore");
|
||||||
outputStream.writeShort(STREAM_MAGIC);
|
outputStream.writeShort(STREAM_MAGIC);
|
||||||
@ -209,12 +210,12 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
private LegacyChunkStoreDeserializer() {}
|
private LegacyChunkStoreDeserializer() {}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
private void writeObject(@NotNull ObjectOutputStream out) throws IOException {
|
||||||
throw new UnsupportedOperationException("You goofed.");
|
throw new UnsupportedOperationException("You goofed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
private void readObject(@NotNull ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||||
in.readInt(); // Magic number
|
in.readInt(); // Magic number
|
||||||
in.readInt(); // Format version
|
in.readInt(); // Format version
|
||||||
long lsb = in.readLong();
|
long lsb = in.readLong();
|
||||||
@ -228,7 +229,7 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
worldHeight = store[0][0].length;
|
worldHeight = store[0][0].length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitSetChunkStore convert()
|
public @NotNull BitSetChunkStore convert()
|
||||||
{
|
{
|
||||||
int currentWorldHeight = getWorldHeight(worldUid, worldHeight);
|
int currentWorldHeight = getWorldHeight(worldUid, worldHeight);
|
||||||
|
|
||||||
@ -249,20 +250,20 @@ public class BitSetChunkStore implements ChunkStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LegacyDeserializationInputStream(InputStream in) throws IOException {
|
public LegacyDeserializationInputStream(@NotNull InputStream in) throws IOException {
|
||||||
super(in);
|
super(in);
|
||||||
enableResolveObject(true);
|
enableResolveObject(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
|
protected @NotNull ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
|
||||||
ObjectStreamClass read = super.readClassDescriptor();
|
ObjectStreamClass read = super.readClassDescriptor();
|
||||||
if (read.getName().contentEquals("com.gmail.nossr50.util.blockmeta.chunkmeta.PrimitiveChunkStore"))
|
if (read.getName().contentEquals("com.gmail.nossr50.util.blockmeta.chunkmeta.PrimitiveChunkStore"))
|
||||||
return ObjectStreamClass.lookup(LegacyChunkStoreDeserializer.class);
|
return ObjectStreamClass.lookup(LegacyChunkStoreDeserializer.class);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkStore readLegacyChunkStore(){
|
public @Nullable ChunkStore readLegacyChunkStore(){
|
||||||
try {
|
try {
|
||||||
LegacyChunkStoreDeserializer deserializer = (LegacyChunkStoreDeserializer)readObject();
|
LegacyChunkStoreDeserializer deserializer = (LegacyChunkStoreDeserializer)readObject();
|
||||||
return deserializer.convert();
|
return deserializer.convert();
|
||||||
|
@ -65,7 +65,7 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized @Nullable McMMOSimpleRegionFile getSimpleRegionFile(World world, int cx, int cz, boolean createIfAbsent) {
|
private synchronized @Nullable McMMOSimpleRegionFile getSimpleRegionFile(@NotNull World world, int cx, int cz, boolean createIfAbsent) {
|
||||||
CoordinateKey regionKey = toRegionKey(world.getUID(), cx, cz);
|
CoordinateKey regionKey = toRegionKey(world.getUID(), cx, cz);
|
||||||
|
|
||||||
return regionMap.computeIfAbsent(regionKey, k -> {
|
return regionMap.computeIfAbsent(regionKey, k -> {
|
||||||
@ -80,7 +80,7 @@ public class HashChunkManager implements ChunkManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable ChunkStore loadChunk(int cx, int cz, World world) {
|
private @Nullable ChunkStore loadChunk(int cx, int cz, @NotNull World world) {
|
||||||
try {
|
try {
|
||||||
return readChunkStore(world, cx, cz);
|
return readChunkStore(world, cx, cz);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user