This repository was archived by the owner on Nov 29, 2021. It is now read-only.
forked from IPVP-MC/queue
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQueueCommand.java
More file actions
160 lines (148 loc) · 6.55 KB
/
QueueCommand.java
File metadata and controls
160 lines (148 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package org.ipvp.queue.command;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.ipvp.queue.Queue;
import org.ipvp.queue.QueuePlugin;
import org.ipvp.queue.QueuedPlayer;
import java.io.IOException;
import static net.md_5.bungee.api.ChatColor.*;
public class QueueCommand extends QueuePluginCommand
{
public QueueCommand(QueuePlugin plugin)
{
super(plugin, "queue");
}
@Override
public void execute(CommandSender sender, String[] args)
{
if(args.length > 0)
{
switch(args[0])
{
case "debug":
{
if(sender.hasPermission("queue.debug"))
{
getPlugin().debug = !getPlugin().debug;
sender.sendMessage(TextComponent.fromLegacyText(YELLOW + "Debug mode has been set to " + getPlugin().debug));
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "You don't have permission to use /queue debug."));
}
return;
}
case "list":
{
if(sender.hasPermission("queue.list"))
{
if(args.length > 1)
{
Queue queue = getPlugin().getQueue(args[1]);
if (queue == null)
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "There is no queue set up for that server."));
}
else
{
StringBuilder response = new StringBuilder();
response.append(GOLD).append("-------------- Players in queue --------------\n");
response.append(GREEN).append(String.format("%-5s %-40s %s", "Pos.", "Player.", "Priority.\n"));
for (QueuedPlayer queuedPlayer : queue)
{
response.append(GOLD).append(String.format("%-5s %s%-40s %s(%d)\n", (queuedPlayer.getPosition() + 1) + ".", GREEN, queuedPlayer.getHandle().getName(), GOLD, queuedPlayer.getPriority()));
}
sender.sendMessage(TextComponent.fromLegacyText(response.toString()));
}
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "Invalid arguments."));
}
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "You don't have permission to use /queue list."));
}
return;
}
case "forget":
{
if(sender.hasPermission("queue.forget"))
{
if(args.length > 1)
{
boolean found = false;
for (Queue queue : getPlugin().getQueues())
{
if (queue.forgetPlayer(args[1]))
{
sender.sendMessage(TextComponent.fromLegacyText(YELLOW + "Player position forgotten in the " + queue.getTarget().getName() + " queue."));
found = true;
}
}
if(!found)
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "Player was not saved in any queue, make sure they have left the queue before running this command."));
}
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "Invalid arguments."));
}
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "You don't have permission to use /queue forget."));
}
return;
}
case "reload":
{
if(!sender.hasPermission("queue.reload")) {
sender.sendMessage(TextComponent.fromLegacyText(RED + "You don't have permission to use /queue reload."));
return;
}
plugin.refreshMaxPlayers();
try
{
plugin.loadConfiguration();
}
catch (IOException e)
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "Error reloading config."));
plugin.getLogger().severe("Error reloading config:\n" + e);
return;
}
sender.sendMessage(TextComponent.fromLegacyText(YELLOW + "Reloading config and server info."));
return;
}
default:
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "That command does not exist."));
return;
}
}
}
// All other /queue variations
if (!(sender instanceof ProxiedPlayer))
{
sender.sendMessage(TextComponent.fromLegacyText("You must be a player to use this command."));
}
else
{
ProxiedPlayer player = (ProxiedPlayer) sender;
QueuedPlayer queuedPlayer = getPlugin().getQueued(player);
Queue queue = queuedPlayer.getQueue();
if (queue == null)
{
sender.sendMessage(TextComponent.fromLegacyText(RED + "You are not in a queue."));
}
else
{
sender.sendMessage(TextComponent.fromLegacyText(String.format(YELLOW + "You are currently in position " + GREEN + "%d " + YELLOW + "of " + GREEN + "%d.", queuedPlayer.getPosition() + 1, queue.size(), queue.getTarget().getName())));
}
}
}
}