Merge branch 'dev' into 'master'

2.0.9

See merge request ajg0702/ajqueue!29
This commit is contained in:
ajgeiss0702
2021-09-28 17:03:49 +00:00
18 changed files with 255 additions and 37 deletions
@@ -0,0 +1,11 @@
package us.ajg0702.queue.api;
import us.ajg0702.queue.api.commands.IBaseCommand;
public interface Implementation {
void registerCommand(IBaseCommand command);
void unregisterCommand(String name);
default void unregisterCommand(IBaseCommand command) {
unregisterCommand(command.getName());
}
}
@@ -79,4 +79,8 @@ public interface AdaptedPlayer extends Handle, Audience {
String getName();
List<String> getPermissions();
default boolean equals(AdaptedPlayer other) {
return this.getUniqueId().equals(other.getUniqueId());
}
}
@@ -11,4 +11,6 @@ public interface PermissionGetter {
int getPriority(AdaptedPlayer player);
int getServerPriotity(String server, AdaptedPlayer player);
boolean hasContextBypass(AdaptedPlayer player, String server);
}
+1 -1
View File
@@ -12,7 +12,7 @@ repositories {
}
allprojects {
version = "2.0.8"
version = "2.0.9"
group = "us.ajg0702"
plugins.apply("java")
@@ -0,0 +1,55 @@
package us.ajg0702.queue.commands.commands.SlashServer;
import com.google.common.collect.ImmutableList;
import us.ajg0702.queue.api.commands.ICommandSender;
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;
import java.util.Locale;
public class SlashServerCommand extends BaseCommand {
final QueueMain main;
final String server;
public SlashServerCommand(QueueMain main, String server) {
this.main = main;
this.server = server;
}
@Override
public String getName() {
return server;
}
@Override
public ImmutableList<String> getAliases() {
return ImmutableList.of();
}
@Override
public String getPermission() {
return null;
}
@Override
public Messages getMessages() {
return main.getMessages();
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!sender.isPlayer()) {
sender.sendMessage(getMessages().getComponent("errors.player-only"));
return;
}
main.getQueueManager().addToQueue(main.getPlatformMethods().senderToPlayer(sender), server);
}
@Override
public List<String> autoComplete(ICommandSender sender, String[] args) {
return new ArrayList<>();
}
}
@@ -51,7 +51,7 @@ public class Pause extends SubCommand {
List<QueueServer> servers;
QueueServer queueServer = main.getQueueManager().findServer(args[0]);
if(queueServer == null && !args[0].equalsIgnoreCase("all")) {
sender.sendMessage(getMessages().getComponent("commands.pause.no-server", "SERVER:"+args[1]));
sender.sendMessage(getMessages().getComponent("commands.pause.no-server", "SERVER:"+args[0]));
return;
} else if(queueServer == null && args[0].equalsIgnoreCase("all")) {
servers = main.getQueueManager().getServers();
@@ -54,6 +54,7 @@ public class Reload extends SubCommand {
main.getTaskManager().rescheduleTasks();
main.getQueueManager().reloadServers();
main.getMessages().reload();
main.getSlashServerManager().reload();
main.getUpdater().setEnabled(main.getConfig().getBoolean("enable-updater"));
@@ -43,8 +43,13 @@ public class Send extends SubCommand {
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
if(args.length < 2) {
sender.sendMessage(getMessages().getComponent("commands.send.usage"));
return;
}
if(main.getQueueManager().findServer(args[1]) == null) {
sender.sendMessage(getMessages().getComponent("errors.server-not-exist", "SERVER:"+args[2]));
sender.sendMessage(getMessages().getComponent("errors.server-not-exist", "SERVER:"+args[1]));
return;
}
@@ -53,7 +58,7 @@ public class Send extends SubCommand {
AdaptedPlayer ply = main.getPlatformMethods().getPlayer(args[0]);
if(ply == null) {
sender.sendMessage(Component.text("player not found"));
sender.sendMessage(Component.text("player not found (even though it was in playerNames)"));
return;
}
if(ply.getName() == null) {
@@ -107,6 +107,16 @@ public class QueueMain extends AjQueueAPI {
return updater;
}
private final Implementation implementation;
public Implementation getImplementation() {
return implementation;
}
private SlashServerManager slashServerManager;
public SlashServerManager getSlashServerManager() {
return slashServerManager;
}
@Override
public void shutdown() {
taskManager.shutdown();
@@ -117,7 +127,8 @@ public class QueueMain extends AjQueueAPI {
private final File dataFolder;
public QueueMain(QueueLogger logger, PlatformMethods platformMethods, File dataFolder) {
public QueueMain(Implementation implementation, QueueLogger logger, PlatformMethods platformMethods, File dataFolder) {
this.implementation = implementation;
logicGetter = new LogicGetterImpl();
@@ -147,6 +158,8 @@ public class QueueMain extends AjQueueAPI {
return;
}
slashServerManager = new SlashServerManager(this);
//noinspection ResultOfMethodCallIgnored
messages.getComponent("one").replaceText(b -> b.match(Pattern.compile("\\e")).replacement("a"));
@@ -232,6 +245,7 @@ public class QueueMain extends AjQueueAPI {
d.put("commands.pause.paused.false", "&aun-paused");
d.put("commands.send.player-not-found", "&cThat player could not be found. Make sure they are online!");
d.put("commands.send.usage", "<red>Usage: /ajqueue send <player> <server>");
d.put("commands.listqueues.header", "&9Queues:");
d.put("commands.listqueues.format", "<hover:show_text:'&7Status: {STATUS}'>{COLOR}{NAME}&7: {COUNT} queued</hover>");
@@ -14,18 +14,12 @@ import us.ajg0702.utils.common.Messages;
import us.ajg0702.utils.common.TimeUtils;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.*;
import java.util.concurrent.*;
public class QueueManagerImpl implements QueueManager {
private List<QueueServer> servers = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<QueueServer> servers = new CopyOnWriteArrayList<>();
private final QueueMain main;
private final Messages msgs;
@@ -272,7 +266,7 @@ public class QueueManagerImpl implements QueueManager {
List<QueueServer> oldServers = ImmutableList.copyOf(servers);
servers = buildServers();
servers = new CopyOnWriteArrayList<>(buildServers());
List<String> groupsRaw = main.getConfig().getStringList("server-groups");
for(String groupRaw : groupsRaw) {
@@ -506,7 +500,8 @@ public class QueueManagerImpl implements QueueManager {
sendPlayers(null);
}
final HashMap<AdaptedPlayer, Long> sendingNowAntiSpam = new HashMap<>();
final ConcurrentHashMap<AdaptedPlayer, Long> sendingNowAntiSpam = new ConcurrentHashMap<>();
final HashMap<QueuePlayer, Integer> sendingAttempts = new HashMap<>();
@Override
@@ -640,6 +635,9 @@ public class QueueManagerImpl implements QueueManager {
@Override
public void clear(AdaptedPlayer player) {
sendingNowAntiSpam.remove(player);
for (AdaptedPlayer next : sendingNowAntiSpam.keySet()) {
if(!next.equals(player)) continue;
sendingNowAntiSpam.remove(next);
}
}
}
@@ -0,0 +1,31 @@
package us.ajg0702.queue.common;
import us.ajg0702.queue.api.Implementation;
import us.ajg0702.queue.commands.commands.SlashServer.SlashServerCommand;
import java.util.ArrayList;
import java.util.List;
public class SlashServerManager {
private final List<SlashServerCommand> serverCommands = new ArrayList<>();
private final QueueMain main;
private final Implementation implementation;
public SlashServerManager(QueueMain main) {
this.main = main;
this.implementation = this.main.getImplementation();
reload();
}
public void reload() {
serverCommands.forEach(implementation::unregisterCommand);
serverCommands.clear();
List<String> slashServerServers = main.getConfig().getStringList("slash-servers");
for(String server : slashServerServers) {
SlashServerCommand command = new SlashServerCommand(main, server);
serverCommands.add(command);
implementation.registerCommand(command);
}
}
}
@@ -130,9 +130,10 @@ public class QueueServerImpl implements QueueServer {
@Override
public void updatePing() {
boolean pingerDebug = main.getConfig().getBoolean("pinger-debug");
HashMap<AdaptedServer, CompletableFuture<AdaptedServerPing>> pingsFutures = new HashMap<>();
for(AdaptedServer server : servers) {
if(main.getConfig().getBoolean("pinger-debug")) {
if(pingerDebug) {
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] sending ping");
}
pingsFutures.put(server, server.ping());
@@ -145,13 +146,15 @@ public class QueueServerImpl implements QueueServer {
try {
ping = futurePing.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
if(main.getConfig().getBoolean("pinger-debug")) {
if(pingerDebug) {
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] offline:");
e.printStackTrace();
}
}
if(ping != null && main.getConfig().getBoolean("pinger-debug")) {
if(ping != null && pingerDebug) {
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] online. motd: "+ping.getPlainDescription()+" players: "+ping.getPlayerCount()+"/"+ping.getMaxPlayers());
} else if(ping == null && pingerDebug) {
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] offline (unknown)");
}
pings.put(server, ping);
@@ -207,6 +210,10 @@ public class QueueServerImpl implements QueueServer {
}
}
}
if(pingerDebug) {
main.getLogger().info("[pinger] ["+server.getServerInfo().getName()+"] Success");
}
}
}
+7 -1
View File
@@ -1,5 +1,5 @@
# Dont touch this number please
config-version: 28
config-version: 29
# This is the main config for ajQueue.
@@ -262,3 +262,9 @@ velocity-kick-message: false
# Should the updater be enabled?
enable-updater: true
# What servers should we make slash server commands for?
# For example, if survival is in this list, then if a player executes /survival
# then they will be put in the queue for survival
# This works for both servers and groups
slash-servers: []
@@ -11,6 +11,7 @@ import net.md_5.bungee.event.EventHandler;
import org.bstats.bungeecord.Metrics;
import org.bstats.charts.SimplePie;
import org.checkerframework.checker.nullness.qual.NonNull;
import us.ajg0702.queue.api.Implementation;
import us.ajg0702.queue.api.commands.IBaseCommand;
import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.queue.commands.BaseCommand;
@@ -25,14 +26,18 @@ import us.ajg0702.queue.platforms.bungeecord.server.BungeeServer;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BungeeQueue extends Plugin implements Listener {
public class BungeeQueue extends Plugin implements Listener, Implementation {
private QueueMain main;
List<IBaseCommand> commands;
Map<String, BungeeCommand> commandMap;
@Override
public void onEnable() {
QueueLogger logger = new BungeeLogger(getLogger());
@@ -41,6 +46,7 @@ public class BungeeQueue extends Plugin implements Listener {
adventure = BungeeAudiences.create(this);
main = new QueueMain(
this,
logger,
new BungeeMethods(this, getProxy(), logger),
dataFolder
@@ -56,9 +62,10 @@ public class BungeeQueue extends Plugin implements Listener {
new ManageCommand(main)
);
commandMap = new HashMap<>();
for(IBaseCommand command : commands) {
getProxy().getPluginManager()
.registerCommand(this, new BungeeCommand((BaseCommand) command));
registerCommand(command);
}
getProxy().getPluginManager().registerListener(this, this);
@@ -129,4 +136,20 @@ public class BungeeQueue extends Plugin implements Listener {
false
);
}
@Override
public void unregisterCommand(String name) {
BungeeCommand bungeeCommand = commandMap.get(name);
if(bungeeCommand == null) return;
getProxy().getPluginManager().unregisterCommand(bungeeCommand);
commandMap.remove(name);
}
@Override
public void registerCommand(IBaseCommand command) {
BungeeCommand bungeeCommand = new BungeeCommand((BaseCommand) command);
commandMap.put(command.getName(), bungeeCommand);
getProxy().getPluginManager()
.registerCommand(this, bungeeCommand);
}
}
@@ -18,6 +18,7 @@ import net.kyori.adventure.text.Component;
import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import us.ajg0702.queue.api.Implementation;
import us.ajg0702.queue.api.commands.IBaseCommand;
import us.ajg0702.queue.commands.BaseCommand;
import us.ajg0702.queue.commands.commands.leavequeue.LeaveCommand;
@@ -44,7 +45,7 @@ import java.util.Optional;
authors = {"ajgeiss0702"}
)
public class VelocityQueue {
public class VelocityQueue implements Implementation {
final ProxyServer proxyServer;
final VelocityLogger logger;
@@ -66,9 +67,15 @@ public class VelocityQueue {
List<IBaseCommand> commands;
CommandManager commandManager;
@Subscribe
public void onProxyInit(ProxyInitializeEvent e) {
commandManager = proxyServer.getCommandManager();
main = new QueueMain(
this,
logger,
new VelocityMethods(this, proxyServer, logger),
dataFolder
@@ -81,20 +88,13 @@ public class VelocityQueue {
new ManageCommand(main)
);
CommandManager commandManager = proxyServer.getCommandManager();
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.create("ajqueue", "tospigot"));
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.from("ajqueue:toproxy"));
for(IBaseCommand command : commands) {
commandManager.register(
commandManager.metaBuilder(command.getName())
.aliases(command.getAliases().toArray(new String[]{}))
.build(),
new VelocityCommand(main, (BaseCommand) command)
);
registerCommand(command);
}
@@ -138,7 +138,6 @@ public class VelocityQueue {
main.getEventHandler().onPlayerLeave(new VelocityPlayer(e.getPlayer()));
}
@SuppressWarnings("SimplifyOptionalCallChains")
@Subscribe
public void onKick(KickedFromServerEvent e) {
if(!e.getPlayer().getCurrentServer().isPresent()) return; // if the player is kicked on initial join, we dont care
@@ -152,4 +151,18 @@ public class VelocityQueue {
);
}
@Override
public void unregisterCommand(String name) {
commandManager.unregister(name);
}
@Override
public void registerCommand(IBaseCommand command) {
commandManager.register(
commandManager.metaBuilder(command.getName())
.aliases(command.getAliases().toArray(new String[]{}))
.build(),
new VelocityCommand(main, (BaseCommand) command)
);
}
}
@@ -36,7 +36,11 @@ public class PremiumLogic implements Logic {
QueueLogger logger = main.getLogger();
boolean debug = main.getConfig().getBoolean("priority-queue-debug");
if(player.hasPermission("ajqueue.bypass") || player.hasPermission("ajqueue.serverbypass."+server.getName())) {
if(
player.hasPermission("ajqueue.bypass") ||
player.hasPermission("ajqueue.serverbypass."+server.getName()) ||
permissionGetter.hasContextBypass(player, server.getName())
) {
if(debug) {
logger.info("[priority] "+player.getName()+" bypass");
}
@@ -60,6 +60,15 @@ public class PermissionGetterImpl implements PermissionGetter {
return getHighestPermission(player, "ajqueue.serverpriority."+server+".");
}
@Override
public boolean hasContextBypass(AdaptedPlayer player, String server) {
if(getSelected() == null) {
return false;
}
List<String> perms = getSelected().getPermissions(player);
return perms.contains("ajqueue.serverbypass."+server);
}
private int getHighestPermission(AdaptedPlayer player, String prefix) {
if(getSelected() == null) {
return -1;
@@ -2,9 +2,11 @@ package us.ajg0702.queue.logic.permissions.hooks;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.context.Context;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.query.QueryMode;
import net.luckperms.api.query.QueryOptions;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.common.QueueMain;
@@ -43,7 +45,40 @@ public class LuckPermsHook implements PermissionHook {
for (Node node : nodes) {
if (!node.getType().equals(NodeType.PERMISSION)) continue;
if (!node.getValue()) continue;
perms.add(node.getKey());
String permission = node.getKey();
if(permission.equalsIgnoreCase("ajqueue.contextbypass")) {
boolean skip = false;
for(Context context : node.getContexts()) {
if(context.getKey().equalsIgnoreCase("server")) {
skip = true;
perms.add("ajqueue.serverbypass."+context.getValue());
}
}
if(skip) continue;
}
if(permission.toLowerCase(Locale.ROOT).startsWith("ajqueue.contextpriority.")) {
boolean skip = false;
int level;
try {
level = Integer.parseInt(permission.substring(0, 24));
} catch(NumberFormatException e) {
main.getLogger().warning("A non-number is in the priority permission "+permission);
continue;
}
for(Context context : node.getContexts()) {
if(context.getKey().equalsIgnoreCase("server")) {
skip = true;
perms.add("ajqueue.serverpriority."+context.getValue()+"."+level);
}
}
if(skip) continue;
}
perms.add(permission);
}
return perms;