diff --git a/build.gradle b/build.gradle index 99d6f1158..b9d6122d7 100644 --- a/build.gradle +++ b/build.gradle @@ -36,4 +36,5 @@ version = "MC${config.minecraft.version}-${project.version}" apply from: 'gradle/forge.gradle' apply from: 'gradle/artifact.gradle' +apply from: 'gradle/sign.gradle' apply from: 'gradle/release.gradle' diff --git a/gradle/artifact.gradle b/gradle/artifact.gradle index 628ada98f..2d7cd9fca 100644 --- a/gradle/artifact.gradle +++ b/gradle/artifact.gradle @@ -6,6 +6,10 @@ jar { } } +javadoc { + include 'li/cil/oc/api/**' +} + // because the normal default jar task has been modified to be obfuscated task deobfJar(type: Jar) { from sourceSets.main.output @@ -22,7 +26,13 @@ task apiJar(type: Jar) { include 'li/cil/oc/api/**' } +task javadocJar(type: Jar, dependsOn: javadoc) { + from 'build/docs/javadoc' + classifier 'javadoc' +} + artifacts { archives deobfJar archives apiJar + archives javadocJar } diff --git a/gradle/forge.gradle b/gradle/forge.gradle index 40bbd152c..06b226691 100644 --- a/gradle/forge.gradle +++ b/gradle/forge.gradle @@ -15,6 +15,10 @@ compileScala { minecraft { version = "${config.minecraft.version}-${config.forge.version}" + + replaceIn "li/cil/oc/OpenComputers.scala" + if (project.hasProperty("keystore_fingerprint")) + replace "@FINGERPRINT@", keystore_fingerprint } processResources { diff --git a/gradle/sign.gradle b/gradle/sign.gradle new file mode 100644 index 000000000..7bf869cba --- /dev/null +++ b/gradle/sign.gradle @@ -0,0 +1,37 @@ +// Based on the code from TinkersConstruct and Cazzar's repo. +// Thanks ProgWML6 and Cazzar! + +// verify the properties exist... or initialize. +if (!project.hasProperty("keystore_location")) // keystore stuff + ext.keystore_location = "" + +if (!project.hasProperty("keystore_alias")) // keystore stuff + ext.keystore_alias = "" + +if (!project.hasProperty("keystore_password")) // keystore stuff + ext.keystore_password = "" + +task("signJar", dependsOn: "reobf") { + inputs.file jar.getArchivePath() + inputs.file keystore_location + inputs.property "keystore_alias", keystore_alias + inputs.property "keystore_password", keystore_password + outputs.file jar.getArchivePath() + + // only sign if the keystore exists + onlyIf { + return !keystore_location.empty + } + + // the actual action - sign the jar. + doLast { + ant.signjar( + destDir: jar.destinationDir, + jar: jar.getArchivePath(), + keystore: keystore_location, + alias: keystore_alias, + storepass: keystore_password, + keypass: keystore_password + ) + } +} \ No newline at end of file diff --git a/src/main/java/li/cil/oc/api/machine/Machine.java b/src/main/java/li/cil/oc/api/machine/Machine.java index df28c65fe..be81b2884 100644 --- a/src/main/java/li/cil/oc/api/machine/Machine.java +++ b/src/main/java/li/cil/oc/api/machine/Machine.java @@ -1,6 +1,5 @@ package li.cil.oc.api.machine; -import li.cil.oc.api.fs.FileSystem; import li.cil.oc.api.network.Callback; import li.cil.oc.api.network.Context; import li.cil.oc.api.network.ManagedEnvironment; @@ -79,7 +78,7 @@ public interface Machine extends ManagedEnvironment, Context { * The address of the file system that holds the machine's read only data * (rom). This file system is populated based on the backing resource file * systems specified for the machines architecture via - * {@link li.cil.oc.api.Machine#addRomResource(Class, FileSystem, String)}. + * {@link li.cil.oc.api.Machine#addRomResource(Class, java.util.concurrent.Callable, String)}. * This may return null if the creation of the file system * failed. *
diff --git a/src/main/java/li/cil/oc/api/network/Network.java b/src/main/java/li/cil/oc/api/network/Network.java index 8cb6b7bc3..3d76f0014 100644 --- a/src/main/java/li/cil/oc/api/network/Network.java +++ b/src/main/java/li/cil/oc/api/network/Network.java @@ -178,7 +178,7 @@ public interface Network { * @param name the name of the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see `neighbors` + * @see #neighbors(Node) */ void sendToNeighbors(Node source, String name, Object... data); @@ -196,7 +196,7 @@ public interface Network { * @param source the node that sends the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see {@link #nodes(Node)} + * @see #nodes(Node) */ void sendToReachable(Node source, String name, Object... data); @@ -218,8 +218,8 @@ public interface Network { * @param source the node that sends the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see {@link #nodes(Node)} - * @see {@link Component#canBeSeenFrom(Node)} + * @see #nodes(Node) + * @see Component#canBeSeenFrom(Node) */ void sendToVisible(Node source, String name, Object... data); } diff --git a/src/main/java/li/cil/oc/api/network/SidedEnvironment.java b/src/main/java/li/cil/oc/api/network/SidedEnvironment.java index 97d647632..5f476ba62 100644 --- a/src/main/java/li/cil/oc/api/network/SidedEnvironment.java +++ b/src/main/java/li/cil/oc/api/network/SidedEnvironment.java @@ -2,6 +2,7 @@ package li.cil.oc.api.network; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; /** @@ -11,9 +12,9 @@ import net.minecraftforge.common.util.ForgeDirection; * * This interface is intended to be used on tile entities that are environments. * It is used to determine which neighbors a tile entity can connect to when - * calling {@link li.cil.oc.api.Network#joinOrCreateNetwork}. It is used by the - * keyboard to only interface with the side on which it is attached, as well as - * the router to offer a different node for each side. + * calling {@link li.cil.oc.api.Network#joinOrCreateNetwork(TileEntity)}. It is + * used by the keyboard to only interface with the side on which it is attached, + * as well as the router to offer a different node for each side. */ public interface SidedEnvironment { /** diff --git a/src/main/java/org/luaj/vm3/Globals.java b/src/main/java/org/luaj/vm3/Globals.java index 829bfdd08..c5161aa84 100644 --- a/src/main/java/org/luaj/vm3/Globals.java +++ b/src/main/java/org/luaj/vm3/Globals.java @@ -80,7 +80,7 @@ import org.luaj.vm3.lib.ResourceFinder; *
* This contains all library functions listed as "basic functions" in the lua documentation for JME.
* The functions dofile and loadfile use the
- * {@link #FINDER} instance to find resource files.
+ * {@link #finder} instance to find resource files.
* Since JME has no file system by default, {@link BaseLib} implements
* {@link ResourceFinder} using {@link Class#getResource(String)},
* which is the closest equivalent on JME.
@@ -69,7 +69,7 @@ import org.luaj.vm3.Varargs;
* This is a direct port of the corresponding library in C.
* @see JseBaseLib
* @see ResourceFinder
- * @see #FINDER
+ * @see #finder
* @see LibFunction
* @see JsePlatform
* @see JmePlatform
@@ -81,7 +81,7 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
public LuaValue call(LuaValue modname, LuaValue env) {
globals = env.checkglobals();
- globals.FINDER = this;
+ globals.finder = this;
globals.baselib = this;
env.set( "_G", env );
env.set( "_VERSION", Lua._VERSION );
@@ -424,7 +424,7 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder {
* @return Varargs containing chunk, or NIL,error-text on error
*/
public Varargs loadFile(String filename, String mode, LuaValue env) {
- InputStream is = globals.FINDER.findResource(filename);
+ InputStream is = globals.finder.findResource(filename);
if ( is == null )
return varargsOf(NIL, valueOf("cannot open "+filename+": No such file or directory"));
try {
diff --git a/src/main/java/org/luaj/vm3/lib/DebugLib.java b/src/main/java/org/luaj/vm3/lib/DebugLib.java
index 59eb63a38..ef4389a19 100644
--- a/src/main/java/org/luaj/vm3/lib/DebugLib.java
+++ b/src/main/java/org/luaj/vm3/lib/DebugLib.java
@@ -72,8 +72,12 @@ import org.luaj.vm3.Varargs;
* @see Lua 5.2 Debug Lib Reference
*/
public class DebugLib extends TwoArgFunction {
- public static final boolean CALLS = (null != System.getProperty("CALLS"));
- public static final boolean TRACE = (null != System.getProperty("TRACE"));
+ public static boolean CALLS;
+ public static boolean TRACE;
+ static {
+ try { CALLS = (null != System.getProperty("CALLS")); } catch (Exception e) {}
+ try { TRACE = (null != System.getProperty("TRACE")); } catch (Exception e) {}
+ }
private static final LuaString LUA = valueOf("Lua");
private static final LuaString QMARK = valueOf("?");
diff --git a/src/main/java/org/luaj/vm3/lib/PackageLib.java b/src/main/java/org/luaj/vm3/lib/PackageLib.java
index 2908bce57..1cae2cb0a 100644
--- a/src/main/java/org/luaj/vm3/lib/PackageLib.java
+++ b/src/main/java/org/luaj/vm3/lib/PackageLib.java
@@ -81,8 +81,13 @@ public class PackageLib extends TwoArgFunction {
/** The default value to use for package.path. This can be set with the system property
* "luaj.package.path"
, and is "?.lua"
by default. */
- public static String DEFAULT_LUA_PATH = System.getProperty("luaj.package.path");
+ public static String DEFAULT_LUA_PATH;
static {
+ try {
+ DEFAULT_LUA_PATH = System.getProperty("luaj.package.path");
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ }
if (DEFAULT_LUA_PATH == null)
DEFAULT_LUA_PATH = "?.lua";
}
@@ -294,7 +299,7 @@ public class PackageLib extends TwoArgFunction {
}
// try opening the file
- InputStream is = globals.FINDER.findResource(filename);
+ InputStream is = globals.finder.findResource(filename);
if (is != null) {
try { is.close(); } catch ( java.io.IOException ioe ) {}
return valueOf(filename);
diff --git a/src/main/java/org/luaj/vm3/lib/ResourceFinder.java b/src/main/java/org/luaj/vm3/lib/ResourceFinder.java
index 32ddfa445..b857a7328 100644
--- a/src/main/java/org/luaj/vm3/lib/ResourceFinder.java
+++ b/src/main/java/org/luaj/vm3/lib/ResourceFinder.java
@@ -31,13 +31,13 @@ import java.io.InputStream;
* for both the Jme and Jse platforms.
*
* The Jme version of base lib {@link BaseLib} - * implements {@link BaseLib#FINDER} via {@link Class#getResourceAsStream(String)}, + * implements {@link Globals#finder} via {@link Class#getResourceAsStream(String)}, * while the Jse version {@link JseBaseLib} implements it using {@link java.io.File#File(String)}. *
* The io library does not use this API for file manipulation. *
* @see BaseLib - * @see BaseLib#FINDER + * @see Globals#finder * @see JseBaseLib * @see JmePlatform * @see JsePlatform diff --git a/src/main/java/org/luaj/vm3/lib/StringLib.java b/src/main/java/org/luaj/vm3/lib/StringLib.java index afde5979b..a4a189290 100644 --- a/src/main/java/org/luaj/vm3/lib/StringLib.java +++ b/src/main/java/org/luaj/vm3/lib/StringLib.java @@ -1155,18 +1155,19 @@ public class StringLib extends TwoArgFunction { if ( poff == plen || poff + 1 == plen ) { error( "unbalanced pattern" ); } - if ( soff >= s.length() || s.luaByte( soff ) != p.luaByte( poff ) ) + final int slen = s.length(); + if ( soff >= slen ) return -1; - else { - int b = p.luaByte( poff ); - int e = p.luaByte( poff + 1 ); - int cont = 1; - while ( ++soff < s.length() ) { - if ( s.luaByte( soff ) == e ) { - if ( --cont == 0 ) return soff + 1; - } - else if ( s.luaByte( soff ) == b ) cont++; + final int b = p.luaByte( poff ); + if ( s.luaByte( soff ) != b ) + return -1; + final int e = p.luaByte( poff + 1 ); + int cont = 1; + while ( ++soff < slen ) { + if ( s.luaByte( soff ) == e ) { + if ( --cont == 0 ) return soff + 1; } + else if ( s.luaByte( soff ) == b ) cont++; } return -1; } diff --git a/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java b/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java index 3bf09200e..5cdb7d9da 100644 --- a/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java +++ b/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java @@ -33,11 +33,11 @@ import org.luaj.vm3.lib.ResourceFinder; /** * Subclass of {@link BaseLib} and {@link LibFunction} which implements the lua basic library functions - * and provides a directory based {@link ResourceFinder} as the {@link #FINDER}. + * and provides a directory based {@link ResourceFinder} as the {@link #finder}. *
* Since JME has no file system by default, {@link BaseLib} implements * {@link ResourceFinder} using {@link Class#getResource(String)}. - * The {@link JseBaseLib} implements {@link FINDER} by scanning the current directory + * The {@link JseBaseLib} implements {@link finder} by scanning the current directory * first, then falling back to {@link Class#getResource(String)} if that fails. * Otherwise, the behavior is the same as that of {@link BaseLib}. *
@@ -62,7 +62,7 @@ import org.luaj.vm3.lib.ResourceFinder; * @see Globals * @see BaseLib * @see ResourceFinder - * @see {@link Globals.FINDER} + * @see {@link Globals.finder} * @see LibFunction * @see JsePlatform * @see org.luaj.vm3.lib.jme.JmePlatform diff --git a/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java b/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java index 596f7f4f1..8ab4cbd7a 100644 --- a/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java +++ b/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java @@ -109,7 +109,7 @@ public class LuajavaLib extends VarArgFunction { // LuaValue modname = args.arg1(); LuaValue env = args.arg(2); LuaTable t = new LuaTable(); - bind( t, LuajavaLib.class, NAMES, BINDCLASS ); + bind( t, this.getClass(), NAMES, BINDCLASS ); env.set("luajava", t); env.get("package").get("loaded").set("luajava", t); return t; diff --git a/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java b/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java index 5c03369ad..f20e294fc 100644 --- a/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java +++ b/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java @@ -95,6 +95,21 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin } } + @Override + public Object eval(Reader reader, Bindings bindings) throws ScriptException { + return ((LuajCompiledScript) compile(reader)).eval(context.globals, bindings); + } + + @Override + public Object eval(String script, Bindings bindings) throws ScriptException { + return eval(new StringReader(script), bindings); + } + + @Override + protected ScriptContext getScriptContext(Bindings nn) { + throw new IllegalStateException("LuajScriptEngine should not be allocating contexts."); + } + @Override public Bindings createBindings() { return new SimpleBindings(); @@ -109,7 +124,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin @Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { - return compile(reader).eval(); + return compile(reader).eval(context); } @Override @@ -142,7 +157,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin return eval(((LuajContext) context).globals, context.getBindings(ScriptContext.ENGINE_SCOPE)); } - private Object eval(Globals g, Bindings b) throws ScriptException { + Object eval(Globals g, Bindings b) throws ScriptException { g.setmetatable(new BindingsMetatable(b)); LuaFunction f = function; if (f.isclosure()) diff --git a/src/main/java/org/luaj/vm3/script/LuajContext.java b/src/main/java/org/luaj/vm3/script/LuajContext.java index b40239829..032fd4a32 100644 --- a/src/main/java/org/luaj/vm3/script/LuajContext.java +++ b/src/main/java/org/luaj/vm3/script/LuajContext.java @@ -103,7 +103,7 @@ public class LuajContext extends SimpleScriptContext implements ScriptContext { @Override public void setWriter(Writer writer) { globals.STDOUT = writer != null? - new PrintStream(new WriterOutputStream(writer)): + new PrintStream(new WriterOutputStream(writer), true): stdout; } @@ -113,7 +113,19 @@ public class LuajContext extends SimpleScriptContext implements ScriptContext { this.w = w; } public void write(int b) throws IOException { - w.write(b); + w.write(new String(new byte[] {(byte)b})); + } + public void write(byte[] b, int o, int l) throws IOException { + w.write(new String(b, o, l)); + } + public void write(byte[] b) throws IOException { + w.write(new String(b)); + } + public void close() throws IOException { + w.close(); + } + public void flush() throws IOException { + w.flush(); } } diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index 0b71756f7..da4830c6f 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -88,6 +88,7 @@ oc:gui.Analyzer.StoredEnergy=§6Gespeicherte Energie§f: %s oc:gui.Analyzer.TotalEnergy=§6Insgesamt gespeicherte Energie§f: %s oc:gui.Analyzer.Users=§6Benutzer§f: %s oc:gui.Chat.NewVersion=Eine neue Version ist verfügbar: %s +oc:gui.Chat.WarningFingerprint=§cWARNUNG§f - ungültige Signatur! Sollte §a'%s'§f sein, aber war §e'%s'§f. Falls du kein Modder bist und die "deobfuscated"-Version des Mods benutzt, solltest du OpenComputers erneut herunterladen, da die JAR die du benutzt vermutlich modifiziert wurde. oc:gui.Chat.WarningLuaFallback=Die native Lua-Implementierung ist nicht verfügbar. Computer können ihren Ausführungszustand nicht speichern. Sie werden automatisch neu starten, sobald ein Chunk neu geladen wird. oc:gui.Chat.WarningPower=Es ist kein unterstützter, Strom erzeugender Mod verfügbar. Computer, Bildschirme und alle anderen Komponenten werden §lkeine§f Energie benötigen. Installiere einen der folgenden Mods, um Stromnutzung zu ermöglichen: BuildCraft, IndustrialCraft2, Thermal Expansion oder Universal Electricity. Deaktiviere Stromverbrauch in der Konfiguration, um diese Warnung zu unterdrücken. oc:gui.Chat.WarningProjectRed=Die verwendete Version von Project: Red ist nicht mit OpenComputers kompatibel. Aktualisiere bitte deine Version von Project: Red. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 10c6bb9d7..745111e79 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -88,6 +88,7 @@ oc:gui.Analyzer.StoredEnergy=§6Stored energy§f: %s oc:gui.Analyzer.TotalEnergy=§6Total stored energy§f: %s oc:gui.Analyzer.Users=§6Users§f: %s oc:gui.Chat.NewVersion=A new version is available: %s +oc:gui.Chat.WarningFingerprint=§cWARNING§f - fingerprint mismatch! Expected §a'%s'§f but got §e'%s'§f. Unless you are a modder and are running the deobfuscated version of the mod, it is §lstrongly§f recommended to redownload OpenComputers, because the JAR you are using may have been tampered with. oc:gui.Chat.WarningLuaFallback=Native Lua libraries are not available, computers will not be able to persist their state. They will reboot on chunk reloads. oc:gui.Chat.WarningPower=No supported power providing mod available. Computers, screens and all other components will §lnot§f require energy. Install one of the following mods to enable power: BuildCraft, IndustrialCraft2, Thermal Expansion or Universal Electricity. Disable power in the config to suppress this warning. oc:gui.Chat.WarningProjectRed=You are using a version of Project: Red that is incompatible with OpenComputers. Try updating your version of Project: Red. diff --git a/src/main/scala/li/cil/oc/OpenComputers.scala b/src/main/scala/li/cil/oc/OpenComputers.scala index 58a7a8850..79f7f4699 100644 --- a/src/main/scala/li/cil/oc/OpenComputers.scala +++ b/src/main/scala/li/cil/oc/OpenComputers.scala @@ -3,14 +3,13 @@ package li.cil.oc import cpw.mods.fml.common.Mod import cpw.mods.fml.common.Mod.EventHandler import cpw.mods.fml.common.SidedProxy -import cpw.mods.fml.common.event.FMLInitializationEvent -import cpw.mods.fml.common.event.FMLPostInitializationEvent -import cpw.mods.fml.common.event.FMLPreInitializationEvent +import cpw.mods.fml.common.event.{FMLFingerprintViolationEvent, FMLInitializationEvent, FMLPostInitializationEvent, FMLPreInitializationEvent} import cpw.mods.fml.common.network.FMLEventChannel import java.util.logging.Logger import li.cil.oc.common.Proxy -@Mod(modid = "OpenComputers", modLanguage = "scala", useMetadata = true) +@Mod(modid = "OpenComputers", modLanguage = "scala", + certificateFingerprint = "@FINGERPRINT@", useMetadata = true) object OpenComputers { val log = Logger.getLogger("OpenComputers") @@ -19,6 +18,11 @@ object OpenComputers { var channel: FMLEventChannel = _ + var tampered: Option[FMLFingerprintViolationEvent] = None + + @EventHandler + def invalidFingerprint(e: FMLFingerprintViolationEvent) = tampered = Some(e) + @EventHandler def preInit(e: FMLPreInitializationEvent) = proxy.preInit(e) diff --git a/src/main/scala/li/cil/oc/common/EventHandler.scala b/src/main/scala/li/cil/oc/common/EventHandler.scala index 63318159c..28449554e 100644 --- a/src/main/scala/li/cil/oc/common/EventHandler.scala +++ b/src/main/scala/li/cil/oc/common/EventHandler.scala @@ -1,15 +1,15 @@ package li.cil.oc.common import cpw.mods.fml.common.eventhandler.SubscribeEvent +import cpw.mods.fml.common.FMLCommonHandler import cpw.mods.fml.common.gameevent.PlayerEvent._ import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent -import cpw.mods.fml.common.{Loader, FMLCommonHandler} import li.cil.oc.api.Network import li.cil.oc.server.driver.Registry import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.LuaStateFactory import li.cil.oc.util.mods.ProjectRed -import li.cil.oc.{UpdateCheck, Items, Settings} +import li.cil.oc.{OpenComputers, UpdateCheck, Items, Settings} import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.item.{ItemMap, ItemStack} import net.minecraft.server.MinecraftServer @@ -57,6 +57,11 @@ object EventHandler { player.addChatMessage(new ChatComponentText("§aOpenComputers§f: ").appendSibling( new ChatComponentTranslation(Settings.namespace + "gui.Chat.WarningPower"))) } + OpenComputers.tampered match { + case Some(event) => player.addChatMessage(new ChatComponentText("§aOpenComputers§f: ").appendSibling( + new ChatComponentTranslation(Settings.namespace + "gui.Chat.WarningFingerprint", event.expectedFingerprint, event.fingerprints.toArray.mkString(", ")))) + case _ => + } // Do update check in local games and for OPs. if (!MinecraftServer.getServer.isDedicatedServer || MinecraftServer.getServer.getConfigurationManager.isPlayerOpped(player.getCommandSenderName)) { UpdateCheck.checkForPlayer(player) diff --git a/src/main/scala/li/cil/oc/common/SaveHandler.scala b/src/main/scala/li/cil/oc/common/SaveHandler.scala index 6a9d8663e..ebcd1d5d1 100644 --- a/src/main/scala/li/cil/oc/common/SaveHandler.scala +++ b/src/main/scala/li/cil/oc/common/SaveHandler.scala @@ -6,9 +6,12 @@ import java.util.logging.Level import li.cil.oc.{OpenComputers, Settings} import net.minecraft.world.ChunkCoordIntPair import net.minecraftforge.common.DimensionManager -import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.event.world.{ChunkDataEvent, WorldEvent} import scala.collection.mutable +// Used by the native lua state to store kernel and stack data in auxiliary +// files instead of directly in the tile entity data, avoiding potential +// problems with the tile entity data becoming too large. object SaveHandler { val saveData = mutable.Map.empty[ChunkCoordIntPair, mutable.Map[String, Array[Byte]]] @@ -46,32 +49,35 @@ object SaveHandler { } } - // Used by the native lua state to store kernel and stack data in auxiliary - // files instead of directly in the tile entity data, avoiding potential - // problems with the tile entity data becoming too large. + @SubscribeEvent + def onChunkSave(e: ChunkDataEvent.Save) = saveData.synchronized { + val path = savePath + val chunk = e.getChunk.getChunkCoordIntPair + val chunkPath = new io.File(path, s"${chunk.chunkXPos}.${chunk.chunkZPos}") + if (chunkPath.exists && chunkPath.isDirectory) { + for (file <- chunkPath.listFiles()) file.delete() + } + saveData.get(chunk) match { + case Some(entries) => + chunkPath.mkdirs() + for ((name, data) <- entries) { + val file = new io.File(chunkPath, name) + try { + // val fos = new GZIPOutputStream(new io.FileOutputStream(file)) + val fos = new io.BufferedOutputStream(new io.FileOutputStream(file)) + fos.write(data) + fos.close() + } + catch { + case e: io.IOException => OpenComputers.log.log(Level.WARNING, s"Error saving auxiliary tile entity data to '${file.getAbsolutePath}.", e) + } + } + case _ => chunkPath.delete() + } + } + @SubscribeEvent def onWorldSave(e: WorldEvent.Save) = saveData.synchronized { - val path = savePath - path.mkdirs() - for ((chunk, entries) <- saveData) { - val chunkPath = new io.File(path, s"${chunk.chunkXPos}.${chunk.chunkZPos}") - chunkPath.mkdirs() - if (chunkPath.exists && chunkPath.isDirectory) { - for (file <- chunkPath.listFiles()) file.delete() - } - for ((name, data) <- entries) { - val file = new io.File(chunkPath, name) - try { - // val fos = new GZIPOutputStream(new io.FileOutputStream(file)) - val fos = new io.BufferedOutputStream(new io.FileOutputStream(file)) - fos.write(data) - fos.close() - } - catch { - case e: io.IOException => OpenComputers.log.log(Level.WARNING, s"Error saving auxiliary tile entity data to '${file.getAbsolutePath}.", e) - } - } - } saveData.clear() } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index 473b8db83..5ec18ae31 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -233,7 +233,7 @@ class Robot(val isRemote: Boolean) extends Computer with ISidedInventory with Bu } else { tag = new NBTTagCompound() - } + } if (name == null) { tag.setNewCompoundTag("display", tag => tag.setString("Name", Robot.randomName)) } @@ -620,7 +620,7 @@ object Robot { catch { case t: Throwable => OpenComputers.log.log(Level.WARNING, "Failed loading robot name list.", t) - Array.empty + Array.empty[String] } def randomName = names((math.random * names.length).toInt)