Improvements
This commit is contained in:
parent
234e25396c
commit
8d16142c4e
@ -12,8 +12,8 @@ This plugin adds the support for [Velocity](https://velocitypowered.com/) to [Au
|
|||||||
3. Put the jar that ends with "-spigot" in the Spigot servers that contains AuthMe
|
3. Put the jar that ends with "-spigot" in the Spigot servers that contains AuthMe
|
||||||
4. Start the Velocity proxy and set up the config.yml with the auth servers
|
4. Start the Velocity proxy and set up the config.yml with the auth servers
|
||||||
|
|
||||||
# Plugin API
|
## Plugin API
|
||||||
Check the plugin API [here](https://github.com/4drian3d/AuthMeVelocity/wiki/Plugin-API)
|
Check the plugin API [here](https://github.com/4drian3d/AuthMeVelocity/wiki/Plugin-API)
|
||||||
|
|
||||||
# Configuration
|
## Configuration
|
||||||
Check the plugin configuration [here](https://github.com/4drian3d/AuthMeVelocity/wiki/Configuration)
|
Check the plugin configuration [here](https://github.com/4drian3d/AuthMeVelocity/wiki/Configuration)
|
@ -1,6 +1,5 @@
|
|||||||
package com.glyart.authmevelocity.proxy.config;
|
package com.glyart.authmevelocity.proxy.config;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -26,9 +25,9 @@ public class AuthMeConfig {
|
|||||||
.header(HEADER)
|
.header(HEADER)
|
||||||
);
|
);
|
||||||
public static void loadConfig(@NotNull Path path, @NotNull Logger logger){
|
public static void loadConfig(@NotNull Path path, @NotNull Logger logger){
|
||||||
File configFile = new File(path.toFile(), "config.conf");
|
Path configPath = path.resolve("config.conf");
|
||||||
final HoconConfigurationLoader loader = configBuilder
|
final HoconConfigurationLoader loader = configBuilder
|
||||||
.file(configFile)
|
.path(configPath)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,7 @@ import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
|||||||
import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent;
|
import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent;
|
||||||
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.EventTask;
|
import com.velocitypowered.api.event.EventTask;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||||
@ -24,7 +25,6 @@ import org.slf4j.Logger;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class ProxyListener {
|
public class ProxyListener {
|
||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
@ -40,35 +40,39 @@ public class ProxyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPluginMessage(final PluginMessageEvent event) {
|
public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) {
|
||||||
if (!(event.getSource() instanceof ServerConnection) || !event.getIdentifier().getId().equals("authmevelocity:main"))
|
if (!(event.getSource() instanceof ServerConnection connection) || !event.getIdentifier().getId().equals("authmevelocity:main")){
|
||||||
return;
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ByteArrayDataInput input = event.dataAsDataStream();
|
ByteArrayDataInput input = event.dataAsDataStream();
|
||||||
String sChannel = input.readUTF();
|
final String sChannel = input.readUTF();
|
||||||
if (!sChannel.equals("LOGIN")) return;
|
if (!sChannel.equals("LOGIN")) {
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String user = input.readUTF();
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
Optional<Player> optionalPlayer = proxy.getPlayer(UUID.fromString(user));
|
//TODO: Test this
|
||||||
if (optionalPlayer.isEmpty()) return;
|
final Player loggedPlayer = connection.getPlayer();
|
||||||
|
|
||||||
Player loggedPlayer = optionalPlayer.get();
|
|
||||||
if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){
|
if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){
|
||||||
createServerConnectionRequest(loggedPlayer, config, proxy, logger);
|
createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection);
|
||||||
|
continuation.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger){
|
private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){
|
||||||
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElseThrow().getServer();
|
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
|
||||||
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer, loginServer));
|
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer, loginServer));
|
||||||
if(config.getToServerOptions().sendToServer()){
|
if(config.getToServerOptions().sendToServer()){
|
||||||
final List<String> serverList = config.getToServerOptions().getTeleportServers();
|
final List<String> serverList = config.getToServerOptions().getTeleportServers();
|
||||||
final String randomServer = serverList.get(rm.nextInt(serverList.size()));
|
final String randomServer = serverList.get(rm.nextInt(serverList.size()));
|
||||||
Optional<RegisteredServer> optionalServer = proxy.getServer(randomServer);
|
Optional<RegisteredServer> optionalServer = proxy.getServer(randomServer);
|
||||||
optionalServer.ifPresentOrElse(serverToSend ->
|
optionalServer.ifPresentOrElse(serverToSend ->
|
||||||
proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAccept(preSendEvent -> {
|
proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAcceptAsync(preSendEvent -> {
|
||||||
if(preSendEvent.getResult().isAllowed()){
|
if(preSendEvent.getResult().isAllowed()){
|
||||||
loggedPlayer.createConnectionRequest(serverToSend).connect().thenAccept(result -> {
|
loggedPlayer.createConnectionRequest(serverToSend).connect().thenAcceptAsync(result -> {
|
||||||
if(!result.isSuccessful()) {
|
if(!result.isSuccessful()) {
|
||||||
logger.info("Unable to connect the player {} to the server {}",
|
logger.info("Unable to connect the player {} to the server {}",
|
||||||
loggedPlayer.getUsername(),
|
loggedPlayer.getUsername(),
|
||||||
@ -101,12 +105,16 @@ public class ProxyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPlayerChat(final PlayerChatEvent event) {
|
public void onPlayerChat(final PlayerChatEvent event, Continuation continuation) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (AuthmeVelocityAPI.isLogged(player)) return;
|
if (AuthmeVelocityAPI.isLogged(player)) {
|
||||||
|
continuation.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Optional<ServerConnection> server = player.getCurrentServer();
|
Optional<ServerConnection> server = player.getCurrentServer();
|
||||||
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) {
|
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) {
|
||||||
|
continuation.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +135,7 @@ public class ProxyListener {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public EventTask onTabComplete(TabCompleteEvent event){
|
public EventTask onTabComplete(TabCompleteEvent event){
|
||||||
final Player player = event.getPlayer();
|
if (!AuthmeVelocityAPI.isLogged(event.getPlayer())){
|
||||||
if (!AuthmeVelocityAPI.isLogged(player)){
|
|
||||||
return EventTask.async(() -> event.getSuggestions().clear());
|
return EventTask.async(() -> event.getSuggestions().clear());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -19,7 +19,6 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
|
|||||||
public void sendLoginToProxy(@NotNull final Player player) {
|
public void sendLoginToProxy(@NotNull final Player player) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("LOGIN");
|
out.writeUTF("LOGIN");
|
||||||
out.writeUTF(player.getUniqueId().toString());
|
|
||||||
|
|
||||||
player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray());
|
player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.glyart.authmevelocity.spigot.events;
|
package com.glyart.authmevelocity.spigot.events;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -10,8 +11,8 @@ public class PreSendLoginEvent extends PlayerEvent implements Cancellable {
|
|||||||
private static final HandlerList HANDLERS = new HandlerList();
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
|
|
||||||
public PreSendLoginEvent(@NotNull final Player player, boolean async) {
|
public PreSendLoginEvent(@NotNull final Player player) {
|
||||||
super(player, async);
|
super(player, !Bukkit.isPrimaryThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,9 +18,9 @@ public class AuthMeListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLogin(LoginEvent event) {
|
public void onLogin(final LoginEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player, false);
|
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player);
|
||||||
Bukkit.getPluginManager().callEvent(preSendLoginEvent);
|
Bukkit.getPluginManager().callEvent(preSendLoginEvent);
|
||||||
if(!preSendLoginEvent.isCancelled()){
|
if(!preSendLoginEvent.isCancelled()){
|
||||||
plugin.sendLoginToProxy(player);
|
plugin.sendLoginToProxy(player);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user