Hunk Slices!

This commit is contained in:
Daniel Mills 2020-10-27 22:14:32 -04:00
parent 39b4649a04
commit aff7e49024
7 changed files with 521 additions and 422 deletions

View File

@ -116,26 +116,56 @@ public class Iris extends MortarPlugin
} }
private static boolean doesSupport3DBiomes() private static boolean doesSupport3DBiomes()
{
try
{ {
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]); int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 15; return v >= 15;
} }
catch(Throwable e)
{
}
return false;
}
private static boolean doesSupportCustomModels() private static boolean doesSupportCustomModels()
{
try
{ {
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]); int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 14; return v >= 14;
} }
catch(Throwable e)
{
}
return false;
}
private static boolean doesSupportAwareness() private static boolean doesSupportAwareness()
{
try
{ {
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]); int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 15; return v >= 15;
} }
catch(Throwable e)
{
}
return false;
}
@Override @Override
public void start() public void start()
{ {
@ -281,17 +311,22 @@ public class Iris extends MortarPlugin
public static void msg(String string) public static void msg(String string)
{ {
lock.lock(); try
{
if(instance == null) if(instance == null)
{ {
System.out.println("[Iris]: " + string); System.out.println("[Iris]: " + string);
lock.unlock();
return; return;
} }
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string; String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
Bukkit.getConsoleSender().sendMessage(msg); Bukkit.getConsoleSender().sendMessage(msg);
lock.unlock(); }
catch(Throwable e)
{
System.out.println("[Iris]: " + string);
}
} }
public static File getCached(String name, String url) public static File getCached(String name, String url)
@ -388,6 +423,13 @@ public class Iris extends MortarPlugin
} }
public static void verbose(String string) public static void verbose(String string)
{
if(true)
{
System.out.println(string);
}
try
{ {
if(IrisSettings.get().verbose) if(IrisSettings.get().verbose)
{ {
@ -395,6 +437,12 @@ public class Iris extends MortarPlugin
} }
} }
catch(Throwable e)
{
msg(C.GRAY + string);
}
}
public static void success(String string) public static void success(String string)
{ {
msg(C.GREEN + string); msg(C.GREEN + string);

View File

@ -1,15 +1,18 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io; package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.util.CompoundTag; import java.io.File;
import lombok.Getter; import java.io.IOException;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.io.File; import com.volmit.iris.util.CompoundTag;
public class HunkCompoundRegion extends HunkRegion { import lombok.Getter;
public class HunkCompoundRegion extends HunkRegion
{
@Getter @Getter
private HunkRegionSlice<BlockData> parallaxSlice; private HunkRegionSlice<BlockData> blockSlice;
@Getter @Getter
private HunkRegionSlice<String> objectSlice; private HunkRegionSlice<String> objectSlice;
@Getter @Getter
@ -17,21 +20,39 @@ public class HunkCompoundRegion extends HunkRegion {
private final int height; private final int height;
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound) { public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound)
{
super(folder, x, z, compound); super(folder, x, z, compound);
this.height = height; this.height = height;
setupSlices(); setupSlices();
} }
public HunkCompoundRegion(int height, File folder, int x, int z) { public HunkCompoundRegion(int height, File folder, int x, int z)
{
super(folder, x, z); super(folder, x, z);
this.height = height; this.height = height;
setupSlices(); setupSlices();
} }
private void setupSlices() { private void setupSlices()
parallaxSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound()); {
blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects"); objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates"); updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
} }
public void save() throws IOException
{
blockSlice.save();
objectSlice.save();
updateSlice.save();
super.save();
}
public void unload()
{
blockSlice.unloadAll();
objectSlice.unloadAll();
updateSlice.unloadAll();
}
} }

View File

