diff --git a/.clangformat b/.clang-format similarity index 76% rename from .clangformat rename to .clang-format index dbbd5f6..92fa8ed 100644 --- a/.clangformat +++ b/.clang-format @@ -1,5 +1,5 @@ --- -#BasedOnStyle: WebKit +Language: 'Java' TabWidth: '4' IndentWidth: '4' UseTab: 'Always' @@ -7,6 +7,7 @@ AlignOperands: 'true' AlignAfterOpenBracket: 'Align' AlignConsecutiveAssignments: 'true' AlignConsecutiveDeclarations: 'true' +AlignConsecutiveMacros: 'true' AlignEscapedNewlines: 'Left' AlignTrailingComments: 'true' AllowAllParametersOfDeclarationOnNextLine: 'true' @@ -20,35 +21,20 @@ AlwaysBreakTemplateDeclarations: 'true' AlwaysBreakBeforeMultilineStrings: 'false' BinPackArguments: 'false' BinPackParameters: 'false' -BreakBeforeBraces: 'Custom' -BraceWrapping: - AfterEnum: 'true' - AfterClass: 'true' - AfterControlStatement: 'true' - AfterStruct: 'true' - AfterFunction: 'true' - AfterNamespace: 'true' - AfterUnion: 'true' - AfterExternBlock: 'true' - BeforeCatch: 'true' - BeforeElse: 'true' - SplitEmptyRecord: 'false' - SplitEmptyNamespace: 'false' - SplitEmptyFunction: 'false' +BreakBeforeBraces: 'Allman' BreakBeforeBinaryOperators: 'true' BreakBeforeTernaryOperators: 'false' -BreakConstructorInitializersBeforeComma: 'false' +BreakConstructorInitializers: 'AfterColon' BreakBeforeInheritanceComma: 'false' +BreakAfterJavaFieldAnnotations: 'true' BreakStringLiterals: 'true' ColumnLimit: '140' CompactNamespaces: 'false' -Cpp11BracedListStyle: 'true' ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' DerivePointerAlignment: 'false' IndentCaseLabels: 'true' IndentPPDirectives: 'AfterHash' KeepEmptyLinesAtTheStartOfBlocks: 'true' -Language: 'Java' NamespaceIndentation: 'All' PointerAlignment: 'Right' ReflowComments: 'true' diff --git a/pom.xml b/pom.xml index 76fc8e8..3f5db04 100644 --- a/pom.xml +++ b/pom.xml @@ -33,9 +33,10 @@ - org.bukkit - bukkit - 1.14.4-R0.1-SNAPSHOT + net.md-5 + bungeecord-api + 1.14-SNAPSHOT + provided diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java index 10c56e7..2d5b19c 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java @@ -5,7 +5,7 @@ import org.apache.sshd.server.command.CommandFactory; import org.apache.sshd.server.channel.ChannelSession; import org.apache.sshd.server.Environment; import org.apache.sshd.server.ExitCallback; -import org.bukkit.Bukkit; + import java.io.IOException; import java.io.InputStream; @@ -55,7 +55,9 @@ public class ConsoleCommandFactory implements CommandFactory { try { SshdPlugin.instance.getLogger() .info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + + SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(SshdPlugin.instance.getProxy().getConsoleSender().getInstance(), command); + //Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } catch (Exception e) { SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage()); } finally { diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java index d967e39..34fb93e 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleShellFactory.java @@ -148,14 +148,16 @@ public class ConsoleShellFactory implements ShellFactory { { // NO ECHO NO PREAMBLE AND SHIT String cmd = command.substring("rpc".length() + 1, command.length()); - Bukkit.dispatchCommand(this.SshdCommandSender, cmd); + SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(this.SshdCommandSender, cmd); + //Bukkit.dispatchCommand(this.SshdCommandSender, cmd); } else { if (!mkpasswd) SshdPlugin.instance.getLogger().info("<" + this.Username + "> " + command); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(SshdPlugin.instance.getProxy().getConsoleSender().getInstance(), command); + //Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } }); } @@ -190,8 +192,8 @@ public class ConsoleShellFactory implements ShellFactory { // Doesn't really guarantee our actual system hostname but // it's better than not having one at all. - cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (" + Bukkit.getServer().getName() + ")\r"); - cr.println(ConsoleLogFormatter.ColorizeString(Bukkit.getServer().getMotd()).replaceAll("\n", "\r\n")); + cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (BungeeCord)\r"); + cr.println(ConsoleLogFormatter.ColorizeString(DO SOMETHING HERE).replaceAll("\n", "\r\n")); cr.println("\r"); cr.println("Type 'exit' to exit the shell." + "\r"); cr.println("===============================================" + "\r"); diff --git a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java index d82da58..382e211 100644 --- a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java +++ b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java @@ -4,7 +4,8 @@ import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory; import org.apache.sshd.server.SshServer; import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; -import org.bukkit.plugin.java.JavaPlugin; +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; import com.ryanmichela.sshd.ConsoleShellFactory; import com.ryanmichela.sshd.MkpasswdCommand; @@ -20,8 +21,7 @@ import java.util.logging.Level; /** * Copyright 2013 Ryan Michela */ -public -class SshdPlugin extends JavaPlugin +public final class SshdPlugin extends Plugin { private SshServer sshd; diff --git a/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java b/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java index 30b7baf..654c6c8 100644 --- a/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java +++ b/src/main/java/com/ryanmichela/sshd/implementations/SSHDCommandSender.java @@ -1,6 +1,12 @@ package com.ryanmichela.sshd.implementations; import com.ryanmichela.sshd.SshdPlugin; +import net.md_5.bungee.command.ConsoleCommandSender; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.ProxyServer; + +/* import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Server; @@ -14,6 +20,7 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; +*/ import com.ryanmichela.sshd.ConsoleShellFactory; @@ -22,118 +29,77 @@ import java.util.Arrays; import java.util.Set; import java.util.logging.Level; -public class SSHDCommandSender implements ConsoleCommandSender, CommandSender { - - private final PermissibleBase perm = new PermissibleBase(this); - private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker(); - // Set by the upstream allocating function - public ConsoleShellFactory.ConsoleShell console; +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SSHDConsoleCommandSender implements CommandSender +{ + @Getter + private static final SSHDConsoleCommandSender instance = new SSHDConsoleCommandSender(); + @Override public void sendMessage(String message) { - this.sendRawMessage(message); + ProxyServer.getInstance().getLogger().info(message); } - public void sendRawMessage(String message) - { - // What the fuck does this code even do? Are we sending to one client or all of them? + public void sendRawMessage(String message) { + // What the fuck does this code even do? Are we sending to one client or all of + // them? if (this.console.ConsoleReader == null) return; - try - { + try { + ProxyServer.getInstance().getLogger().info(message); this.console.ConsoleReader.println(ChatColor.stripColor(message)); - } - catch (IOException e) - { + } catch (IOException e) { SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e); } } - public void sendMessage(String[] messages) { + @Override + public void sendMessages(String... messages) { Arrays.asList(messages).forEach(this::sendMessage); } - public String getName() { - return "SSHD Console"; + @Override + public void sendMessage(BaseComponent... message) { + sendMessage(BaseComponent.toLegacyText(message)); } - public boolean isOp() { + @Override + public void sendMessage(BaseComponent message) { + sendMessage(message.toLegacyText()); + } + + @Override + public String getName() { + return "CONSOLE"; + } + + @Override + public Collection getGroups() { + return Collections.emptySet(); + } + + @Override + public void addGroups(String... groups) { + throw new UnsupportedOperationException("Console may not have groups"); + } + + @Override + public void removeGroups(String... groups) { + throw new UnsupportedOperationException("Console may not have groups"); + } + + @Override + public boolean hasPermission(String permission) { return true; } - public void setOp(boolean value) { - throw new UnsupportedOperationException("Cannot change operator status of server console"); + @Override + public void setPermission(String permission, boolean value) { + throw new UnsupportedOperationException("Console has all permissions"); } - public boolean beginConversation(Conversation conversation) { - return this.conversationTracker.beginConversation(conversation); + @Override + public Collection getPermissions() { + return Collections.emptySet(); } - - public void abandonConversation(Conversation conversation) { - this.conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller())); - } - - public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) { - this.conversationTracker.abandonConversation(conversation, details); - } - - public void acceptConversationInput(String input) { - this.conversationTracker.acceptConversationInput(input); - } - - public boolean isConversing() { - return this.conversationTracker.isConversing(); - } - - public boolean isPermissionSet(String name) { - return this.perm.isPermissionSet(name); - } - - public boolean isPermissionSet(Permission perm) { - return this.perm.isPermissionSet(perm); - } - - public boolean hasPermission(String name) { - return this.perm.hasPermission(name); - } - - public boolean hasPermission(Permission perm) { - return this.perm.hasPermission(perm); - } - - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { - return this.perm.addAttachment(plugin, name, value); - } - - public PermissionAttachment addAttachment(Plugin plugin) { - return this.perm.addAttachment(plugin); - } - - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { - return this.perm.addAttachment(plugin, name, value, ticks); - } - - public PermissionAttachment addAttachment(Plugin plugin, int ticks) { - return this.perm.addAttachment(plugin, ticks); - } - - public void removeAttachment(PermissionAttachment attachment) { - this.perm.removeAttachment(attachment); - } - - public void recalculatePermissions() { - this.perm.recalculatePermissions(); - } - - public Set getEffectivePermissions() { - return this.perm.getEffectivePermissions(); - } - - public boolean isPlayer() { - return false; - } - - public Server getServer() { - return Bukkit.getServer(); - } - -} +} \ No newline at end of file