This commit is contained in:
Daniel Mills 2020-07-27 05:15:21 -04:00
parent e5e46f3239
commit e1067aeb83
14 changed files with 511 additions and 141 deletions

View File

@ -27,13 +27,17 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import org.zeroturnaround.zip.ZipUtil;
import com.google.gson.Gson;
import ninja.bytecode.iris.generator.IrisChunkGenerator;
import ninja.bytecode.iris.object.IrisBiome;
import ninja.bytecode.iris.object.IrisDimension;
import ninja.bytecode.iris.object.IrisGenerator;
import ninja.bytecode.iris.object.IrisObject;
import ninja.bytecode.iris.object.IrisObjectPlacement;
import ninja.bytecode.iris.object.IrisRegion;
import ninja.bytecode.iris.util.BiomeResult;
import ninja.bytecode.iris.util.BlockDataTools;
import ninja.bytecode.iris.util.BoardManager;
@ -51,10 +55,12 @@ import ninja.bytecode.iris.util.ScoreDirection;
import ninja.bytecode.iris.wand.WandController;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.collections.KSet;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RollingSequence;
import ninja.bytecode.shuriken.reaction.O;
import ninja.bytecode.shuriken.tools.JarScanner;
@ -587,6 +593,114 @@ public class Iris extends JavaPlugin implements BoardProvider
}
}
if(args[0].equalsIgnoreCase("package") || args[0].equalsIgnoreCase("pkg"))
{
String dim = "overworld";
if(args.length > 1)
{
dim = args[1];
}
boolean obfuscate = false;
for(String i : args)
{
if(i.equalsIgnoreCase("-o"))
{
obfuscate = true;
}
}
String dimm = dim;
IrisDimension dimension = data.getDimensionLoader().load(dimm);
File folder = new File(getDataFolder(), "exports/" + dimension.getLoadKey());
folder.mkdirs();
Iris.info("Packaging Dimension " + dimension.getName());
KSet<IrisRegion> regions = new KSet<>();
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
dimension.getRegions().forEach((i) -> regions.add(data.getRegionLoader().load(i)));
regions.forEach((i) -> biomes.addAll(i.getAllBiomes()));
biomes.forEach((i) -> i.getGenerators().forEach((j) -> generators.add(j.getCachedGenerator())));
KMap<String, String> renameObjects = new KMap<>();
for(IrisBiome i : biomes)
{
for(IrisObjectPlacement j : i.getObjects())
{
KList<String> newNames = new KList<>();
for(String k : j.getPlace())
{
if(renameObjects.containsKey(k))
{
newNames.add(renameObjects.get(k));
continue;
}
String name = obfuscate ? UUID.randomUUID().toString().replaceAll("-", "") : k;
newNames.add(name);
renameObjects.put(k, name);
}
if(obfuscate)
{
j.setPlace(newNames);
}
}
}
KMap<String, KList<String>> lookupObjects = renameObjects.flip();
biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) ->
{
try
{
Iris.info("- " + k + " (Object)");
IO.copyFile(Iris.data.getObjectLoader().findFile(lookupObjects.get(k).get(0)), new File(folder, "objects/" + k + ".iob"));
}
catch(Throwable e)
{
}
})));
try
{
IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(dimension)).toString(0));
for(IrisGenerator i : generators)
{
Iris.info("- " + i.getLoadKey() + " (Generator)");
IO.writeAll(new File(folder, "generators/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0));
}
for(IrisRegion i : regions)
{
Iris.info("- " + i.getName() + " (Region)");
IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0));
}
for(IrisBiome i : biomes)
{
Iris.info("- " + i.getName() + " (Biome)");
IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0));
}
ZipUtil.pack(folder, new File(getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris"));
IO.delete(folder);
}
catch(Throwable e)
{
L.ex(e);
}
sender.sendMessage("Done!");
}
if(args[0].equalsIgnoreCase("dev"))
{
String dim = "overworld";

View File

@ -9,14 +9,17 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.IrisContext;
import ninja.bytecode.iris.object.IrisBiome;
import ninja.bytecode.iris.object.IrisRegion;
import ninja.bytecode.iris.util.BiomeResult;
import ninja.bytecode.shuriken.collections.KMap;
@Data
@EqualsAndHashCode(callSuper = false)
public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext
{
private Method initLighting;
private KMap<Player, IrisBiome> b = new KMap<>();
public IrisChunkGenerator(String dimensionName, int threads)
{

View File

@ -8,6 +8,8 @@ import org.bukkit.block.data.BlockData;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.layer.post.PostNippleSmoother;
import ninja.bytecode.iris.layer.post.PostPotholeFiller;
import ninja.bytecode.iris.layer.post.PostSlabber;
import ninja.bytecode.iris.layer.post.PostWallPatcher;
import ninja.bytecode.iris.object.IrisDimension;
import ninja.bytecode.iris.util.IPostBlockAccess;
import ninja.bytecode.iris.util.IrisPostBlockFilter;
@ -40,12 +42,20 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
super.onInit(world, rng);
filters.add(new PostNippleSmoother(this));
filters.add(new PostPotholeFiller(this));
filters.add(new PostWallPatcher(this));
filters.add(new PostSlabber(this));
}
@Override
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid)
{
super.onGenerate(random, x, z, data, grid);
if(!getDimension().isPostProcess())
{
return;
}
currentData = data;
currentPostX = x;
currentPostZ = z;
@ -64,7 +74,10 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
{
for(IrisPostBlockFilter f : filters)
{
f.onPost(rxx, rzz);
int rxxx = rxx;
int rzzx = rzz;
f.onPost(rxxx, rzzx);
}
});
}

