progress
This commit is contained in:
@@ -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"))
|
||||
|
||||
@@ -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 Version(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;
|
||||
|
||||
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<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
|
||||
private ServerBuilder serverBuilder;
|
||||
public ServerBuilder getServerBuilder() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user