mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
- Added doclet
- Added documentation to some classes - Started working on tutorial and website
This commit is contained in:
1 parent
97c7f42400
commit
f3ea7f7831
51 files changed
+11420
-61
No files matched your search
+75
-1
@@ -11,10 +11,13 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
@@ -27,7 +30,7 @@ import minetweaker.runtime.IScriptProvider;
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ScriptProviderMemory {
|
||||
public class ScriptProviderMemory implements IScriptProvider {
|
||||
public static byte[] collect(Iterable<IScriptProvider> providers) {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try {
|
||||
@@ -67,7 +70,11 @@ public class ScriptProviderMemory {
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
private final Map<String, MemoryModule> modules;
|
||||
|
||||
public ScriptProviderMemory(byte[] scripts) {
|
||||
modules = new HashMap<String, MemoryModule>();
|
||||
|
||||
try {
|
||||
InflaterInputStream inflater = new InflaterInputStream(new ByteArrayInputStream(scripts));
|
||||
DataInputStream inflaterData = new DataInputStream(inflater);
|
||||
@@ -84,6 +91,7 @@ public class ScriptProviderMemory {
|
||||
|
||||
fileName = inflaterData.readUTF();
|
||||
}
|
||||
modules.put(moduleName, new MemoryModule(moduleName, files));
|
||||
|
||||
moduleName = inflaterData.readUTF();
|
||||
}
|
||||
@@ -93,6 +101,72 @@ public class ScriptProviderMemory {
|
||||
MineTweakerAPI.logger.logError("Could not load transmitted scripts: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IScriptIterator> getScripts() {
|
||||
return new ProviderIterator();
|
||||
}
|
||||
|
||||
private class ProviderIterator implements Iterator<IScriptIterator> {
|
||||
private Iterator<MemoryModule> baseIterator = modules.values().iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return baseIterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptIterator next() {
|
||||
return new ScriptIterator(baseIterator.next());
|
||||
}
|
||||
}
|
||||
|
||||
private class ScriptIterator implements IScriptIterator {
|
||||
private final MemoryModule module;
|
||||
private final Iterator<MemoryFile> files;
|
||||
private MemoryFile current;
|
||||
|
||||
public ScriptIterator(MemoryModule module) {
|
||||
this.module = module;
|
||||
files = module.data.iterator();
|
||||
current = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupName() {
|
||||
return module.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
if (files.hasNext()) {
|
||||
current = files.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return current.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream open() throws IOException {
|
||||
return new ByteArrayInputStream(current.data);
|
||||
}
|
||||
}
|
||||
|
||||
private class MemoryModule {
|
||||
private final String name;
|
||||
private final List<MemoryFile> data;
|
||||
|
||||
public MemoryModule(String name, List<MemoryFile> data) {
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
private class MemoryFile {
|
||||
private final String name;
|
||||
|
||||
Reference in new issue
Block a user