Skip to content

Realized why AuthMeVelocity Doesnt Support Ambassador you don't have API #55

@ghost

Description

To allow another Velocity plugin to access the MapWithExpiration hashmap in your Ambassador plugin, you can create an API that provides a way for other plugins to interact with it. Here's a basic example of how you can create such an API:

  1. Define an interface that exposes the functionality you want to provide to other plugins. This interface should be placed in a separate package to ensure it's accessible to other plugins.

  2. Implement the interface in your Ambassador class and register an instance of this class as a service that other plugins can access.

Here's how you can do it:

  1. Define the interface in a new package (e.g., org.adde0109.ambassador.api):
package org.adde0109.ambassador.api;

import org.adde0109.ambassador.Ambassador;

import java.util.Map;

public interface AmbassadorAPI {
    Map<String, Ambassador.RegisteredServer> getTemporaryForced();
}
  1. Implement the interface in your Ambassador class:
import org.adde0109.ambassador.api.AmbassadorAPI;

public class Ambassador implements AmbassadorAPI {

    // Existing code...

    @Override
    public Map<String, RegisteredServer> getTemporaryForced() {
        return TEMPORARY_FORCED;
    }

    // Existing code...
}
  1. Register an instance of your Ambassador class as a service in your Ambassador plugin's onProxyInitialization method:
import com.velocitypowered.api.plugin.PluginManager;

public class Ambassador {

    // Existing code...

    @Inject
    public Ambassador(ProxyServer server, PluginManager pluginManager, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
        this.server = server;
        this.logger = logger;
        this.dataDirectory = dataDirectory;
        this.metricsFactory = metricsFactory;
        Ambassador.instance = this;

        // Register the API
        pluginManager.registerService(AmbassadorAPI.class, this, this.server, PluginContainer.MINECRAFT);
    }

    // Existing code...
}
  1. Another plugin can now retrieve the MapWithExpiration hashmap from your Ambassador plugin like this:
import org.adde0109.ambassador.api.AmbassadorAPI;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.plugin.PluginContainer;

public class YourPlugin {

    private final AmbassadorAPI ambassadorAPI;

    public YourPlugin(ProxyServer server, PluginContainer pluginContainer) {
        this.ambassadorAPI = server.getServices().get(AmbassadorAPI.class).get();
    }

    public void someMethod() {
        // Access the TEMPORARY_FORCED hashmap
        Map<String, RegisteredServer> temporaryForced = ambassadorAPI.getTemporaryForced();
        // Use the hashmap as needed
    }
}

By following these steps, you can create an API for your Ambassador plugin that allows other Velocity plugins to access the MapWithExpiration hashmap.

By allowing access to at least this HashMap will allow the authme plugins to properly bypass authorization for when users are being sent to modded servers as they require the ambassador plugin to disconnect them and reconnect bypassing the authorization hub so doing this will still be secure will ensuring they properly logged in on the lobby to go to the modded server before hand etc..

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions