Fix codestyle

This commit is contained in:
Haarolean 2018-05-06 19:42:57 +03:00
parent 8f6319d979
commit 7330b1eead
11 changed files with 49 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import java.util.Map;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class ConfigPasswordAuthenticator implements PasswordAuthenticator { public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
private Map<String, Integer> failCounts = new HashMap<String, Integer>(); private Map<String, Integer> failCounts = new HashMap<String, Integer>();
@Override @Override

View File

@ -4,15 +4,16 @@ package com.ryanmichela.sshd;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
import jline.console.completer.Completer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap; import org.bukkit.command.CommandMap;
import jline.console.completer.Completer;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
public class ConsoleCommandCompleter implements Completer { public class ConsoleCommandCompleter implements Completer {
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
Waitable<List<String>> waitable = new Waitable<List<String>>() { Waitable<List<String>> waitable = new Waitable<List<String>>() {
@Override @Override

View File

@ -14,12 +14,14 @@ import java.io.OutputStream;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class ConsoleCommandFactory implements CommandFactory { public class ConsoleCommandFactory implements CommandFactory {
@Override @Override
public Command createCommand(String command) { public Command createCommand(String command) {
return new ConsoleCommand(command); return new ConsoleCommand(command);
} }
public class ConsoleCommand implements Command { public class ConsoleCommand implements Command {
private String command; private String command;
private InputStream in; private InputStream in;
@ -50,7 +52,8 @@ public class ConsoleCommandFactory implements CommandFactory {
@Override @Override
public void start(Environment environment) throws IOException { public void start(Environment environment) throws IOException {
try { try {
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 -" + e.getMessage()); SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());

View File

@ -54,20 +54,29 @@ public class ConsoleLogFormatter extends Formatter {
// ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender // ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender
final Map<ChatColor, String> replacements = new EnumMap<>(ChatColor.class); final Map<ChatColor, String> replacements = new EnumMap<>(ChatColor.class);
replacements.put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()); replacements
replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()); .put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()); replacements
replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()); .put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()); replacements.put(ChatColor.DARK_GREEN,
replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()); Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
replacements.put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()); replacements
.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
replacements
.put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
replacements.put(ChatColor.DARK_PURPLE,
Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
replacements
.put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString()); replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()); replacements
.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString()); replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString()); replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString()); replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString()); replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()); replacements.put(ChatColor.LIGHT_PURPLE,
Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString()); replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString()); replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString()); replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());

View File

@ -1,8 +1,7 @@
package com.ryanmichela.sshd; package com.ryanmichela.sshd;
import org.apache.sshd.common.SshException;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import org.apache.sshd.common.SshException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -12,6 +11,7 @@ import java.util.logging.*;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class FlushyStreamHandler extends StreamHandler { public class FlushyStreamHandler extends StreamHandler {
private ConsoleReader reader; private ConsoleReader reader;
public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader) { public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader) {

View File

@ -13,6 +13,7 @@ import java.security.spec.RSAPublicKeySpec;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class PemDecoder extends java.io.BufferedReader { public class PemDecoder extends java.io.BufferedReader {
private static final String BEGIN = "^-+\\s*BEGIN.+"; private static final String BEGIN = "^-+\\s*BEGIN.+";
private static final String END = "^-+\\s*END.+"; private static final String END = "^-+\\s*END.+";
private static final String COMMENT = "Comment:"; private static final String COMMENT = "Comment:";
@ -29,7 +30,7 @@ public class PemDecoder extends java.io.BufferedReader {
return null; return null;
} }
for(line = readLine(); line != null; line = readLine()) { for (line = readLine(); line != null; line = readLine()) {
if (!line.matches(END) && !line.startsWith(COMMENT)) { if (!line.matches(END) && !line.startsWith(COMMENT)) {
b64.append(line.trim()); b64.append(line.trim());
} }
@ -84,7 +85,7 @@ public class PemDecoder extends java.io.BufferedReader {
private int decodeInt() { private int decodeInt() {
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16) return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF); | ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
} }
private BigInteger decodeBigInt() { private BigInteger decodeBigInt() {

View File

@ -12,6 +12,7 @@ import java.security.PublicKey;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class PublicKeyAuthenticator implements PublickeyAuthenticator { public class PublicKeyAuthenticator implements PublickeyAuthenticator {
private File authorizedKeysDir; private File authorizedKeysDir;
public PublicKeyAuthenticator(File authorizedKeysDir) { public PublicKeyAuthenticator(File authorizedKeysDir) {
@ -39,10 +40,13 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator {
SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath()); SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
} }
} catch (Exception e) { } catch (Exception e) {
SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage()); SshdPlugin.instance.getLogger()
.severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage());
} }
} else { } else {
SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username + ". Make sure the user's key is named the same as their user name without a file extension."); SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username +
". Make sure the user's key is named the same as their user name " +
"without a file extension.");
} }
return false; return false;

