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

View File

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

View File

@ -1,5 +1,7 @@
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.server.Command;
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.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;
public class ConsoleShellFactory implements Factory<Command> {
@ -28,7 +29,7 @@ public class ConsoleShellFactory implements Factory<Command> {
private Environment environment;
private Thread thread;
StreamHandler streamHandler;
StreamHandlerAppender streamHandlerAppender;
ConsoleReader consoleReader;
public InputStream getIn() {
@ -70,9 +71,10 @@ public class ConsoleShellFactory implements Factory<Command> {
consoleReader.setExpandEvents(true);
consoleReader.addCompleter(new ConsoleCommandCompleter());
streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
Bukkit.getLogger().addHandler(streamHandler);
Logger.getLogger("").addHandler(streamHandler);
StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
streamHandlerAppender = new StreamHandlerAppender(streamHandler);
((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender);
environment = env;
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() {
Bukkit.getLogger().removeHandler(streamHandler);
Logger.getLogger("").removeHandler(streamHandler);
((Logger) LogManager.getRootLogger()).removeAppender(streamHandlerAppender);
}
public void run() {
@ -97,7 +98,7 @@ public class ConsoleShellFactory implements Factory<Command> {
if (command.equals("exit")) {
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);
}
}

View File

@ -55,7 +55,7 @@ public class SshdPlugin extends JavaPlugin {
public void onDisable() {
try {
sshd.stop();
} catch (InterruptedException e) {
} catch (Exception e) {
// 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
version: "1.0"
version: "1.1"
author: Ryan Michela
main: com.ryanmichela.sshd.SshdPlugin