mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-17 06:03:53 +00:00
Cleanup
This commit is contained in:
@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package com.sk89q.worldedit.data;
|
||||
|
||||
import java.util.List;
|
||||
@ -38,7 +37,7 @@ public class Chunk {
|
||||
private byte[] data;
|
||||
private int rootX;
|
||||
private int rootZ;
|
||||
private Map<BlockVector,Map<String,Tag>> tileEntities;
|
||||
private Map<BlockVector, Map<String, Tag>> tileEntities;
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
@ -49,13 +48,13 @@ public class Chunk {
|
||||
public Chunk(CompoundTag tag) throws DataException {
|
||||
rootTag = tag;
|
||||
|
||||
blocks = ((ByteArrayTag)getChildTag(
|
||||
blocks = ((ByteArrayTag) getChildTag(
|
||||
rootTag.getValue(), "Blocks", ByteArrayTag.class)).getValue();
|
||||
data = ((ByteArrayTag)getChildTag(
|
||||
data = ((ByteArrayTag) getChildTag(
|
||||
rootTag.getValue(), "Data", ByteArrayTag.class)).getValue();
|
||||
rootX = ((IntTag)getChildTag(
|
||||
rootX = ((IntTag) getChildTag(
|
||||
rootTag.getValue(), "xPos", IntTag.class)).getValue();
|
||||
rootZ = ((IntTag)getChildTag(
|
||||
rootZ = ((IntTag) getChildTag(
|
||||
rootTag.getValue(), "zPos", IntTag.class)).getValue();
|
||||
|
||||
if (blocks.length != 32768) {
|
||||
@ -121,37 +120,37 @@ public class Chunk {
|
||||
* @throws DataException
|
||||
*/
|
||||
private void populateTileEntities() throws DataException {
|
||||
List<Tag> tags = (List<Tag>)((ListTag)getChildTag(
|
||||
List<Tag> tags = (List<Tag>) ((ListTag) getChildTag(
|
||||
rootTag.getValue(), "TileEntities", ListTag.class))
|
||||
.getValue();
|
||||
|
||||
tileEntities = new HashMap<BlockVector,Map<String,Tag>>();
|
||||
tileEntities = new HashMap<BlockVector, Map<String, Tag>>();
|
||||
|
||||
for (Tag tag : tags) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new InvalidFormatException("CompoundTag expected in TileEntities");
|
||||
}
|
||||
|
||||
CompoundTag t = (CompoundTag)tag;
|
||||
CompoundTag t = (CompoundTag) tag;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
|
||||
for (Map.Entry<String,Tag> entry : t.getValue().entrySet()) {
|
||||
for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
|
||||
if (entry.getKey().equals("x")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
x = ((IntTag)entry.getValue()).getValue();
|
||||
x = ((IntTag) entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("y")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
y = ((IntTag)entry.getValue()).getValue();
|
||||
y = ((IntTag) entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("z")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
z = ((IntTag)entry.getValue()).getValue();
|
||||
z = ((IntTag) entry.getValue()).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,9 +171,10 @@ public class Chunk {
|
||||
* @return
|
||||
* @throws DataException
|
||||
*/
|
||||
private Map<String,Tag> getBlockTileEntity(Vector pos) throws DataException {
|
||||
if (tileEntities == null)
|
||||
private Map<String, Tag> getBlockTileEntity(Vector pos) throws DataException {
|
||||
if (tileEntities == null) {
|
||||
populateTileEntities();
|
||||
}
|
||||
|
||||
return tileEntities.get(new BlockVector(pos));
|
||||
}
|
||||
@ -208,8 +208,8 @@ public class Chunk {
|
||||
}
|
||||
|
||||
if (block instanceof TileEntityBlock) {
|
||||
Map<String,Tag> tileEntity = getBlockTileEntity(pos);
|
||||
((TileEntityBlock)block).fromTileEntityNBT(tileEntity);
|
||||
Map<String, Tag> tileEntity = getBlockTileEntity(pos);
|
||||
((TileEntityBlock) block).fromTileEntityNBT(tileEntity);
|
||||
}
|
||||
|
||||
return block;
|
||||
@ -224,7 +224,7 @@ public class Chunk {
|
||||
* @return child tag
|
||||
* @throws InvalidFormatException
|
||||
*/
|
||||
public static Tag getChildTag(Map<String,Tag> items, String key,
|
||||
public static Tag getChildTag(Map<String, Tag> items, String key,
|
||||
Class<? extends Tag> expected)
|
||||
throws InvalidFormatException {
|
||||
if (!items.containsKey(key)) {
|
||||
@ -232,8 +232,7 @@ public class Chunk {
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new InvalidFormatException(
|
||||
key + " tag is not of tag type " + expected.getName());
|
||||
throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ public abstract class ChunkStore {
|
||||
* @return
|
||||
*/
|
||||
public static BlockVector2D toChunk(Vector pos) {
|
||||
int chunkX = (int)Math.floor(pos.getBlockX() / 16.0);
|
||||
int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0);
|
||||
int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
|
||||
int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);
|
||||
|
||||
return new BlockVector2D(chunkX, chunkZ);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class FileMcRegionChunkStore extends McRegionChunkStore {
|
||||
if (!file.exists()) {
|
||||
file = new File(path, "DIM-1" + File.separator + fileName);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -23,10 +23,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ForwardSeekableInputStream extends InputStream {
|
||||
|
||||
|
||||
protected InputStream parent;
|
||||
protected long position = 0;
|
||||
|
||||
|
||||
public ForwardSeekableInputStream(InputStream parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
@ -83,18 +83,18 @@ public class ForwardSeekableInputStream extends InputStream {
|
||||
position += skipped;
|
||||
return skipped;
|
||||
}
|
||||
|
||||
|
||||
public void seek(long n) throws IOException {
|
||||
long diff = n - position;
|
||||
|
||||
|
||||
if (diff < 0) {
|
||||
throw new IOException("Can't seek backwards");
|
||||
}
|
||||
|
||||
|
||||
if (diff == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (skip(diff) < diff) {
|
||||
throw new IOException("Failed to seek " + diff + " bytes");
|
||||
}
|
||||
|
@ -96,14 +96,14 @@ public abstract class LegacyChunkStore extends ChunkStore {
|
||||
+ tag.getClass().getName());
|
||||
}
|
||||
|
||||
Map<String,Tag> children = (Map<String,Tag>)((CompoundTag)tag).getValue();
|
||||
Map<String, Tag> children = (Map<String, Tag>) ((CompoundTag) tag).getValue();
|
||||
CompoundTag rootTag = null;
|
||||
|
||||
// Find Level tag
|
||||
for (Map.Entry<String,Tag> entry : children.entrySet()) {
|
||||
for (Map.Entry<String, Tag> entry : children.entrySet()) {
|
||||
if (entry.getKey().equals("Level")) {
|
||||
if (entry.getValue() instanceof CompoundTag) {
|
||||
rootTag = (CompoundTag)entry.getValue();
|
||||
rootTag = (CompoundTag) entry.getValue();
|
||||
break;
|
||||
} else {
|
||||
throw new ChunkStoreException("CompoundTag expected for 'Level'; got "
|
||||
@ -130,7 +130,7 @@ public abstract class LegacyChunkStore extends ChunkStore {
|
||||
* @return
|
||||
*/
|
||||
private static int divisorMod(int a, int n) {
|
||||
return (int)(a - n * Math.floor(Math.floor(a) / (double)n));
|
||||
return (int) (a - n * Math.floor(Math.floor(a) / (double) n));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ import com.sk89q.worldedit.Vector2D;
|
||||
public abstract class McRegionChunkStore extends ChunkStore {
|
||||
protected String curFilename = null;
|
||||
protected McRegionReader cachedReader = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get the filename of a region file.
|
||||
*
|
||||
@ -40,12 +40,12 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
public static String getFilename(Vector2D pos) {
|
||||
int x = pos.getBlockX();
|
||||
int z = pos.getBlockZ();
|
||||
|
||||
|
||||
String filename = "r." + (x >> 5) + "." + (z >> 5) + ".mcr";
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException {
|
||||
String filename = getFilename(pos);
|
||||
if (curFilename != null) {
|
||||
@ -67,7 +67,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
@Override
|
||||
public CompoundTag getChunkTag(Vector2D pos, String worldname) throws DataException,
|
||||
IOException {
|
||||
|
||||
|
||||
McRegionReader reader = getReader(pos, worldname);
|
||||
InputStream stream = reader.getChunkInputStream(pos);
|
||||
NBTInputStream nbt = new NBTInputStream(stream);
|
||||
@ -80,14 +80,14 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
+ tag.getClass().getName());
|
||||
}
|
||||
|
||||
Map<String,Tag> children = (Map<String,Tag>)((CompoundTag)tag).getValue();
|
||||
Map<String, Tag> children = (Map<String, Tag>) ((CompoundTag) tag).getValue();
|
||||
CompoundTag rootTag = null;
|
||||
|
||||
// Find Level tag
|
||||
for (Map.Entry<String,Tag> entry : children.entrySet()) {
|
||||
for (Map.Entry<String, Tag> entry : children.entrySet()) {
|
||||
if (entry.getKey().equals("Level")) {
|
||||
if (entry.getValue() instanceof CompoundTag) {
|
||||
rootTag = (CompoundTag)entry.getValue();
|
||||
rootTag = (CompoundTag) entry.getValue();
|
||||
break;
|
||||
} else {
|
||||
throw new ChunkStoreException("CompoundTag expected for 'Level'; got "
|
||||
@ -115,7 +115,6 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
*/
|
||||
protected abstract InputStream getInputStream(String name, String worldname)
|
||||
throws IOException, DataException;
|
||||
|
||||
|
||||
/**
|
||||
* Close resources.
|
||||
|
@ -74,7 +74,7 @@ public class McRegionReader {
|
||||
|
||||
protected ForwardSeekableInputStream stream;
|
||||
protected DataInputStream dataStream;
|
||||
|
||||
|
||||
protected int offsets[];
|
||||
|
||||
/**
|
||||
@ -87,10 +87,10 @@ public class McRegionReader {
|
||||
public McRegionReader(InputStream stream) throws DataException, IOException {
|
||||
this.stream = new ForwardSeekableInputStream(stream);
|
||||
this.dataStream = new DataInputStream(this.stream);
|
||||
|
||||
|
||||
readHeader();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the header.
|
||||
*
|
||||
@ -119,13 +119,13 @@ public class McRegionReader {
|
||||
|
||||
int x = pos.getBlockX() & 31;
|
||||
int z = pos.getBlockZ() & 31;
|
||||
|
||||
|
||||
if (x < 0 || x >= 32 || z < 0 || z >= 32) {
|
||||
throw new DataException("MCRegion file does not contain " + x + "," + z);
|
||||
}
|
||||
|
||||
int offset = getOffset(x, z);
|
||||
|
||||
|
||||
// The chunk hasn't been generated
|
||||
if (offset == 0) {
|
||||
return null;
|
||||
@ -143,7 +143,7 @@ public class McRegionReader {
|
||||
}
|
||||
|
||||
byte version = dataStream.readByte();
|
||||
|
||||
|
||||
if (version == VERSION_GZIP) {
|
||||
byte[] data = new byte[length - 1];
|
||||
if (dataStream.read(data) < length - 1) {
|
||||
@ -185,7 +185,7 @@ public class McRegionReader {
|
||||
public boolean hasChunk(int x, int z) {
|
||||
return getOffset(x, z) != 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the stream.
|
||||
*
|
||||
@ -194,4 +194,4 @@ public class McRegionReader {
|
||||
public void close() throws IOException {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,10 +112,9 @@ public class TrueZipLegacyChunkStore extends LegacyChunkStore {
|
||||
|
||||
// So not there either...
|
||||
if (testEntry == null) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements(); ) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements();) {
|
||||
|
||||
testEntry = (ZipEntry)e.nextElement();
|
||||
testEntry = (ZipEntry) e.nextElement();
|
||||
|
||||
// Whoo, found level.dat!
|
||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||
|
@ -100,8 +100,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||
// World pattern
|
||||
Pattern worldPattern = Pattern.compile(worldname + "\\$");
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
|
||||
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||
// Check for world
|
||||
if (worldPattern.matcher(worldname).matches()) {
|
||||
@ -158,8 +157,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isValid() {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
|
||||
|
||||
ZipEntry testEntry = e.nextElement();
|
||||
|
||||
|
@ -109,10 +109,9 @@ public class ZippedLegacyChunkStore extends LegacyChunkStore {
|
||||
|
||||
// So not there either...
|
||||
if (testEntry == null) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements(); ) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
|
||||
|
||||
testEntry = (ZipEntry)e.nextElement();
|
||||
testEntry = (ZipEntry) e.nextElement();
|
||||
|
||||
// Whoo, found level.dat!
|
||||
if (pattern.matcher(testEntry.getName()).matches()) {
|
||||
|
@ -95,8 +95,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
}
|
||||
} else {
|
||||
Pattern pattern = Pattern.compile(".*\\.mcr$");
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
|
||||
ZipEntry testEntry = (ZipEntry) e.nextElement();
|
||||
// Check for world
|
||||
if (testEntry.getName().startsWith(worldname + "/")) {
|
||||
@ -105,10 +104,10 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
name = folder + "/" + name;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if world is found
|
||||
if (folder == null) {
|
||||
throw new MissingWorldException("Target world is not present in ZIP.", worldname);
|
||||
@ -152,8 +151,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries();
|
||||
e.hasMoreElements();) {
|
||||
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
|
||||
|
||||
ZipEntry testEntry = e.nextElement();
|
||||
|
||||
|
Reference in New Issue
Block a user