Ambassador
Ambassador copied to clipboard
Realized why AuthMeVelocity Doesnt Support Ambassador you don't have API
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:
-
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.
-
Implement the interface in your
Ambassadorclass and register an instance of this class as a service that other plugins can access.
Here's how you can do it:
- 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();
}
- Implement the interface in your
Ambassadorclass:
import org.adde0109.ambassador.api.AmbassadorAPI;
public class Ambassador implements AmbassadorAPI {
// Existing code...
@Override
public Map<String, RegisteredServer> getTemporaryForced() {
return TEMPORARY_FORCED;
}
// Existing code...
}
- Register an instance of your
Ambassadorclass as a service in yourAmbassadorplugin'sonProxyInitializationmethod:
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...
}
- Another plugin can now retrieve the
MapWithExpirationhashmap from yourAmbassadorplugin 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..
@adde0109 your more then welcome to compile these and include them as your own just give proper references where needed for AuthMeVelocity code usage is all! https://github.com/john1234brown/Ambassador https://github.com/john1234brown/NexAuth-spigot
I've done this with the NextAuth Plugin instead using the same setup as AuthMeVelocity it is worth note trying to do it for AuthMe support for others who would like to use this with authMe rather than my version and setup!
Make a PR please