Skip to content

Commit

Permalink
Work on customizable queue types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Oct 31, 2022
1 parent 8888d0e commit 5c8d990
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

@RequiredArgsConstructor
public final class PAPIExpansion extends PlaceholderExpansion {
private final PistonQueuePlaceholder plugin;
Expand All @@ -31,28 +33,16 @@ public boolean canRegister() {

@Override
public String onRequest(OfflinePlayer player, String identifier) {
if (identifier.equals("online_queue_regular")) {
return String.valueOf(plugin.getOnlineQueueRegular());
}

if (identifier.equals("online_queue_priority")) {
return String.valueOf(plugin.getOnlineQueuePriority());
}

if (identifier.equals("online_queue_veteran")) {
return String.valueOf(plugin.getOnlineQueueVeteran());
}

if (identifier.equals("online_main_regular")) {
return String.valueOf(plugin.getOnlineMainRegular());
}

if (identifier.equals("online_main_priority")) {
return String.valueOf(plugin.getOnlineMainPriority());
for (Map.Entry<String, Integer> entry : plugin.getOnlineQueue().entrySet()) {
if (identifier.equalsIgnoreCase("online_queue_" + entry.getKey())) {
return String.valueOf(entry.getValue());
}
}

if (identifier.equals("online_main_veteran")) {
return String.valueOf(plugin.getOnlineMainVeteran());
for (Map.Entry<String, Integer> entry : plugin.getOnlineMain().entrySet()) {
if (identifier.equalsIgnoreCase("online_main_" + entry.getKey())) {
return String.valueOf(entry.getValue());
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

@Getter
public final class PistonQueuePlaceholder extends JavaPlugin implements PluginMessageListener {
private int onlineQueueRegular = 0;
private int onlineQueuePriority = 0;
private int onlineQueueVeteran = 0;
private int onlineMainRegular = 0;
private int onlineMainPriority = 0;
private int onlineMainVeteran = 0;
private final Map<String, Integer> onlineQueue = new ConcurrentHashMap<>();
private final Map<String, Integer> onlineMain = new ConcurrentHashMap<>();

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

if (subChannel.equalsIgnoreCase("onlineQueue")) {
onlineQueueRegular = in.readInt();
onlineQueuePriority = in.readInt();
onlineQueueVeteran = in.readInt();
int count = in.readInt();

for (int i = 0; i < count; i++) {
String queue = in.readUTF();
int online = in.readInt();

onlineQueue.put(queue, online);
}
} else if (subChannel.equalsIgnoreCase("onlineMain")) {
onlineMainRegular = in.readInt();
onlineMainPriority = in.readInt();
onlineMainVeteran = in.readInt();
int count = in.readInt();

for (int i = 0; i < count; i++) {
String queue = in.readUTF();
int online = in.readInt();

onlineMain.put(queue, online);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import net.pistonmaster.pistonqueue.shared.utils.UpdateChecker;
import org.bstats.bungeecord.Metrics;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -56,9 +56,9 @@ public void onEnable() {
PluginManager manager = getProxy().getPluginManager();

info(ChatColor.BLUE + "Loading config");
processConfig(getDataFolder());
processConfig(getDataDirectory());

StorageTool.setupTool(getDataFolder());
StorageTool.setupTool(getDataDirectory());
initializeReservationSlots();

info(ChatColor.BLUE + "Looking for hooks");
Expand Down Expand Up @@ -146,8 +146,8 @@ public String getVersion() {
}

@Override
public File getDataDirectory() {
return getDataFolder();
public Path getDataDirectory() {
return getDataFolder().toPath();
}

private ServerInfoWrapper wrapServer(ServerInfo serverInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void onSend(ServerConnectEvent event) {
public void onQueueSend(ServerSwitchEvent event) {
onConnected(wrap(event));
}

@EventHandler
public void onKick(ServerKickEvent event) {
onKick(wrap(event));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

import net.pistonmaster.pistonmotd.api.PlaceholderParser;
import net.pistonmaster.pistonmotd.api.PlaceholderUtil;
import net.pistonmaster.pistonqueue.shared.QueueAPI;
import net.pistonmaster.pistonqueue.shared.Config;
import net.pistonmaster.pistonqueue.shared.QueueType;

public final class PistonMOTDPlaceholder implements PlaceholderParser {
public PistonMOTDPlaceholder() {
Expand All @@ -30,8 +31,9 @@ public PistonMOTDPlaceholder() {

@Override
public String parseString(String s) {
return s.replace("%pistonqueue_regular%", String.valueOf(QueueAPI.getRegularSize()))
.replace("%pistonqueue_priority%", String.valueOf(QueueAPI.getPrioritySize()))
.replace("%pistonqueue_veteran%", String.valueOf(QueueAPI.getVeteranSize()));
for (QueueType type : Config.QUEUE_TYPES) {
s = s.replace("%pistonqueue_" + type.getName().toLowerCase() + "%", String.valueOf(type.getQueueMap().size()));
}
return s;
}
}
11 changes: 5 additions & 6 deletions src/main/java/net/pistonmaster/pistonqueue/shared/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

public final class Config {
public static String SERVER_NAME, SERVER_IS_FULL_MESSAGE, QUEUE_POSITION, JOINING_MAIN_SERVER,
QUEUE_BYPASS_PERMISSION, QUEUE_SERVER, QUEUE_PRIORITY_PERMISSION, USERNAME_REGEX,
QUEUE_BYPASS_PERMISSION, QUEUE_SERVER, USERNAME_REGEX,
KICK_MESSAGE, ADMIN_PERMISSION, MAIN_SERVER, AUTH_SERVER, SERVER_DOWN_KICK_MESSAGE,
QUEUE_VETERAN_PERMISSION, USERNAME_REGEX_MESSAGE, PAUSE_QUEUE_IF_MAIN_DOWN_MESSAGE,
USERNAME_REGEX_MESSAGE, PAUSE_QUEUE_IF_MAIN_DOWN_MESSAGE,
SHADOW_BAN_MESSAGE, IF_MAIN_DOWN_SEND_TO_QUEUE_MESSAGE, RECOVERY_MESSAGE;

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

public static int QUEUE_MOVE_DELAY, SERVER_ONLINE_CHECK_DELAY, POSITION_MESSAGE_DELAY,
START_TIME, REGULAR_SLOTS, PRIORITY_SLOTS, VETERAN_SLOTS, CUSTOM_PERCENT_PERCENTAGE,
START_TIME, CUSTOM_PERCENT_PERCENTAGE,
MAX_PLAYERS_PER_MOVE;

public static List<String> HEADER, FOOTER, HEADER_PRIORITY, FOOTER_PRIORITY,
HEADER_VETERAN, FOOTER_VETERAN, DOWN_WORD_LIST;

public static List<String> DOWN_WORD_LIST;
public static QueueType[] QUEUE_TYPES; // Not allowed to be resized due to data corruption
public static BanType SHADOW_BAN_TYPE;

private Config() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ default void onCommand(CommandSourceWrapper sender, String[] args, PistonQueuePl
case "stats":
sendLine(sender);
sender.sendMessage(getWrapperFactory().text("Queue stats").color(TextColorWrapper.GOLD));
sender.sendMessage(getWrapperFactory().text("Regular: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getRegularSize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
sender.sendMessage(getWrapperFactory().text("Priority: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getPrioritySize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
sender.sendMessage(getWrapperFactory().text("Veteran: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(QueueAPI.getVeteranSize())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
for (QueueType type : Config.QUEUE_TYPES) {
sender.sendMessage(getWrapperFactory().text(type.getName() + ": ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(String.valueOf(type.getQueueMap().size())).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
}
sendLine(sender);
break;
case "slotstats":
if (sender.hasPermission(Config.ADMIN_PERMISSION)) {
sendLine(sender);
sender.sendMessage(getWrapperFactory().text("Main slot stats").color(TextColorWrapper.GOLD));
sender.sendMessage(getWrapperFactory().text("Regular: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.REGULAR.getPlayersWithTypeInMain().get() + "/" + QueueType.REGULAR.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
sender.sendMessage(getWrapperFactory().text("Priority: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.PRIORITY.getPlayersWithTypeInMain().get() + "/" + QueueType.PRIORITY.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
sender.sendMessage(getWrapperFactory().text("Veteran: ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(QueueType.VETERAN.getPlayersWithTypeInMain().get() + "/" + QueueType.VETERAN.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
for (QueueType type : Config.QUEUE_TYPES) {
sender.sendMessage(getWrapperFactory().text(type.getName() + ": ").color(TextColorWrapper.GOLD).append(getWrapperFactory().text(type.getPlayersWithTypeInMain().get() + " / " + type.getReservedSlots()).color(TextColorWrapper.GOLD).decorate(TextDecorationWrapper.BOLD)));
}
sendLine(sender);
} else {
noPermission(sender);
Expand Down
Loading

0 comments on commit 5c8d990

Please sign in to comment.