Fixed #6 once more
Added exit command alias
This commit is contained in:
Haarolean 2018-05-06 19:42:39 +03:00
parent 272e7cf8dc
commit 8f6319d979
2 changed files with 18 additions and 8 deletions

View File

@ -29,6 +29,7 @@ public class ConsoleShellFactory implements Factory<Command> {
} }
public static class ConsoleShell implements Command, Runnable { public static class ConsoleShell implements Command, Runnable {
private InputStream in; private InputStream in;
private OutputStream out; private OutputStream out;
private OutputStream err; private OutputStream err;
@ -101,14 +102,16 @@ public class ConsoleShellFactory implements Factory<Command> {
while (true) { while (true) {
String command = consoleReader.readLine("\r>", null); String command = consoleReader.readLine("\r>", null);
if (command == null) continue; if (command == null) continue;
if (command.equals("exit")) break; if (command.equals("exit") || command.equals("quit")) break;
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> { Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc")) { if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") &&
command.startsWith("rpc")) {
//NO ECHO NO PREAMBLE AND SHIT //NO ECHO NO PREAMBLE AND SHIT
String cmd = command.substring("rpc".length() + 1, command.length()); String cmd = command.substring("rpc".length() + 1, command.length());
Bukkit.dispatchCommand(sshdCommandSender, cmd); Bukkit.dispatchCommand(sshdCommandSender, cmd);
} else { } else {
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command); SshdPlugin.instance.getLogger()
.info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
} }
}); });

View File

@ -1,5 +1,7 @@
package com.ryanmichela.sshd; package com.ryanmichela.sshd;
import org.apache.sshd.common.SshException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -7,6 +9,7 @@ import java.io.OutputStream;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class FlushyOutputStream extends OutputStream { public class FlushyOutputStream extends OutputStream {
private OutputStream base; private OutputStream base;
private boolean isClosed = false; private boolean isClosed = false;
@ -16,23 +19,27 @@ public class FlushyOutputStream extends OutputStream {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
if(isClosed) return; if (isClosed) return;
base.write(b); base.write(b);
base.flush(); base.flush();
} }
@Override @Override
public void write(byte[] b) throws IOException { public void write(byte[] b) throws IOException {
if(isClosed) return; if (isClosed) return;
base.write(b); base.write(b);
base.flush(); base.flush();
} }
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
if(isClosed) return; if (isClosed) return;
base.write(b, off, len); try {
base.flush(); base.write(b, off, len);
base.flush();
} catch (SshException e) {
if (!e.getMessage().contains("channel already closed")) throw e;
}
} }
@Override @Override