add /ajq kick
This commit is contained in:
@@ -117,6 +117,13 @@ public interface QueueManager {
|
|||||||
*/
|
*/
|
||||||
ImmutableList<QueuePlayer> findPlayerInQueues(AdaptedPlayer p);
|
ImmutableList<QueuePlayer> findPlayerInQueues(AdaptedPlayer p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds QueuePlayers that have this username
|
||||||
|
* @param name The username to look up
|
||||||
|
* @return A list of QueuePlayers that have this username
|
||||||
|
*/
|
||||||
|
ImmutableList<QueuePlayer> findPlayerInQueuesByName(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all of the queues the player is currently queued for
|
* Gets all of the queues the player is currently queued for
|
||||||
* @param p The player
|
* @param p The player
|
||||||
|
|||||||
@@ -192,6 +192,12 @@ public interface QueueServer {
|
|||||||
*/
|
*/
|
||||||
boolean isGroup();
|
boolean isGroup();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the player in this queue and returns the representative QueuePlayer
|
||||||
|
* @return The QueuePlayer representing the player, null if not found
|
||||||
|
*/
|
||||||
|
QueuePlayer findPlayer(String player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the player in this queue and returns the representative QueuePlayer
|
* Finds the player in this queue and returns the representative QueuePlayer
|
||||||
* @return The QueuePlayer representing the player, null if not found
|
* @return The QueuePlayer representing the player, null if not found
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package us.ajg0702.queue.commands.commands.manage;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
|
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.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Kick extends SubCommand {
|
||||||
|
|
||||||
|
final QueueMain main;
|
||||||
|
public Kick(QueueMain main) {
|
||||||
|
this.main = main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "kick";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<String> getAliases() {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "ajqueue.manage.kick";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Messages getMessages() {
|
||||||
|
return main.getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(ICommandSender sender, String[] args) {
|
||||||
|
if(!checkPermission(sender)) return;
|
||||||
|
|
||||||
|
if(args.length < 1) {
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.kick.usage"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<QueuePlayer> kickPlayers;
|
||||||
|
|
||||||
|
if(args.length == 1) {
|
||||||
|
kickPlayers = main.getQueueManager().findPlayerInQueuesByName(args[0]);
|
||||||
|
} else {
|
||||||
|
QueueServer queue = main.getQueueManager().findServer(args[1]);
|
||||||
|
if(queue == null) {
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.kick.unknown-server", "QUEUE:"+args[1]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
kickPlayers = Collections.singletonList(queue.findPlayer(args[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(kickPlayers.size() == 0) {
|
||||||
|
sender.sendMessage(getMessages().getComponent("commands.kick.no-player", "PLAYER:"+args[0]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(QueuePlayer player : kickPlayers) {
|
||||||
|
player.getQueueServer().removePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(getMessages().getComponent(
|
||||||
|
"commands.kick.success",
|
||||||
|
"PLAYER:"+args[0],
|
||||||
|
"NUM:"+kickPlayers.size(),
|
||||||
|
"s:"+ (kickPlayers.size() == 1 ? "" : "s")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoComplete(ICommandSender sender, String[] args) {
|
||||||
|
if(args.length == 1) {
|
||||||
|
return main.getPlatformMethods().getPlayerNames(false);
|
||||||
|
}
|
||||||
|
if(args.length == 2) {
|
||||||
|
return main.getQueueManager().getServerNames();
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ public class ManageCommand extends BaseCommand {
|
|||||||
addSubCommand(new PermissionList(main));
|
addSubCommand(new PermissionList(main));
|
||||||
addSubCommand(new Whitelist(main));
|
addSubCommand(new Whitelist(main));
|
||||||
addSubCommand(new Update(main));
|
addSubCommand(new Update(main));
|
||||||
|
addSubCommand(new Kick(main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -210,6 +210,10 @@ public class QueueMain extends AjQueueAPI {
|
|||||||
d.put("commands.leave-queue", "&aYou left the queue for {SERVER}!");
|
d.put("commands.leave-queue", "&aYou left the queue for {SERVER}!");
|
||||||
d.put("commands.reload", "&aConfig and messages reloaded successfully!");
|
d.put("commands.reload", "&aConfig and messages reloaded successfully!");
|
||||||
d.put("commands.joinqueue.usage", "&cUsage: /joinqueue <server>");
|
d.put("commands.joinqueue.usage", "&cUsage: /joinqueue <server>");
|
||||||
|
d.put("commands.kick.usage", "<red>Usage: /ajqueue kick <player> [queue]");
|
||||||
|
d.put("commands.kick.no-player", "&cCould not find {PLAYER}! Make sure they are in a queue!");
|
||||||
|
d.put("commands.kick.unknown-server", "&cCould not find queue {QUEUE}. Make sure you spelled it correctly!");
|
||||||
|
d.put("commands.kick.success", "<green>Kicked <white>{PLAYER} <green>from {NUM} queue{s}!");
|
||||||
|
|
||||||
d.put("noperm", "&cYou do not have permission to do this!");
|
d.put("noperm", "&cYou do not have permission to do this!");
|
||||||
|
|
||||||
|
|||||||
@@ -523,7 +523,6 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(QueueServer server : sendingServers) {
|
for(QueueServer server : sendingServers) {
|
||||||
Debugger.debug("Sending players for "+server.getName());
|
|
||||||
for(QueuePlayer queuePlayer : server.getQueue()) {
|
for(QueuePlayer queuePlayer : server.getQueue()) {
|
||||||
if(queuePlayer.getPlayer() != null) continue;
|
if(queuePlayer.getPlayer() != null) continue;
|
||||||
if(main.getLogic().playerDisconnectedTooLong(queuePlayer)) {
|
if(main.getLogic().playerDisconnectedTooLong(queuePlayer)) {
|
||||||
@@ -635,6 +634,18 @@ public class QueueManagerImpl implements QueueManager {
|
|||||||
return ImmutableList.copyOf(srs);
|
return ImmutableList.copyOf(srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImmutableList<QueuePlayer> findPlayerInQueuesByName(String name) {
|
||||||
|
List<QueuePlayer> srs = new ArrayList<>();
|
||||||
|
for(QueueServer s : servers) {
|
||||||
|
QueuePlayer player = s.findPlayer(name);
|
||||||
|
if(player != null) {
|
||||||
|
srs.add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ImmutableList.copyOf(srs);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<QueueServer> getPlayerQueues(AdaptedPlayer p) {
|
public ImmutableList<QueueServer> getPlayerQueues(AdaptedPlayer p) {
|
||||||
List<QueueServer> srs = new ArrayList<>();
|
List<QueueServer> srs = new ArrayList<>();
|
||||||
|
|||||||
@@ -404,6 +404,15 @@ public class QueueServerImpl implements QueueServer {
|
|||||||
return servers.size() > 1;
|
return servers.size() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueuePlayer findPlayer(String player) {
|
||||||
|
for(QueuePlayer queuePlayer : queue) {
|
||||||
|
if(queuePlayer.getName().equalsIgnoreCase(player)) {
|
||||||
|
return queuePlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
public QueuePlayer findPlayer(AdaptedPlayer player) {
|
||||||
return findPlayer(player.getUniqueId());
|
return findPlayer(player.getUniqueId());
|
||||||
|
|||||||
Reference in New Issue
Block a user