View File

@ -17,6 +17,7 @@ import ninja.bytecode.iris.object.IrisRegion;
import ninja.bytecode.iris.object.atomics.AtomicSliver;
import ninja.bytecode.iris.util.BiomeMap;
import ninja.bytecode.iris.util.BiomeResult;
import ninja.bytecode.iris.util.BlockDataTools;
import ninja.bytecode.iris.util.HeightMap;
import ninja.bytecode.iris.util.RNG;
import ninja.bytecode.shuriken.collections.KList;
@ -132,11 +133,24 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
}
}
if(onto.equals(Material.ACACIA_LEAVES) || onto.equals(Material.BIRCH_LEAVES) || onto.equals(Material.DARK_OAK_LEAVES) || onto.equals(Material.JUNGLE_LEAVES) || onto.equals(Material.OAK_LEAVES) || onto.equals(Material.SPRUCE_LEAVES))
{
if(!mat.isSolid())
{
return false;
}
}
return true;
}
private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block)
{
if(!getDimension().isDecorate())
{
return;
}
int j = 0;
for(IrisBiomeDecorator i : biome.getDecorators())
@ -155,6 +169,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
continue;
}
if(d.getMaterial().equals(Material.CACTUS))
{
if(!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND))
{
sliver.set(k, BlockDataTools.getBlockData("RED_SAND"));
}
}
if(d instanceof Bisected && k < 254)
{
Bisected t = ((Bisected) d.clone());
@ -190,6 +212,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private void decorateUnderwater(IrisBiome biome, AtomicSliver sliver, double wx, int y, double wz, int rx, int rz, BlockData block)
{
if(!getDimension().isDecorate())
{
return;
}
int j = 0;
for(IrisBiomeDecorator i : biome.getDecorators())
@ -257,7 +284,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z);
IrisRegion region = sampleRegion(x, z);
int height = sampleHeight(x, z);
int height = (int) Math.round(getTerrainHeight(x, z));
double sh = region.getShoreHeight(wx, wz);
IrisBiome current = sampleBiome(x, z).getBiome();

View File

@ -29,9 +29,9 @@ public class GenLayerCave extends GenLayer
{
//@builder
super(iris, rng);
shuffle = CNG.signature(rng.nextParallelRNG(2348566));
gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00452);
gg = new FastNoise(324895 * rng.nextParallelRNG(45678).imax());
shuffle = CNG.signature(rng.nextParallelRNG(1348566));
gincline = new CNG(rng.nextParallelRNG(26512), 1D, 3).scale(0.00452);
gg = new FastNoise(324895 * rng.nextParallelRNG(49678).imax());
//@done
}