View File

@ -8,6 +8,7 @@ import java.lang.reflect.Modifier;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class ReflectionUtil { public class ReflectionUtil {
public static void setProtectedValue(Object o, String field, Object newValue) { public static void setProtectedValue(Object o, String field, Object newValue) {
setProtectedValue(o.getClass(), o, field, newValue); setProtectedValue(o.getClass(), o, field, newValue);
} }
@ -36,9 +37,9 @@ public class ReflectionUtil {
public static <T> T getProtectedValue(Object obj, String fieldName) { public static <T> T getProtectedValue(Object obj, String fieldName) {
try { try {
Class c = obj.getClass(); Class c = obj.getClass();
while(c != Object.class) { while (c != Object.class) {
Field[] fields = c.getDeclaredFields(); Field[] fields = c.getDeclaredFields();
for(Field f : fields) { for (Field f : fields) {
if (f.getName() == fieldName) { if (f.getName() == fieldName) {
f.setAccessible(true); f.setAccessible(true);
return (T) f.get(obj); return (T) f.get(obj);
@ -76,7 +77,7 @@ public class ReflectionUtil {
public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) { public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) {
try { try {
Class[] pTypes = new Class[args.length]; Class[] pTypes = new Class[args.length];
for(int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Integer) { if (args[i] instanceof Integer) {
pTypes[i] = int.class; pTypes[i] = int.class;
} else { } else {
@ -87,8 +88,7 @@ public class ReflectionUtil {
Method m = c.getDeclaredMethod(method, pTypes); Method m = c.getDeclaredMethod(method, pTypes);
m.setAccessible(true); m.setAccessible(true);
return m.invoke(o, args); return m.invoke(o, args);
} } catch (Exception ex) {
catch (Exception ex) {
System.out.println("*** " + c.getName() + "." + method + "(): " + ex); System.out.println("*** " + c.getName() + "." + method + "(): " + ex);
return null; return null;
} }

View File

@ -16,6 +16,7 @@ import java.util.logging.Level;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public class SshdPlugin extends JavaPlugin { public class SshdPlugin extends JavaPlugin {
private SshServer sshd; private SshServer sshd;
public static SshdPlugin instance; public static SshdPlugin instance;

View File

@ -14,6 +14,7 @@ import java.util.logging.StreamHandler;
* Copyright 2014 Ryan Michela * Copyright 2014 Ryan Michela
*/ */
public class StreamHandlerAppender implements Appender { public class StreamHandlerAppender implements Appender {
private StreamHandler streamHandler; private StreamHandler streamHandler;
private UUID uuid; private UUID uuid;
@ -26,13 +27,13 @@ public class StreamHandlerAppender implements Appender {
public void append(LogEvent logEvent) { public void append(LogEvent logEvent) {
java.util.logging.Level level; java.util.logging.Level level;
if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG)) { if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG)) {
level = java.util.logging.Level.FINE; level = java.util.logging.Level.FINE;
} else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO)) { } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO)) {
level = java.util.logging.Level.INFO; level = java.util.logging.Level.INFO;
} else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN)) { } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN)) {
level = java.util.logging.Level.WARNING; level = java.util.logging.Level.WARNING;
} else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR)) { } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR)) {
level = java.util.logging.Level.SEVERE; level = java.util.logging.Level.SEVERE;
} else { } else {
level = java.util.logging.Level.INFO; level = java.util.logging.Level.INFO;

View File

@ -6,11 +6,13 @@ import java.util.concurrent.ExecutionException;
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public abstract class Waitable<T> implements Runnable { public abstract class Waitable<T> implements Runnable {
private enum Status { private enum Status {
WAITING, WAITING,
RUNNING, RUNNING,
FINISHED, FINISHED,
} }
Throwable t = null; Throwable t = null;
T value = null; T value = null;
Status status = Status.WAITING; Status status = Status.WAITING;