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

@ -117,23 +117,53 @@ public class Iris extends MortarPlugin
private static boolean doesSupport3DBiomes()
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
try
{
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()
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
try
{
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()
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
try
{
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
@ -281,17 +311,22 @@ public class Iris extends MortarPlugin
public static void msg(String string)
{
lock.lock();
if(instance == null)
try
{
System.out.println("[Iris]: " + string);
lock.unlock();
return;
if(instance == null)
{
System.out.println("[Iris]: " + string);
return;
}
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
Bukkit.getConsoleSender().sendMessage(msg);
}
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
Bukkit.getConsoleSender().sendMessage(msg);
lock.unlock();
catch(Throwable e)
{
System.out.println("[Iris]: " + string);
}
}
public static File getCached(String name, String url)
@ -389,7 +424,20 @@ public class Iris extends MortarPlugin
public static void verbose(String string)
{
if(IrisSettings.get().verbose)
if(true)
{
System.out.println(string);
}
try
{
if(IrisSettings.get().verbose)
{
msg(C.GRAY + string);
}
}
catch(Throwable e)
{
msg(C.GRAY + string);
}

View File

@ -1,37 +1,58 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.util.CompoundTag;
import lombok.Getter;
import java.io.File;
import java.io.IOException;
import org.bukkit.block.data.BlockData;
import java.io.File;
import com.volmit.iris.util.CompoundTag;
public class HunkCompoundRegion extends HunkRegion {
import lombok.Getter;
@Getter
private HunkRegionSlice<BlockData> parallaxSlice;
@Getter
private HunkRegionSlice<String> objectSlice;
@Getter
private HunkRegionSlice<Boolean> updateSlice;
public class HunkCompoundRegion extends HunkRegion
{
@Getter
private HunkRegionSlice<BlockData> blockSlice;
@Getter
private HunkRegionSlice<String> objectSlice;
@Getter
private HunkRegionSlice<Boolean> updateSlice;
private final int height;
private final int height;
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound) {
super(folder, x, z, compound);
this.height = height;
setupSlices();
}
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound)
{
super(folder, x, z, compound);
this.height = height;
setupSlices();
}
public HunkCompoundRegion(int height, File folder, int x, int z) {
super(folder, x, z);
this.height = height;
setupSlices();
}
public HunkCompoundRegion(int height, File folder, int x, int z)
{
super(folder, x, z);
this.height = height;
setupSlices();
}
private void setupSlices() {
parallaxSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
}
private void setupSlices()
{
blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
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,67 +1,85 @@
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.FileInputStream;
import java.io.FileOutputStream;
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
public class HunkRegion
{
private final File folder;
private CompoundTag compound;
private final int x;
private final int z;
private final File folder;
private CompoundTag compound;
private final int x;
private final int z;
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
this.compound = compound;
this.folder = folder;
this.x = x;
this.z = z;
folder.mkdirs();
}
public HunkRegion(File folder, int x, int z, CompoundTag compound)
{
this.compound = fix(compound);
this.folder = folder;
this.x = x;
this.z = z;
folder.mkdirs();
}
public HunkRegion(File folder, int x, int z) {
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
File f = getFile();
public HunkRegion(File folder, int x, int z)
{
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
File f = getFile();
if(f.exists())
{
try
{
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
compound = (CompoundTag) in.readTag();
in.close();
}
if(f.exists())
{
try
{
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
compound = fix((CompoundTag) in.readTag());
in.close();
}
catch(Throwable e)
{
catch(Throwable e)
{
}
}
}
}
}
}
public File getFile()
{
return new File(folder, x + "." + z + ".dat");
}
private CompoundTag fix(CompoundTag readTag)
{
Map<String, Tag> v = readTag.getValue();
public void save() throws IOException
{
synchronized (compound)
{
File f = getFile();
FileOutputStream fos = new FileOutputStream(f);
NBTOutputStream out = new NBTOutputStream(fos);
out.writeTag(compound);
out.close();
}
}
if(!(v instanceof KMap))
{
return new CompoundTag(readTag.getName(), new KMap<String, Tag>(v));
}
return readTag;
}
public File getFile()
{
return new File(folder, x + "." + z + ".dat");
}
public void save() throws IOException
{
synchronized(compound)
{
File f = getFile();
FileOutputStream fos = new FileOutputStream(f);
NBTOutputStream out = new NBTOutputStream(fos);
out.writeTag(compound);
out.close();
Iris.verbose("Saved Region: " + getX() + " " + getZ());
}
}
}

View File

@ -1,190 +1,215 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
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 java.io.IOException;
import org.bukkit.block.data.BlockData;
import java.io.IOException;
import java.util.function.Function;
import com.volmit.iris.Iris;
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 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 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 CompoundTag compound;
private final String key;
private final KMap<Short, Hunk<T>> loadedChunks;
private final KList<Short> save;
private final int height;
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 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 CompoundTag compound;
private final String key;
private final KMap<Short, Hunk<T>> loadedChunks;
private final KList<Short> save;
private final int height;
public HunkRegionSlice(int height, Function3<Integer,Integer,Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
{
this.height = height;
this.loadedChunks = new KMap<>();
this.factory = factory;
this.adapter = adapter;
this.compound = compound;
this.save = new KList<>();
this.key = key;
}
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
{
this.height = height;
this.loadedChunks = new KMap<>();
this.factory = factory;
this.adapter = adapter;
this.compound = compound;
this.save = new KList<>();
this.key = key;
}
public void clear()
{
for(String i : new KList<>(compound.getValue().keySet()))
{
if(i.startsWith(key + "."))
{
compound.getValue().remove(i);
}
}
}
public void clear()
{
synchronized(save)
{
for(String i : new KList<>(compound.getValue().keySet()))
{
if(i.startsWith(key + "."))
{
compound.getValue().remove(i);
}
}
}
}
public boolean contains(int x, int z)
{
return compound.getValue().containsKey(key(x, z));
}
public void save()
{
for(short i : save)
{
save((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
}
public void delete(int x, int z)
{
compound.getValue().remove(key(x,z));
}
save.clear();
}
public Hunk<T> read(int x, int z) throws IOException
{
Tag t = compound.getValue().get(key(x,z));
public boolean contains(int x, int z)
{
return compound.getValue().containsKey(key(x, z));
}
if(!(t instanceof ByteArrayTag))
{
return null;
}
public void delete(int x, int z)
{
compound.getValue().remove(key(x, z));
}
return adapter.read(factory, (ByteArrayTag) t);
}
public Hunk<T> read(int x, int z) throws IOException
{
Tag t = compound.getValue().get(key(x, z));
public void write(Hunk<T> hunk, int x, int z) throws IOException
{
compound.getValue().put(key(x,z), hunk.writeByteArrayTag(adapter, key));
}
if(!(t instanceof ByteArrayTag))
{
Iris.verbose("NOT BYTE ARRAY!");
return null;
}
public synchronized void close()
{
for(Short i : loadedChunks.k())
{
unload((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
}
return adapter.read(factory, (ByteArrayTag) t);
}
save.clear();
loadedChunks.clear();
}
public void write(Hunk<T> hunk, int x, int z) throws IOException
{
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
}
public synchronized void save(Hunk<T> region, int x, int z)
{
try {
write(region, x, z);
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized void unloadAll()
{
for(Short i : loadedChunks.k())
{
unload((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
}
public boolean isLoaded(int x, int z)
{
return loadedChunks.containsKey(ikey(x,z));
}
save.clear();
loadedChunks.clear();
}
public synchronized void save(int x, int z)
{
if(isLoaded(x,z))
{
save(get(x,z), x, z);
}
}
public synchronized void save(Hunk<T> region, int x, int z)
{
try
{
write(region, x, z);
}
catch(IOException e)
{
e.printStackTrace();
}
}
public synchronized void unload(int x, int z)
{
short key = ikey(x,z);
public boolean isLoaded(int x, int z)
{
return loadedChunks.containsKey(ikey(x, z));
}
if(isLoaded(x, z))
{
if(save.contains(key))
{
save(x,z);
save.remove(key);
}
public synchronized void save(int x, int z)
{
if(isLoaded(x, z))
{
save(get(x, z), x, z);
}
}
loadedChunks.remove(key);
}
}
public synchronized void unload(int x, int z)
{
short key = ikey(x, z);
public synchronized Hunk<T> load(int x, int z)
{
if(isLoaded(x,z))
{
return loadedChunks.get(ikey(x,z));
}
if(isLoaded(x, z))
{
if(save.contains(key))
{
save(x, z);
save.remove(key);
}
Hunk<T> v = null;
loadedChunks.remove(key);
}
}
if(contains(x ,z))
{
try {
v = read(x,z);
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized Hunk<T> load(int x, int z)
{
if(isLoaded(x, z))
{
return loadedChunks.get(ikey(x, z));
}
if(v == null)
{
v = factory.apply(16, height, 16);
}
loadedChunks.put(ikey(x,z), v);
Hunk<T> v = null;
return v;
}
if(contains(x, z))
{
try
{
v = read(x, z);
}
public Hunk<T> get(int x, int z)
{
short key = ikey(x,z);
catch(IOException e)
{
e.printStackTrace();
}
}
Hunk<T> c = loadedChunks.get(key);
if(v == null)
{
v = factory.apply(16, height, 16);
}
loadedChunks.put(ikey(x, z), v);
if(c == null)
{
c = load(x, z);
}
return v;
}
return c;
}
public Hunk<T> get(int x, int z)
{
short key = ikey(x, z);
public Hunk<T> getR(int x, int z)
{
return get(x,z).readOnly();
}
Hunk<T> c = loadedChunks.get(key);
public Hunk<T> getRW(int x, int z)
{
save.addIfMissing(ikey(x,z));
return get(x,z);
}
if(c == null)
{
c = load(x, z);
}
private short ikey(int x, int z)
{
return ((short)(((x & 0xFF) << 8) | (z & 0xFF)));
}
return c;
}
private String key(int x, int z)
{
if(x < 0 || x >=32 || z < 0 || z >= 32)
{
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
}
public Hunk<T> getR(int x, int z)
{
return get(x, z).readOnly();
}
return key + "." + Integer.toString(((short)(((x & 0xFF) << 8) | (z & 0xFF))), 36);
}
public Hunk<T> getRW(int x, int z)
{
save.addIfMissing(ikey(x, z));
return get(x, z);
}
private short ikey(int x, int z)
{
return ((short) (((x & 0xFF) << 8) | (z & 0xFF)));
}
private String key(int x, int z)
{
if(x < 0 || x >= 32 || z < 0 || z >= 32)
{
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);
}
}

View File

@ -1,142 +1,154 @@
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.io.HunkCompoundRegion;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import org.bukkit.block.data.BlockData;
import java.io.File;
import java.io.IOException;
public class ParallaxWorld implements ParallaxAccess
{
private final KMap<Long, HunkCompoundRegion> loadedRegions;
private final KList<Long> save;
private final File folder;
private final int height;
public class ParallaxWorld implements ParallaxAccess {
private final KMap<Long, HunkCompoundRegion> loadedRegions;
private final KList<Long> save;
private final File folder;
private final int height;
public ParallaxWorld(int height, File folder)
{
this.height = height;
this.folder = folder;
save = new KList<>();
loadedRegions = new KMap<>();
folder.mkdirs();
}
public ParallaxWorld(int height, File folder)
{
this.height = height;
this.folder = folder;
save = new KList<>();
loadedRegions = new KMap<>();
folder.mkdirs();
}
public synchronized void close()
{
for(HunkCompoundRegion i : loadedRegions.v())
{
unload(i.getX(), i.getZ());
}
public synchronized void close()
{
for(HunkCompoundRegion i : loadedRegions.v())
{
unload(i.getX(), i.getZ());
}
save.clear();
loadedRegions.clear();
}
save.clear();
loadedRegions.clear();
}
public synchronized void save(HunkCompoundRegion region)
{
try
{
region.save();
}
public synchronized void save(HunkCompoundRegion region)
{
try {
region.save();
} catch (IOException e) {
e.printStackTrace();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
public boolean isLoaded(int x, int z)
{
return loadedRegions.containsKey(key(x,z));
}
public boolean isLoaded(int x, int z)
{
return loadedRegions.containsKey(key(x, z));
}
public synchronized void save(int x, int z)
{
if(isLoaded(x,z))
{
save(getR(x,z));
}
}
public synchronized void save(int x, int z)
{
if(isLoaded(x, z))
{
save(getR(x, z));
}
}
public synchronized void unload(int x, int z)
{
long key = key(x,z);
public synchronized void unload(int x, int z)
{
long key = key(x, z);
if(isLoaded(x, z))
{
if(save.contains(key))
{
save(x,z);
save.remove(key);
}
if(isLoaded(x, z))
{
if(save.contains(key))
{
save(x, z);
save.remove(key);
}
loadedRegions.remove(key);
}
}
loadedRegions.remove(key).unload();
}
}
public synchronized HunkCompoundRegion load(int x, int z)
{
if(isLoaded(x,z))
{
return loadedRegions.get(key(x,z));
}
public synchronized HunkCompoundRegion load(int x, int z)
{
if(isLoaded(x, z))
{
return loadedRegions.get(key(x, z));
}
HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z);
loadedRegions.put(key(x,z), v);
return v;
}
HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z);
loadedRegions.put(key(x, z), v);
return v;
}
public HunkCompoundRegion getR(int x, int z)
{
long key = key(x,z);
public HunkCompoundRegion getR(int x, int z)
{
long key = key(x, z);
HunkCompoundRegion region = loadedRegions.get(key);
HunkCompoundRegion region = loadedRegions.get(key);
if(region == null)
{
region = load(x, z);
}
if(region == null)
{
region = load(x, z);
}
return region;
}
return region;
}
public HunkCompoundRegion getRW(int x, int z)
{
save.addIfMissing(key(x,z));
return getR(x,z);
}
public HunkCompoundRegion getRW(int x, int z)
{
save.addIfMissing(key(x, z));
return getR(x, z);
}
private long key(int x, int z)
{
return (((long)x) << 32) | (((long)z) & 0xffffffffL);
}
private long key(int x, int z)
{
return (((long) x) << 32) | (((long) z) & 0xffffffffL);
}
@Override
public Hunk<BlockData> getBlocksR(int x, int z) {
return getR(x>>5, z>>5).getParallaxSlice().getR(x & 31,z & 31);
}
@Override
public Hunk<BlockData> getBlocksR(int x, int z)
{
return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31);
}
@Override
public synchronized Hunk<BlockData> getBlocksRW(int x, int z) {
return getRW(x>>5, z>>5).getParallaxSlice().getRW(x & 31,z & 31);
}
@Override
public synchronized Hunk<BlockData> getBlocksRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
}
@Override
public Hunk<String> getObjectsR(int x, int z) {
return getR(x>>5, z>>5).getObjectSlice().getR(x & 31,z & 31);
}
@Override
public Hunk<String> getObjectsR(int x, int z)
{
return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31);
}
@Override
public synchronized Hunk<String> getObjectsRW(int x, int z) {
return getRW(x>>5, z>>5).getObjectSlice().getRW(x & 31,z & 31);
}
@Override
public synchronized Hunk<String> getObjectsRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
}
@Override
public Hunk<Boolean> getUpdatesR(int x, int z) {
return getR(x>>5, z>>5).getUpdateSlice().getR(x & 31,z & 31);
}
@Override
public Hunk<Boolean> getUpdatesR(int x, int z)
{
return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31);
}
@Override
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z) {
return getRW(x>>5, z>>5).getUpdateSlice().getRW(x & 31,z & 31);
}
@Override
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
}
}

View File

@ -1,38 +1,5 @@
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;
/**
@ -41,43 +8,51 @@ import java.util.Map;
* @author Graham Edgecombe
*
*/
public final class CompoundTag extends Tag {
public final class CompoundTag extends Tag
{
/**
* The value.
*/
private final Map<String, Tag> value;
/**
* The value.
*/
private final Map<String, Tag> value;
/**
* Creates the tag.
*
* @param name The name.
* @param value The value.
*/
public CompoundTag(String name, Map<String, Tag> value) {
super(name);
this.value = Collections.unmodifiableMap(value);
}
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public CompoundTag(String name, Map<String, Tag> value)
{
super(name);
this.value = value;
}
@Override
public Map<String, Tag> getValue() {
return value;
}
@Override
public Map<String, Tag> getValue()
{
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : value.entrySet()) {
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
}
bldr.append("}");
return bldr.toString();
}
@Override
public String toString()
{
String name = getName();
String append = "";
if(name != null && !name.equals(""))
{
append = "(\"" + this.getName() + "\")";
}
StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
for(Map.Entry<String, Tag> entry : value.entrySet())
{
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
}
bldr.append("}");
return bldr.toString();
}
}

View File

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