@ -1,16 +1,19 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io; package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NBTInputStream;
import com.volmit.iris.util.NBTOutputStream;
import lombok.Data;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import com.volmit.iris.Iris;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NBTInputStream;
import com.volmit.iris.util.NBTOutputStream;
import com.volmit.iris.util.Tag;
import lombok.Data;
@Data @Data
public class HunkRegion public class HunkRegion
@ -20,15 +23,17 @@ public class HunkRegion
private final int x; private final int x;
private final int z; private final int z;
public HunkRegion(File folder, int x, int z, CompoundTag compound) { public HunkRegion(File folder, int x, int z, CompoundTag compound)
this.compound = compound; {
this.compound = fix(compound);
this.folder = folder; this.folder = folder;
this.x = x; this.x = x;
this.z = z; this.z = z;
folder.mkdirs(); folder.mkdirs();
} }
public HunkRegion(File folder, int x, int z) { public HunkRegion(File folder, int x, int z)
{
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>())); this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
File f = getFile(); File f = getFile();
@ -37,7 +42,7 @@ public class HunkRegion
try try
{ {
NBTInputStream in = new NBTInputStream(new FileInputStream(f)); NBTInputStream in = new NBTInputStream(new FileInputStream(f));
compound = (CompoundTag) in.readTag(); compound = fix((CompoundTag) in.readTag());
in.close(); in.close();
} }
@ -48,6 +53,18 @@ public class HunkRegion
} }
} }
private CompoundTag fix(CompoundTag readTag)
{
Map<String, Tag> v = readTag.getValue();
if(!(v instanceof KMap))
{
return new CompoundTag(readTag.getName(), new KMap<String, Tag>(v));
}
return readTag;
}
public File getFile() public File getFile()
{ {
return new File(folder, x + "." + z + ".dat"); return new File(folder, x + "." + z + ".dat");
@ -55,13 +72,14 @@ public class HunkRegion
public void save() throws IOException public void save() throws IOException
{ {
synchronized (compound) synchronized(compound)
{ {
File f = getFile(); File f = getFile();
FileOutputStream fos = new FileOutputStream(f); FileOutputStream fos = new FileOutputStream(f);
NBTOutputStream out = new NBTOutputStream(fos); NBTOutputStream out = new NBTOutputStream(fos);
out.writeTag(compound); out.writeTag(compound);
out.close(); out.close();
Iris.verbose("Saved Region: " + getX() + " " + getZ());
} }
} }
} }

View File

