almost done :)
This commit is contained in:
+1
-2
@@ -64,8 +64,7 @@ public class VelocityMethods implements PlatformMethods {
|
||||
Optional<PluginContainer> plugin = proxyServer.getPluginManager().getPlugin("ajqueue");
|
||||
if(!plugin.isPresent()) return "?E";
|
||||
Optional<String> version = plugin.get().getDescription().getVersion();
|
||||
if(!version.isPresent()) return "?V";
|
||||
return version.get();
|
||||
return version.orElse("?V");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+24
-5
@@ -5,6 +5,7 @@ import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
@@ -13,6 +14,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||
@@ -22,14 +24,16 @@ import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
||||
import us.ajg0702.queue.platforms.velocity.server.ServerBuilderImpl;
|
||||
import us.ajg0702.queue.platforms.velocity.server.VelocityServerBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import us.ajg0702.queue.platforms.velocity.server.VelocityServer;
|
||||
|
||||
@Plugin(
|
||||
id = "ajqueue",
|
||||
@@ -65,7 +69,7 @@ public class VelocityQueue {
|
||||
new VelocityMethods(this, proxyServer, logger),
|
||||
dataFolder
|
||||
);
|
||||
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
||||
main.setServerBuilder(new VelocityServerBuilder(main, proxyServer));
|
||||
|
||||
commands = Arrays.asList(
|
||||
new QueueCommand(main),
|
||||
@@ -101,7 +105,6 @@ public class VelocityQueue {
|
||||
|
||||
if(e.getIdentifier().getId().equals("ajqueue:tospigot")) {
|
||||
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
||||
return;
|
||||
}
|
||||
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
|
||||
@@ -115,12 +118,28 @@ public class VelocityQueue {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@Subscribe
|
||||
public void onJoin(ServerPostConnectEvent e) {
|
||||
if(e.getPreviousServer() != null) return; // only run if the player just joined
|
||||
main.getEventHandler().onPlayerJoin(new VelocityPlayer(e.getPlayer()));
|
||||
if(e.getPreviousServer() != null) { // only run if the player just joined
|
||||
main.getEventHandler().onPlayerJoin(new VelocityPlayer(e.getPlayer()));
|
||||
}
|
||||
main.getEventHandler().onPlayerJoinServer(new VelocityPlayer(e.getPlayer()));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLeave(DisconnectEvent e) {
|
||||
main.getEventHandler().onPlayerLeave(new VelocityPlayer(e.getPlayer()));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKick(KickedFromServerEvent e) {
|
||||
if(!e.getPlayer().getCurrentServer().isPresent()) return; // if the player is kicked on initial join, we dont care
|
||||
Optional<Component> reasonOptional = e.getServerKickReason();
|
||||
main.getEventHandler().onServerKick(
|
||||
new VelocityPlayer(e.getPlayer()),
|
||||
new VelocityServer(e.getServer()),
|
||||
reasonOptional.orElseGet(() -> Component.text("Proxy lost connection")),
|
||||
// According to Tux on discord, velocity doesnt give a reason when the proxy loses connection to the connected server
|
||||
e.kickedDuringServerConnect()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-2
@@ -10,8 +10,6 @@ import java.util.List;
|
||||
|
||||
public class VelocityCommand implements RawCommand {
|
||||
|
||||
|
||||
|
||||
final QueueMain main;
|
||||
final BaseCommand command;
|
||||
|
||||
|
||||
+13
-1
@@ -9,6 +9,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -63,7 +64,18 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
@Override
|
||||
public void connect(AdaptedServer server) {
|
||||
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
|
||||
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect().thenAcceptAsync(
|
||||
result -> {
|
||||
if(!result.isSuccessful()) {
|
||||
QueueMain.getInstance().getEventHandler().onServerKick(
|
||||
this,
|
||||
server,
|
||||
result.getReasonComponent().orElseGet(() -> Component.text("Connection failed")),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-7
@@ -13,11 +13,11 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ServerBuilderImpl implements ServerBuilder {
|
||||
public class VelocityServerBuilder implements ServerBuilder {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
private final QueueMain main;
|
||||
public ServerBuilderImpl(QueueMain main, ProxyServer proxyServer) {
|
||||
public VelocityServerBuilder(QueueMain main, ProxyServer proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
this.main = main;
|
||||
}
|
||||
@@ -35,15 +35,11 @@ public class ServerBuilderImpl implements ServerBuilder {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalIsPresent")
|
||||
@Override
|
||||
public AdaptedServer getServer(String name) {
|
||||
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
||||
if(!serverOptional.isPresent()) return null;
|
||||
return new VelocityServer(serverOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueueServer buildGroup(String name, List<AdaptedServer> servers) {
|
||||
return new QueueServerImpl(name, main, servers);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user