├── .github └── FUNDING.yml ├── README.md ├── synccommands-bungeecord ├── src │ └── main │ │ ├── resources │ │ └── bungee.yml │ │ └── java │ │ └── io │ │ └── github │ │ └── efekurbann │ │ └── synccommands │ │ ├── executor │ │ └── impl │ │ │ └── BungeeExecutor.java │ │ ├── logging │ │ └── impl │ │ │ └── BungeeLogger.java │ │ ├── util │ │ └── ChatUtils.java │ │ ├── scheduler │ │ └── impl │ │ │ └── BungeeScheduler.java │ │ ├── listener │ │ └── CommandListener.java │ │ ├── config │ │ └── Config.java │ │ ├── command │ │ └── BSyncCommand.java │ │ └── SyncCommandsBungee.java └── pom.xml ├── synccommands-common ├── src │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── efekurbann │ │ │ └── synccommands │ │ │ ├── enums │ │ │ └── ConnectionType.java │ │ │ ├── executor │ │ │ └── ConsoleExecutor.java │ │ │ ├── logging │ │ │ └── Logger.java │ │ │ ├── scheduler │ │ │ └── Scheduler.java │ │ │ ├── objects │ │ │ ├── server │ │ │ │ ├── MQServer.java │ │ │ │ └── Server.java │ │ │ └── Command.java │ │ │ ├── messaging │ │ │ ├── codec │ │ │ │ └── GsonCodec.java │ │ │ ├── impl │ │ │ │ ├── socket │ │ │ │ │ ├── SocketImpl.java │ │ │ │ │ ├── SocketClient.java │ │ │ │ │ └── SocketServer.java │ │ │ │ ├── redis │ │ │ │ │ └── Redis.java │ │ │ │ └── rabbitmq │ │ │ │ │ └── RabbitMQ.java │ │ │ └── Messaging.java │ │ │ └── util │ │ │ └── UpdateChecker.java │ │ └── resources │ │ └── config.yml └── pom.xml ├── synccommands-spigot ├── src │ └── main │ │ ├── resources │ │ └── plugin.yml │ │ └── java │ │ └── io │ │ └── github │ │ └── efekurbann │ │ └── synccommands │ │ ├── logging │ │ └── BukkitLogger.java │ │ ├── executor │ │ └── impl │ │ │ └── BukkitExecutor.java │ │ ├── util │ │ └── ChatUtils.java │ │ ├── scheduler │ │ └── impl │ │ │ └── BukkitScheduler.java │ │ ├── config │ │ └── Config.java │ │ ├── listener │ │ └── CommandListener.java │ │ ├── command │ │ └── SyncCommand.java │ │ └── SyncCommandsSpigot.java └── pom.xml ├── synccommands-velocity ├── src │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── efekurbann │ │ └── synccommands │ │ ├── logging │ │ └── impl │ │ │ └── VelocityLogger.java │ │ ├── executor │ │ └── impl │ │ │ └── VelocityExecutor.java │ │ ├── scheduler │ │ └── impl │ │ │ └── VelocityScheduler.java │ │ ├── config │ │ └── Config.java │ │ ├── command │ │ └── VSyncCommand.java │ │ └── SyncCommandsVelocity.java └── pom.xml ├── LICENSE ├── .gitignore └── pom.xml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [efekurbann] 4 | custom: ['https://www.buymeacoffee.com/efekurban'] 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Send commands between server instances. Supports 1.8 - 1.19. 2 | 3 | Redis & Socket & RabbitMQ Support 4 | 5 | Spigot: https://www.spigotmc.org/resources/99596/ 6 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/resources/bungee.yml: -------------------------------------------------------------------------------- 1 | name: SyncCommands 2 | version: ${project.version} 3 | main: io.github.efekurbann.synccommands.SyncCommandsBungee 4 | description: ${project.description} 5 | author: hyperion -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/enums/ConnectionType.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.enums; 2 | 3 | public enum ConnectionType { 4 | 5 | REDIS, SOCKET, RABBITMQ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/executor/ConsoleExecutor.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.executor; 2 | 3 | public interface ConsoleExecutor { 4 | 5 | void execute(String command); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/logging/Logger.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.logging; 2 | 3 | public interface Logger { 4 | 5 | void info(String message); 6 | 7 | void severe(String message); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/scheduler/Scheduler.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.scheduler; 2 | 3 | public interface Scheduler { 4 | 5 | void runAsync(Runnable runnable); 6 | 7 | void runSync(Runnable runnable); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: SyncCommands 2 | version: ${project.version} 3 | main: io.github.efekurbann.synccommands.SyncCommandsSpigot 4 | api-version: 1.13 5 | authors: [ hyperion ] 6 | description: ${project.description} 7 | commands: 8 | sync: 9 | aliases: 10 | - ssync -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/executor/impl/BungeeExecutor.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.executor.impl; 2 | 3 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 4 | import net.md_5.bungee.api.ProxyServer; 5 | 6 | public class BungeeExecutor implements ConsoleExecutor { 7 | @Override 8 | public void execute(String command) { 9 | ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/logging/impl/VelocityLogger.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.logging.impl; 2 | 3 | import io.github.efekurbann.synccommands.logging.Logger; 4 | 5 | public class VelocityLogger implements Logger { 6 | 7 | private final org.slf4j.Logger logger; 8 | 9 | public VelocityLogger(org.slf4j.Logger logger) { 10 | this.logger = logger; 11 | } 12 | 13 | @Override 14 | public void info(String message) { 15 | logger.info(message); 16 | } 17 | 18 | @Override 19 | public void severe(String message) { 20 | logger.error(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/logging/BukkitLogger.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.logging; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsSpigot; 4 | 5 | public class BukkitLogger implements Logger { 6 | 7 | private final SyncCommandsSpigot plugin; 8 | 9 | public BukkitLogger(SyncCommandsSpigot plugin) { 10 | this.plugin = plugin; 11 | } 12 | 13 | @Override 14 | public void info(String message) { 15 | plugin.getLogger().info(message); 16 | } 17 | 18 | @Override 19 | public void severe(String message) { 20 | plugin.getLogger().severe(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/objects/server/MQServer.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.objects.server; 2 | 3 | public class MQServer extends Server { 4 | 5 | private final String username; 6 | private final String vhost; 7 | 8 | public MQServer(String serverName, String host, int port, String password, boolean secure, String username, String vhost) { 9 | super(serverName, host, port, password, secure); 10 | this.username = username; 11 | this.vhost = vhost; 12 | } 13 | 14 | public String getVirtualHost() { 15 | return vhost; 16 | } 17 | 18 | public String getUsername() { 19 | return username; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/executor/impl/BukkitExecutor.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.executor.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsSpigot; 4 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 5 | import org.bukkit.Bukkit; 6 | 7 | public class BukkitExecutor implements ConsoleExecutor { 8 | 9 | private final SyncCommandsSpigot plugin; 10 | 11 | public BukkitExecutor(SyncCommandsSpigot plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void execute(String command) { 17 | plugin.getScheduler().runSync(() -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/executor/impl/VelocityExecutor.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.executor.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsVelocity; 4 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 5 | 6 | public class VelocityExecutor implements ConsoleExecutor { 7 | 8 | private final SyncCommandsVelocity plugin; 9 | 10 | public VelocityExecutor(SyncCommandsVelocity plugin) { 11 | this.plugin = plugin; 12 | } 13 | 14 | @Override 15 | public void execute(String command) { 16 | plugin.getProxyServer().getCommandManager().executeAsync(plugin.getProxyServer().getConsoleCommandSource(), command); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/logging/impl/BungeeLogger.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.logging.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsBungee; 4 | import io.github.efekurbann.synccommands.logging.Logger; 5 | 6 | public class BungeeLogger implements Logger { 7 | 8 | private final SyncCommandsBungee plugin; 9 | 10 | public BungeeLogger(SyncCommandsBungee plugin) { 11 | this.plugin = plugin; 12 | } 13 | 14 | @Override 15 | public void info(String message) { 16 | plugin.getLogger().info(message); 17 | } 18 | 19 | @Override 20 | public void severe(String message) { 21 | plugin.getLogger().severe(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/util/ChatUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.util; 2 | 3 | import net.md_5.bungee.api.ChatColor; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class ChatUtils { 9 | 10 | private final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); 11 | 12 | public static String color(String message) { 13 | Matcher matcher = HEX_PATTERN.matcher(message); 14 | StringBuffer buffer = new StringBuffer(); 15 | while (matcher.find()) { 16 | matcher.appendReplacement(buffer, ChatColor.of(matcher.group()).toString()); 17 | } 18 | return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/util/ChatUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.util; 2 | 3 | import net.md_5.bungee.api.ChatColor; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class ChatUtils { 9 | 10 | private final static Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}"); 11 | 12 | public static String color(String message) { 13 | Matcher matcher = HEX_PATTERN.matcher(message); 14 | StringBuffer buffer = new StringBuffer(); 15 | while (matcher.find()) { 16 | matcher.appendReplacement(buffer, ChatColor.of(matcher.group()).toString()); 17 | } 18 | return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/scheduler/impl/BukkitScheduler.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.scheduler.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsSpigot; 4 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 5 | import org.bukkit.Bukkit; 6 | 7 | public class BukkitScheduler implements Scheduler { 8 | 9 | private final SyncCommandsSpigot plugin; 10 | 11 | public BukkitScheduler(SyncCommandsSpigot plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void runAsync(Runnable runnable) { 17 | Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable); 18 | } 19 | 20 | @Override 21 | public void runSync(Runnable runnable) { 22 | Bukkit.getScheduler().runTask(plugin, runnable); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/objects/Command.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.objects; 2 | 3 | import io.github.efekurbann.synccommands.objects.server.Server; 4 | 5 | public class Command { 6 | 7 | private final String command; 8 | private final Server[] targetServers; 9 | private final Server publisher; 10 | 11 | public Command(String command, Server publisher, Server... targetServers) { 12 | this.command = command; 13 | this.publisher = publisher; 14 | 15 | this.targetServers = targetServers; 16 | } 17 | 18 | public String getCommand() { 19 | return command; 20 | } 21 | 22 | public Server[] getTargetServers() { 23 | return targetServers; 24 | } 25 | 26 | public Server getPublisher() { 27 | return publisher; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/scheduler/impl/VelocityScheduler.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.scheduler.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsVelocity; 4 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 5 | 6 | public class VelocityScheduler implements Scheduler { 7 | 8 | private final SyncCommandsVelocity plugin; 9 | 10 | public VelocityScheduler(SyncCommandsVelocity plugin) { 11 | this.plugin = plugin; 12 | } 13 | 14 | @Override 15 | public void runAsync(Runnable runnable) { 16 | plugin.getProxyServer().getScheduler().buildTask(plugin, runnable).schedule(); 17 | } 18 | 19 | @Override 20 | public void runSync(Runnable runnable) { 21 | plugin.getProxyServer().getScheduler().buildTask(plugin, runnable).schedule(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/scheduler/impl/BungeeScheduler.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.scheduler.impl; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsBungee; 4 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 5 | import net.md_5.bungee.api.ProxyServer; 6 | 7 | public class BungeeScheduler implements Scheduler { 8 | 9 | private final SyncCommandsBungee plugin; 10 | 11 | public BungeeScheduler(SyncCommandsBungee plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void runAsync(Runnable runnable) { 17 | ProxyServer.getInstance().getScheduler().runAsync(plugin, runnable); 18 | } 19 | 20 | @Override 21 | public void runSync(Runnable runnable) { 22 | // since there is no "main thread" stuff in bungee, we are going to run it async 23 | ProxyServer.getInstance().getScheduler().runAsync(plugin, runnable); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/objects/server/Server.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.objects.server; 2 | 3 | public class Server { 4 | 5 | private final String serverName; 6 | private final String host; 7 | private final int port; 8 | private final String password; 9 | private final boolean secure; 10 | 11 | public Server(String serverName, String host, int port, String password, boolean secure) { 12 | this.serverName = serverName; 13 | this.host = host; 14 | this.port = port; 15 | this.password = password; 16 | this.secure = secure; 17 | } 18 | 19 | public String getServerName() { 20 | return serverName; 21 | } 22 | 23 | public String getHost() { 24 | return host; 25 | } 26 | 27 | public int getPort() { 28 | return port; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public boolean isSecure() { 36 | return secure; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Efe Kurban 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/config/Config.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.config; 2 | 3 | import org.bukkit.configuration.file.YamlConfiguration; 4 | import org.bukkit.plugin.Plugin; 5 | 6 | import java.io.File; 7 | 8 | public class Config extends YamlConfiguration { 9 | 10 | private final File file; 11 | private final Plugin plugin; 12 | 13 | public Config(Plugin plugin, String name){ 14 | this.plugin = plugin; 15 | file = new File(plugin.getDataFolder(), name); 16 | 17 | if (file.exists()) 18 | reload(); 19 | } 20 | 21 | public void create(){ 22 | if (!file.exists()) { 23 | file.getParentFile().mkdirs(); 24 | plugin.saveResource(file.getName(), false); 25 | } 26 | reload(); 27 | } 28 | 29 | public void reload() { 30 | try { 31 | this.load(this.file); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | public void save() { 38 | try { 39 | this.save(this.file); 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/listener/CommandListener.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.listener; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsBungee; 4 | import net.md_5.bungee.api.connection.ProxiedPlayer; 5 | import net.md_5.bungee.api.event.ChatEvent; 6 | import net.md_5.bungee.api.plugin.Listener; 7 | import net.md_5.bungee.event.EventHandler; 8 | 9 | public class CommandListener implements Listener { 10 | 11 | private final SyncCommandsBungee plugin; 12 | 13 | public CommandListener(SyncCommandsBungee plugin) { 14 | this.plugin = plugin; 15 | } 16 | 17 | @EventHandler 18 | public void onCommand(ChatEvent event) { 19 | if (!event.isCommand()) return; 20 | String command = event.getMessage().replace("/", ""); 21 | 22 | ProxiedPlayer sender = (ProxiedPlayer) event.getSender(); 23 | if (!plugin.getAutoSyncMode().asMap().containsKey(sender.getUniqueId())) return; 24 | if (command.startsWith("bsync") || command.startsWith("bungeesync") || command.startsWith("syncbungee")) return; 25 | 26 | String target = plugin.getAutoSyncMode().getIfPresent(sender.getUniqueId()); 27 | 28 | event.setMessage(String.format("/bsync %s %s", target, command)); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/codec/GsonCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Big credit to lucko's helper 4 | 5 | https://github.com/lucko/helper 6 | 7 | */ 8 | package io.github.efekurbann.synccommands.messaging.codec; 9 | 10 | import com.google.gson.Gson; 11 | import com.google.gson.reflect.TypeToken; 12 | 13 | import java.io.*; 14 | import java.nio.charset.StandardCharsets; 15 | 16 | public class GsonCodec { 17 | 18 | private final Gson gson; 19 | private final TypeToken type; 20 | 21 | public GsonCodec(Gson gson, TypeToken type) { 22 | this.gson = gson; 23 | this.type = type; 24 | } 25 | 26 | public byte[] encode(T message) { 27 | ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); 28 | try (Writer writer = new OutputStreamWriter(byteOut, StandardCharsets.UTF_8)) { 29 | this.gson.toJson(message, this.type.getType(), writer); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | return byteOut.toByteArray(); 34 | } 35 | 36 | public T decode(byte[] buf) { 37 | ByteArrayInputStream byteIn = new ByteArrayInputStream(buf); 38 | try (Reader reader = new InputStreamReader(byteIn, StandardCharsets.UTF_8)) { 39 | return this.gson.fromJson(reader, this.type.getType()); 40 | } catch (IOException e) { 41 | e.printStackTrace(); 42 | return null; 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /synccommands-common/src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | serverName: "testServer" # anything you want 2 | 3 | connection: # connection to listen for new commands 4 | # currently there are 3 different types; socket, redis and rabbitmq. 5 | # you must use the same type as the other servers, otherwise it wont work. 6 | type: socket 7 | host: "localhost" 8 | port: 1234 9 | password: "supersecretpassword" 10 | secure: true # if you are going to use socket, I highly recommend you to keep this enabled and change the password. 11 | 12 | # these settings are only for RabbitMQ, if you are not going to use RabbitMQ just ignore this section. 13 | username: "guest" 14 | vhost: "/" 15 | 16 | servers: # connections to send commands, not listen 17 | server1: # command would be /(b)sync server1 {command} 18 | host: "localhost" 19 | port: 1235 20 | password: "supersecretpassword" 21 | secure: true 22 | server2: # command would be /(b)sync server2 {command} 23 | host: "localhost" 24 | port: 1236 25 | password: "supersecretpassword" 26 | secure: true 27 | # testServer: # command would be /(b)sync testServer {command} 28 | # host: "localhost" 29 | # port: 13861 30 | # password: "supersecretpassword" 31 | # secure: false 32 | # 33 | # you are able to add the current server, but it is disabled by default because it may not be useful for everyone 34 | 35 | groups: 36 | skyblock: 37 | - server1 # it has to be the target server's name. case sensitive. 38 | - server2 39 | bedwars: 40 | - server3 41 | - server4 42 | proxy: # You have more than one proxy? Don't worry! 43 | - bungee1 44 | - bungee2 45 | 46 | no-permission: "&cYou do not have enough permission to perform this command!" -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/config/Config.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.config; 2 | 3 | import com.google.common.io.ByteStreams; 4 | import net.md_5.bungee.api.plugin.Plugin; 5 | import net.md_5.bungee.config.Configuration; 6 | import net.md_5.bungee.config.ConfigurationProvider; 7 | import net.md_5.bungee.config.YamlConfiguration; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | import java.nio.file.Files; 14 | 15 | public class Config { 16 | 17 | private Configuration config; 18 | private final Plugin plugin; 19 | private final String name; 20 | 21 | public Config(Plugin plugin, String name) { 22 | this.plugin = plugin; 23 | this.name = name; 24 | } 25 | 26 | public void create() { 27 | if (!plugin.getDataFolder().exists()) { 28 | plugin.getDataFolder().mkdir(); 29 | } 30 | File configFile = new File(plugin.getDataFolder(), name); 31 | if (!configFile.exists()) { 32 | try (InputStream is = plugin.getResourceAsStream(name); 33 | OutputStream os = Files.newOutputStream(configFile.toPath())) { 34 | configFile.createNewFile(); 35 | ByteStreams.copy(is, os); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | try { 42 | config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | 48 | public Configuration getConfig() { 49 | return config; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/impl/socket/SocketImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging.impl.socket; 2 | 3 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 4 | import io.github.efekurbann.synccommands.logging.Logger; 5 | import io.github.efekurbann.synccommands.messaging.Messaging; 6 | import io.github.efekurbann.synccommands.objects.Command; 7 | import io.github.efekurbann.synccommands.objects.server.Server; 8 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 9 | 10 | import java.io.IOException; 11 | 12 | public class SocketImpl extends Messaging { 13 | 14 | private SocketServer socketServer; 15 | private final SocketClient socketClient; 16 | 17 | public SocketImpl(Server server, ConsoleExecutor executor, Logger logger, Scheduler scheduler) { 18 | super(server, executor, logger, scheduler); 19 | this.socketClient = new SocketClient(this); 20 | } 21 | 22 | @Override 23 | public void connect(String host, int port, String password, boolean secure) throws IOException { 24 | this.socketServer = new SocketServer(this, secure); 25 | } 26 | 27 | @Override 28 | public void addListeners() { 29 | this.socketServer.start(); 30 | } 31 | 32 | @Override 33 | public void publishCommand(Command command) { 34 | scheduler.runAsync(()->this.socketClient.sendCommand(command)); 35 | } 36 | 37 | @Override 38 | public void close() { 39 | if (this.socketServer.getServerSocket().isClosed()) return; 40 | 41 | try { 42 | this.socketServer.getServerSocket().close(); 43 | } catch (IOException ignored) { 44 | // ik ik ik 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/impl/socket/SocketClient.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging.impl.socket; 2 | 3 | import io.github.efekurbann.synccommands.objects.Command; 4 | import io.github.efekurbann.synccommands.objects.server.Server; 5 | 6 | import java.io.DataOutputStream; 7 | import java.io.IOException; 8 | import java.net.ConnectException; 9 | import java.net.InetAddress; 10 | import java.net.Socket; 11 | 12 | public class SocketClient { 13 | 14 | private final SocketImpl socket; 15 | 16 | public SocketClient(SocketImpl socket) { 17 | this.socket = socket; 18 | } 19 | 20 | public void sendCommand(Command command) { 21 | for (Server server : command.getTargetServers()) { 22 | try (Socket socket = new Socket(InetAddress.getByName(server.getHost()), server.getPort()); 23 | DataOutputStream out = new DataOutputStream(socket.getOutputStream())) { 24 | if (socket.isClosed()) continue; 25 | 26 | out.writeUTF(server.getServerName()); 27 | out.writeUTF(command.getCommand()); 28 | out.writeUTF(command.getPublisher().getServerName()); 29 | out.writeUTF(server.getPassword()); 30 | 31 | } catch (IOException ex) { 32 | if (ex instanceof ConnectException) { 33 | socket.getLogger().severe(String.format("Tried to send command to %s but could not reach. " + 34 | "Is it offline?", server.getServerName())); 35 | continue; 36 | } 37 | ex.printStackTrace(); 38 | } 39 | } 40 | 41 | this.socket.printCommandSentMessage(command); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/util/UpdateChecker.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.util; 2 | 3 | import io.github.efekurbann.synccommands.logging.Logger; 4 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 5 | 6 | import javax.net.ssl.HttpsURLConnection; 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | import java.net.URL; 11 | 12 | public class UpdateChecker { 13 | 14 | private static final String RESOURCE_ID = "99596"; 15 | private static final String URL = "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID; 16 | 17 | private final Logger logger; 18 | private final Scheduler scheduler; 19 | private final String version; 20 | private boolean upToDate; 21 | 22 | public UpdateChecker(String version, Logger logger, Scheduler scheduler) { 23 | this.logger = logger; 24 | this.scheduler = scheduler; 25 | this.version = version; 26 | } 27 | 28 | public void checkUpdates() { 29 | this.scheduler.runAsync(()-> { 30 | try { 31 | HttpsURLConnection con = (HttpsURLConnection) new URL(URL).openConnection(); 32 | InputStreamReader reader = new InputStreamReader(con.getInputStream()); 33 | String latestVersion = (new BufferedReader(reader)).readLine(); 34 | this.upToDate = latestVersion.equals(version); 35 | 36 | if (!this.upToDate) { 37 | logger.info("An update was found for SyncCommands!"); 38 | logger.info("Download from: https://www.spigotmc.org/resources/" + RESOURCE_ID); 39 | } else 40 | logger.info("Plugin is up to date, no update found."); 41 | } catch (IOException exception) { 42 | this.logger.info("Could not check for updates: " + exception.getMessage()); 43 | } 44 | }); 45 | } 46 | 47 | public boolean isUpToDate() { 48 | return upToDate; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/listener/CommandListener.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.listener; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsSpigot; 4 | import org.bukkit.command.CommandSender; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 9 | import org.bukkit.event.server.ServerCommandEvent; 10 | 11 | public class CommandListener implements Listener { 12 | 13 | private final SyncCommandsSpigot plugin; 14 | 15 | public CommandListener(SyncCommandsSpigot plugin) { 16 | this.plugin = plugin; 17 | } 18 | 19 | @EventHandler 20 | public void onCommand(PlayerCommandPreprocessEvent event) { 21 | String command = event.getMessage().replace("/", ""); 22 | 23 | Player player = event.getPlayer(); 24 | if (!plugin.getAutoSyncMode().asMap().containsKey(player.getName())) return; 25 | if (command.startsWith("bsync") || command.startsWith("bungeesync") || command.startsWith("syncbungee") 26 | || command.startsWith("sync") || command.startsWith("ssync")) return; 27 | 28 | String target = plugin.getAutoSyncMode().getIfPresent(player.getName()); 29 | 30 | event.setMessage(String.format("/sync %s %s", target, command)); 31 | } 32 | 33 | @EventHandler 34 | public void onCommand(ServerCommandEvent event) { 35 | String command = event.getCommand().replace("/", ""); 36 | 37 | CommandSender sender = event.getSender(); 38 | if (!plugin.getAutoSyncMode().asMap().containsKey(sender.getName())) return; 39 | if (command.startsWith("bsync") || command.startsWith("bungeesync") || command.startsWith("syncbungee") 40 | || command.startsWith("sync") || command.startsWith("ssync")) return; 41 | 42 | String target = plugin.getAutoSyncMode().getIfPresent(sender.getName()); 43 | 44 | event.setCommand(String.format("sync %s %s", target, command)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | 11 | # Compiled class file 12 | *.class 13 | 14 | # Log file 15 | *.log 16 | 17 | # BlueJ files 18 | *.ctxt 19 | 20 | # Package Files # 21 | *.jar 22 | *.war 23 | *.nar 24 | *.ear 25 | *.zip 26 | *.tar.gz 27 | *.rar 28 | 29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 30 | hs_err_pid* 31 | 32 | *~ 33 | 34 | # temporary files which can be created if a process still has a handle open of a deleted file 35 | .fuse_hidden* 36 | 37 | # KDE directory preferences 38 | .directory 39 | 40 | # Linux trash folder which might appear on any partition or disk 41 | .Trash-* 42 | 43 | # .nfs files are created when an open file is removed but is still being accessed 44 | .nfs* 45 | 46 | # General 47 | .DS_Store 48 | .AppleDouble 49 | .LSOverride 50 | 51 | # Icon must end with two \r 52 | Icon 53 | 54 | # Thumbnails 55 | ._* 56 | 57 | # Files that might appear in the root of a volume 58 | .DocumentRevisions-V100 59 | .fseventsd 60 | .Spotlight-V100 61 | .TemporaryItems 62 | .Trashes 63 | .VolumeIcon.icns 64 | .com.apple.timemachine.donotpresent 65 | 66 | # Directories potentially created on remote AFP share 67 | .AppleDB 68 | .AppleDesktop 69 | Network Trash Folder 70 | Temporary Items 71 | .apdisk 72 | 73 | # Windows thumbnail cache files 74 | Thumbs.db 75 | Thumbs.db:encryptable 76 | ehthumbs.db 77 | ehthumbs_vista.db 78 | 79 | # Dump file 80 | *.stackdump 81 | 82 | # Folder config file 83 | [Dd]esktop.ini 84 | 85 | # Recycle Bin used on file shares 86 | $RECYCLE.BIN/ 87 | 88 | # Windows Installer files 89 | *.cab 90 | *.msi 91 | *.msix 92 | *.msm 93 | *.msp 94 | 95 | # Windows shortcuts 96 | *.lnk 97 | 98 | */target/ 99 | 100 | pom.xml.tag 101 | pom.xml.releaseBackup 102 | pom.xml.versionsBackup 103 | pom.xml.next 104 | 105 | release.properties 106 | dependency-reduced-pom.xml 107 | buildNumber.properties 108 | .mvn/timing.properties 109 | .mvn/wrapper/maven-wrapper.jar 110 | .flattened-pom.xml 111 | 112 | # Common working directory 113 | run/ 114 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/config/Config.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.config; 2 | 3 | import com.google.common.io.ByteStreams; 4 | import io.github.efekurbann.synccommands.SyncCommandsVelocity; 5 | import ninja.leaping.configurate.ConfigurationNode; 6 | import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.io.OutputStream; 12 | import java.nio.file.Files; 13 | import java.nio.file.Path; 14 | 15 | public class Config { 16 | 17 | private final YAMLConfigurationLoader loader; 18 | private final SyncCommandsVelocity plugin; 19 | 20 | private ConfigurationNode root; 21 | 22 | public Config(SyncCommandsVelocity plugin, Path path) { 23 | this.plugin = plugin; 24 | this.loader = YAMLConfigurationLoader.builder().setPath(path).build(); 25 | } 26 | 27 | public void create() { 28 | if (!plugin.getDataDirectory().toFile().exists()) { 29 | plugin.getDataDirectory().toFile().mkdirs(); 30 | } 31 | 32 | File configFile = new File(plugin.getDataDirectory().toFile(), "config.yml"); 33 | if (!configFile.exists()) { 34 | try (InputStream is = plugin.getClass().getClassLoader().getResourceAsStream("config.yml"); 35 | OutputStream os = Files.newOutputStream(configFile.toPath())) { 36 | configFile.createNewFile(); 37 | ByteStreams.copy(is, os); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | try { 44 | this.root = loader.load(); 45 | } catch (IOException e) { 46 | plugin.getLogger().severe("An error occurred while loading this configuration!"); 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | public void save() { 52 | try { 53 | loader.save(root); 54 | } catch (final IOException e) { 55 | plugin.getLogger().severe("Unable to save your messages configuration! Sorry! " + e.getMessage()); 56 | } 57 | } 58 | 59 | public ConfigurationNode getRoot() { 60 | return root; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /synccommands-bungeecord/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.efekurbann 9 | SyncCommands 10 | 4.0.1 11 | 12 | 13 | synccommands-bungeecord 14 | jar 15 | 16 | SyncCommands BungeeCord 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-shade-plugin 27 | 28 | 29 | 30 | 31 | src/main/resources 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | sonatype 40 | https://oss.sonatype.org/content/groups/public/ 41 | 42 | 43 | 44 | 45 | 46 | net.md-5 47 | bungeecord-api 48 | 1.19-R0.1-SNAPSHOT 49 | provided 50 | 51 | 52 | io.github.efekurbann 53 | synccommands-common 54 | ${project.version} 55 | compile 56 | 57 | 58 | org.bstats 59 | bstats-bungeecord 60 | 3.0.0 61 | compile 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /synccommands-velocity/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.efekurbann 9 | SyncCommands 10 | 4.0.1 11 | 12 | 13 | synccommands-velocity 14 | jar 15 | 16 | SyncCommands Velocity 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-shade-plugin 27 | 28 | 29 | 30 | 31 | src/main/resources 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | papermc-repo 40 | https://papermc.io/repo/repository/maven-public/ 41 | 42 | 43 | 44 | 45 | 46 | com.velocitypowered 47 | velocity-api 48 | 3.1.1 49 | provided 50 | 51 | 52 | 53 | io.github.efekurbann 54 | synccommands-common 55 | ${project.version} 56 | compile 57 | 58 | 59 | 60 | org.bstats 61 | bstats-velocity 62 | 3.0.0 63 | compile 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /synccommands-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.efekurbann 9 | SyncCommands 10 | 4.0.1 11 | 12 | 13 | synccommands-common 14 | jar 15 | 16 | 17 | 18 | 19 | org.apache.maven.plugins 20 | maven-compiler-plugin 21 | 22 | 23 | org.apache.maven.plugins 24 | maven-shade-plugin 25 | 26 | 27 | 28 | 29 | src/main/resources 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | redis.clients 38 | jedis 39 | 4.2.3 40 | 41 | 42 | 43 | com.google.code.gson 44 | gson 45 | 46 | 47 | 48 | 49 | 50 | com.google.code.gson 51 | gson 52 | 2.9.0 53 | 54 | provided 55 | 56 | 57 | 58 | com.rabbitmq 59 | amqp-client 60 | 5.14.2 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/Messaging.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 6 | import io.github.efekurbann.synccommands.logging.Logger; 7 | import io.github.efekurbann.synccommands.messaging.codec.GsonCodec; 8 | import io.github.efekurbann.synccommands.objects.Command; 9 | import io.github.efekurbann.synccommands.objects.server.Server; 10 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | public abstract class Messaging { 17 | 18 | protected final Logger logger; 19 | protected final Server server; 20 | protected final ConsoleExecutor executor; 21 | protected final Scheduler scheduler; 22 | protected final GsonCodec codec = new GsonCodec<>(new Gson(), TypeToken.get(Command.class)); 23 | 24 | public Messaging(Server server, ConsoleExecutor executor, Logger logger, Scheduler scheduler) { 25 | this.server = server; 26 | this.executor = executor; 27 | this.logger = logger; 28 | this.scheduler = scheduler; 29 | } 30 | 31 | public abstract void connect(String host, int port, String password, boolean secure) throws Exception; 32 | 33 | public abstract void addListeners(); 34 | 35 | public abstract void publishCommand(Command command); 36 | 37 | public abstract void close(); 38 | 39 | public ConsoleExecutor getExecutor() { 40 | return executor; 41 | } 42 | 43 | public Logger getLogger() { 44 | return logger; 45 | } 46 | 47 | public Server getServer() { 48 | return server; 49 | } 50 | 51 | public void execute(Command command) { 52 | logger.info(String.format("Successfully executed command: \"%s\" from server %s", 53 | command.getCommand(), command.getPublisher().getServerName())); 54 | executor.execute(command.getCommand()); 55 | } 56 | 57 | public void execute(String command, String publisher) { 58 | logger.info(String.format("Successfully executed command: \"%s\" from server %s", command, publisher)); 59 | executor.execute(command); 60 | } 61 | 62 | public void printCommandSentMessage(Command command) { 63 | List list = Arrays.stream(command.getTargetServers()).map(Server::getServerName).collect(Collectors.toList()); 64 | this.logger.info(String.format("Successfully sent command to server(s): %s", String.join(", ", list))); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /synccommands-spigot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | io.github.efekurbann 9 | SyncCommands 10 | 4.0.1 11 | 12 | 13 | synccommands-spigot 14 | jar 15 | 16 | SyncCommands Spigot 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-shade-plugin 27 | 28 | 29 | 30 | 31 | src/main/resources 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | spigotmc-repo 40 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 41 | 42 | 43 | sonatype 44 | https://oss.sonatype.org/content/groups/public/ 45 | 46 | 47 | 48 | 49 | 50 | org.spigotmc 51 | spigot-api 52 | 1.19.2-R0.1-SNAPSHOT 53 | provided 54 | 55 | 56 | io.github.efekurbann 57 | synccommands-common 58 | ${project.version} 59 | compile 60 | 61 | 62 | org.jetbrains 63 | annotations 64 | 23.0.0 65 | provided 66 | 67 | 68 | org.bstats 69 | bstats-bukkit 70 | 3.0.0 71 | compile 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/impl/socket/SocketServer.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging.impl.socket; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | import java.net.ServerSocket; 6 | import java.net.Socket; 7 | 8 | public class SocketServer extends Thread { 9 | 10 | private final String password; 11 | private final boolean secure; 12 | private final ServerSocket serverSocket; 13 | private final SocketImpl socket; 14 | 15 | public SocketServer(SocketImpl socket, boolean secure) throws IOException { 16 | this.socket = socket; 17 | this.password = socket.getServer().getPassword(); 18 | this.secure = secure; 19 | this.serverSocket = new ServerSocket(socket.getServer().getPort()); 20 | 21 | setName("SyncCommands Socket Thread"); 22 | } 23 | 24 | @Override 25 | public void run() { 26 | while (!serverSocket.isClosed()) { 27 | if (serverSocket.isClosed()) break; 28 | try (Socket socket = serverSocket.accept(); 29 | DataInputStream input = new DataInputStream(socket.getInputStream())) { 30 | 31 | String targetServer = input.readUTF(); 32 | if (!targetServer.equals("all") && !targetServer.equalsIgnoreCase(this.socket.getServer().getServerName())) return; 33 | 34 | String command = input.readUTF(); 35 | String publisher = input.readUTF(); 36 | 37 | if (secure) { 38 | String pass = input.readUTF(); 39 | if (!pass.equals(password)) { 40 | this.socket.getLogger().severe("Someone tried to execute command without permission!"); 41 | this.socket.getLogger().severe("Command: " + command); 42 | this.socket.getLogger().severe("Publisher: " + publisher); 43 | this.socket.getLogger().severe("IP: " + socket.getInetAddress().getHostAddress()); 44 | this.socket.getLogger().severe("Hostname: " + socket.getInetAddress().getHostName()); 45 | this.socket.getLogger().severe("This is a really important warning, do not ignore this!"); 46 | continue; 47 | } 48 | } 49 | 50 | this.socket.execute(command, publisher); 51 | } catch (IOException e) { 52 | if (e.getMessage() != null && e.getMessage().equalsIgnoreCase("socket closed")) break; 53 | 54 | e.printStackTrace(); 55 | } 56 | } 57 | } 58 | 59 | public ServerSocket getServerSocket() { 60 | return serverSocket; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.github.efekurbann 8 | SyncCommands 9 | 4.0.1 10 | pom 11 | 12 | Best Command Synchronization Plugin in the market. 13 | 14 | 15 | 1.8 16 | UTF-8 17 | 18 | 19 | 20 | ${project.name} v${project.version} 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | 3.8.1 27 | 28 | ${java.version} 29 | ${java.version} 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-shade-plugin 35 | 3.2.4 36 | 37 | 38 | package 39 | 40 | shade 41 | 42 | 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | redis.clients 51 | io.github.efekurbann.synccommands.thirdparty.redis.clients 52 | 53 | 54 | org.bstats 55 | io.github.efekurbann.synccommands.thirdparty.org.bstats 56 | 57 | 58 | com.rabbitmq 59 | io.github.efekurbann.synccommands.thirdparty.com.rabbitmq 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | synccommands-common 70 | synccommands-spigot 71 | synccommands-bungeecord 72 | synccommands-velocity 73 | 74 | 75 | -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/command/BSyncCommand.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.command; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsBungee; 4 | import io.github.efekurbann.synccommands.objects.Command; 5 | import io.github.efekurbann.synccommands.objects.server.Server; 6 | import io.github.efekurbann.synccommands.util.ChatUtils; 7 | import net.md_5.bungee.api.CommandSender; 8 | import net.md_5.bungee.api.ProxyServer; 9 | import net.md_5.bungee.api.chat.TextComponent; 10 | import net.md_5.bungee.api.connection.ProxiedPlayer; 11 | 12 | import java.util.Arrays; 13 | 14 | public class BSyncCommand extends net.md_5.bungee.api.plugin.Command { 15 | 16 | private final SyncCommandsBungee plugin; 17 | 18 | public BSyncCommand(SyncCommandsBungee plugin) { 19 | super("bsync", null, "bungeesync", "syncbungee"); 20 | this.plugin = plugin; 21 | } 22 | 23 | @Override 24 | public void execute(CommandSender sender, String[] args) { 25 | if (!sender.hasPermission("synccommands.proxy.admin")) { 26 | sender.sendMessage(TextComponent.fromLegacyText( 27 | ChatUtils.color(plugin.getConfig().getString("no-permission")))); 28 | return; 29 | } 30 | 31 | if (args.length == 1 && !ProxyServer.getInstance().getConsole().equals(sender)) { 32 | ProxiedPlayer player = (ProxiedPlayer) sender; 33 | String target = args[0]; 34 | if (!plugin.getGroups().containsKey(target) 35 | && !plugin.getServers().containsKey(target) 36 | && !target.equalsIgnoreCase("all")) { 37 | sender.sendMessage(TextComponent.fromLegacyText(ChatUtils.color(String.format("&cCould not find %s!", target)))); 38 | return; 39 | } 40 | 41 | if (!plugin.getAutoSyncMode().asMap().containsKey(player.getUniqueId())) { 42 | plugin.getAutoSyncMode().put(player.getUniqueId(), target); 43 | sender.sendMessage(TextComponent.fromLegacyText( 44 | ChatUtils.color(String.format("&aSuccessfully enabled the auto sync mode for %s!", target))) 45 | ); 46 | sender.sendMessage(TextComponent.fromLegacyText( 47 | ChatUtils.color("&aFrom now on, all the commands that you execute will be synced.")) 48 | ); 49 | } else { 50 | plugin.getAutoSyncMode().invalidate(player.getUniqueId()); 51 | sender.sendMessage(TextComponent.fromLegacyText(ChatUtils.color("&cDisabled the auto sync mode!"))); 52 | } 53 | 54 | return; 55 | } 56 | 57 | if (args.length < 2) { 58 | sender.sendMessage(TextComponent.fromLegacyText( 59 | ChatUtils.color("&cCorrect usage: /bsync "))); 60 | return; 61 | } 62 | 63 | String command = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); 64 | 65 | if (args[0].equalsIgnoreCase("all")) { 66 | Server[] servers = plugin.getServers().values().toArray(new Server[0]); 67 | 68 | plugin.getMessaging().publishCommand(new Command(command, plugin.getThisServer(), servers)); 69 | } else if (plugin.getServers().get(args[0]) != null) 70 | plugin.getMessaging().publishCommand(new Command(command, plugin.getThisServer(), plugin.getServers().get(args[0]))); 71 | else if (plugin.getGroups().get(args[0]) != null) { 72 | Server[] servers = plugin.getGroups().get(args[0]).toArray(new Server[0]); 73 | 74 | plugin.getMessaging().publishCommand(new Command(command, plugin.getThisServer(), servers)); 75 | } else { 76 | sender.sendMessage(TextComponent.fromLegacyText(ChatUtils.color(String.format("&cCould not find %s!", args[0])))); 77 | return; 78 | } 79 | 80 | sender.sendMessage(TextComponent.fromLegacyText(ChatUtils.color("&aSuccessfully sent command."))); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/impl/redis/Redis.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging.impl.redis; 2 | 3 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 4 | import io.github.efekurbann.synccommands.logging.Logger; 5 | import io.github.efekurbann.synccommands.messaging.Messaging; 6 | import io.github.efekurbann.synccommands.objects.Command; 7 | import io.github.efekurbann.synccommands.objects.server.Server; 8 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 9 | import redis.clients.jedis.BinaryJedisPubSub; 10 | import redis.clients.jedis.Jedis; 11 | import redis.clients.jedis.JedisPool; 12 | import redis.clients.jedis.JedisPoolConfig; 13 | 14 | import java.nio.charset.StandardCharsets; 15 | import java.util.Arrays; 16 | import java.util.concurrent.locks.ReentrantLock; 17 | 18 | public class Redis extends Messaging { 19 | 20 | private JedisPool jedisPool; 21 | private RedisPubSub listener; 22 | 23 | public Redis(Server server, ConsoleExecutor executor, Logger logger, Scheduler scheduler) { 24 | super(server, executor, logger, scheduler); 25 | } 26 | 27 | @Override 28 | public void connect(String host, int port, String password, boolean secure) { 29 | JedisPoolConfig config = new JedisPoolConfig(); 30 | config.setMaxTotal(16); 31 | jedisPool = new JedisPool(config, host, port, 2000, password, secure); 32 | 33 | try (Jedis jedis = jedisPool.getResource()) { 34 | jedis.ping(); 35 | } 36 | 37 | } 38 | 39 | @Override 40 | public void addListeners() { 41 | Thread thread = new Thread(() -> { 42 | try (Jedis jedis = Redis.this.jedisPool.getResource()) { 43 | Redis.this.listener = new RedisPubSub(); 44 | jedis.subscribe(listener, "synccommands".getBytes(StandardCharsets.UTF_8)); 45 | } 46 | }); 47 | 48 | thread.setName("SyncCommands Redis Thread"); 49 | thread.start(); 50 | } 51 | 52 | @Override 53 | public void publishCommand(Command command) { 54 | scheduler.runAsync(() -> { 55 | try (Jedis jedis = this.jedisPool.getResource()) { 56 | jedis.publish("synccommands".getBytes(StandardCharsets.UTF_8), codec.encode(command)); 57 | 58 | printCommandSentMessage(command); 59 | } 60 | }); 61 | } 62 | 63 | @Override 64 | public void close() { 65 | listener.unsubscribe(); 66 | jedisPool.close(); 67 | } 68 | 69 | class RedisPubSub extends BinaryJedisPubSub { 70 | 71 | private final ReentrantLock lock = new ReentrantLock(); 72 | 73 | @Override 74 | public void onMessage(byte[] channel, byte[] message) { 75 | String channelName = new String(channel, StandardCharsets.UTF_8); 76 | if (!channelName.equalsIgnoreCase("synccommands")) return; 77 | 78 | Command command = codec.decode(message); 79 | 80 | if (!command.getTargetServers()[0].getServerName().equals("all") && Arrays.stream(command.getTargetServers()) 81 | .noneMatch(s -> s.getServerName().equalsIgnoreCase(Redis.this.server.getServerName()))) return; 82 | 83 | execute(command); 84 | } 85 | 86 | @Override 87 | public void unsubscribe(byte[]... channels) { 88 | this.lock.lock(); 89 | try { 90 | super.unsubscribe(channels); 91 | } finally { 92 | this.lock.unlock(); 93 | } 94 | } 95 | 96 | @Override 97 | public void subscribe(byte[]... channels) { 98 | this.lock.lock(); 99 | try { 100 | for (byte[] channel : channels) { 101 | super.subscribe(channel); 102 | } 103 | } finally { 104 | this.lock.unlock(); 105 | } 106 | } 107 | } 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/command/SyncCommand.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.command; 2 | 3 | import io.github.efekurbann.synccommands.SyncCommandsSpigot; 4 | import io.github.efekurbann.synccommands.objects.Command; 5 | import io.github.efekurbann.synccommands.objects.server.Server; 6 | import io.github.efekurbann.synccommands.util.ChatUtils; 7 | import org.bukkit.command.CommandExecutor; 8 | import org.bukkit.command.CommandSender; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | import java.util.Arrays; 12 | 13 | public class SyncCommand implements CommandExecutor { 14 | 15 | private final SyncCommandsSpigot plugin; 16 | 17 | public SyncCommand(SyncCommandsSpigot plugin) { 18 | this.plugin = plugin; 19 | } 20 | 21 | @Override 22 | public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { 23 | if (!sender.hasPermission("synccommands.admin")) { 24 | sender.sendMessage(ChatUtils.color(plugin.getConfig().getString("no-permission"))); 25 | return true; 26 | } 27 | 28 | if (args.length == 1) { 29 | String target = args[0]; 30 | if (!plugin.getGroups().containsKey(target) 31 | && !plugin.getServers().containsKey(target) 32 | && !target.equalsIgnoreCase("all")) { 33 | sender.sendMessage(ChatUtils.color(String.format("&cCould not find %s!", target))); 34 | return true; 35 | } 36 | 37 | if (!plugin.getAutoSyncMode().asMap().containsKey(sender.getName())) { 38 | plugin.getAutoSyncMode().put(sender.getName(), target); 39 | sender.sendMessage( 40 | ChatUtils.color(String.format("&aSuccessfully enabled the auto sync mode for %s!", target)) 41 | ); 42 | sender.sendMessage( 43 | ChatUtils.color("&aFrom now on, all the commands that you execute will be synced.") 44 | ); 45 | sender.sendMessage( 46 | ChatUtils.color("&6&lNOTE! &eSince the proxies are hierarchically higher than spigot," + 47 | " your command will be proceed on your proxy first.") 48 | ); 49 | sender.sendMessage( 50 | ChatUtils.color("&eThat means if you use a bungeecord command like /alert, " + 51 | "we can not detect that. And it wont be synced.") 52 | ); 53 | } else { 54 | plugin.getAutoSyncMode().invalidate(sender.getName()); 55 | sender.sendMessage(ChatUtils.color("&cDisabled the auto sync mode!")); 56 | } 57 | 58 | return true; 59 | } 60 | 61 | if (args.length < 2) { 62 | sender.sendMessage(ChatUtils.color("&cCorrect usage: /sync ")); 63 | return true; 64 | } 65 | 66 | String cmd = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); 67 | 68 | if (args[0].equalsIgnoreCase("all")) { 69 | Server[] servers = plugin.getServers().values().toArray(new Server[0]); 70 | 71 | plugin.getMessaging().publishCommand(new Command(cmd, plugin.getThisServer(), servers)); 72 | } else if (plugin.getServers().get(args[0]) != null) 73 | plugin.getMessaging().publishCommand(new Command(cmd, plugin.getThisServer(), plugin.getServers().get(args[0]))); 74 | else if (plugin.getGroups().get(args[0]) != null) { 75 | Server[] servers = plugin.getGroups().get(args[0]).toArray(new Server[0]); 76 | 77 | plugin.getMessaging().publishCommand(new Command(cmd, plugin.getThisServer(), servers)); 78 | } else { 79 | sender.sendMessage(ChatUtils.color(String.format("&cCould not find %s!", args[0]))); 80 | return true; 81 | } 82 | 83 | sender.sendMessage(ChatUtils.color("&aSuccessfully sent command.")); 84 | return true; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/command/VSyncCommand.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.command; 2 | 3 | import com.velocitypowered.api.command.CommandSource; 4 | import com.velocitypowered.api.command.SimpleCommand; 5 | import com.velocitypowered.api.proxy.Player; 6 | import io.github.efekurbann.synccommands.SyncCommandsVelocity; 7 | import io.github.efekurbann.synccommands.objects.Command; 8 | import io.github.efekurbann.synccommands.objects.server.Server; 9 | import net.kyori.adventure.text.Component; 10 | import net.kyori.adventure.text.format.NamedTextColor; 11 | import net.kyori.adventure.text.format.TextDecoration; 12 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 13 | 14 | import java.util.Arrays; 15 | 16 | public class VSyncCommand implements SimpleCommand { 17 | 18 | private final SyncCommandsVelocity plugin; 19 | 20 | public VSyncCommand(SyncCommandsVelocity plugin) { 21 | this.plugin = plugin; 22 | } 23 | 24 | @Override 25 | public void execute(Invocation invocation) { 26 | CommandSource sender = invocation.source(); 27 | String[] args = invocation.arguments(); 28 | 29 | if (!invocation.source().hasPermission("synccommands.proxy.admin")) { 30 | sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize( 31 | plugin.getConfig().getRoot().getNode("no-permission").getString() 32 | ).decoration(TextDecoration.ITALIC, false)); 33 | return; 34 | } 35 | 36 | if (args.length == 1 && !plugin.getProxyServer().getConsoleCommandSource().equals(sender)) { 37 | String target = args[0]; 38 | if (!plugin.getGroups().containsKey(target) 39 | && !plugin.getServers().containsKey(target) 40 | && !target.equalsIgnoreCase("all")) { 41 | sender.sendMessage(Component.text(String.format("Could not find %s!", target)).color(NamedTextColor.RED)); 42 | return; 43 | } 44 | 45 | Player player = (Player) sender; 46 | if (!plugin.getAutoSyncMode().asMap().containsKey(player.getUniqueId())) { 47 | plugin.getAutoSyncMode().put(player.getUniqueId(), target); 48 | 49 | sender.sendMessage(Component.text( 50 | String.format("Successfully enabled the auto sync mode for %s!", target) 51 | ).color(NamedTextColor.GREEN)); 52 | sender.sendMessage(Component.text( 53 | "From now on, all the commands that you execute will be synced." 54 | ).color(NamedTextColor.GREEN)); 55 | } else { 56 | plugin.getAutoSyncMode().invalidate(player.getUniqueId()); 57 | sender.sendMessage(Component.text("Disabled the auto sync mode!").color(NamedTextColor.RED)); 58 | } 59 | 60 | return; 61 | } 62 | 63 | if (args.length < 2) { 64 | sender.sendMessage(Component.text("Correct usage: /vsync ").color(NamedTextColor.RED)); 65 | return; 66 | } 67 | 68 | String command = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); 69 | 70 | if (args[0].equalsIgnoreCase("all")) { 71 | Server[] servers = plugin.getServers().values().toArray(new Server[0]); 72 | 73 | plugin.getMessaging().publishCommand(new Command(command, plugin.getServer(), servers)); 74 | } else if (plugin.getServers().get(args[0]) != null) 75 | plugin.getMessaging().publishCommand(new Command(command, plugin.getServer(), plugin.getServers().get(args[0]))); 76 | else if (plugin.getGroups().get(args[0]) != null) { 77 | Server[] servers = plugin.getGroups().get(args[0]).toArray(new Server[0]); 78 | 79 | plugin.getMessaging().publishCommand(new Command(command, plugin.getServer(), servers)); 80 | } else { 81 | sender.sendMessage(Component.text(String.format("Could not find %s!", args[0])).color(NamedTextColor.RED)); 82 | return; 83 | } 84 | 85 | sender.sendMessage(Component.text("Successfully sent command.").color(NamedTextColor.GREEN)); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /synccommands-common/src/main/java/io/github/efekurbann/synccommands/messaging/impl/rabbitmq/RabbitMQ.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands.messaging.impl.rabbitmq; 2 | 3 | import com.rabbitmq.client.*; 4 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 5 | import io.github.efekurbann.synccommands.logging.Logger; 6 | import io.github.efekurbann.synccommands.messaging.Messaging; 7 | import io.github.efekurbann.synccommands.objects.Command; 8 | import io.github.efekurbann.synccommands.objects.server.MQServer; 9 | import io.github.efekurbann.synccommands.objects.server.Server; 10 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 11 | 12 | import java.io.IOException; 13 | import java.util.Arrays; 14 | import java.util.concurrent.TimeoutException; 15 | 16 | public class RabbitMQ extends Messaging { 17 | 18 | private static final String EXCHANGE = "synccommands"; 19 | private static final String ROUTING_KEY = "synccommands:command"; 20 | 21 | private final String username; 22 | private final String virtualHost; 23 | private Connection connection; 24 | private Channel channel; 25 | private RabbitMQListener listener; 26 | 27 | public RabbitMQ(Server server, ConsoleExecutor executor, Logger logger, Scheduler scheduler) { 28 | super(server, executor, logger, scheduler); 29 | 30 | MQServer mqServer = (MQServer) server; 31 | this.username = mqServer.getUsername(); 32 | this.virtualHost = mqServer.getVirtualHost(); 33 | } 34 | 35 | @Override 36 | public void connect(String host, int port, String password, boolean secure) throws Exception { // secure is not used in RabbitMQ 37 | 38 | ConnectionFactory connectionFactory = new ConnectionFactory(); 39 | connectionFactory.setHost(host); 40 | connectionFactory.setPort(port); 41 | connectionFactory.setVirtualHost(virtualHost); 42 | connectionFactory.setUsername(username); 43 | connectionFactory.setPassword(password); 44 | connectionFactory.setAutomaticRecoveryEnabled(true); 45 | connectionFactory.setNetworkRecoveryInterval(30_000); 46 | 47 | addListeners(); // we are calling it in here because consuming requires a listener so it has to be initialized 48 | 49 | 50 | this.connection = connectionFactory.newConnection(); 51 | this.channel = this.connection.createChannel(); 52 | 53 | String queue = this.channel.queueDeclare("", false, true, true, null).getQueue(); 54 | this.channel.exchangeDeclare(EXCHANGE, BuiltinExchangeType.TOPIC, false, true, null); 55 | this.channel.queueBind(queue, EXCHANGE, ROUTING_KEY); 56 | this.channel.basicConsume(queue, true, this.listener, tag -> {}); 57 | 58 | } 59 | 60 | @Override 61 | public void addListeners() { 62 | this.listener = new RabbitMQListener(); 63 | 64 | listener.setName("SyncCommands - RabbitMQ Thread"); 65 | listener.start(); 66 | } 67 | 68 | @Override 69 | public void publishCommand(Command command) { 70 | scheduler.runAsync(() -> { 71 | try { 72 | channel.basicPublish(EXCHANGE, ROUTING_KEY, null, codec.encode(command)); 73 | 74 | printCommandSentMessage(command); 75 | } catch (IOException e) { 76 | e.printStackTrace(); 77 | } 78 | }); 79 | } 80 | 81 | @Override 82 | public void close() { 83 | try { 84 | this.channel.close(); 85 | this.connection.close(); 86 | this.listener.interrupt(); 87 | } catch (IOException | TimeoutException e) { 88 | e.printStackTrace(); 89 | } 90 | } 91 | 92 | // i am not sure if the extending Thread is required but i'll use it anyways. 93 | // this need to be checked since i do not have a rabbitmq server, i can't. 94 | // this class extends thread just to be sure, it may not be required for rabbitmq. 95 | class RabbitMQListener extends Thread implements DeliverCallback { 96 | 97 | @Override 98 | public void handle(String message, Delivery delivery) { 99 | Command command = codec.decode(delivery.getBody()); 100 | 101 | if (!command.getTargetServers()[0].getServerName().equals("all") && Arrays.stream(command.getTargetServers()) 102 | .noneMatch(s -> s.getServerName().equalsIgnoreCase(RabbitMQ.this.server.getServerName()))) return; 103 | 104 | execute(command); 105 | } 106 | 107 | } 108 | 109 | 110 | } -------------------------------------------------------------------------------- /synccommands-bungeecord/src/main/java/io/github/efekurbann/synccommands/SyncCommandsBungee.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands; 2 | 3 | import com.google.common.cache.Cache; 4 | import com.google.common.cache.CacheBuilder; 5 | import io.github.efekurbann.synccommands.command.BSyncCommand; 6 | import io.github.efekurbann.synccommands.config.Config; 7 | import io.github.efekurbann.synccommands.enums.ConnectionType; 8 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 9 | import io.github.efekurbann.synccommands.executor.impl.BungeeExecutor; 10 | import io.github.efekurbann.synccommands.listener.CommandListener; 11 | import io.github.efekurbann.synccommands.logging.Logger; 12 | import io.github.efekurbann.synccommands.logging.impl.BungeeLogger; 13 | import io.github.efekurbann.synccommands.messaging.Messaging; 14 | import io.github.efekurbann.synccommands.messaging.impl.rabbitmq.RabbitMQ; 15 | import io.github.efekurbann.synccommands.messaging.impl.redis.Redis; 16 | import io.github.efekurbann.synccommands.messaging.impl.socket.SocketImpl; 17 | import io.github.efekurbann.synccommands.objects.server.MQServer; 18 | import io.github.efekurbann.synccommands.objects.server.Server; 19 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 20 | import io.github.efekurbann.synccommands.scheduler.impl.BungeeScheduler; 21 | import io.github.efekurbann.synccommands.util.UpdateChecker; 22 | import net.md_5.bungee.api.ProxyServer; 23 | import net.md_5.bungee.api.plugin.Plugin; 24 | import net.md_5.bungee.config.Configuration; 25 | import org.bstats.bungeecord.Metrics; 26 | 27 | import java.util.*; 28 | import java.util.concurrent.TimeUnit; 29 | 30 | public final class SyncCommandsBungee extends Plugin { 31 | 32 | private final Config config = new Config(this, "config.yml"); 33 | private final ConsoleExecutor consoleExecutor = new BungeeExecutor(); 34 | private final Scheduler scheduler = new BungeeScheduler(this); 35 | private final Logger logger = new BungeeLogger(this); 36 | private final Map servers = new HashMap<>(); 37 | private final Map> groups = new HashMap<>(); 38 | private final Cache autoSyncMode = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); 39 | private Server server; 40 | private Messaging messaging; 41 | private boolean connectedSuccessfully; 42 | 43 | @Override 44 | public void onEnable() { 45 | this.config.create(); 46 | 47 | this.getLogger().info("Creating connection..."); 48 | 49 | ConnectionType type; 50 | try { 51 | type = ConnectionType.valueOf(this.getConfig().getString("connection.type", "socket") 52 | .toUpperCase(Locale.ENGLISH)); 53 | } catch (IllegalArgumentException exception) { 54 | this.getLogger().info("Invalid connection type detected! Valid types: Redis, RabbitMQ, Socket"); 55 | this.onDisable(); 56 | return; 57 | } 58 | 59 | if (!this.connect(type)) { 60 | onDisable(); 61 | return; 62 | } 63 | 64 | this.getLogger().info("Setting up servers..."); 65 | setupServers(type); 66 | 67 | this.getLogger().info("Setting up groups..."); 68 | setupGroups(); 69 | 70 | this.getProxy().getPluginManager().registerCommand(this, new BSyncCommand(this)); 71 | this.getProxy().getPluginManager().registerListener(this, new CommandListener(this)); 72 | 73 | new Metrics(this, 14139); 74 | 75 | // some forks sends ugly messages on initialization 76 | // so we will check updates after 3 seconds 77 | ProxyServer.getInstance().getScheduler().schedule(this, 78 | ()-> new UpdateChecker(this.getDescription().getVersion(), logger, scheduler).checkUpdates(), 79 | 3, TimeUnit.SECONDS); 80 | 81 | this.getLogger().info("Everything seems good. Plugin enabled!"); 82 | } 83 | 84 | @Override 85 | public void onDisable() { 86 | if (connectedSuccessfully) 87 | this.messaging.close(); 88 | } 89 | 90 | private boolean connect(ConnectionType type) { 91 | if (type != ConnectionType.RABBITMQ) { 92 | this.server = new Server( 93 | this.getConfig().getString("serverName"), 94 | this.getConfig().getString("connection.host"), 95 | this.getConfig().getInt("connection.port"), 96 | this.getConfig().getString("connection.password"), 97 | this.getConfig().getBoolean("connection.secure")); 98 | } else { 99 | this.server = new MQServer( 100 | this.getConfig().getString("serverName"), 101 | this.getConfig().getString("connection.host"), 102 | this.getConfig().getInt("connection.port"), 103 | this.getConfig().getString("connection.password"), 104 | this.getConfig().getBoolean("connection.secure"), 105 | this.getConfig().getString("connection.username"), 106 | this.getConfig().getString("connection.vhost")); 107 | } 108 | 109 | switch (type) { 110 | case SOCKET: 111 | this.messaging = new SocketImpl(server, consoleExecutor, logger, scheduler); 112 | break; 113 | case REDIS: 114 | this.messaging = new Redis(server, consoleExecutor, logger, scheduler); 115 | break; 116 | case RABBITMQ: 117 | this.messaging = new RabbitMQ(server, consoleExecutor, logger, scheduler); 118 | break; 119 | } 120 | 121 | // this may not be the best solution but I just don't want people to see those ugly exceptions 122 | try { 123 | this.messaging.connect( 124 | server.getHost(), 125 | server.getPort(), 126 | server.getPassword(), 127 | server.isSecure() 128 | ); 129 | 130 | this.getLogger().info("Setting up message listeners..."); 131 | 132 | if (type != ConnectionType.RABBITMQ) // no need to call the method twice 133 | this.messaging.addListeners(); 134 | 135 | this.connectedSuccessfully = true; 136 | } catch (Exception ex) { 137 | this.getLogger().info("Something went wrong! We could not setup a connection!"); 138 | this.getLogger().info("Please fix your configuration! Plugin disabling..."); 139 | this.getLogger().info("Exception message: " + ex.getMessage()); 140 | this.connectedSuccessfully = false; 141 | } 142 | 143 | return this.connectedSuccessfully; 144 | } 145 | 146 | private void setupServers(ConnectionType type) { 147 | if (getConfig().getSection("servers") == null) return; 148 | 149 | for (String key : getConfig().getSection("servers").getKeys()) { 150 | Server s; 151 | if (type != ConnectionType.RABBITMQ) { 152 | s = new Server( 153 | key, 154 | getConfig().getString("servers." + key + ".host"), 155 | getConfig().getInt("servers." + key + ".port"), 156 | getConfig().getString("servers." + key + ".password"), 157 | getConfig().getBoolean("servers." + key + ".secure")); 158 | } else { 159 | s = new MQServer( 160 | key, 161 | getConfig().getString("servers." + key + ".host"), 162 | getConfig().getInt("servers." + key + ".port"), 163 | getConfig().getString("servers." + key + ".password"), 164 | getConfig().getBoolean("servers." + key + ".secure"), 165 | getConfig().getString("servers." + key + ".username"), 166 | getConfig().getString("servers." + key + ".vhost")); 167 | } 168 | this.servers.put(key, s); 169 | } 170 | 171 | this.servers.put(this.server.getServerName(), this.server); 172 | } 173 | 174 | private void setupGroups() { 175 | if (getConfig().getSection("groups") == null) return; 176 | 177 | for (String key : getConfig().getSection("groups").getKeys()) { 178 | Set servers = new HashSet<>(); 179 | 180 | for (String server : getConfig().getStringList("groups." + key)) { 181 | servers.add(this.servers.get(server)); 182 | } 183 | 184 | this.groups.put(key, servers); 185 | } 186 | } 187 | 188 | public Configuration getConfig() { 189 | return config.getConfig(); 190 | } 191 | 192 | public Messaging getMessaging() { 193 | return messaging; 194 | } 195 | 196 | public Server getThisServer() { 197 | return server; 198 | } 199 | 200 | public Map getServers() { 201 | return servers; 202 | } 203 | 204 | public Map> getGroups() { 205 | return groups; 206 | } 207 | 208 | public Cache getAutoSyncMode() { 209 | return autoSyncMode; 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /synccommands-spigot/src/main/java/io/github/efekurbann/synccommands/SyncCommandsSpigot.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands; 2 | 3 | import com.google.common.cache.Cache; 4 | import com.google.common.cache.CacheBuilder; 5 | import io.github.efekurbann.synccommands.command.SyncCommand; 6 | import io.github.efekurbann.synccommands.config.Config; 7 | import io.github.efekurbann.synccommands.enums.ConnectionType; 8 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 9 | import io.github.efekurbann.synccommands.executor.impl.BukkitExecutor; 10 | import io.github.efekurbann.synccommands.listener.CommandListener; 11 | import io.github.efekurbann.synccommands.logging.BukkitLogger; 12 | import io.github.efekurbann.synccommands.logging.Logger; 13 | import io.github.efekurbann.synccommands.messaging.Messaging; 14 | import io.github.efekurbann.synccommands.messaging.impl.rabbitmq.RabbitMQ; 15 | import io.github.efekurbann.synccommands.messaging.impl.redis.Redis; 16 | import io.github.efekurbann.synccommands.messaging.impl.socket.SocketImpl; 17 | import io.github.efekurbann.synccommands.objects.server.MQServer; 18 | import io.github.efekurbann.synccommands.objects.server.Server; 19 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 20 | import io.github.efekurbann.synccommands.scheduler.impl.BukkitScheduler; 21 | import io.github.efekurbann.synccommands.util.UpdateChecker; 22 | import org.bstats.bukkit.Metrics; 23 | import org.bukkit.ChatColor; 24 | import org.bukkit.entity.Player; 25 | import org.bukkit.event.EventHandler; 26 | import org.bukkit.event.Listener; 27 | import org.bukkit.event.player.PlayerJoinEvent; 28 | import org.bukkit.plugin.java.JavaPlugin; 29 | import org.jetbrains.annotations.NotNull; 30 | 31 | import java.util.*; 32 | import java.util.concurrent.TimeUnit; 33 | 34 | public final class SyncCommandsSpigot extends JavaPlugin { 35 | 36 | private final Config config = new Config(this, "config.yml"); 37 | private final ConsoleExecutor consoleExecutor = new BukkitExecutor(this); 38 | private final Map servers = new HashMap<>(); 39 | private final Map> groups = new HashMap<>(); 40 | // we will store the names instead of uuids 41 | private final Cache autoSyncMode = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); 42 | private final Scheduler scheduler = new BukkitScheduler(this); 43 | private final Logger logger = new BukkitLogger(this); 44 | private UpdateChecker updateChecker; 45 | private Messaging messaging; 46 | private Server server; 47 | private boolean connectedSuccessfully; 48 | 49 | @Override 50 | public void onEnable() { 51 | config.create(); 52 | 53 | this.getLogger().info("Creating connection..."); 54 | 55 | ConnectionType type; 56 | try { 57 | type = ConnectionType.valueOf(this.getConfig().getString("connection.type", "socket") 58 | .toUpperCase(Locale.ENGLISH)); 59 | } catch (IllegalArgumentException exception) { 60 | this.getLogger().info("Invalid connection type detected! Valid types: Redis, RabbitMQ, Socket"); 61 | this.getServer().getPluginManager().disablePlugin(this); 62 | return; 63 | } 64 | 65 | if (!this.connect(type)) return; 66 | 67 | this.getLogger().info("Setting up servers..."); 68 | setupServers(type); 69 | 70 | this.getLogger().info("Setting up groups..."); 71 | setupGroups(); 72 | 73 | this.getCommand("sync").setExecutor(new SyncCommand(this)); 74 | this.getServer().getPluginManager().registerEvents(new CommandListener(this), this); 75 | 76 | new Metrics(this, 14138); 77 | 78 | (updateChecker = new UpdateChecker(this.getDescription().getVersion(), logger, scheduler)).checkUpdates(); 79 | 80 | this.getServer().getPluginManager().registerEvents(new Listener() { 81 | @EventHandler 82 | public void onJoin(PlayerJoinEvent event) { 83 | Player player = event.getPlayer(); 84 | 85 | if (!player.hasPermission("synccommands.admin")) return; 86 | 87 | if (!updateChecker.isUpToDate()) { 88 | player.sendMessage(ChatColor.GOLD + "[SyncCommands]" + ChatColor.YELLOW + " An update was found!"); 89 | player.sendMessage(ChatColor.GOLD + "[SyncCommands]" + ChatColor.YELLOW + 90 | " Download from: https://www.spigotmc.org/resources/99596"); 91 | } 92 | } 93 | }, this); 94 | 95 | this.getLogger().info("Everything seems good. Plugin enabled!"); 96 | } 97 | 98 | @Override 99 | public void onDisable() { 100 | if (connectedSuccessfully) 101 | this.messaging.close(); 102 | } 103 | 104 | private boolean connect(ConnectionType type) { 105 | if (type != ConnectionType.RABBITMQ) { 106 | this.server = new Server( 107 | this.getConfig().getString("serverName"), 108 | this.getConfig().getString("connection.host"), 109 | this.getConfig().getInt("connection.port"), 110 | this.getConfig().getString("connection.password"), 111 | this.getConfig().getBoolean("connection.secure")); 112 | } else { 113 | this.server = new MQServer( 114 | this.getConfig().getString("serverName"), 115 | this.getConfig().getString("connection.host"), 116 | this.getConfig().getInt("connection.port"), 117 | this.getConfig().getString("connection.password"), 118 | this.getConfig().getBoolean("connection.secure"), 119 | this.getConfig().getString("connection.username"), 120 | this.getConfig().getString("connection.vhost")); 121 | } 122 | 123 | switch (type) { 124 | case SOCKET: 125 | this.messaging = new SocketImpl(server, consoleExecutor, logger, scheduler); 126 | break; 127 | case REDIS: 128 | this.messaging = new Redis(server, consoleExecutor, logger, scheduler); 129 | break; 130 | case RABBITMQ: 131 | this.messaging = new RabbitMQ(server, consoleExecutor, logger, scheduler); 132 | break; 133 | } 134 | 135 | // this may not be the best solution, but I just don't want people to see those ugly exceptions 136 | try { 137 | this.messaging.connect( 138 | server.getHost(), 139 | server.getPort(), 140 | server.getPassword(), 141 | server.isSecure() 142 | ); 143 | 144 | this.getLogger().info("Setting up message listeners..."); 145 | 146 | if (type != ConnectionType.RABBITMQ) // no need to call the method twice 147 | this.messaging.addListeners(); 148 | 149 | this.connectedSuccessfully = true; 150 | } catch (Exception ex) { 151 | this.getLogger().info("Something went wrong! We could not setup a connection!"); 152 | this.getLogger().info("Please fix your configuration! Plugin disabling..."); 153 | this.getLogger().info("Exception message: " + ex.getMessage()); 154 | this.getServer().getPluginManager().disablePlugin(this); 155 | this.connectedSuccessfully = false; 156 | } 157 | 158 | return this.connectedSuccessfully; 159 | } 160 | 161 | private void setupServers(ConnectionType type) { 162 | if (this.getConfig().getConfigurationSection("servers") == null) return; 163 | 164 | for (String key : getConfig().getConfigurationSection("servers").getKeys(false)) { 165 | Server s; 166 | if (type != ConnectionType.RABBITMQ) { 167 | s = new Server( 168 | key, 169 | getConfig().getString("servers." + key + ".host"), 170 | getConfig().getInt("servers." + key + ".port"), 171 | getConfig().getString("servers." + key + ".password"), 172 | getConfig().getBoolean("servers." + key + ".secure")); 173 | } else { 174 | s = new MQServer( 175 | key, 176 | getConfig().getString("servers." + key + ".host"), 177 | getConfig().getInt("servers." + key + ".port"), 178 | getConfig().getString("servers." + key + ".password"), 179 | getConfig().getBoolean("servers." + key + ".secure"), 180 | getConfig().getString("servers." + key + ".username"), 181 | getConfig().getString("servers." + key + ".vhost")); 182 | } 183 | this.servers.put(key, s); 184 | } 185 | 186 | this.servers.put(this.server.getServerName(), this.server); 187 | } 188 | 189 | private void setupGroups() { 190 | if (getConfig().getConfigurationSection("groups") == null) return; 191 | 192 | for (String key : getConfig().getConfigurationSection("groups").getKeys(false)) { 193 | Set servers = new HashSet<>(); 194 | 195 | for (String server : getConfig().getStringList("groups." + key)) { 196 | servers.add(this.servers.get(server)); 197 | } 198 | 199 | this.groups.put(key, servers); 200 | } 201 | } 202 | 203 | @NotNull 204 | @Override 205 | public Config getConfig() { 206 | return config; 207 | } 208 | 209 | public Map getServers() { 210 | return servers; 211 | } 212 | 213 | @NotNull 214 | public Server getThisServer() { 215 | return server; 216 | } 217 | 218 | public Messaging getMessaging() { 219 | return messaging; 220 | } 221 | 222 | public Scheduler getScheduler() { 223 | return scheduler; 224 | } 225 | 226 | public Map> getGroups() { 227 | return groups; 228 | } 229 | 230 | public Cache getAutoSyncMode() { 231 | return autoSyncMode; 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /synccommands-velocity/src/main/java/io/github/efekurbann/synccommands/SyncCommandsVelocity.java: -------------------------------------------------------------------------------- 1 | package io.github.efekurbann.synccommands; 2 | 3 | import com.google.common.cache.Cache; 4 | import com.google.common.cache.CacheBuilder; 5 | import com.google.common.reflect.TypeToken; 6 | import com.google.inject.Inject; 7 | import com.velocitypowered.api.command.CommandMeta; 8 | import com.velocitypowered.api.event.Subscribe; 9 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 10 | import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; 11 | import com.velocitypowered.api.plugin.Plugin; 12 | import com.velocitypowered.api.plugin.PluginDescription; 13 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 14 | import com.velocitypowered.api.proxy.ProxyServer; 15 | import io.github.efekurbann.synccommands.command.VSyncCommand; 16 | import io.github.efekurbann.synccommands.config.Config; 17 | import io.github.efekurbann.synccommands.enums.ConnectionType; 18 | import io.github.efekurbann.synccommands.executor.ConsoleExecutor; 19 | import io.github.efekurbann.synccommands.executor.impl.VelocityExecutor; 20 | import io.github.efekurbann.synccommands.logging.Logger; 21 | import io.github.efekurbann.synccommands.logging.impl.VelocityLogger; 22 | import io.github.efekurbann.synccommands.messaging.Messaging; 23 | import io.github.efekurbann.synccommands.messaging.impl.rabbitmq.RabbitMQ; 24 | import io.github.efekurbann.synccommands.messaging.impl.redis.Redis; 25 | import io.github.efekurbann.synccommands.messaging.impl.socket.SocketImpl; 26 | import io.github.efekurbann.synccommands.objects.server.MQServer; 27 | import io.github.efekurbann.synccommands.objects.server.Server; 28 | import io.github.efekurbann.synccommands.scheduler.Scheduler; 29 | import io.github.efekurbann.synccommands.scheduler.impl.VelocityScheduler; 30 | import io.github.efekurbann.synccommands.util.UpdateChecker; 31 | import ninja.leaping.configurate.ConfigurationNode; 32 | import ninja.leaping.configurate.objectmapping.ObjectMappingException; 33 | import org.bstats.velocity.Metrics; 34 | 35 | import java.nio.file.Path; 36 | import java.nio.file.Paths; 37 | import java.util.*; 38 | import java.util.concurrent.TimeUnit; 39 | 40 | @Plugin( 41 | id = "synccommands", 42 | name = "SyncCommands", 43 | version = "4.0.1", // I really need to find a better way to do this... I forget to change this one all the time 44 | url = "https://efekurbann.github.io", 45 | description = "Best Command Synchronization Plugin in the market.", 46 | authors = {"hyperion"} 47 | ) 48 | public class SyncCommandsVelocity { 49 | 50 | private final ProxyServer proxyServer; 51 | private final org.slf4j.Logger pluginLogger; 52 | private final Path dataDirectory; 53 | private final Metrics.Factory metricsFactory; 54 | private final PluginDescription description; 55 | private final ConsoleExecutor consoleExecutor = new VelocityExecutor(this); 56 | private final Map servers = new HashMap<>(); 57 | private final Map> groups = new HashMap<>(); 58 | private final Scheduler scheduler = new VelocityScheduler(this); 59 | private final Cache autoSyncMode = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); 60 | 61 | private Messaging messaging; 62 | private Server server; 63 | private boolean connectedSuccessfully; 64 | private Logger logger; 65 | 66 | private Config config; 67 | 68 | @Inject 69 | public SyncCommandsVelocity(ProxyServer server, org.slf4j.Logger logger, @DataDirectory Path dataDirectory, 70 | Metrics.Factory metricsFactory, PluginDescription description) { 71 | this.proxyServer = server; 72 | this.pluginLogger = logger; 73 | this.dataDirectory = dataDirectory; 74 | this.metricsFactory = metricsFactory; 75 | this.description = description; 76 | } 77 | 78 | @Subscribe 79 | public void onProxyInitialization(ProxyInitializeEvent event) { 80 | config = new Config(this, Paths.get(dataDirectory.toString(), "config.yml")); 81 | config.create(); 82 | 83 | this.logger = new VelocityLogger(pluginLogger); 84 | 85 | this.getLogger().info("Creating connection..."); 86 | 87 | ConnectionType type; 88 | try { 89 | type = ConnectionType.valueOf(this.getConfig().getRoot().getNode("connection", "type") 90 | .getString().toUpperCase(Locale.ENGLISH)); 91 | } catch (IllegalArgumentException exception) { 92 | this.getLogger().info("Invalid connection type detected! Valid types: Redis, RabbitMQ, Socket"); 93 | return; 94 | } 95 | 96 | if (!this.connect(type)) return; 97 | 98 | this.getLogger().info("Setting up servers..."); 99 | setupServers(type); 100 | 101 | this.getLogger().info("Setting up groups..."); 102 | setupGroups(); 103 | 104 | metricsFactory.make(this, 15759); 105 | 106 | new UpdateChecker(description.getVersion().orElse("unknown"), logger, scheduler).checkUpdates(); 107 | 108 | CommandMeta meta = proxyServer.getCommandManager().metaBuilder("vsync").build(); 109 | proxyServer.getCommandManager().register(meta, new VSyncCommand(this)); 110 | 111 | this.getLogger().info("Everything seems good. Plugin enabled!"); 112 | } 113 | 114 | @Subscribe 115 | public void onProxyShutdown(ProxyShutdownEvent event) { 116 | if (connectedSuccessfully) 117 | this.messaging.close(); 118 | } 119 | 120 | private boolean connect(ConnectionType type) { 121 | if (type != ConnectionType.RABBITMQ) { 122 | this.server = new Server( 123 | this.getConfig().getRoot().getNode("serverName").getString(), 124 | this.getConfig().getRoot().getNode("connection", "host").getString(), 125 | this.getConfig().getRoot().getNode("connection", "port").getInt(), 126 | this.getConfig().getRoot().getNode("connection", "password").getString(), 127 | this.getConfig().getRoot().getNode("connection", "secure").getBoolean()); 128 | } else { 129 | this.server = new MQServer( 130 | this.getConfig().getRoot().getNode("serverName").getString(), 131 | this.getConfig().getRoot().getNode("connection", "host").getString(), 132 | this.getConfig().getRoot().getNode("connection", "port").getInt(), 133 | this.getConfig().getRoot().getNode("connection", "password").getString(), 134 | this.getConfig().getRoot().getNode("connection", "secure").getBoolean(), 135 | this.getConfig().getRoot().getNode("connection", "username").getString(), 136 | this.getConfig().getRoot().getNode("connection", "vhost").getString()); 137 | } 138 | 139 | switch (type) { 140 | case SOCKET: 141 | this.messaging = new SocketImpl(server, consoleExecutor, logger, scheduler); 142 | break; 143 | case REDIS: 144 | this.messaging = new Redis(server, consoleExecutor, logger, scheduler); 145 | break; 146 | case RABBITMQ: 147 | this.messaging = new RabbitMQ(server, consoleExecutor, logger, scheduler); 148 | break; 149 | } 150 | 151 | // this may not be the best solution, but I just don't want people to see those ugly exceptions 152 | try { 153 | this.messaging.connect( 154 | server.getHost(), 155 | server.getPort(), 156 | server.getPassword(), 157 | server.isSecure() 158 | ); 159 | 160 | this.getLogger().info("Setting up message listeners..."); 161 | 162 | if (type != ConnectionType.RABBITMQ) // no need to call the method twice 163 | this.messaging.addListeners(); 164 | 165 | this.connectedSuccessfully = true; 166 | } catch (Exception ex) { 167 | this.getLogger().info("Something went wrong! We could not setup a connection!"); 168 | this.getLogger().info("Please fix your configuration! Plugin disabling..."); 169 | this.getLogger().info("Exception message: " + ex.getMessage()); 170 | this.connectedSuccessfully = false; 171 | } 172 | 173 | return this.connectedSuccessfully; 174 | } 175 | 176 | private void setupServers(ConnectionType type) { 177 | for (Map.Entry node : 178 | this.getConfig().getRoot().getNode("servers").getChildrenMap().entrySet()) { 179 | Server s; 180 | if (type != ConnectionType.RABBITMQ) { 181 | s = new Server( 182 | (String) node.getKey(), 183 | node.getValue().getNode("host").getString(), 184 | node.getValue().getNode("port").getInt(), 185 | node.getValue().getNode("password").getString(), 186 | node.getValue().getNode("secure").getBoolean()); 187 | } else { 188 | s = new MQServer( 189 | (String) node.getKey(), 190 | node.getValue().getNode("host").getString(), 191 | node.getValue().getNode("port").getInt(), 192 | node.getValue().getNode("password").getString(), 193 | node.getValue().getNode("secure").getBoolean(), 194 | node.getValue().getNode("username").getString(), 195 | node.getValue().getNode("vhost").getString()); 196 | } 197 | this.servers.put((String) node.getKey(), s); 198 | } 199 | 200 | this.servers.put(this.server.getServerName(), this.server); 201 | } 202 | 203 | private void setupGroups() { 204 | for (Map.Entry node : 205 | this.getConfig().getRoot().getNode("groups").getChildrenMap().entrySet()) { 206 | Set servers = new HashSet<>(); 207 | 208 | try { 209 | for (String s : node.getValue().getList(TypeToken.of(String.class))) { 210 | servers.add(this.servers.get(s)); 211 | } 212 | } catch (ObjectMappingException e) { 213 | e.printStackTrace(); 214 | } 215 | 216 | this.groups.put((String) node.getKey(), servers); 217 | } 218 | } 219 | 220 | public Map getServers() { 221 | return servers; 222 | } 223 | 224 | public Cache getAutoSyncMode() { 225 | return autoSyncMode; 226 | } 227 | 228 | public Map> getGroups() { 229 | return groups; 230 | } 231 | 232 | public Server getServer() { 233 | return server; 234 | } 235 | 236 | public ProxyServer getProxyServer() { 237 | return proxyServer; 238 | } 239 | 240 | public Config getConfig() { 241 | return config; 242 | } 243 | 244 | public Logger getLogger() { 245 | return logger; 246 | } 247 | 248 | public Path getDataDirectory() { 249 | return dataDirectory; 250 | } 251 | 252 | public Messaging getMessaging() { 253 | return messaging; 254 | } 255 | } 256 | --------------------------------------------------------------------------------