From 5e4974b75a62b85f2116d3957562cdb363243caf Mon Sep 17 00:00:00 2001 From: arpruss Date: Sun, 22 Feb 2015 22:03:03 -0600 Subject: [PATCH] 0.07 --- .../raspberryjammod/RaspberryJamMod.java | 2 +- .../ScriptExternalCommand.java | 40 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java b/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java index 3e6ea1b..9feab8e 100644 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java @@ -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; diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java b/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java index 1eeea40..c5b9208 100755 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java @@ -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; @@ -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(); @@ -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();