progress
This commit is contained in:
+6
-9
@@ -15,6 +15,7 @@ import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -23,25 +24,18 @@ import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PlatformMethodsImpl implements PlatformMethods {
|
||||
public class VelocityMethods implements PlatformMethods {
|
||||
|
||||
final ProxyServer proxyServer;
|
||||
final Logger logger;
|
||||
final VelocityQueue plugin;
|
||||
|
||||
public PlatformMethodsImpl(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) {
|
||||
public VelocityMethods(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) {
|
||||
this.proxyServer = proxyServer;
|
||||
this.logger = logger;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJoinQueueChannelMessages(QueueServer queueServer, QueuePlayer queuePlayer) {
|
||||
AdaptedPlayer player = queuePlayer.getPlayer();
|
||||
if(player == null) return;
|
||||
player.sendMessage(Component.text());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
|
||||
if(player == null) return;
|
||||
@@ -58,6 +52,9 @@ public class PlatformMethodsImpl implements PlatformMethods {
|
||||
|
||||
@Override
|
||||
public AdaptedPlayer senderToPlayer(ICommandSender sender) {
|
||||
if(sender instanceof PlayerSender) {
|
||||
return ((PlayerSender) sender).getHandle();
|
||||
}
|
||||
return new VelocityPlayer((Player) sender.getHandle());
|
||||
}
|
||||
|
||||
+35
-4
@@ -2,14 +2,18 @@ package us.ajg0702.queue.platforms.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.ResultedEvent;
|
||||
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.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
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;
|
||||
@@ -58,7 +62,7 @@ public class VelocityQueue {
|
||||
public void onProxyInit(ProxyInitializeEvent e) {
|
||||
main = new QueueMain(
|
||||
logger,
|
||||
new PlatformMethodsImpl(this, proxyServer, logger),
|
||||
new VelocityMethods(this, proxyServer, logger),
|
||||
dataFolder
|
||||
);
|
||||
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
||||
@@ -73,6 +77,10 @@ public class VelocityQueue {
|
||||
CommandManager commandManager = proxyServer.getCommandManager();
|
||||
|
||||
|
||||
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.from("ajqueue:tospigot"));
|
||||
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.from("ajqueue:toproxy"));
|
||||
|
||||
|
||||
for(IBaseCommand command : commands) {
|
||||
commandManager.register(
|
||||
commandManager.metaBuilder(command.getName())
|
||||
@@ -83,18 +91,41 @@ public class VelocityQueue {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent e) {
|
||||
main.shutdown();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessage(PluginMessageEvent e) {
|
||||
System.out.println("Recieved message: "+e.getIdentifier().getId());
|
||||
|
||||
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")) {
|
||||
System.out.println("Skipping message: "+e.getIdentifier().getId());
|
||||
return;
|
||||
}
|
||||
if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return;
|
||||
e.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
|
||||
System.out.println("Processing message: "+e.getIdentifier().getId());
|
||||
|
||||
if(!(e.getTarget() instanceof Player)) return;
|
||||
|
||||
main.getEventHandler().handleMessage(new VelocityPlayer((Player) e.getTarget()), e.getData());
|
||||
}
|
||||
|
||||
@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()));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLeave(DisconnectEvent e) {
|
||||
main.getEventHandler().onPlayerLeave(new VelocityPlayer(e.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user