View File

@ -0,0 +1,50 @@
package ninja.bytecode.iris.layer.post;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import ninja.bytecode.iris.generator.PostBlockChunkGenerator;
import ninja.bytecode.iris.util.IrisPostBlockFilter;
import ninja.bytecode.iris.util.RNG;
public class PostSlabber extends IrisPostBlockFilter
{
public static final Material AIR = Material.AIR;
public static final Material WATER = Material.WATER;
private RNG rng;
public PostSlabber(PostBlockChunkGenerator gen)
{
super(gen);
rng = gen.getMasterRandom().nextParallelRNG(1239456);
}
@Override
public void onPost(int x, int z)
{
int h = highestTerrainBlock(x, z);
if(highestTerrainBlock(x + 1, z) == h + 1 || highestTerrainBlock(x, z + 1) == h + 1 || highestTerrainBlock(x - 1, z) == h + 1 || highestTerrainBlock(x, z - 1) == h + 1)
{
BlockData d = gen.sampleTrueBiome(x, z).getBiome().getSlab().get(rng, x, h, z);
if(d != null)
{
if(d.getMaterial().equals(AIR))
{
return;
}
if(d instanceof Waterlogged)
{
((Waterlogged) d).setWaterlogged(getPostBlock(x, h + 1, z).getMaterial().equals(Material.WATER));
}
if(getPostBlock(x, h + 2, z).getMaterial().equals(AIR) || getPostBlock(x, h + 2, z).getMaterial().equals(WATER))
{
setPostBlock(x, h + 1, z, d);
}
}
}
}
}

View File

@ -0,0 +1,56 @@
package ninja.bytecode.iris.layer.post;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import ninja.bytecode.iris.generator.PostBlockChunkGenerator;
import ninja.bytecode.iris.object.IrisBiome;
import ninja.bytecode.iris.util.IrisPostBlockFilter;
import ninja.bytecode.iris.util.RNG;
public class PostWallPatcher extends IrisPostBlockFilter
{
public static final Material AIR = Material.AIR;
private RNG rng;
public PostWallPatcher(PostBlockChunkGenerator gen)
{
super(gen);
rng = gen.getMasterRandom().nextParallelRNG(1239456);
}
@Override
public void onPost(int x, int z)
{
IrisBiome biome = gen.sampleTrueBiome(x, z).getBiome();
if(!biome.getWall().getPalette().isEmpty())
{
int h = highestTerrainBlock(x, z);
int ha = highestTerrainBlock(x + 1, z);
int hb = highestTerrainBlock(x, z + 1);
int hc = highestTerrainBlock(x - 1, z);
int hd = highestTerrainBlock(x, z - 1);
if(ha < h - 2 || hb < h - 2 || hc < h - 2 || hd < h - 2)
{
int max = Math.abs(Math.max(h - ha, Math.max(h - hb, Math.max(h - hc, h - hd))));
for(int i = h; i > h - max; i--)
{
BlockData d = biome.getWall().get(rng, x + i, i + h, z + i);
if(d != null)
{
if(d.getMaterial().equals(AIR))
{
continue;
}
setPostBlock(x, i, z, d);
}
}
}
}
}
}

View File

@ -49,6 +49,12 @@ public class IrisBiome extends IrisRegistrant
@Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 9 biomes down the tree.")
private KList<String> children = new KList<>();
@Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.")
private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero();
@Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)")
private IrisBiomePaletteLayer wall = new IrisBiomePaletteLayer().zero();
@Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.")
private KList<IrisBiomePaletteLayer> layers = new KList<IrisBiomePaletteLayer>().qadd(new IrisBiomePaletteLayer());

View File

@ -65,6 +65,11 @@ public class IrisBiomePaletteLayer
}
}
if(getBlockData().isEmpty())
{
return null;
}
return getBlockData().get(0);
}
@ -109,4 +114,10 @@ public class IrisBiomePaletteLayer
return blockData;
}
public IrisBiomePaletteLayer zero()
{
palette.clear();
return this;
}
}

