progress
This commit is contained in:
@@ -19,7 +19,7 @@ public interface IBaseCommand {
|
||||
|
||||
void addSubCommand(ISubCommand subCommand);
|
||||
|
||||
void execute(ICommandSender ssender, String[] args);
|
||||
void execute(ICommandSender sender, String[] args);
|
||||
|
||||
List<String> autoComplete(ICommandSender sender, String[] args);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package us.ajg0702.queue.commands.commands.leavequeue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||
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.BaseCommand;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.utils.common.Messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LeaveCommand extends BaseCommand {
|
||||
|
||||
|
||||
private final QueueMain main;
|
||||
|
||||
public LeaveCommand(QueueMain main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "leavequeue";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<String> getAliases() {
|
||||
return ImmutableList.of("leaveq");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ISubCommand> getSubCommands() {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Messages getMessages() {
|
||||
return main.getMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubCommand(ISubCommand subCommand) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
System.out.println("leave command");
|
||||
if(!sender.isPlayer()) {
|
||||
System.out.println("not player");
|
||||
sender.sendMessage(getMessages().getComponent("errors.player-only"));
|
||||
return;
|
||||
}
|
||||
System.out.println("player");
|
||||
AdaptedPlayer player = main.getPlatformMethods().senderToPlayer(sender);
|
||||
List<QueueServer> servers = main.getQueueManager().getPlayerQueues(player);
|
||||
|
||||
if(servers.size() == 0) {
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave.no-queues"));
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("0");
|
||||
|
||||
if(servers.size() == 1) {
|
||||
servers.get(0).removePlayer(player);
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave-queue", "SERVER:"+servers.get(0).getAlias()));
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("1");
|
||||
|
||||
if(args.length <= 0) {
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave.more-args", "QUEUES:"+getQueueList(servers)));
|
||||
return;
|
||||
}
|
||||
|
||||
String leaving = args[0];
|
||||
QueueServer leavingServer = main.getQueueManager().findServer(leaving);
|
||||
if(leavingServer == null) {
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave.not-queued", "QUEUES:"+getQueueList(servers)));
|
||||
return;
|
||||
}
|
||||
QueuePlayer queuePlayer = leavingServer.findPlayer(player);
|
||||
if(queuePlayer == null) {
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave.not-queued", "QUEUES:"+getQueueList(servers)));
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("2");
|
||||
|
||||
leavingServer.removePlayer(queuePlayer);
|
||||
sender.sendMessage(getMessages().getComponent("commands.leave-queue", "SERVER:"+leavingServer.getAlias()));
|
||||
|
||||
}
|
||||
|
||||
private String getQueueList(List<QueueServer> servers) {
|
||||
StringBuilder queueList = new StringBuilder();
|
||||
for(QueueServer server : servers) {
|
||||
queueList.append(getMessages().getString("commands.leave.queues-list-format").replaceAll("\\{NAME}", server.getName()));
|
||||
}
|
||||
if(queueList.length() > 2) {
|
||||
queueList = new StringBuilder(queueList.substring(0, queueList.length() - 2));
|
||||
}
|
||||
return queueList.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||
List<QueuePlayer> servers = main.getQueueManager().findPlayerInQueues(main.getPlatformMethods().senderToPlayer(sender));
|
||||
List<String> serverNames = new ArrayList<>();
|
||||
for(QueuePlayer queuePlayer : servers) {
|
||||
serverNames.add(queuePlayer.getQueueServer().getName());
|
||||
}
|
||||
return serverNames;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package us.ajg0702.queue.commands.commands.manage;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
import us.ajg0702.queue.api.commands.ISubCommand;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
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 ManageCommand extends BaseCommand {
|
||||
|
||||
QueueMain main;
|
||||
|
||||
public ManageCommand(QueueMain main) {
|
||||
this.main = main;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ajqueue";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<String> getAliases() {
|
||||
return ImmutableList.of("ajq");
|
||||
}
|
||||
|
||||
List<ISubCommand> subCommands = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public ImmutableList<ISubCommand> getSubCommands() {
|
||||
return ImmutableList.copyOf(subCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermission() {
|
||||
return "ajqueue.manage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Messages getMessages() {
|
||||
return main.getMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubCommand(ISubCommand subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package us.ajg0702.queue.common;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import us.ajg0702.queue.api.QueueManager;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
|
||||
+5
-1
@@ -8,6 +8,7 @@ import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import us.ajg0702.queue.commands.BaseCommand;
|
||||
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
|
||||
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.platforms.velocity.commands.VelocityCommand;
|
||||
@@ -56,7 +57,10 @@ public class VelocityQueue {
|
||||
CommandManager commandManager = proxyServer.getCommandManager();
|
||||
|
||||
|
||||
List<BaseCommand> commands = Arrays.asList(new QueueCommand(main));
|
||||
List<BaseCommand> commands = Arrays.asList(
|
||||
new QueueCommand(main),
|
||||
new LeaveCommand(main)
|
||||
);
|
||||
|
||||
for(BaseCommand command : commands) {
|
||||
commandManager.register(
|
||||
|
||||
+6
@@ -3,6 +3,7 @@ package us.ajg0702.queue.platforms.velocity.commands;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import us.ajg0702.queue.api.commands.ICommandSender;
|
||||
|
||||
public class VelocitySender implements ICommandSender {
|
||||
@@ -23,6 +24,11 @@ public class VelocitySender implements ICommandSender {
|
||||
return !(handle instanceof ConsoleCommandSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Component message) {
|
||||
handle.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSource getHandle() {
|
||||
return handle;
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
package us.ajg0702.queue.platforms.velocity.players;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class ServerBuilderImpl implements ServerBuilder {
|
||||
@Override
|
||||
public AdaptedServer getServer(String name) {
|
||||
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
|
||||
if(serverOptional.isEmpty()) return null;
|
||||
if(serverOptional.isPresent()) return null;
|
||||
return new VelocityServer(serverOptional.get());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -27,14 +27,14 @@ public class VelocityServerPing implements AdaptedServerPing {
|
||||
@Override
|
||||
public int getPlayerCount() {
|
||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||
if(players.isEmpty()) return 0;
|
||||
if(players.isPresent()) return 0;
|
||||
return players.get().getOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPlayers() {
|
||||
Optional<ServerPing.Players> players = handle.getPlayers();
|
||||
if(players.isEmpty()) return 0;
|
||||
if(players.isPresent()) return 0;
|
||||
return players.get().getMax();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user