Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting script files if .sorting flag file is in script directory. #274

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void execute(String[] arguments, IPlayer player)
IItemStack out = shapeless.getOutput();
MineTweakerAPI.logError("Could not dump recipe for " + out, ex);
} else {
MineTweakerAPI.logError("Could not dump recipe", ex)
MineTweakerAPI.logError("Could not dump recipe", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package minetweaker.expand;

import minetweaker.api.data.*;
import stanhebben.zenscript.annotations.*;

import java.util.Arrays;
import minetweaker.api.data.DataList;
import minetweaker.api.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;

/**
* Makes arrays convertable to IData.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package minetweaker.expand;

import minetweaker.api.data.*;
import stanhebben.zenscript.annotations.*;

/**
* Makes byte arrays convertable to IData.
*
* @author Jared
*/
@ZenExpansion("byte[]")
public class ExpandByteArray {

@ZenCaster
public static IData asData(byte[] values) {
return new DataByteArray(values, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

package minetweaker.expand;

import minetweaker.api.data.*;
import stanhebben.zenscript.annotations.*;

/**
* Makes int arrays convertable to IData.
*
* @author Jared
*/
@ZenExpansion("int[]")
public class ExpandIntArray {

@ZenCaster
public static IData asData(int[] values) {
return new DataIntArray(values, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import minetweaker.MineTweakerAPI;
Expand All @@ -20,6 +21,7 @@
* @author Stan
*/
public class ScriptProviderDirectory implements IScriptProvider {
public final static String SORTING_FLAG = ".sorting";
private final File directory;

public ScriptProviderDirectory(File directory) {
Expand All @@ -29,11 +31,40 @@ public ScriptProviderDirectory(File directory) {
this.directory = directory;
}

protected File[] getFiles()
{
if( directory.exists() )
{
//Build path to flag file
StringBuilder sortFlag = new StringBuilder();
sortFlag.append(directory.getAbsolutePath());
sortFlag.append("/");
sortFlag.append(SORTING_FLAG);

File file = new File( sortFlag.toString() );
File files[] = directory.listFiles();

//Sorting flag file exists
if( file.exists() )
{
Arrays.sort(files);
}
return files;
}
else
{
return null;
}
}

@Override
public Iterator<IScriptIterator> getScripts() {
List<IScriptIterator> scripts = new ArrayList<IScriptIterator>();
if (directory.exists()) {
for (File file : directory.listFiles()) {
File files[] = this.getFiles();

if( files != null )
{
for (File file : files) {
if (file.isDirectory()) {
scripts.add(new ScriptIteratorDirectory(file));
} else if (file.getName().endsWith(".zs")) {
Expand All @@ -46,7 +77,7 @@ public Iterator<IScriptIterator> getScripts() {
}
}
}
}
}
return scripts.iterator();
}
}