Tons of changes:

- Added interface to game, client and server
- Added transformations
- Made ingredient conditions more practical to use, no longer requires imports
- Started implementation of event handling
- Moved commands and logic to the common API code
- Added common interface to MineTweaker recipes
- Added string methods
- Moved the logger from static value to static getter
- Fixed crashes on dedicated servers
- Fixed bracket resolution for <id:meta> values in 1.6.4
- Fixed scripts not being sent to multiplayer clients in 1.6.4
This commit is contained in:
Stan Hebben committed 2014-07-04 22:03:03 +02:00
1 parent 7f6235f30d
commit 115593efa5
131 files changed
+3215 -1930

No files matched your search

@@ -16,6 +16,6 @@ public class GlobalFunctions {
private GlobalFunctions() {}
public static void print(String message) {
MineTweakerAPI.logger.logInfo(message);
MineTweakerAPI.getLogger().logInfo(message);
}
}
@@ -142,12 +142,20 @@ public class GlobalRegistry {
private static class MyErrorLogger implements IZenErrorLogger {
@Override
public void error(ZenPosition position, String message) {
MineTweakerAPI.logger.logError(position.toString() + ": " + message);
if (position == null) {
MineTweakerAPI.getLogger().logError("system: " + message);
} else {
MineTweakerAPI.getLogger().logError(position + ": " + message);
}
}
@Override
public void warning(ZenPosition position, String message) {
MineTweakerAPI.logger.logWarning(position.toString() + ": " + message);
if (position == null) {
MineTweakerAPI.getLogger().logWarning("system: " + message);
} else {
MineTweakerAPI.getLogger().logWarning(position + ": " + message);
}
}
}
@@ -251,12 +259,12 @@ public class GlobalRegistry {
@Override
public void error(ZenPosition position, String message) {
MineTweakerAPI.logger.logError(position.toString() + " > " + message);
MineTweakerAPI.getLogger().logError(position.toString() + " > " + message);
}
@Override
public void warning(ZenPosition position, String message) {
MineTweakerAPI.logger.logWarning(position.toString() + " > " + message);
MineTweakerAPI.getLogger().logWarning(position.toString() + " > " + message);
}
}
}
@@ -6,7 +6,6 @@
package minetweaker.runtime;
import java.io.Closeable;
import java.util.List;
import minetweaker.IUndoableAction;
import minetweaker.api.item.IIngredient;
@@ -18,7 +17,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
* @author Stan
*/
@ZenClass("minetweaker.IMineTweaker")
public interface IMineTweaker {
public interface ITweaker {
/**
* Executes a specified MineTweaker action. Will print a log message and
* adds the action to the undo list.
@@ -35,7 +35,7 @@ import stanhebben.zenscript.parser.ParseException;
*
* @author Stan Hebben
*/
public class Tweaker implements IMineTweaker {
public class MTTweaker implements ITweaker {
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
@@ -45,7 +45,7 @@ public class Tweaker implements IMineTweaker {
@Override
public void apply(IUndoableAction action) {
MineTweakerAPI.logger.logInfo(action.describe());
MineTweakerAPI.getLogger().logInfo(action.describe());
Object overrideKey = action.getOverrideKey();
if (wereStuck.contains(action)) {
@@ -76,10 +76,10 @@ public class Tweaker implements IMineTweaker {
for (int i = actions.size() - 1; i >= 0; i--) {
IUndoableAction action = actions.get(i);
if (action.canUndo()) {
MineTweakerAPI.logger.logInfo(action.describeUndo());
MineTweakerAPI.getLogger().logInfo(action.describeUndo());
action.undo();
} else {
MineTweakerAPI.logger.logInfo("[Stuck] " + action.describe());
MineTweakerAPI.getLogger().logInfo("[Stuck] " + action.describe());
stuck.add(0, action);
wereStuck.add(action);
@@ -100,6 +100,8 @@ public class Tweaker implements IMineTweaker {
@Override
public void load() {
System.out.println("Loading scripts");
scriptData = ScriptProviderMemory.collect(scriptProvider);
Set<String> executed = new HashSet<String>();
@@ -127,11 +129,12 @@ public class Tweaker implements IMineTweaker {
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
files.add(pfile);
} catch (IOException ex) {
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
MineTweakerAPI.getLogger().logError("Could not load script " + script.getName() + ": " + ex.getMessage());
} catch (ParseException ex) {
MineTweakerAPI.logger.logError("Error parsing " + ex.getFile() + ":" + ex.getLine() + " -- " + ex.getExplanation());
//ex.printStackTrace();
MineTweakerAPI.getLogger().logError("Error parsing " + ex.getFile().getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
} catch (Exception ex) {
MineTweakerAPI.logger.logError("Error loading " + script.getName() + ": " + ex.toString());
MineTweakerAPI.getLogger().logError("Error loading " + script.getName() + ": " + ex.toString());
ex.printStackTrace();
}
@@ -151,16 +154,16 @@ public class Tweaker implements IMineTweaker {
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
module.getMain().run();
} catch (Exception ex) {
MineTweakerAPI.logger.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
MineTweakerAPI.getLogger().logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
ex.printStackTrace();
}
}
}
if (wereStuck.size() > 0) {
MineTweakerAPI.logger.logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
MineTweakerAPI.getLogger().logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
for (IUndoableAction action : wereStuck) {
MineTweakerAPI.logger.logInfo("Stuck: " + action.describe());
MineTweakerAPI.getLogger().logInfo("Stuck: " + action.describe());
}
}
}
@@ -23,22 +23,26 @@ public class ScriptProviderDirectory implements IScriptProvider {
private final File directory;
public ScriptProviderDirectory(File directory) {
if (directory == null) throw new IllegalArgumentException("directory cannot be null");
this.directory = directory;
}
@Override
public Iterator<IScriptIterator> getScripts() {
List<IScriptIterator> scripts = new ArrayList<IScriptIterator>();
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
scripts.add(new ScriptIteratorDirectory(file));
} else if (file.getName().endsWith(".zs")) {
scripts.add(new ScriptIteratorSingle(file));
} else if (file.getName().endsWith(".zip")) {
try {
scripts.add(new ScriptIteratorZip(file));
} catch (IOException ex) {
MineTweakerAPI.logger.logError("Could not load " + file.getName() + ": " + ex.getMessage());
if (directory.exists()) {
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
scripts.add(new ScriptIteratorDirectory(file));
} else if (file.getName().endsWith(".zs")) {
scripts.add(new ScriptIteratorSingle(file));
} else if (file.getName().endsWith(".zip")) {
try {
scripts.add(new ScriptIteratorZip(file));
} catch (IOException ex) {
MineTweakerAPI.getLogger().logError("Could not load " + file.getName() + ": " + ex.getMessage());
}
}
}
}
@@ -63,7 +63,7 @@ public class ScriptProviderMemory implements IScriptProvider {
deflater.close();
} catch (IOException ex) {
MineTweakerAPI.logger.logError("Could not collect scripts: " + ex.getMessage());
MineTweakerAPI.getLogger().logError("Could not collect scripts: " + ex.getMessage());
}
return output.toByteArray();
}
@@ -96,7 +96,7 @@ public class ScriptProviderMemory implements IScriptProvider {
inflaterData.close();
} catch (IOException ex) {
MineTweakerAPI.logger.logError("Could not load transmitted scripts: " + ex.getMessage());
MineTweakerAPI.getLogger().logError("Could not load transmitted scripts: " + ex.getMessage());
}
}