Fix plugin for 1.7.x

This commit is contained in:
Ryan Michela 2014-07-03 00:18:34 -07:00
parent 2326c7e2cb
commit f9a3ddec43
6 changed files with 99 additions and 14 deletions

View File

@ -30,7 +30,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.1-SNAPSHOT</version> <version>1.7.9-R0.2</version>
<scope>provided</scope> <scope>provided</scope>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
@ -70,6 +70,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<minimizeJar>true</minimizeJar>
</configuration> </configuration>
</plugin> </plugin>
<!-- Compile plugin --> <!-- Compile plugin -->
@ -78,8 +79,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>3.0</version>
<configuration> <configuration>
<source>1.7</source> <source>1.6</source>
<target>1.7</target> <target>1.6</target>
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -53,7 +53,7 @@ public class ConsoleCommandFactory implements CommandFactory {
SshdPlugin.instance.getLogger().info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); SshdPlugin.instance.getLogger().info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (Exception e) { } catch (Exception e) {
SshdPlugin.instance.getLogger().severe("Error processing command from SSH"); SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
} finally { } finally {
callback.onExit(0); callback.onExit(0);
} }

View File

@ -1,5 +1,7 @@
package com.ryanmichela.sshd; package com.ryanmichela.sshd;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.apache.sshd.common.Factory; import org.apache.sshd.common.Factory;
import org.apache.sshd.server.Command; import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment; import org.apache.sshd.server.Environment;
@ -10,7 +12,6 @@ import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.logging.Logger;
import java.util.logging.StreamHandler; import java.util.logging.StreamHandler;
public class ConsoleShellFactory implements Factory<Command> { public class ConsoleShellFactory implements Factory<Command> {
@ -28,7 +29,7 @@ public class ConsoleShellFactory implements Factory<Command> {
private Environment environment; private Environment environment;
private Thread thread; private Thread thread;
StreamHandler streamHandler; StreamHandlerAppender streamHandlerAppender;
ConsoleReader consoleReader; ConsoleReader consoleReader;
public InputStream getIn() { public InputStream getIn() {
@ -70,9 +71,10 @@ public class ConsoleShellFactory implements Factory<Command> {
consoleReader.setExpandEvents(true); consoleReader.setExpandEvents(true);
consoleReader.addCompleter(new ConsoleCommandCompleter()); consoleReader.addCompleter(new ConsoleCommandCompleter());
streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader); StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
Bukkit.getLogger().addHandler(streamHandler); streamHandlerAppender = new StreamHandlerAppender(streamHandler);
Logger.getLogger("").addHandler(streamHandler);
((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender);
environment = env; environment = env;
thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER)); thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER));
@ -83,8 +85,7 @@ public class ConsoleShellFactory implements Factory<Command> {
} }
public void destroy() { public void destroy() {
Bukkit.getLogger().removeHandler(streamHandler); ((Logger) LogManager.getRootLogger()).removeAppender(streamHandlerAppender);
Logger.getLogger("").removeHandler(streamHandler);
} }
public void run() { public void run() {
@ -97,7 +98,7 @@ public class ConsoleShellFactory implements Factory<Command> {
if (command.equals("exit")) { if (command.equals("exit")) {
break; break;
} }
SshdPlugin.instance.getLogger().info("[U: " + 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

@ -55,7 +55,7 @@ public class SshdPlugin extends JavaPlugin {
public void onDisable() { public void onDisable() {
try { try {
sshd.stop(); sshd.stop();
} catch (InterruptedException e) { } catch (Exception e) {
// do nothing // do nothing
} }
} }

View File

@ -0,0 +1,83 @@
package com.ryanmichela.sshd;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.ErrorHandler;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import java.io.Serializable;
import java.util.UUID;
import java.util.logging.LogRecord;
import java.util.logging.StreamHandler;
/**
* Copyright 2014 Ryan Michela
*/
public class StreamHandlerAppender implements Appender {
private StreamHandler streamHandler;
private UUID uuid;
public StreamHandlerAppender(StreamHandler streamHandler) {
this.streamHandler = streamHandler;
uuid = UUID.randomUUID();
}
@Override
public void append(LogEvent logEvent) {
java.util.logging.Level level;
switch (logEvent.getLevel())
{
case DEBUG: level = java.util.logging.Level.FINE; break;
case INFO: level = java.util.logging.Level.INFO; break;
case WARN: level = java.util.logging.Level.WARNING; break;
case ERROR: level = java.util.logging.Level.SEVERE; break;
default: level = java.util.logging.Level.INFO; break;
}
String message = logEvent.getMessage().getFormattedMessage();
LogRecord logRecord = new LogRecord(level, message);
streamHandler.publish(logRecord);
}
@Override
public String getName() {
return "StreamHandlerAppender:" + uuid.toString();
}
@Override
public Layout<? extends Serializable> getLayout() {
return null;
}
@Override
public boolean ignoreExceptions() {
return false;
}
@Override
public ErrorHandler getHandler() {
return null;
}
@Override
public void setHandler(ErrorHandler errorHandler) {
}
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public boolean isStarted() {
return true;
}
}

View File

@ -1,4 +1,4 @@
name: SSHD name: SSHD
version: "1.0" version: "1.1"
author: Ryan Michela author: Ryan Michela
main: com.ryanmichela.sshd.SshdPlugin main: com.ryanmichela.sshd.SshdPlugin