Skip to content

Commit 5c8d990

Browse files
Work on customizable queue types
1 parent 8888d0e commit 5c8d990

File tree

16 files changed

+182
-209
lines changed

16 files changed

+182
-209
lines changed

PistonQueuePlaceholder/src/main/java/net/pistonmaster/pistonqueue/placeholder/PAPIExpansion.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.bukkit.OfflinePlayer;
66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.Map;
9+
810
@RequiredArgsConstructor
911
public final class PAPIExpansion extends PlaceholderExpansion {
1012
private final PistonQueuePlaceholder plugin;
@@ -31,28 +33,16 @@ public boolean canRegister() {
3133

3234
@Override
3335
public String onRequest(OfflinePlayer player, String identifier) {
34-
if (identifier.equals("online_queue_regular")) {
35-
return String.valueOf(plugin.getOnlineQueueRegular());
36-
}
37-
38-
if (identifier.equals("online_queue_priority")) {
39-
return String.valueOf(plugin.getOnlineQueuePriority());
40-
}
41-
42-
if (identifier.equals("online_queue_veteran")) {
43-
return String.valueOf(plugin.getOnlineQueueVeteran());
44-
}
45-
46-
if (identifier.equals("online_main_regular")) {
47-
return String.valueOf(plugin.getOnlineMainRegular());
48-
}
49-
50-
if (identifier.equals("online_main_priority")) {
51-
return String.valueOf(plugin.getOnlineMainPriority());
36+
for (Map.Entry<String, Integer> entry : plugin.getOnlineQueue().entrySet()) {
37+
if (identifier.equalsIgnoreCase("online_queue_" + entry.getKey())) {
38+
return String.valueOf(entry.getValue());
39+
}
5240
}
5341

54-
if (identifier.equals("online_main_veteran")) {
55-
return String.valueOf(plugin.getOnlineMainVeteran());
42+
for (Map.Entry<String, Integer> entry : plugin.getOnlineMain().entrySet()) {
43+
if (identifier.equalsIgnoreCase("online_main_" + entry.getKey())) {
44+
return String.valueOf(entry.getValue());
45+
}
5646
}
5747

5848
return null;

PistonQueuePlaceholder/src/main/java/net/pistonmaster/pistonqueue/placeholder/PistonQueuePlaceholder.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
import org.bukkit.plugin.messaging.PluginMessageListener;
1111
import org.jetbrains.annotations.NotNull;
1212

13+
import java.util.Map;
14+
import java.util.concurrent.ConcurrentHashMap;
1315
import java.util.logging.Logger;
1416

1517
@Getter
1618
public final class PistonQueuePlaceholder extends JavaPlugin implements PluginMessageListener {
17-
private int onlineQueueRegular = 0;
18-
private int onlineQueuePriority = 0;
19-
private int onlineQueueVeteran = 0;
20-
private int onlineMainRegular = 0;
21-
private int onlineMainPriority = 0;
22-
private int onlineMainVeteran = 0;
19+
private final Map<String, Integer> onlineQueue = new ConcurrentHashMap<>();
20+
private final Map<String, Integer> onlineMain = new ConcurrentHashMap<>();
2321

2422
@Override
2523
public void onEnable() {
@@ -47,13 +45,23 @@ public void onPluginMessageReceived(String channel, @NotNull Player player, byte
4745
String subChannel = in.readUTF();
4846

4947
if (subChannel.equalsIgnoreCase("onlineQueue")) {
50-
onlineQueueRegular = in.readInt();
51-
onlineQueuePriority = in.readInt();
52-
onlineQueueVeteran = in.readInt();
48+
int count = in.readInt();
49+
50+
for (int i = 0; i < count; i++) {
51+
String queue = in.readUTF();
52+
int online = in.readInt();
53+
54+
onlineQueue.put(queue, online);
55+
}
5356
} else if (subChannel.equalsIgnoreCase("onlineMain")) {
54-
onlineMainRegular = in.readInt();
55-
onlineMainPriority = in.readInt();
56-
onlineMainVeteran = in.readInt();
57+
int count = in.readInt();
58+
59+
for (int i = 0; i < count; i++) {
60+
String queue = in.readUTF();
61+
int online = in.readInt();
62+
63+
onlineMain.put(queue, online);
64+
}
5765
}
5866
}
5967

src/main/java-templates/net/pistonmaster/pistonqueue/data/PluginData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/bungee/PistonQueueBungee.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import net.pistonmaster.pistonqueue.shared.utils.UpdateChecker;
3939
import org.bstats.bungeecord.Metrics;
4040

41-
import java.io.File;
41+
import java.nio.file.Path;
4242
import java.util.Collections;
4343
import java.util.List;
4444
import java.util.Optional;
@@ -56,9 +56,9 @@ public void onEnable() {
5656
PluginManager manager = getProxy().getPluginManager();
5757

5858
info(ChatColor.BLUE + "Loading config");
59-
processConfig(getDataFolder());
59+
processConfig(getDataDirectory());
6060

61-
StorageTool.setupTool(getDataFolder());
61+
StorageTool.setupTool(getDataDirectory());
6262
initializeReservationSlots();
6363

6464
info(ChatColor.BLUE + "Looking for hooks");
@@ -146,8 +146,8 @@ public String getVersion() {
146146
}
147147

148148
@Override
149-
public File getDataDirectory() {
150-
return getDataFolder();
149+
public Path getDataDirectory() {
150+
return getDataFolder().toPath();
151151
}
152152

153153
private ServerInfoWrapper wrapServer(ServerInfo serverInfo) {

src/main/java/net/pistonmaster/pistonqueue/bungee/listeners/QueueListenerBungee.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void onSend(ServerConnectEvent event) {
5959
public void onQueueSend(ServerSwitchEvent event) {
6060
onConnected(wrap(event));
6161
}
62+
6263
@EventHandler
6364
public void onKick(ServerKickEvent event) {
6465
onKick(wrap(event));

src/main/java/net/pistonmaster/pistonqueue/hooks/PistonMOTDPlaceholder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
import net.pistonmaster.pistonmotd.api.PlaceholderParser;
2323
import net.pistonmaster.pistonmotd.api.PlaceholderUtil;
24-
import net.pistonmaster.pistonqueue.shared.QueueAPI;
24+
import net.pistonmaster.pistonqueue.shared.Config;
25+
import net.pistonmaster.pistonqueue.shared.QueueType;
2526

2627
public final class PistonMOTDPlaceholder implements PlaceholderParser {
2728
public PistonMOTDPlaceholder() {
@@ -30,8 +31,9 @@ public PistonMOTDPlaceholder() {
3031

3132
@Override
3233
public String parseString(String s) {
33-
return s.replace("%pistonqueue_regular%", String.valueOf(QueueAPI.getRegularSize()))
34-
.replace("%pistonqueue_priority%", String.valueOf(QueueAPI.getPrioritySize()))
35-
.replace("%pistonqueue_veteran%", String.valueOf(QueueAPI.getVeteranSize()));
34+
for (QueueType type : Config.QUEUE_TYPES) {
35+
s = s.replace("%pistonqueue_" + type.getName().toLowerCase() + "%", String.valueOf(type.getQueueMap().size()));
36+
}
37+
return s;
3638
}
3739
}

src/main/java/net/pistonmaster/pistonqueue/shared/Config.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
public final class Config {
2727
public static String SERVER_NAME, SERVER_IS_FULL_MESSAGE, QUEUE_POSITION, JOINING_MAIN_SERVER,
28-
QUEUE_BYPASS_PERMISSION, QUEUE_SERVER, QUEUE_PRIORITY_PERMISSION, USERNAME_REGEX,
28+
QUEUE_BYPASS_PERMISSION, QUEUE_SERVER, USERNAME_REGEX,
2929
KICK_MESSAGE, ADMIN_PERMISSION, MAIN_SERVER, AUTH_SERVER, SERVER_DOWN_KICK_MESSAGE,
30-
QUEUE_VETERAN_PERMISSION, USERNAME_REGEX_MESSAGE, PAUSE_QUEUE_IF_MAIN_DOWN_MESSAGE,
30+
USERNAME_REGEX_MESSAGE, PAUSE_QUEUE_IF_MAIN_DOWN_MESSAGE,
3131
SHADOW_BAN_MESSAGE, IF_MAIN_DOWN_SEND_TO_QUEUE_MESSAGE, RECOVERY_MESSAGE;
3232

3333
public static boolean POSITION_MESSAGE_HOT_BAR, ENABLE_KICK_MESSAGE,
@@ -36,12 +36,11 @@ public final class Config {
3636
IF_MAIN_DOWN_SEND_TO_QUEUE, RECOVERY, ENABLE_USERNAME_REGEX, SEND_XP_SOUND;
3737

3838
public static int QUEUE_MOVE_DELAY, SERVER_ONLINE_CHECK_DELAY, POSITION_MESSAGE_DELAY,
39-
START_TIME, REGULAR_SLOTS, PRIORITY_SLOTS, VETERAN_SLOTS, CUSTOM_PERCENT_PERCENTAGE,
39+
START_TIME, CUSTOM_PERCENT_PERCENTAGE,
4040
MAX_PLAYERS_PER_MOVE;
4141

42-
public static List<String> HEADER, FOOTER, HEADER_PRIORITY, FOOTER_PRIORITY,
43-
HEADER_VETERAN, FOOTER_VETERAN, DOWN_WORD_LIST;
44-
42+
public static List<String> DOWN_WORD_LIST;
43+
public static QueueType[] QUEUE_TYPES; // Not allowed to be resized due to data corruption
4544
public static BanType SHADOW_BAN_TYPE;
4645

4746
private Config() {

src/main/java/net/pistonmaster/pistonqueue/shared/MainCommandShared.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ default void onCommand(CommandSourceWrapper sender, String[] args, PistonQueuePl
4141
case "stats":
4242
sendLine(sender);
4343
sender.sendMessage(getWrapperFactory().text("Queue stats").color(TextColorWrapper.GOLD));
44-
sender.sendMessage(getWrapperFactory().text("Regular: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getRegularSize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
45-
sender.sendMessage(getWrapperFactory().text("Priority: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getPrioritySize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
46-
sender.sendMessage(getWrapperFactory().text("Veteran: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getVeteranSize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
44+
for (QueueType type : Config.QUEUE_TYPES) {
45+
sender.sendMessage(getWrapperFactory().text(type.getName() + ": ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(type.getQueueMap().size())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
46+
}
4747
sendLine(sender);
4848
break;
4949
case "slotstats":
5050
if (sender.hasPermission(Config.ADMIN_PERMISSION)) {
5151
sendLine(sender);
5252
sender.sendMessage(getWrapperFactory().text("Main slot stats").color(TextColorWrapper.GOLD));
53-
sender.sendMessage(getWrapperFactory().text("Regular: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.REGULAR.getPlayersWithTypeInMain().get() + "/" + QueueType.REGULAR.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
54-
sender.sendMessage(getWrapperFactory().text("Priority: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.PRIORITY.getPlayersWithTypeInMain().get() + "/" + QueueType.PRIORITY.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
55-
sender.sendMessage(getWrapperFactory().text("Veteran: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.VETERAN.getPlayersWithTypeInMain().get() + "/" + QueueType.VETERAN.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
53+
for (QueueType type : Config.QUEUE_TYPES) {
54+
sender.sendMessage(getWrapperFactory().text(type.getName() + ": ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(type.getPlayersWithTypeInMain().get() + " / " + type.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
55+
}
5656
sendLine(sender);
5757
} else {
5858
noPermission(sender);

0 commit comments

Comments
 (0)