View File

@ -39,6 +39,15 @@ public class IrisDimension extends IrisRegistrant
@Desc("Generate caves or not.")
private boolean caves = true;
@Desc("Carve terrain or not")
private boolean carving = true;
@Desc("Generate decorations or not")
private boolean decorate = true;
@Desc("Use post processing features. Usually for production only as there is a gen speed cost.")
private boolean postProcess = true;
@Desc("The ceiling dimension. Leave blank for normal sky.")
private String ceiling = "";

View File

@ -4,10 +4,13 @@ import java.util.concurrent.locks.ReentrantLock;
import lombok.Data;
import lombok.EqualsAndHashCode;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.CNG;
import ninja.bytecode.iris.util.Desc;
import ninja.bytecode.iris.util.RNG;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.collections.KSet;
@Desc("Represents an iris region")
@Data
@ -91,4 +94,34 @@ public class IrisRegion extends IrisRegistrant
return shoreHeightGenerator.fitDoubleD(shoreHeightMin, shoreHeightMax, x / shoreHeightZoom, z / shoreHeightZoom);
}
public KList<IrisBiome> getAllBiomes()
{
KMap<String, IrisBiome> b = new KMap<>();
KSet<String> names = new KSet<>();
names.addAll(landBiomes);
names.addAll(seaBiomes);
names.addAll(shoreBiomes);
spotBiomes.forEach((i) -> names.add(i.getBiome()));
ridgeBiomes.forEach((i) -> names.add(i.getBiome()));
while(!names.isEmpty())
{
for(String i : new KList<>(names))
{
if(b.containsKey(i))
{
names.remove(i);
continue;
}
IrisBiome biome = Iris.data.getBiomeLoader().load(i);
b.put(biome.getLoadKey(), biome);
names.remove(i);
names.addAll(biome.getChildren());
}
}
return b.v();
}
}

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import org.bukkit.World;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.ChronoLatch;
import ninja.bytecode.iris.util.ChunkPosition;
import ninja.bytecode.shuriken.collections.KMap;
@ -18,6 +19,7 @@ public class AtomicWorldData
private KMap<ChunkPosition, AtomicSliverMap> loadedChunks;
private KMap<ChunkPosition, AtomicRegionData> loadedSections;
private KMap<ChunkPosition, Long> lastRegion;
private KMap<ChunkPosition, Long> lastChunk;
private String prefix;
private ChronoLatch cl = new ChronoLatch(15000);
@ -27,6 +29,7 @@ public class AtomicWorldData
loadedSections = new KMap<>();
loadedChunks = new KMap<>();
lastRegion = new KMap<>();
lastChunk = new KMap<>();
this.prefix = prefix;
getSubregionFolder().mkdirs();
}
@ -165,7 +168,7 @@ public class AtomicWorldData
public AtomicSliverMap loadChunk(int x, int z) throws IOException
{
ChunkPosition pos = new ChunkPosition(x, z);
lastChunk.put(pos, M.ms());
if(loadedChunks.containsKey(pos))
{
return loadedChunks.get(pos);
@ -262,5 +265,21 @@ public class AtomicWorldData
}
}
}
for(ChunkPosition i : lastChunk.k())
{
if(M.ms() - lastChunk.get(i) > 60000)
{
try
{
saveChunk(i);
}
catch(IOException e)
{
Iris.warn("Failed to save chunk");
}
}
}
}
}

View File