@ -1,21 +1,25 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io; package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk; import java.io.IOException;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisObject;
import com.volmit.iris.util.*;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.io.IOException; import com.volmit.iris.Iris;
import java.util.function.Function; import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.util.ByteArrayTag;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.Tag;
public class HunkRegionSlice<T> { public class HunkRegionSlice<T>
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h,c) -> new HunkRegionSlice<>(h,Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata"); {
public static final Function3<Integer, CompoundTag, String,HunkRegionSlice<String>> STRING = (h,c,t) -> new HunkRegionSlice<>(h,Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t); public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
public static final Function3<Integer, CompoundTag, String,HunkRegionSlice<Boolean>> BOOLEAN = (h,c,t) -> new HunkRegionSlice<>(h,Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t); public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
private final Function3<Integer,Integer,Integer, Hunk<T>> factory; public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
private final HunkIOAdapter<T> adapter; private final HunkIOAdapter<T> adapter;
private final CompoundTag compound; private final CompoundTag compound;
private final String key; private final String key;
@ -23,7 +27,7 @@ public class HunkRegionSlice<T> {
private final KList<Short> save; private final KList<Short> save;
private final int height; private final int height;
public HunkRegionSlice(int height, Function3<Integer,Integer,Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
{ {
this.height = height; this.height = height;
this.loadedChunks = new KMap<>(); this.loadedChunks = new KMap<>();
@ -35,6 +39,8 @@ public class HunkRegionSlice<T> {
} }
public void clear() public void clear()
{
synchronized(save)
{ {
for(String i : new KList<>(compound.getValue().keySet())) for(String i : new KList<>(compound.getValue().keySet()))
{ {
@ -44,6 +50,17 @@ public class HunkRegionSlice<T> {
} }
} }
} }
}
public void save()
{
for(short i : save)
{
save((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
}
save.clear();
}
public boolean contains(int x, int z) public boolean contains(int x, int z)
{ {
@ -52,15 +69,16 @@ public class HunkRegionSlice<T> {
public void delete(int x, int z) public void delete(int x, int z)
{ {
compound.getValue().remove(key(x,z)); compound.getValue().remove(key(x, z));
} }
public Hunk<T> read(int x, int z) throws IOException public Hunk<T> read(int x, int z) throws IOException
{ {
Tag t = compound.getValue().get(key(x,z)); Tag t = compound.getValue().get(key(x, z));
if(!(t instanceof ByteArrayTag)) if(!(t instanceof ByteArrayTag))
{ {
Iris.verbose("NOT BYTE ARRAY!");
return null; return null;
} }
@ -69,10 +87,10 @@ public class HunkRegionSlice<T> {
public void write(Hunk<T> hunk, int x, int z) throws IOException public void write(Hunk<T> hunk, int x, int z) throws IOException
{ {
compound.getValue().put(key(x,z), hunk.writeByteArrayTag(adapter, key)); compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
} }
public synchronized void close() public synchronized void unloadAll()
{ {
for(Short i : loadedChunks.k()) for(Short i : loadedChunks.k())
{ {
@ -85,35 +103,38 @@ public class HunkRegionSlice<T> {
public synchronized void save(Hunk<T> region, int x, int z) public synchronized void save(Hunk<T> region, int x, int z)
{ {
try { try
{
write(region, x, z); write(region, x, z);
} catch (IOException e) { }
catch(IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean isLoaded(int x, int z) public boolean isLoaded(int x, int z)
{ {
return loadedChunks.containsKey(ikey(x,z)); return loadedChunks.containsKey(ikey(x, z));
} }
public synchronized void save(int x, int z) public synchronized void save(int x, int z)
{ {
if(isLoaded(x,z)) if(isLoaded(x, z))
{ {
save(get(x,z), x, z); save(get(x, z), x, z);
} }
} }
public synchronized void unload(int x, int z) public synchronized void unload(int x, int z)
{ {
short key = ikey(x,z); short key = ikey(x, z);
if(isLoaded(x, z)) if(isLoaded(x, z))
{ {
if(save.contains(key)) if(save.contains(key))
{ {
save(x,z); save(x, z);
save.remove(key); save.remove(key);
} }
@ -123,18 +144,22 @@ public class HunkRegionSlice<T> {
public synchronized Hunk<T> load(int x, int z) public synchronized Hunk<T> load(int x, int z)
{ {
if(isLoaded(x,z)) if(isLoaded(x, z))
{ {
return loadedChunks.get(ikey(x,z)); return loadedChunks.get(ikey(x, z));
} }
Hunk<T> v = null; Hunk<T> v = null;
if(contains(x ,z)) if(contains(x, z))
{
try
{
v = read(x, z);
}
catch(IOException e)
{ {
try {
v = read(x,z);
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -143,14 +168,14 @@ public class HunkRegionSlice<T> {
{ {
v = factory.apply(16, height, 16); v = factory.apply(16, height, 16);
} }
loadedChunks.put(ikey(x,z), v); loadedChunks.put(ikey(x, z), v);
return v; return v;
} }
public Hunk<T> get(int x, int z) public Hunk<T> get(int x, int z)
{ {
short key = ikey(x,z); short key = ikey(x, z);
Hunk<T> c = loadedChunks.get(key); Hunk<T> c = loadedChunks.get(key);
@ -164,27 +189,27 @@ public class HunkRegionSlice<T> {
public Hunk<T> getR(int x, int z) public Hunk<T> getR(int x, int z)
{ {
return get(x,z).readOnly(); return get(x, z).readOnly();
} }
public Hunk<T> getRW(int x, int z) public Hunk<T> getRW(int x, int z)
{ {
save.addIfMissing(ikey(x,z)); save.addIfMissing(ikey(x, z));
return get(x,z); return get(x, z);
} }
private short ikey(int x, int z) private short ikey(int x, int z)
{ {
return ((short)(((x & 0xFF) << 8) | (z & 0xFF))); return ((short) (((x & 0xFF) << 8) | (z & 0xFF)));
} }
private String key(int x, int z) private String key(int x, int z)
{ {
if(x < 0 || x >=32 || z < 0 || z >= 32) if(x < 0 || x >= 32 || z < 0 || z >= 32)
{ {
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31"); throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
} }
return key + "." + Integer.toString(((short)(((x & 0xFF) << 8) | (z & 0xFF))), 36); return key + "." + Integer.toString(((short) (((x & 0xFF) << 8) | (z & 0xFF))), 36);
} }
} }

View File

@ -1,15 +1,17 @@
package com.volmit.iris.gen.v2.scaffold.parallax; package com.volmit.iris.gen.v2.scaffold.parallax;
import java.io.File;
import java.io.IOException;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk; import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.gen.v2.scaffold.hunk.io.HunkCompoundRegion; import com.volmit.iris.gen.v2.scaffold.hunk.io.HunkCompoundRegion;
import com.volmit.iris.util.KList; import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap; import com.volmit.iris.util.KMap;
import org.bukkit.block.data.BlockData;
import java.io.File; public class ParallaxWorld implements ParallaxAccess
import java.io.IOException; {
public class ParallaxWorld implements ParallaxAccess {
private final KMap<Long, HunkCompoundRegion> loadedRegions; private final KMap<Long, HunkCompoundRegion> loadedRegions;
private final KList<Long> save; private final KList<Long> save;
private final File folder; private final File folder;
@ -37,57 +39,61 @@ public class ParallaxWorld implements ParallaxAccess {
public synchronized void save(HunkCompoundRegion region) public synchronized void save(HunkCompoundRegion region)
{ {
try { try
{
region.save(); region.save();
} catch (IOException e) { }
catch(IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean isLoaded(int x, int z) public boolean isLoaded(int x, int z)
{ {
return loadedRegions.containsKey(key(x,z)); return loadedRegions.containsKey(key(x, z));
} }
public synchronized void save(int x, int z) public synchronized void save(int x, int z)
{ {
if(isLoaded(x,z)) if(isLoaded(x, z))
{ {
save(getR(x,z)); save(getR(x, z));
} }
} }
public synchronized void unload(int x, int z) public synchronized void unload(int x, int z)
{ {
long key = key(x,z); long key = key(x, z);
if(isLoaded(x, z)) if(isLoaded(x, z))
{ {
if(save.contains(key)) if(save.contains(key))
{ {
save(x,z); save(x, z);
save.remove(key); save.remove(key);
} }
loadedRegions.remove(key); loadedRegions.remove(key).unload();
} }
} }
public synchronized HunkCompoundRegion load(int x, int z) public synchronized HunkCompoundRegion load(int x, int z)
{ {
if(isLoaded(x,z)) if(isLoaded(x, z))
{ {
return loadedRegions.get(key(x,z)); return loadedRegions.get(key(x, z));
} }
HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z); HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z);
loadedRegions.put(key(x,z), v); loadedRegions.put(key(x, z), v);
return v; return v;
} }
public HunkCompoundRegion getR(int x, int z) public HunkCompoundRegion getR(int x, int z)
{ {
long key = key(x,z); long key = key(x, z);
HunkCompoundRegion region = loadedRegions.get(key); HunkCompoundRegion region = loadedRegions.get(key);
@ -101,42 +107,48 @@ public class ParallaxWorld implements ParallaxAccess {
public HunkCompoundRegion getRW(int x, int z) public HunkCompoundRegion getRW(int x, int z)
{ {
save.addIfMissing(key(x,z)); save.addIfMissing(key(x, z));
return getR(x,z); return getR(x, z);
} }
private long key(int x, int z) private long key(int x, int z)
{ {
return (((long)x) << 32) | (((long)z) & 0xffffffffL); return (((long) x) << 32) | (((long) z) & 0xffffffffL);
} }
@Override @Override
public Hunk<BlockData> getBlocksR(int x, int z) { public Hunk<BlockData> getBlocksR(int x, int z)
return getR(x>>5, z>>5).getParallaxSlice().getR(x & 31,z & 31); {
return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31);
} }
@Override @Override
public synchronized Hunk<BlockData> getBlocksRW(int x, int z) { public synchronized Hunk<BlockData> getBlocksRW(int x, int z)
return getRW(x>>5, z>>5).getParallaxSlice().getRW(x & 31,z & 31); {
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
} }
@Override @Override
public Hunk<String> getObjectsR(int x, int z) { public Hunk<String> getObjectsR(int x, int z)
return getR(x>>5, z>>5).getObjectSlice().getR(x & 31,z & 31); {
return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31);
} }
@Override @Override
public synchronized Hunk<String> getObjectsRW(int x, int z) { public synchronized Hunk<String> getObjectsRW(int x, int z)
return getRW(x>>5, z>>5).getObjectSlice().getRW(x & 31,z & 31); {
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
} }
@Override @Override
public Hunk<Boolean> getUpdatesR(int x, int z) { public Hunk<Boolean> getUpdatesR(int x, int z)
return getR(x>>5, z>>5).getUpdateSlice().getR(x & 31,z & 31); {
return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31);
} }
@Override @Override
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z) { public synchronized Hunk<Boolean> getUpdatesRW(int x, int z)
return getRW(x>>5, z>>5).getUpdateSlice().getRW(x & 31,z & 31); {
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
} }
} }

View File

@ -1,38 +1,5 @@
package com.volmit.iris.util; package com.volmit.iris.util;
/*
* JNBT License
*
* Copyright (c) 2010 Graham Edgecombe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import java.util.Collections;
import java.util.Map; import java.util.Map;
/** /**
@ -41,7 +8,8 @@ import java.util.Map;
* @author Graham Edgecombe * @author Graham Edgecombe
* *
*/ */
public final class CompoundTag extends Tag { public final class CompoundTag extends Tag
{
/** /**
* The value. * The value.
@ -51,29 +19,36 @@ public final class CompoundTag extends Tag {
/** /**
* Creates the tag. * Creates the tag.
* *
* @param name The name. * @param name
* @param value The value. * The name.
* @param value
* The value.
*/ */
public CompoundTag(String name, Map<String, Tag> value) { public CompoundTag(String name, Map<String, Tag> value)
{
super(name); super(name);
this.value = Collections.unmodifiableMap(value); this.value = value;
} }
@Override @Override
public Map<String, Tag> getValue() { public Map<String, Tag> getValue()
{
return value; return value;
} }
@Override @Override
public String toString() { public String toString()
{
String name = getName(); String name = getName();
String append = ""; String append = "";
if (name != null && !name.equals("")) { if(name != null && !name.equals(""))
{
append = "(\"" + this.getName() + "\")"; append = "(\"" + this.getName() + "\")";
} }
StringBuilder bldr = new StringBuilder(); StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n"); bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : value.entrySet()) { for(Map.Entry<String, Tag> entry : value.entrySet())
{
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n"); bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
} }
bldr.append("}"); bldr.append("}");

View File

@ -16,7 +16,7 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V>
super(); super();
} }
public KMap(KMap<K, V> gMap) public KMap(Map<K, V> gMap)
{ {
this(); this();
put(gMap); put(gMap);