Skip to content

Commit

Permalink
0.07
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Feb 23, 2015
1 parent 6b9a85d commit 5e4974b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class RaspberryJamMod
{
public static final String MODID = "raspberryjammod";
public static final String VERSION = "0.05";
public static final String VERSION = "0.07";
public static final String NAME = "Raspberry Jam Mod";
private MinecraftCommunicator mcc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package mobi.omegacentauri.raspberryjammod;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.ProcessBuilder.Redirect;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -12,6 +16,8 @@
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;

public abstract class ScriptExternalCommand implements ICommand {
abstract protected String getScriptProcessorCommand();
Expand Down Expand Up @@ -148,18 +154,48 @@ public void execute(ICommandSender sender, String[] args)
cmd.add(args[i]);

ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
// pb.redirectErrorStream(true);
pb.directory(script.getParentFile());
pb.inheritIO();
// pb.inheritIO();
pb.command(cmd);
try {
System.out.println("Running "+script);
runningScript = pb.start();
gobble(runningScript.getInputStream(), "");
gobble(runningScript.getErrorStream(), "[ERR] ");
} catch (IOException e) {
throw new CommandException("Error "+e);
}
}

private void gobble(final InputStream stream, final String label) {
Thread t = new Thread() {

@Override
public void run() {
BufferedReader br;

br = new BufferedReader(new InputStreamReader(stream));

String line;
try {
while ( null != ( line = br.readLine()) ) {
line.trim();
Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentText(label + line));
}
} catch (IOException e) {
}

try {
br.close();
} catch (IOException e) {
}
}
};
t.setDaemon(true);
t.start();
}

protected File getScript(String base) {
String[] paths = getScriptPaths();

Expand Down

0 comments on commit 5e4974b

Please sign in to comment.