diff --git a/api/src/main/java/us/ajg0702/queue/api/EventHandler.java b/api/src/main/java/us/ajg0702/queue/api/EventHandler.java new file mode 100644 index 0000000..8156f90 --- /dev/null +++ b/api/src/main/java/us/ajg0702/queue/api/EventHandler.java @@ -0,0 +1,7 @@ +package us.ajg0702.queue.api; + +import us.ajg0702.queue.api.players.AdaptedPlayer; + +public interface EventHandler { + void handleMessage(AdaptedPlayer reciever, byte[] data); +} diff --git a/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java b/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java index 02705bd..ad66992 100644 --- a/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java +++ b/api/src/main/java/us/ajg0702/queue/api/PlatformMethods.java @@ -1,10 +1,13 @@ package us.ajg0702.queue.api; +import us.ajg0702.queue.api.commands.IBaseCommand; 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 java.util.List; + public interface PlatformMethods { /** * BungeeUtils.sendCustomData(p, "position", pos+""); @@ -33,4 +36,14 @@ public interface PlatformMethods { String getPluginVersion(); + List getOnlinePlayers(); + List getPlayerNames(boolean lowercase); + AdaptedPlayer getPlayer(String name); + + List getServerNames(); + + + List getCommands(); + + ICommandSender constructSender(AdaptedPlayer player); } diff --git a/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java b/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java index 0b63552..6a8ced7 100644 --- a/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java +++ b/api/src/main/java/us/ajg0702/queue/api/players/AdaptedPlayer.java @@ -64,4 +64,10 @@ public interface AdaptedPlayer extends Handle, Audience { * Does not use the queue. */ void connect(AdaptedServer server); + + /** + * Gets the player's username + * @return the player's username + */ + String getName(); } diff --git a/api/src/main/java/us/ajg0702/queue/api/players/QueuePlayer.java b/api/src/main/java/us/ajg0702/queue/api/players/QueuePlayer.java index 41aafae..be2db7d 100644 --- a/api/src/main/java/us/ajg0702/queue/api/players/QueuePlayer.java +++ b/api/src/main/java/us/ajg0702/queue/api/players/QueuePlayer.java @@ -50,4 +50,10 @@ public interface QueuePlayer { * Gets if this player has priority */ boolean hasPriority(); + + /** + * Gets the player's username + * @return the player's username + */ + String getName(); } diff --git a/api/src/main/java/us/ajg0702/queue/api/server/AdaptedServer.java b/api/src/main/java/us/ajg0702/queue/api/server/AdaptedServer.java index 72ef5d8..494e6db 100644 --- a/api/src/main/java/us/ajg0702/queue/api/server/AdaptedServer.java +++ b/api/src/main/java/us/ajg0702/queue/api/server/AdaptedServer.java @@ -3,6 +3,7 @@ package us.ajg0702.queue.api.server; import us.ajg0702.queue.api.players.AdaptedPlayer; import us.ajg0702.queue.api.util.Handle; +import java.util.List; import java.util.concurrent.CompletableFuture; @SuppressWarnings("unused") @@ -36,4 +37,5 @@ public interface AdaptedServer extends Handle { @SuppressWarnings("SameReturnValue") boolean canAccess(AdaptedPlayer player); + List getPlayers(); } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index bc64320..43b4b32 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -15,6 +15,8 @@ dependencies { compileOnly("com.google.guava:guava:30.1.1-jre") compileOnly("us.ajg0702:ajUtils:1.1.6") + compileOnly("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT") + compileOnly("org.spongepowered:configurate-yaml:4.0.0") implementation(project(":api")) diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java b/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java new file mode 100644 index 0000000..62e30f6 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/PlayerSender.java @@ -0,0 +1,28 @@ +package us.ajg0702.queue.commands.commands; + +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.players.AdaptedPlayer; + +public class PlayerSender implements ICommandSender { + + final AdaptedPlayer handle; + + public VelocitySender(CommandSource handle) { + this.handle = handle; + } + + @Override + public boolean hasPermission(String permission) { + return false; + } + + @Override + public boolean isPlayer() { + return false; + } + + @Override + public Object getHandle() { + return null; + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java new file mode 100644 index 0000000..d9661ee --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ISP.java @@ -0,0 +1,50 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; + +public class ISP extends SubCommand { + + final QueueMain main; + public ISP(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "isp"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.isp"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + sender.sendMessage(Component.text(main.getLogic().isPremium())); + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java index e0efd7a..e1518fc 100644 --- a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/ManageCommand.java @@ -24,6 +24,9 @@ public class ManageCommand extends BaseCommand { addSubCommand(new Tasks(main)); addSubCommand(new Version(main)); addSubCommand(new Pause(main)); + addSubCommand(new ISP(main)); + addSubCommand(new QueueList(main)); + addSubCommand(new Send(main)); } diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/QueueList.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/QueueList.java new file mode 100644 index 0000000..b481916 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/QueueList.java @@ -0,0 +1,93 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.PatternReplacementResult; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.players.QueuePlayer; +import us.ajg0702.queue.api.queues.QueueServer; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class QueueList extends SubCommand { + + final QueueMain main; + public QueueList(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "list"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.list"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + int total = 0; + for(QueueServer server : main.getQueueManager().getServers()) { + + Component msg = getMessages().getComponent("list.format", + "SERVER:"+server.getName() + ); + Component playerList = Component.empty(); + List players = server.getQueue(); + boolean none = true; + for(QueuePlayer p : players) { + playerList = playerList.append(getMessages().getComponent("list.playerlist", + "NAME:" + p.getName() + )); + none = false; + } + if(none) { + playerList = playerList.append(getMessages().getComponent("list.none")); + playerList = playerList.append(Component.text(", ")); + } + Component finalPlayerList = playerList; + msg = msg.replaceText(b -> b.match(Pattern.compile("\\{LIST}")).replacement(finalPlayerList)); + char[] commaCountString = PlainTextComponentSerializer.plainText().serialize(msg).toCharArray(); + int commas = 0; + for(Character fChar : commaCountString) { + if(fChar == ',') commas++; + } + + int finalCommas = commas; + msg = msg.replaceText(b -> b.match(",(?!.*,)").replacement("").condition((r, c, re) -> { + if(c == finalCommas) { + return PatternReplacementResult.REPLACE; + } + return PatternReplacementResult.CONTINUE; + })); + total += players.size(); + msg = msg.replaceText(b -> b.match(Pattern.compile("\\{COUNT}")).replacement(players.size()+"")); + sender.sendMessage(msg); + } + sender.sendMessage(getMessages().getComponent("list.total", "TOTAL:"+total)); + } + + @Override + public java.util.List autoComplete(ICommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Send.java b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Send.java new file mode 100644 index 0000000..37cc4bf --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/commands/commands/manage/Send.java @@ -0,0 +1,103 @@ +package us.ajg0702.queue.commands.commands.manage; + +import com.google.common.collect.ImmutableList; +import net.kyori.adventure.text.Component; +import us.ajg0702.queue.api.commands.ICommandSender; +import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.queue.api.queues.QueueServer; +import us.ajg0702.queue.api.server.AdaptedServer; +import us.ajg0702.queue.commands.SubCommand; +import us.ajg0702.queue.common.QueueMain; +import us.ajg0702.utils.common.Messages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Send extends SubCommand { + + final QueueMain main; + public Send(QueueMain main) { + this.main = main; + } + + @Override + public String getName() { + return "send"; + } + + @Override + public ImmutableList getAliases() { + return ImmutableList.of(); + } + + @Override + public String getPermission() { + return "ajqueue.send"; + } + + @Override + public Messages getMessages() { + return main.getMessages(); + } + + @Override + public void execute(ICommandSender sender, String[] args) { + if(!checkPermission(sender)) return; + + if(main.getQueueManager().findServer(args[1]) == null) { + sender.sendMessage(getMessages().getComponent("errors.server-not-exist", "SERVER:"+args[2])); + return; + } + + List playerNames = main.getPlatformMethods().getPlayerNames(true); + if(playerNames.contains(args[0].toLowerCase())) { + + AdaptedPlayer ply = main.getPlatformMethods().getPlayer(args[0]); + if(ply == null) { + sender.sendMessage(Component.text("player not found")); + return; + } + if(ply.getName() == null) { + sender.sendMessage(Component.text("name null")); + } + main.getQueueManager().addToQueue(ply, args[1]); + sender.sendMessage(getMessages().getComponent("send", + "PLAYER:"+ply.getName(), + "SERVER:"+args[1]) + ); + } else if(main.getQueueManager().getServerNames().contains(args[0])) { + + AdaptedServer from = main.getServerBuilder().getServer(args[0]); + if(from == null) { + sender.sendMessage(getMessages().getComponent("errors.server-not-exist", "SERVER:"+args[0])); + return; + } + List players = new ArrayList<>(from.getPlayers()); + for(AdaptedPlayer ply : players) { + main.getQueueManager().addToQueue(ply, args[1]); + } + + sender.sendMessage(getMessages().getComponent("send", "PLAYER:"+args[0], "SERVER:"+args[1])); + + } else { + sender.sendMessage(getMessages().getComponent("commands.send.player-not-found")); + } + } + + @Override + public List autoComplete(ICommandSender sender, String[] args) { + if(args.length == 1) { + List options = new ArrayList<>(main.getPlatformMethods().getServerNames()); + options.addAll(main.getPlatformMethods().getPlayerNames(false)); + return options; + } + if(args.length == 2) { + return main.getQueueManager().getServerNames(); + } + return new ArrayList<>(); + } + + + +} diff --git a/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java new file mode 100644 index 0000000..394af84 --- /dev/null +++ b/common/src/main/java/us/ajg0702/queue/common/EventHandlerImpl.java @@ -0,0 +1,88 @@ +package us.ajg0702.queue.common; + +import us.ajg0702.queue.api.EventHandler; +import us.ajg0702.queue.api.players.AdaptedPlayer; +import us.ajg0702.utils.bungee.BungeeUtils; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + +public class EventHandlerImpl implements EventHandler { + + QueueMain main; + public EventHandlerImpl(QueueMain main) { + this.main = main; + } + + @Override + public void handleMessage(AdaptedPlayer recievingPlayer, byte[] data) { + DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); + try { + String subchannel = in.readUTF(); + + if(subchannel.equals("queue")) { + String rawData = in.readUTF(); + String[] args = new String[1]; + args[0] = rawData; + main.getPlatformMethods().getCommands().get(0).execute(new , args); + //man.addToQueue(player, data); + + } + if(subchannel.equals("massqueue")) { + String data = in.readUTF(); + String[] parts = data.split(","); + for(String part : parts) { + String[] pparts = part.split(":"); + if(pparts.length < 2) continue; + String pname = pparts[0]; + String pserver = pparts[1]; + ProxiedPlayer p = ProxyServer.getInstance().getPlayer(pname); + String[] args = new String[1]; + args[0] = pserver; + moveCommand.execute(p, args); + } + } + if(subchannel.equals("queuename")) { + BungeeUtils.sendCustomData(player, "queuename", aliases.getAlias(man.getQueuedName(player))); + } + if(subchannel.equals("position")) { + QueueServer server = man.getSingleServer(player); + String pos = msgs.getString("placeholders.position.none"); + if(server != null) { + pos = server.getQueue().indexOf(player)+1+""; + } + BungeeUtils.sendCustomData(player, "position", pos); + } + if(subchannel.equals("positionof")) { + QueueServer server = man.getSingleServer(player); + String pos = msgs.getString("placeholders.position.none"); + if(server != null) { + pos = server.getQueue().size()+""; + } + BungeeUtils.sendCustomData(player, "positionof", pos); + } + if(subchannel.equals("inqueue")) { + QueueServer server = man.getSingleServer(player); + BungeeUtils.sendCustomData(player, "inqueue", (server != null)+""); + } + if(subchannel.equals("queuedfor")) { + String srv = in.readUTF(); + QueueServer server = man.findServer(srv); + if(server == null) return; + BungeeUtils.sendCustomData(player, "queuedfor", srv, server.getQueue().size()+""); + } + if(subchannel.equals("leavequeue")) { + String arg = ""; + try { + arg = in.readUTF(); + } catch(Exception ignored) {} + getProxy().getPluginManager().dispatchCommand(player, "leavequeue"+arg); + } + + } catch (IOException e1) { + getLogger().warning("An error occured while reading data from spigot side:"); + e1.printStackTrace(); + } + } +} diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java index 97f60ae..c57fc7a 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueMain.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueMain.java @@ -1,10 +1,7 @@ package us.ajg0702.queue.common; import org.spongepowered.configurate.ConfigurateException; -import us.ajg0702.queue.api.AliasManager; -import us.ajg0702.queue.api.Logic; -import us.ajg0702.queue.api.PlatformMethods; -import us.ajg0702.queue.api.QueueManager; +import us.ajg0702.queue.api.*; import us.ajg0702.queue.api.server.ServerBuilder; import us.ajg0702.queue.logic.LogicGetter; import us.ajg0702.utils.common.Config; @@ -67,6 +64,11 @@ public class QueueMain { return taskManager; } + private final EventHandler eventHandler = new EventHandlerImpl(this); + public EventHandler getEventHandler() { + return eventHandler; + } + private final List> serverCompletableFutures = new ArrayList<>(); private ServerBuilder serverBuilder; public ServerBuilder getServerBuilder() { diff --git a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java index ed4de0c..5a9b80d 100644 --- a/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/QueueManagerImpl.java @@ -138,7 +138,10 @@ public class QueueManagerImpl implements QueueManager { @Override public boolean addToQueue(AdaptedPlayer player, String serverName) { QueueServer server = findServer(serverName); - if(server == null) return false; + if(server == null) { + player.sendMessage(msgs.getComponent("errors.server-not-exist", "SERVER:"+serverName)); + return false; + } return addToQueue(player, server); } diff --git a/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java b/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java index b21765f..723e4d1 100644 --- a/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java +++ b/common/src/main/java/us/ajg0702/queue/common/players/QueuePlayerImpl.java @@ -16,6 +16,7 @@ public class QueuePlayerImpl implements QueuePlayer { private final int highestPriority; private final UUID uuid; + private final String name; public QueuePlayerImpl(AdaptedPlayer player, QueueServer server, int highestPriority) { this.player = player; @@ -24,6 +25,7 @@ public class QueuePlayerImpl implements QueuePlayer { this.highestPriority = highestPriority; uuid = player.getUniqueId(); + name = player.getName(); } @Override @@ -66,4 +68,9 @@ public class QueuePlayerImpl implements QueuePlayer { public boolean hasPriority() { return highestPriority > 0; } + + @Override + public String getName() { + return name; + } } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java index 009662e..713f081 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/PlatformMethodsImpl.java @@ -3,14 +3,19 @@ package us.ajg0702.queue.platforms.velocity; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.Component; import us.ajg0702.queue.api.PlatformMethods; +import us.ajg0702.queue.api.commands.IBaseCommand; 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.platforms.velocity.players.VelocityPlayer; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.logging.Logger; @@ -18,10 +23,12 @@ public class PlatformMethodsImpl implements PlatformMethods { final ProxyServer proxyServer; final Logger logger; + final VelocityQueue plugin; - public PlatformMethodsImpl(ProxyServer proxyServer, Logger logger) { + public PlatformMethodsImpl(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) { this.proxyServer = proxyServer; this.logger = logger; + this.plugin = plugin; } @Override @@ -33,7 +40,8 @@ public class PlatformMethodsImpl implements PlatformMethods { @Override public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) { - + if(player == null) return; + Player velocityPlayer = ((VelocityPlayer) player).getHandle(); } @Override @@ -49,4 +57,50 @@ public class PlatformMethodsImpl implements PlatformMethods { if(!version.isPresent()) return "?V"; return version.get(); } + + @Override + public List getOnlinePlayers() { + List players = new ArrayList<>(); + for(Player player : proxyServer.getAllPlayers()) { + players.add(new VelocityPlayer(player)); + } + return players; + } + + @Override + public List getPlayerNames(boolean lowercase) { + List players = new ArrayList<>(); + for(Player player : proxyServer.getAllPlayers()) { + if(lowercase) { + players.add(player.getUsername().toLowerCase(Locale.ROOT)); + } else { + players.add(player.getUsername()); + } + } + return players; + } + + @Override + public AdaptedPlayer getPlayer(String name) { + Optional player = proxyServer.getPlayer(name); + if(!player.isPresent()) { + System.out.println("Player "+name+" not found"); + return null; + } + return new VelocityPlayer(player.get()); + } + + @Override + public List getServerNames() { + List names = new ArrayList<>(); + for(RegisteredServer server : proxyServer.getAllServers()) { + names.add(server.getServerInfo().getName()); + } + return names; + } + + @Override + public List getCommands() { + return plugin.commands; + } } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java index 77c2039..a684f88 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/VelocityQueue.java @@ -2,11 +2,15 @@ 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.PluginMessageEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 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 us.ajg0702.queue.api.commands.IBaseCommand; import us.ajg0702.queue.commands.BaseCommand; import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand; import us.ajg0702.queue.commands.commands.listqueues.ListCommand; @@ -14,6 +18,7 @@ import us.ajg0702.queue.commands.commands.manage.ManageCommand; 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 java.io.File; @@ -47,32 +52,48 @@ public class VelocityQueue { this.dataFolder = dataFolder.toFile(); } + List commands; + @Subscribe public void onProxyInit(ProxyInitializeEvent e) { main = new QueueMain( logger, - new PlatformMethodsImpl(proxyServer, logger), + new PlatformMethodsImpl(this, proxyServer, logger), dataFolder ); main.setServerBuilder(new ServerBuilderImpl(main, proxyServer)); - CommandManager commandManager = proxyServer.getCommandManager(); - - - List commands = Arrays.asList( + commands = Arrays.asList( new QueueCommand(main), new LeaveCommand(main), new ListCommand(main), new ManageCommand(main) ); - for(BaseCommand command : commands) { + CommandManager commandManager = proxyServer.getCommandManager(); + + + for(IBaseCommand command : commands) { commandManager.register( commandManager.metaBuilder(command.getName()) .aliases(command.getAliases().toArray(new String[]{})) .build(), - new VelocityCommand(main, command) + new VelocityCommand(main, (BaseCommand) command) ); } } + + @Subscribe + public void onPluginMessage(PluginMessageEvent e) { + if(e.getIdentifier().getId().equals("ajqueue:tospigot")) { + e.setResult(PluginMessageEvent.ForwardResult.handled()); + return; + } + if(!e.getIdentifier().getId().equals("ajqueue:toproxy")) return; + e.setResult(PluginMessageEvent.ForwardResult.handled()); + + if(!(e.getTarget() instanceof Player)) return; + + main.getEventHandler().handleMessage(new VelocityPlayer((Player) e.getTarget()), e.getData()); + } } diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java index c8d21f1..25548b6 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/commands/VelocityCommand.java @@ -10,6 +10,8 @@ import java.util.List; public class VelocityCommand implements RawCommand { + + final QueueMain main; final BaseCommand command; diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java index 31954e4..0d72b6d 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/players/VelocityPlayer.java @@ -65,6 +65,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience { handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect(); } + @Override + public String getName() { + return handle.getUsername(); + } + @Override public Player getHandle() { return handle; diff --git a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServer.java b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServer.java index f9f9cf5..5d0eac1 100644 --- a/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServer.java +++ b/platforms/velocity/src/main/java/us/ajg0702/queue/platforms/velocity/server/VelocityServer.java @@ -1,12 +1,17 @@ package us.ajg0702.queue.platforms.velocity.server; +import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerPing; import us.ajg0702.queue.api.players.AdaptedPlayer; import us.ajg0702.queue.api.server.AdaptedServer; import us.ajg0702.queue.api.server.AdaptedServerInfo; import us.ajg0702.queue.api.server.AdaptedServerPing; +import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -48,6 +53,15 @@ public class VelocityServer implements AdaptedServer { return true; } + @Override + public List getPlayers() { + List players = new ArrayList<>(); + for(Player player : handle.getPlayersConnected()) { + players.add(new VelocityPlayer(player)); + } + return players; + } + @Override public RegisteredServer getHandle() { return handle; diff --git a/settings.gradle.kts b/settings.gradle.kts index 68d5aae..0b2c159 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,8 @@ rootProject.name = "ajQueue" include(":api") include(":common") +include(":spigot") + include(":platforms:velocity") include(":free") \ No newline at end of file diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts new file mode 100644 index 0000000..7743cd1 --- /dev/null +++ b/spigot/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + `java-library` + `maven-publish` +} + +group = "us.ajg0702.queue.spigot" + +repositories { + mavenCentral() + + maven { url = uri("https://repo.ajg0702.us") } +} + +dependencies { + implementation("net.kyori:adventure-api:4.8.1") + compileOnly("com.google.guava:guava:30.1.1-jre") + + compileOnly("us.ajg0702:ajUtils:1.1.6") +} + +publishing { + publications { + create("mavenJava") { + artifact(tasks["jar"]) + } + } + + repositories { + + val mavenUrl = "https://repo.ajg0702.us/releases" + + if(!System.getenv("REPO_TOKEN").isNullOrEmpty()) { + maven { + url = uri(mavenUrl) + name = "ajRepo" + + credentials { + username = "plugins" + password = System.getenv("REPO_TOKEN") + } + } + } + } +} \ No newline at end of file