mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
6b208b98bc
commit
a309488cdf
214 files changed
+9283
-9265
No files matched your search
@@ -1,11 +1,20 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.runtime;
|
||||
|
||||
import static stanhebben.zenscript.ZenModule.compileScripts;
|
||||
import static stanhebben.zenscript.ZenModule.extractClassName;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
@@ -16,169 +25,162 @@ import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.parser.ParseException;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
||||
import static stanhebben.zenscript.ZenModule.compileScripts;
|
||||
import static stanhebben.zenscript.ZenModule.extractClassName;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MTTweaker implements ITweaker {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
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>();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private IScriptProvider scriptProvider;
|
||||
private byte[] scriptData;
|
||||
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>();
|
||||
|
||||
@Override
|
||||
public byte[] getStagedScriptData() {
|
||||
return ScriptProviderMemory.collect(scriptProvider);
|
||||
}
|
||||
private IScriptProvider scriptProvider;
|
||||
private byte[] scriptData;
|
||||
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logInfo(action.describe());
|
||||
@Override
|
||||
public byte[] getStagedScriptData() {
|
||||
return ScriptProviderMemory.collect(scriptProvider);
|
||||
}
|
||||
|
||||
Object overrideKey = action.getOverrideKey();
|
||||
if (wereStuck.contains(action)) {
|
||||
MineTweakerAPI.logInfo("WAS STUCK");
|
||||
wereStuck.remove(action);
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logInfo(action.describe());
|
||||
|
||||
if (overrideKey != null) {
|
||||
stuckOverridable.remove(overrideKey);
|
||||
}
|
||||
} else {
|
||||
if (overrideKey != null && stuckOverridable.containsKey(overrideKey)) {
|
||||
wereStuck.remove(stuckOverridable.get(overrideKey));
|
||||
stuckOverridable.remove(overrideKey);
|
||||
}
|
||||
Object overrideKey = action.getOverrideKey();
|
||||
if (wereStuck.contains(action)) {
|
||||
MineTweakerAPI.logInfo("WAS STUCK");
|
||||
wereStuck.remove(action);
|
||||
|
||||
action.apply();
|
||||
}
|
||||
if (overrideKey != null) {
|
||||
stuckOverridable.remove(overrideKey);
|
||||
}
|
||||
} else {
|
||||
if (overrideKey != null && stuckOverridable.containsKey(overrideKey)) {
|
||||
wereStuck.remove(stuckOverridable.get(overrideKey));
|
||||
stuckOverridable.remove(overrideKey);
|
||||
}
|
||||
|
||||
actions.add(action);
|
||||
}
|
||||
action.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IIngredient items) {
|
||||
GlobalRegistry.remove(items);
|
||||
}
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IUndoableAction> rollback() {
|
||||
// Note: Requires a OnRollback event to be fired. If this is called from MineTweakerImplementationAPI it's handled there.
|
||||
List<IUndoableAction> stuck = new ArrayList<>();
|
||||
for (int i = actions.size() - 1; i >= 0; i--) {
|
||||
IUndoableAction action = actions.get(i);
|
||||
if (action.canUndo()) {
|
||||
MineTweakerAPI.logInfo(action.describeUndo());
|
||||
action.undo();
|
||||
} else {
|
||||
MineTweakerAPI.logInfo("[Stuck] 1 " + action.describe());
|
||||
@Override
|
||||
public void remove(IIngredient items) {
|
||||
GlobalRegistry.remove(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IUndoableAction> rollback() {
|
||||
// Note: Requires a OnRollback event to be fired. If this is called from MineTweakerImplementationAPI it's
|
||||
// handled there.
|
||||
List<IUndoableAction> stuck = new ArrayList<>();
|
||||
for (int i = actions.size() - 1; i >= 0; i--) {
|
||||
IUndoableAction action = actions.get(i);
|
||||
if (action.canUndo()) {
|
||||
MineTweakerAPI.logInfo(action.describeUndo());
|
||||
action.undo();
|
||||
} else {
|
||||
MineTweakerAPI.logInfo("[Stuck] 1 " + action.describe());
|
||||
MineTweakerAPI.logInfo("[Stuck] 2 " + action.describeUndo());
|
||||
MineTweakerAPI.logInfo("[Stuck] 3 " + action.toString());
|
||||
|
||||
stuck.add(0, action);
|
||||
wereStuck.add(action);
|
||||
wereStuck.add(action);
|
||||
|
||||
Object overrideKey = action.getOverrideKey();
|
||||
if (overrideKey != null) {
|
||||
stuckOverridable.put(overrideKey, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
actions.clear();
|
||||
return stuck;
|
||||
}
|
||||
Object overrideKey = action.getOverrideKey();
|
||||
if (overrideKey != null) {
|
||||
stuckOverridable.put(overrideKey, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
actions.clear();
|
||||
return stuck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScriptProvider(IScriptProvider provider) {
|
||||
scriptProvider = provider;
|
||||
}
|
||||
@Override
|
||||
public void setScriptProvider(IScriptProvider provider) {
|
||||
scriptProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
ZenModule.loadedClasses.clear();
|
||||
System.out.println("Loading scripts");
|
||||
@Override
|
||||
public void load() {
|
||||
ZenModule.loadedClasses.clear();
|
||||
System.out.println("Loading scripts");
|
||||
|
||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||
Set<String> executed = new HashSet<>();
|
||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||
Set<String> executed = new HashSet<>();
|
||||
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
Map<String, byte[]> classes = new HashMap<>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
Map<String, byte[]> classes = new HashMap<>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
|
||||
List<ZenParsedFile> files = new ArrayList<>();
|
||||
List<ZenParsedFile> files = new ArrayList<>();
|
||||
|
||||
while (script.next()) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new InputStreamReader(new BufferedInputStream(script.open()), StandardCharsets.UTF_8);
|
||||
while (script.next()) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new InputStreamReader(new BufferedInputStream(script.open()), StandardCharsets.UTF_8);
|
||||
|
||||
String filename = script.getName();
|
||||
String className = extractClassName(filename);
|
||||
String filename = script.getName();
|
||||
String className = extractClassName(filename);
|
||||
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment(), filename, false);
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
} catch (ParseException ex) {
|
||||
// ex.printStackTrace();
|
||||
MineTweakerAPI.logError("Error parsing " + ex.getFile().getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logError("Error loading " + script.getName() + ": " + ex.toString(), ex);
|
||||
}
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment(), filename, false);
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
} catch (ParseException ex) {
|
||||
// ex.printStackTrace();
|
||||
MineTweakerAPI.logError(
|
||||
"Error parsing " + ex.getFile()
|
||||
.getFileName() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logError("Error loading " + script.getName() + ": " + ex.toString(), ex);
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String filename = script.getGroupName();
|
||||
System.out.println("MineTweaker: Loading " + filename);
|
||||
compileScripts(filename, files, environmentGlobal, DEBUG);
|
||||
try {
|
||||
String filename = script.getGroupName();
|
||||
System.out.println("MineTweaker: Loading " + filename);
|
||||
compileScripts(filename, files, environmentGlobal, DEBUG);
|
||||
|
||||
// execute scripts
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Throwable ex) {
|
||||
MineTweakerAPI.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
// execute scripts
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Throwable ex) {
|
||||
MineTweakerAPI.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wereStuck.size() > 0) {
|
||||
MineTweakerAPI.logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
|
||||
for (IUndoableAction action : wereStuck) {
|
||||
MineTweakerAPI.logInfo("Stuck: " + action.describe());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wereStuck.size() > 0) {
|
||||
MineTweakerAPI.logWarning(Integer.toString(wereStuck.size()) + " modifications were stuck");
|
||||
for (IUndoableAction action : wereStuck) {
|
||||
MineTweakerAPI.logInfo("Stuck: " + action.describe());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getScriptData() {
|
||||
return scriptData;
|
||||
}
|
||||
@Override
|
||||
public byte[] getScriptData() {
|
||||
return scriptData;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user