Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. Util class:
  2. --------------------------------UTIL CLASS START-------------------------------------
  3.  public static void runShellCommandAsync(CommandSender sender, String command)
  4.     {
  5.         new BukkitRunnable()
  6.         {
  7.             @Override
  8.             public void run()
  9.             {
  10.                 try {
  11.               runShellCommand(sender, command);
  12.                 }
  13.                 catch(IOException ex) {
  14.                     LF_Log.severe(ex);
  15.                     sender.sendMessage("Invalid command");
  16.                 }
  17.                 catch(InterruptedException ex) {
  18.                     sender.sendMessage("Error, see logs for more details");
  19.                     LF_Log.severe(ex);
  20.                 }
  21.             }
  22.         }.runTaskAsynchronously(LFUtils.plugin);
  23.      
  24.     }
  25.  
  26.     public static void runShellCommand(CommandSender sender, String command) throws InterruptedException, IOException
  27.     {
  28.         Process proc = Runtime.getRuntime().exec(command);
  29.  
  30.         // Read the output
  31.         BufferedReader reader
  32.                 = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  33.  
  34.         String line = "";
  35.         while ((line = reader.readLine()) != null)
  36.         {
  37.             sender.sendMessage(line);
  38.         }
  39.  
  40.         proc.waitFor();
  41.     }
  42.  
  43. -------------- UTIL CLASS OVER ----------------------------
  44.  
  45. Command:
  46. ----------------------- COMMAND START -------------------------
  47.  
  48.         if(args.length == 0) {
  49.             return false;
  50.         }
  51.         runShellCommandAsync(sender, StringUtils.join(args, " "));
  52.         return true;
  53.    
  54. ----------------------COMMAND END-----------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement