- Updated to new Forge version

- Added script locking
This commit is contained in:
Stan Hebben committed 2015-06-27 08:26:38 +02:00
1 parent ea47aec970
commit 00bcf843e5
9 files changed
+93 -7

No files matched your search

@@ -586,6 +586,29 @@ public class MineTweakerImplementationAPI {
events.onPlayerLoggedOut(LISTEN_LOGOUT);
}
byte[] currentScript = MineTweakerAPI.tweaker.getScriptData();
if (currentScript != null) {
System.out.println("Already loaded a script before");
// alread loaded a script
byte[] stagedScript = MineTweakerAPI.tweaker.getStagedScriptData();
if (Arrays.equals(currentScript, stagedScript)) {
System.out.println("No reload needed");
return; // no reload necessary
}
if (MineTweakerAPI.game.isLocked()) {
System.out.println("Reload blocked");
MineTweakerAPI.game.signalLockError();
return;
}
} else {
System.out.println("First time loading a script, go ahead");
}
MineTweakerAPI.tweaker.rollback();
if (MineTweakerAPI.server != null) {
@@ -94,4 +94,26 @@ public interface IGame {
*/
@ZenMethod
public String localize(String key, String lang);
/**
* Lock the game and disable reload. Recommended for distributed versions.
*
* Once locked, reload cannot be unlocked - a game restart is required to
* alter the scripts.
*/
@ZenMethod
public void lock();
/**
* Returns the lock state. True if locked.
*
* @return lock state
*/
@ZenGetter("locked")
public boolean isLocked();
/**
* Signals a modified script while in locked mode.
*/
public void signalLockError();
}
@@ -18,6 +18,13 @@ import stanhebben.zenscript.annotations.ZenMethod;
*/
@ZenClass("minetweaker.IMineTweaker")
public interface ITweaker {
/**
* Retrieves the script data to be loaded.
*
* @return
*/
public byte[] getStagedScriptData();
/**
* Executes a specified MineTweaker action. Will print a log message and
* adds the action to the undo list.
@@ -45,6 +45,11 @@ public class MTTweaker implements ITweaker {
private IScriptProvider scriptProvider;
private byte[] scriptData;
@Override
public byte[] getStagedScriptData() {
return ScriptProviderMemory.collect(scriptProvider);
}
@Override
public void apply(IUndoableAction action) {
MineTweakerAPI.logInfo(action.describe());