Search in sources :

Example 6 with ProxyServer

use of com.velocitypowered.api.proxy.ProxyServer in project LuckPerms by lucko.

the class VelocityCommandExecutor method register.

public void register() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getCommandManager().register(PRIMARY_ALIAS, this, ALIASES);
    // register slash aliases so the console can run '/lpv' in the same way as 'lpv'.
    proxy.getCommandManager().register(SLASH_PRIMARY_ALIAS, new ForwardingCommand(this) {

        @Override
        public boolean hasPermission(Invocation invocation) {
            return invocation.source() instanceof ConsoleCommandSource;
        }
    }, SLASH_ALIASES);
}
Also used : ConsoleCommandSource(com.velocitypowered.api.proxy.ConsoleCommandSource) ProxyServer(com.velocitypowered.api.proxy.ProxyServer)

Example 7 with ProxyServer

use of com.velocitypowered.api.proxy.ProxyServer in project LuckPerms by lucko.

the class PluginMessageMessenger method init.

public void init() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getChannelRegistrar().register(CHANNEL);
    proxy.getEventManager().register(this.plugin.getBootstrap(), this);
}
Also used : ProxyServer(com.velocitypowered.api.proxy.ProxyServer)

Example 8 with ProxyServer

use of com.velocitypowered.api.proxy.ProxyServer in project LuckPerms by lucko.

the class PluginMessageMessenger method close.

@Override
public void close() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getChannelRegistrar().unregister(CHANNEL);
    proxy.getEventManager().unregisterListener(this.plugin.getBootstrap(), this);
}
Also used : ProxyServer(com.velocitypowered.api.proxy.ProxyServer)

Example 9 with ProxyServer

use of com.velocitypowered.api.proxy.ProxyServer in project LibertyBans by A248.

the class VelocityCulpritFinderTest method findCulprit.

@Test
public void findCulprit(@Mock ProxyServer server, @Mock PluginManager pluginManager, @Mock PluginContainer pluginString, @Mock PluginContainer pluginOwnClass) {
    class OwnClass {
    }
    {
        when(server.getPluginManager()).thenReturn(pluginManager);
        when(pluginManager.getPlugins()).thenReturn(List.of(pluginString, pluginOwnClass));
        when(pluginString.getInstance()).thenAnswer((i) -> Optional.of("a".concat("b")));
        setDescription(pluginString, "JDK", "0");
        when(pluginOwnClass.getInstance()).thenAnswer((i) -> Optional.of(new OwnClass()));
        setDescription(pluginOwnClass, "Self", "1");
    }
    CulpritFinder culpritFinder = new VelocityCulpritFinder(server);
    assertEquals("JDK 0", culpritFinder.findCulprit(List.class));
    assertEquals("Self 1", culpritFinder.findCulprit(getClass()));
}
Also used : MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CulpritFinder(space.arim.libertybans.bootstrap.CulpritFinder) PluginDescription(com.velocitypowered.api.plugin.PluginDescription) Mock(org.mockito.Mock) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Optional(java.util.Optional) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PluginManager(com.velocitypowered.api.plugin.PluginManager) Mockito.mock(org.mockito.Mockito.mock) CulpritFinder(space.arim.libertybans.bootstrap.CulpritFinder) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 10 with ProxyServer

use of com.velocitypowered.api.proxy.ProxyServer in project CommandSyncServer by Wind-Development.

the class SyncConnection method startConnection.

/**
 * Starts the connection
 *
 * @param clientSocket The client's socket
 */
public void startConnection(Socket clientSocket) {
    SyncPlugin.getInstance().getLogger().info("New connection from " + this.connectionName + " established.");
    // Initializes a new connection from a client
    Runnable connectionRunnable = (() -> {
        try {
            // The connected client's input
            BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            // Output for communication with client
            PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);
            // Handle keep alives
            startKeepAliveHandler();
            // Handle client messages
            String clientInput;
            while (true) {
                clientInput = in.readLine();
                // Exit connection if keep alive has expired
                if (hasUnregistered) {
                    break;
                }
                // Exit connection if told to do so by the client
                if (clientInput.equalsIgnoreCase(".")) {
                    closeConnection();
                    break;
                } else if (clientInput.toLowerCase().contains("name ")) {
                    String finalName = clientInput.toLowerCase().replace("name ", "");
                    SyncConnection.this.connectionName = finalName;
                } else if (clientInput.equalsIgnoreCase("keep alive packet")) {
                    keepAliveTimeOutTime = 100;
                } else if (clientInput.toLowerCase().contains("run command ")) {
                    String processCommand = clientInput.toLowerCase().replace("run command ", "");
                    ProxyServer server = SyncPlugin.getInstance().getServer();
                    SyncPlugin.getInstance().getLogger().info("received command " + processCommand);
                    server.getCommandManager().executeAsync(server.getConsoleCommandSource(), processCommand);
                    SyncPlugin.getInstance().getLogger().info("ran command " + processCommand);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    // Start the connection with the client on its own thread
    connectionPool.execute(connectionRunnable);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) ProxyServer(com.velocitypowered.api.proxy.ProxyServer)

Aggregations

ProxyServer (com.velocitypowered.api.proxy.ProxyServer)10 PluginContainer (com.velocitypowered.api.plugin.PluginContainer)3 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 Logger (org.slf4j.Logger)2 PluginDescription (com.velocitypowered.api.plugin.PluginDescription)1 PluginManager (com.velocitypowered.api.plugin.PluginManager)1 ConsoleCommandSource (com.velocitypowered.api.proxy.ConsoleCommandSource)1 Player (com.velocitypowered.api.proxy.Player)1 Scheduler (com.velocitypowered.api.scheduler.Scheduler)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Executor (java.util.concurrent.Executor)1 ChatRegulator (me.dreamerzero.chatregulator.ChatRegulator)1