@ -378,6 +378,7 @@ public class IO
public static void writeAll(File f, Object c) throws IOException
{
f.getParentFile().mkdirs();
PrintWriter pw = new PrintWriter(new FileWriter(f));
pw.println(c.toString());
pw.close();
@ -572,8 +573,8 @@ public class IO
/**
* Unconditionally close an <code>Reader</code>.
* <p>
* Equivalent to {@link Reader#close()}, except any exceptions will be
* ignored. This is typically used in finally blocks.
* Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
* This is typically used in finally blocks.
*
* @param input
* the Reader to close, may be null or already closed
@ -586,7 +587,8 @@ public class IO
{
input.close();
}
} catch(IOException ioe)
}
catch(IOException ioe)
{
// ignore
}
@ -595,8 +597,8 @@ public class IO
/**
* Unconditionally close a <code>Writer</code>.
* <p>
* Equivalent to {@link Writer#close()}, except any exceptions will be
* ignored. This is typically used in finally blocks.
* Equivalent to {@link Writer#close()}, except any exceptions will be ignored.
* This is typically used in finally blocks.
*
* @param output
* the Writer to close, may be null or already closed
@ -609,7 +611,8 @@ public class IO
{
output.close();
}
} catch(IOException ioe)
}
catch(IOException ioe)
{
// ignore
}
@ -632,7 +635,8 @@ public class IO
{
input.close();
}
} catch(IOException ioe)
}
catch(IOException ioe)
{
// ignore
}
@ -655,7 +659,8 @@ public class IO
{
output.close();
}
} catch(IOException ioe)
}
catch(IOException ioe)
{
// ignore
}
@ -685,8 +690,8 @@ public class IO
}
/**
* Get the contents of a <code>Reader</code> as a <code>byte[]</code> using
* the default character encoding of the platform.
* Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the
* default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
@ -707,8 +712,8 @@ public class IO
}
/**
* Get the contents of a <code>Reader</code> as a <code>byte[]</code> using
* the specified character encoding.
* Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the
* specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
@ -735,8 +740,8 @@ public class IO
}
/**
* Get the contents of a <code>String</code> as a <code>byte[]</code> using
* the default character encoding of the platform.
* Get the contents of a <code>String</code> as a <code>byte[]</code> using the
* default character encoding of the platform.
* <p>
* This is the same as {@link String#getBytes()}.
*
@ -757,8 +762,8 @@ public class IO
// read char[]
// -----------------------------------------------------------------------
/**
* Get the contents of an <code>InputStream</code> as a character array
* using the default character encoding of the platform.
* Get the contents of an <code>InputStream</code> as a character array using
* the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
@ -780,8 +785,8 @@ public class IO
}
/**
* Get the contents of an <code>InputStream</code> as a character array
* using the specified character encoding.
* Get the contents of an <code>InputStream</code> as a character array using
* the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
@ -832,8 +837,8 @@ public class IO
// read toString
// -----------------------------------------------------------------------
/**
* Get the contents of an <code>InputStream</code> as a String using the
* default character encoding of the platform.
* Get the contents of an <code>InputStream</code> as a String using the default
* character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
@ -942,7 +947,8 @@ public class IO
if(encoding == null)
{
return new String(input);
} else
}
else
{
return new String(input, encoding);
}
@ -998,7 +1004,8 @@ public class IO
if(encoding == null)
{
return readLines(input);
} else
}
else
{
InputStreamReader reader = new InputStreamReader(input, encoding);
return readLines(reader);
@ -1006,8 +1013,8 @@ public class IO
}
/**
* Get the contents of a <code>Reader</code> as a list of Strings, one entry
* per line.
* Get the contents of a <code>Reader</code> as a list of Strings, one entry per
* line.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
@ -1036,8 +1043,8 @@ public class IO
// -----------------------------------------------------------------------
/**
* Convert the specified string to an input stream, encoded as bytes using
* the default character encoding of the platform.
* Convert the specified string to an input stream, encoded as bytes using the
* default character encoding of the platform.
*
* @param input
* the string to convert
@ -1051,8 +1058,8 @@ public class IO
}
/**
* Convert the specified string to an input stream, encoded as bytes using
* the specified character encoding.
* Convert the specified string to an input stream, encoded as bytes using the
* specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
@ -1078,8 +1085,7 @@ public class IO
* Writes bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
*
* @param data
* the byte array to write, do not modify during output, null
* ignored
* the byte array to write, do not modify during output, null ignored
* @param output
* the <code>OutputStream</code> to write to
* @throws NullPointerException
@ -1103,8 +1109,7 @@ public class IO
* This method uses {@link String#String(byte[])}.
*
* @param data
* the byte array to write, do not modify during output, null
* ignored
* the byte array to write, do not modify during output, null ignored
* @param output
* the <code>Writer</code> to write to
* @throws NullPointerException
@ -1131,8 +1136,7 @@ public class IO
* This method uses {@link String#String(byte[], String)}.
*
* @param data
* the byte array to write, do not modify during output, null
* ignored
* the byte array to write, do not modify during output, null ignored
* @param output
* the <code>Writer</code> to write to
* @param encoding
@ -1150,7 +1154,8 @@ public class IO
if(encoding == null)
{
write(data, output);
} else
}
else
{
output.write(new String(data, encoding));
}
@ -1160,12 +1165,11 @@ public class IO
// write char[]
// -----------------------------------------------------------------------
/**
* Writes chars from a <code>char[]</code> to a <code>Writer</code> using
* the default character encoding of the platform.
* Writes chars from a <code>char[]</code> to a <code>Writer</code> using the
* default character encoding of the platform.
*
* @param data
* the char array to write, do not modify during output, null
* ignored
* the char array to write, do not modify during output, null ignored
* @param output
* the <code>Writer</code> to write to
* @throws NullPointerException
@ -1186,12 +1190,10 @@ public class IO
* Writes chars from a <code>char[]</code> to bytes on an
* <code>OutputStream</code>.
* <p>
* This method uses {@link String#String(char[])} and
* {@link String#getBytes()}.
* This method uses {@link String#String(char[])} and {@link String#getBytes()}.
*
* @param data
* the char array to write, do not modify during output, null
* ignored
* the char array to write, do not modify during output, null ignored
* @param output
* the <code>OutputStream</code> to write to
* @throws NullPointerException
@ -1219,8 +1221,7 @@ public class IO
* {@link String#getBytes(String)}.
*
* @param data
* the char array to write, do not modify during output, null
* ignored
* the char array to write, do not modify during output, null ignored
* @param output
* the <code>OutputStream</code> to write to
* @param encoding
@ -1238,7 +1239,8 @@ public class IO
if(encoding == null)
{
write(data, output);
} else
}
else
{
output.write(new String(data).getBytes(encoding));
}
@ -1321,7 +1323,8 @@ public class IO
if(encoding == null)
{
write(data, output);
} else
}
else
{
output.write(data.getBytes(encoding));
}
@ -1404,7 +1407,8 @@ public class IO
if(encoding == null)
{
write(data, output);
} else
}
else
{
output.write(data.toString().getBytes(encoding));
}
@ -1414,17 +1418,16 @@ public class IO
// writeLines
// -----------------------------------------------------------------------
/**
* Writes the <code>toString()</code> value of each item in a collection to
* an <code>OutputStream</code> line by line, using the default character
* encoding of the platform and the specified line ending.
* Writes the <code>toString()</code> value of each item in a collection to an
* <code>OutputStream</code> line by line, using the default character encoding
* of the platform and the specified line ending.
*
* @param lines
* the lines to write, null entries produce blank lines
* @param lineEnding
* the line separator to use, null is system default
* @param output
* the <code>OutputStream</code> to write to, not null, not
* closed
* the <code>OutputStream</code> to write to, not null, not closed
* @throws NullPointerException
* if the output is null
* @throws IOException
@ -1453,8 +1456,8 @@ public class IO
}
/**
* Writes the <code>toString()</code> value of each item in a collection to
* an <code>OutputStream</code> line by line, using the specified character
* Writes the <code>toString()</code> value of each item in a collection to an
* <code>OutputStream</code> line by line, using the specified character
* encoding and the specified line ending.
* <p>
* Character encoding names can be found at
@ -1465,8 +1468,7 @@ public class IO
* @param lineEnding
* the line separator to use, null is system default
* @param output
* the <code>OutputStream</code> to write to, not null, not
* closed
* the <code>OutputStream</code> to write to, not null, not closed
* @param encoding
* the encoding to use, null means platform default
* @throws NullPointerException
@ -1480,7 +1482,8 @@ public class IO
if(encoding == null)
{
writeLines(lines, lineEnding, output);
} else
}
else
{
if(lines == null)
{
@ -1503,8 +1506,8 @@ public class IO
}
/**
* Writes the <code>toString()</code> value of each item in a collection to
* a <code>Writer</code> line by line, using the specified line ending.
* Writes the <code>toString()</code> value of each item in a collection to a
* <code>Writer</code> line by line, using the specified line ending.
*
* @param lines
* the lines to write, null entries produce blank lines
@ -1542,15 +1545,14 @@ public class IO
// copy from InputStream
// -----------------------------------------------------------------------
/**
* Copy bytes from an <code>InputStream</code> to an
* <code>OutputStream</code>.
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p>
* Large streams (over 2GB) will return a bytes copied value of
* <code>-1</code> after the copy has completed since the correct number of
* bytes cannot be returned as an int. For large streams use the
* Large streams (over 2GB) will return a bytes copied value of <code>-1</code>
* after the copy has completed since the correct number of bytes cannot be
* returned as an int. For large streams use the
* <code>copyLarge(InputStream, OutputStream)</code> method.
*
* @param input
@ -1608,8 +1610,8 @@ public class IO
}
/**
* Copy bytes from an <code>InputStream</code> to chars on a
* <code>Writer</code> using the default character encoding of the platform.
* Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code>
* using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
@ -1633,8 +1635,8 @@ public class IO
}
/**
* Copy bytes from an <code>InputStream</code> to chars on a
* <code>Writer</code> using the specified character encoding.
* Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code>
* using the specified character encoding.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
@ -1661,7 +1663,8 @@ public class IO
if(encoding == null)
{
copy(input, output);
} else
}
else
{
InputStreamReader in = new InputStreamReader(input, encoding);
copy(in, output);
@ -1676,9 +1679,9 @@ public class IO
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
* <p>
* Large streams (over 2GB) will return a chars copied value of
* <code>-1</code> after the copy has completed since the correct number of
* chars cannot be returned as an int. For large streams use the
* Large streams (over 2GB) will return a chars copied value of <code>-1</code>
* after the copy has completed since the correct number of chars cannot be
* returned as an int. For large streams use the
* <code>copyLarge(Reader, Writer)</code> method.
*
* @param input
@ -1768,8 +1771,8 @@ public class IO
/**
* Copy chars from a <code>Reader</code> to bytes on an
* <code>OutputStream</code> using the specified character encoding, and
* calling flush.
* <code>OutputStream</code> using the specified character encoding, and calling
* flush.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
@ -1799,7 +1802,8 @@ public class IO
if(encoding == null)
{
copy(input, output);
} else
}
else
{
OutputStreamWriter out = new OutputStreamWriter(output, encoding);
copy(input, out);
@ -1811,8 +1815,7 @@ public class IO
// content equals
// -----------------------------------------------------------------------
/**
* Compare the contents of two Streams to determine if they are equal or
* not.
* Compare the contents of two Streams to determine if they are equal or not.
* <p>
* This method buffers the input internally using
* <code>BufferedInputStream</code> if they are not already buffered.
@ -1855,11 +1858,10 @@ public class IO
}
/**
* Compare the contents of two Readers to determine if they are equal or
* not.
* Compare the contents of two Readers to determine if they are equal or not.
* <p>
* This method buffers the input internally using
* <code>BufferedReader</code> if they are not already buffered.
* This method buffers the input internally using <code>BufferedReader</code> if
* they are not already buffered.
*
* @param input1
* the first reader

View File

@ -149,6 +149,33 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
}
}
public File findFile(String name)
{
lock.lock();
for(File i : getFolders(name))
{
for(File j : i.listFiles())
{
if(j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name))
{
return j;
}
}
File file = new File(i, name + ".iob");
if(file.exists())
{
return file;
}
}
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
lock.unlock();
return null;
}
public IrisObject load(String name)
{
String key = name + "-" + objectClass.getCanonicalName();