progress
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package us.ajg0702.queue.api;
|
package us.ajg0702.queue.api;
|
||||||
|
|
||||||
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PlatformMethods {
|
public interface PlatformMethods {
|
||||||
/**
|
/**
|
||||||
* BungeeUtils.sendCustomData(p, "position", pos+"");
|
* BungeeUtils.sendCustomData(p, "position", pos+"");
|
||||||
@@ -33,4 +36,14 @@ public interface PlatformMethods {
|
|||||||
|
|
||||||
String getPluginVersion();
|
String getPluginVersion();
|
||||||
|
|
||||||
|
List<AdaptedPlayer> getOnlinePlayers();
|
||||||
|
List<String> getPlayerNames(boolean lowercase);
|
||||||
|
AdaptedPlayer getPlayer(String name);
|
||||||
|
|
||||||
|
List<String> getServerNames();
|
||||||
|
|
||||||
|
|
||||||
|
List<IBaseCommand> getCommands();
|
||||||
|
|
||||||
|
ICommandSender constructSender(AdaptedPlayer player);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,4 +64,10 @@ public interface AdaptedPlayer extends Handle, Audience {
|
|||||||
* Does not use the queue.
|
* Does not use the queue.
|
||||||
*/
|
*/
|
||||||
void connect(AdaptedServer server);
|
void connect(AdaptedServer server);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player's username
|
||||||
|
* @return the player's username
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,4 +50,10 @@ public interface QueuePlayer {
|
|||||||
* Gets if this player has priority
|
* Gets if this player has priority
|
||||||
*/
|
*/
|
||||||
boolean hasPriority();
|
boolean hasPriority();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player's username
|
||||||
|
* @return the player's username
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package us.ajg0702.queue.api.server;
|
|||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.util.Handle;
|
import us.ajg0702.queue.api.util.Handle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@@ -36,4 +37,5 @@ public interface AdaptedServer extends Handle {
|
|||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
boolean canAccess(AdaptedPlayer player);
|
boolean canAccess(AdaptedPlayer player);
|
||||||
|
|
||||||
|
List<AdaptedPlayer> getPlayers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ dependencies {
|
|||||||
compileOnly("com.google.guava:guava:30.1.1-jre")
|
compileOnly("com.google.guava:guava:30.1.1-jre")
|
||||||
compileOnly("us.ajg0702:ajUtils:1.1.6")
|
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")
|
compileOnly("org.spongepowered:configurate-yaml:4.0.0")
|
||||||
|
|
||||||
implementation(project(":api"))
|
implementation(project(":api"))
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<String> 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<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,9 @@ public class ManageCommand extends BaseCommand {
|
|||||||
addSubCommand(new Tasks(main));
|
addSubCommand(new Tasks(main));
|
||||||
addSubCommand(new Version(main));
|
addSubCommand(new Version(main));
|
||||||
addSubCommand(new Pause(main));
|
addSubCommand(new Pause(main));
|
||||||
|
addSubCommand(new ISP(main));
|
||||||
|
addSubCommand(new QueueList(main));
|
||||||
|
addSubCommand(new Send(main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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<String> 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<QueuePlayer> 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<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<String> 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<String> 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<AdaptedPlayer> 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<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
if(args.length == 1) {
|
||||||
|
List<String> 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<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
package us.ajg0702.queue.common;
|
package us.ajg0702.queue.common;
|
||||||
|
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import us.ajg0702.queue.api.AliasManager;
|
import us.ajg0702.queue.api.*;
|
||||||
import us.ajg0702.queue.api.Logic;
|
|
||||||
import us.ajg0702.queue.api.PlatformMethods;
|
|
||||||
import us.ajg0702.queue.api.QueueManager;
|
|
||||||
import us.ajg0702.queue.api.server.ServerBuilder;
|
import us.ajg0702.queue.api.server.ServerBuilder;
|
||||||
import us.ajg0702.queue.logic.LogicGetter;
|
import us.ajg0702.queue.logic.LogicGetter;
|
||||||
import us.ajg0702.utils.common.Config;
|
import us.ajg0702.utils.common.Config;
|
||||||
@@ -67,6 +64,11 @@ public class QueueMain {
|
|||||||
return taskManager;
|
return taskManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final EventHandler eventHandler = new EventHandlerImpl(this);
|
||||||
|
public EventHandler getEventHandler() {
|
||||||
|
return eventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
private final List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
private final List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
||||||
private ServerBuilder serverBuilder;
|
private ServerBuilder serverBuilder;
|
||||||
public ServerBuilder getServerBuilder() {
|
public ServerBuilder getServerBuilder() {
|
||||||
|
|||||||
@@ -138,7 +138,10 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean addToQueue(AdaptedPlayer player, String serverName) {
|
public boolean addToQueue(AdaptedPlayer player, String serverName) {
|
||||||
QueueServer server = findServer(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);
|
return addToQueue(player, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
private final int highestPriority;
|
private final int highestPriority;
|
||||||
|
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
public QueuePlayerImpl(AdaptedPlayer player, QueueServer server, int highestPriority) {
|
public QueuePlayerImpl(AdaptedPlayer player, QueueServer server, int highestPriority) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@@ -24,6 +25,7 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
this.highestPriority = highestPriority;
|
this.highestPriority = highestPriority;
|
||||||
|
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
|
name = player.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,4 +68,9 @@ public class QueuePlayerImpl implements QueuePlayer {
|
|||||||
public boolean hasPriority() {
|
public boolean hasPriority() {
|
||||||
return highestPriority > 0;
|
return highestPriority > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-2
@@ -3,14 +3,19 @@ package us.ajg0702.queue.platforms.velocity;
|
|||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import us.ajg0702.queue.api.PlatformMethods;
|
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.commands.ICommandSender;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||||
import us.ajg0702.queue.api.queues.QueueServer;
|
import us.ajg0702.queue.api.queues.QueueServer;
|
||||||
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;
|
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.Optional;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -18,10 +23,12 @@ public class PlatformMethodsImpl implements PlatformMethods {
|
|||||||
|
|
||||||
final ProxyServer proxyServer;
|
final ProxyServer proxyServer;
|
||||||
final Logger logger;
|
final Logger logger;
|
||||||
|
final VelocityQueue plugin;
|
||||||
|
|
||||||
public PlatformMethodsImpl(ProxyServer proxyServer, Logger logger) {
|
public PlatformMethodsImpl(VelocityQueue plugin, ProxyServer proxyServer, Logger logger) {
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,7 +40,8 @@ public class PlatformMethodsImpl implements PlatformMethods {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
|
public void sendPluginMessage(AdaptedPlayer player, String channel, String... data) {
|
||||||
|
if(player == null) return;
|
||||||
|
Player velocityPlayer = ((VelocityPlayer) player).getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -49,4 +57,50 @@ public class PlatformMethodsImpl implements PlatformMethods {
|
|||||||
if(!version.isPresent()) return "?V";
|
if(!version.isPresent()) return "?V";
|
||||||
return version.get();
|
return version.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AdaptedPlayer> getOnlinePlayers() {
|
||||||
|
List<AdaptedPlayer> players = new ArrayList<>();
|
||||||
|
for(Player player : proxyServer.getAllPlayers()) {
|
||||||
|
players.add(new VelocityPlayer(player));
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getPlayerNames(boolean lowercase) {
|
||||||
|
List<String> 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> player = proxyServer.getPlayer(name);
|
||||||
|
if(!player.isPresent()) {
|
||||||
|
System.out.println("Player "+name+" not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new VelocityPlayer(player.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getServerNames() {
|
||||||
|
List<String> names = new ArrayList<>();
|
||||||
|
for(RegisteredServer server : proxyServer.getAllServers()) {
|
||||||
|
names.add(server.getServerInfo().getName());
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IBaseCommand> getCommands() {
|
||||||
|
return plugin.commands;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-7
@@ -2,11 +2,15 @@ package us.ajg0702.queue.platforms.velocity;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.command.CommandManager;
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||||
import us.ajg0702.queue.commands.BaseCommand;
|
import us.ajg0702.queue.commands.BaseCommand;
|
||||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||||
import us.ajg0702.queue.commands.commands.listqueues.ListCommand;
|
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.commands.commands.queue.QueueCommand;
|
||||||
import us.ajg0702.queue.common.QueueMain;
|
import us.ajg0702.queue.common.QueueMain;
|
||||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
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.ServerBuilderImpl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -47,32 +52,48 @@ public class VelocityQueue {
|
|||||||
this.dataFolder = dataFolder.toFile();
|
this.dataFolder = dataFolder.toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<IBaseCommand> commands;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInit(ProxyInitializeEvent e) {
|
public void onProxyInit(ProxyInitializeEvent e) {
|
||||||
main = new QueueMain(
|
main = new QueueMain(
|
||||||
logger,
|
logger,
|
||||||
new PlatformMethodsImpl(proxyServer, logger),
|
new PlatformMethodsImpl(this, proxyServer, logger),
|
||||||
dataFolder
|
dataFolder
|
||||||
);
|
);
|
||||||
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
main.setServerBuilder(new ServerBuilderImpl(main, proxyServer));
|
||||||
|
|
||||||
CommandManager commandManager = proxyServer.getCommandManager();
|
commands = Arrays.asList(
|
||||||
|
|
||||||
|
|
||||||
List<BaseCommand> commands = Arrays.asList(
|
|
||||||
new QueueCommand(main),
|
new QueueCommand(main),
|
||||||
new LeaveCommand(main),
|
new LeaveCommand(main),
|
||||||
new ListCommand(main),
|
new ListCommand(main),
|
||||||
new ManageCommand(main)
|
new ManageCommand(main)
|
||||||
);
|
);
|
||||||
|
|
||||||
for(BaseCommand command : commands) {
|
CommandManager commandManager = proxyServer.getCommandManager();
|
||||||
|
|
||||||
|
|
||||||
|
for(IBaseCommand command : commands) {
|
||||||
commandManager.register(
|
commandManager.register(
|
||||||
commandManager.metaBuilder(command.getName())
|
commandManager.metaBuilder(command.getName())
|
||||||
.aliases(command.getAliases().toArray(new String[]{}))
|
.aliases(command.getAliases().toArray(new String[]{}))
|
||||||
.build(),
|
.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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -10,6 +10,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class VelocityCommand implements RawCommand {
|
public class VelocityCommand implements RawCommand {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final QueueMain main;
|
final QueueMain main;
|
||||||
final BaseCommand command;
|
final BaseCommand command;
|
||||||
|
|
||||||
|
|||||||
+5
@@ -65,6 +65,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
|||||||
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
|
handle.createConnectionRequest((RegisteredServer) server.getHandle()).connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return handle.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getHandle() {
|
public Player getHandle() {
|
||||||
return handle;
|
return handle;
|
||||||
|
|||||||
+14
@@ -1,12 +1,17 @@
|
|||||||
package us.ajg0702.queue.platforms.velocity.server;
|
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.RegisteredServer;
|
||||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServerInfo;
|
import us.ajg0702.queue.api.server.AdaptedServerInfo;
|
||||||
import us.ajg0702.queue.api.server.AdaptedServerPing;
|
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.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
@@ -48,6 +53,15 @@ public class VelocityServer implements AdaptedServer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AdaptedPlayer> getPlayers() {
|
||||||
|
List<AdaptedPlayer> players = new ArrayList<>();
|
||||||
|
for(Player player : handle.getPlayersConnected()) {
|
||||||
|
players.add(new VelocityPlayer(player));
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegisteredServer getHandle() {
|
public RegisteredServer getHandle() {
|
||||||
return handle;
|
return handle;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ rootProject.name = "ajQueue"
|
|||||||
include(":api")
|
include(":api")
|
||||||
include(":common")
|
include(":common")
|
||||||
|
|
||||||
|
include(":spigot")
|
||||||
|
|
||||||
include(":platforms:velocity")
|
include(":platforms:velocity")
|
||||||
|
|
||||||
include(":free")
|
include(":free")
|
||||||
@@ -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<MavenPublication>("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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user