clean some stuff up

This commit is contained in:
ajgeiss0702
2021-07-12 14:37:12 -07:00
parent 6f24594945
commit 0999c2dee4
29 changed files with 64 additions and 92 deletions
@@ -1,5 +1,6 @@
package us.ajg0702.queue.api;
@SuppressWarnings("unused")
public interface AliasManager {
/**
* Gets an alias from the server/group's name
@@ -4,7 +4,7 @@ import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
import java.util.List;
@SuppressWarnings({"SameReturnValue", "unused"})
public interface Logic {
/**
@@ -15,7 +15,6 @@ public interface Logic {
/**
* The priority logic that is executed if the plugin is premium.
* @param list The current queue
* @param server The server/group name that is being queued for
* @param player The player that is being queued
*/
@@ -2,6 +2,7 @@ package us.ajg0702.queue.api;
import us.ajg0702.utils.common.Config;
@SuppressWarnings("unused")
public interface LogicGetter {
Logic constructLogic();
AliasManager constructAliasManager(Config config);
@@ -4,7 +4,6 @@ import us.ajg0702.queue.api.commands.ICommandSender;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
import us.ajg0702.queue.api.server.AdaptedServer;
public interface PlatformMethods {
/**
@@ -22,6 +21,7 @@ public interface PlatformMethods {
* @param channel The (sub)channel
* @param data The data
*/
@SuppressWarnings("EmptyMethod")
void sendPluginMessage(AdaptedPlayer player, String channel, String... data);
/**
@@ -21,6 +21,7 @@ public interface QueueManager {
* @param serverName The name of the server or group to add the player too
* @return True if adding was successfull, false if not.
*/
@SuppressWarnings("UnusedReturnValue")
boolean addToQueue(AdaptedPlayer player, String serverName);
/**
@@ -5,6 +5,7 @@ import us.ajg0702.utils.common.Messages;
import java.util.List;
@SuppressWarnings("unused")
public interface IBaseCommand {
String getName();
@@ -1,8 +1,4 @@
package us.ajg0702.queue.api.commands;
import com.google.common.collect.ImmutableList;
import java.util.List;
public interface ISubCommand extends IBaseCommand {
}
@@ -2,6 +2,7 @@ package us.ajg0702.queue.api.players;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import us.ajg0702.queue.api.server.AdaptedServer;
import us.ajg0702.queue.api.util.Handle;
@@ -10,25 +11,27 @@ import java.util.UUID;
/**
* Represents a cross-platform player
*/
@SuppressWarnings("unused")
public interface AdaptedPlayer extends Handle, Audience {
/**
* Check if the plauer is currently connected
* @return True if connected, false if not
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean isConnected();
/**
* Send a player a message from a Component
* @param message The message to send
*/
void sendMessage(Component message);
void sendMessage(@NotNull Component message);
/**
* Sends an actionbar message to the player
* @param message The message to send
*/
void sendActionBar(Component message);
void sendActionBar(@NotNull Component message);
/**
* Send a player a message from a string
@@ -13,6 +13,7 @@ import java.util.UUID;
/**
* Represents a server or a group that can be queued for
*/
@SuppressWarnings("unused")
public interface QueueServer {
/**
@@ -52,6 +53,12 @@ public interface QueueServer {
*/
long getLastSentTime();
/**
* Sets the time the last person was sent
* @param lastSentTime the time the last person was sent
*/
void setLastSentTime(long lastSentTime);
/**
@@ -210,7 +217,7 @@ public interface QueueServer {
* elliot is bad
* @return true because elliot is bad
*/
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "SameReturnValue"})
default boolean elliot_is_bad() {
return true;
}
@@ -5,6 +5,7 @@ import us.ajg0702.queue.api.util.Handle;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unused")
public interface AdaptedServer extends Handle {
/**
@@ -32,6 +33,7 @@ public interface AdaptedServer extends Handle {
* @param player The player to check
* @return False if the server is restricted and the player does not have permission to join.
*/
@SuppressWarnings("SameReturnValue")
boolean canAccess(AdaptedPlayer player);
}
@@ -3,6 +3,7 @@ package us.ajg0702.queue.api.server;
import net.kyori.adventure.text.Component;
import us.ajg0702.queue.api.util.Handle;
@SuppressWarnings("unused")
public interface AdaptedServerPing extends Handle {
/**
* Gets the component of the description (aka MOTD)
@@ -47,11 +47,6 @@ public class LeaveCommand extends BaseCommand {
return main.getMessages();
}
@Override
public void addSubCommand(ISubCommand subCommand) {
}
@Override
public void execute(ICommandSender sender, String[] args) {
System.out.println("leave command");
@@ -11,7 +11,6 @@ import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ListCommand extends BaseCommand {
@@ -47,11 +46,6 @@ public class ListCommand extends BaseCommand {
return main.getMessages();
}
@Override
public void addSubCommand(ISubCommand subCommand) {
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
@@ -63,9 +57,7 @@ public class ListCommand extends BaseCommand {
Component m = main.getMessages().getComponent("commands.listqueues.header");
boolean none = true;
for(QueueServer s : main.getQueueManager().getServers()) {
none = false;
String color = "&a";
if(!s.isOnline()) {
color = "&c";
@@ -5,7 +5,6 @@ import net.kyori.adventure.text.Component;
import us.ajg0702.queue.api.commands.ICommandSender;
import us.ajg0702.queue.api.commands.ISubCommand;
import us.ajg0702.queue.commands.BaseCommand;
import us.ajg0702.queue.commands.SubCommand;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;
@@ -16,7 +15,7 @@ import java.util.Locale;
public class ManageCommand extends BaseCommand {
QueueMain main;
final QueueMain main;
public ManageCommand(QueueMain main) {
this.main = main;
@@ -36,7 +35,7 @@ public class ManageCommand extends BaseCommand {
return ImmutableList.of("ajq");
}
List<ISubCommand> subCommands = new ArrayList<>();
final List<ISubCommand> subCommands = new ArrayList<>();
@Override
public ImmutableList<ISubCommand> getSubCommands() {
@@ -5,7 +5,6 @@ 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.commands.ISubCommand;
import us.ajg0702.queue.commands.SubCommand;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;
@@ -15,7 +14,7 @@ import java.util.List;
public class Reload extends SubCommand {
QueueMain main;
final QueueMain main;
public Reload(QueueMain main) {
this.main = main;
}
@@ -40,11 +39,6 @@ public class Reload extends SubCommand {
return main.getMessages();
}
@Override
public void addSubCommand(ISubCommand subCommand) {
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
@@ -2,10 +2,7 @@ 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.commands.ISubCommand;
import us.ajg0702.queue.commands.SubCommand;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.Messages;
@@ -15,7 +12,7 @@ import java.util.List;
public class Tasks extends SubCommand {
QueueMain main;
final QueueMain main;
public Tasks(QueueMain main) {
this.main = main;
}
@@ -40,11 +37,6 @@ public class Tasks extends SubCommand {
return main.getMessages();
}
@Override
public void addSubCommand(ISubCommand subCommand) {
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
@@ -49,11 +49,6 @@ public class QueueCommand extends BaseCommand {
return main.getMessages();
}
@Override
public void addSubCommand(ISubCommand subCommand) {
}
@Override
public void execute(ICommandSender sender, String[] args) {
if(!checkPermission(sender)) return;
@@ -67,7 +67,7 @@ public class QueueMain {
return taskManager;
}
private List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
private final List<CompletableFuture<ServerBuilder>> serverCompletableFutures = new ArrayList<>();
private ServerBuilder serverBuilder;
public ServerBuilder getServerBuilder() {
return serverBuilder;
@@ -94,7 +94,7 @@ public class QueueMain {
}
private File dataFolder;
private final File dataFolder;
public QueueMain(Logger logger, PlatformMethods platformMethods, File dataFolder) {
@@ -1,8 +1,6 @@
package us.ajg0702.queue.common;
import com.google.common.collect.ImmutableList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import us.ajg0702.queue.api.QueueManager;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
@@ -347,8 +345,8 @@ public class QueueManagerImpl implements QueueManager {
sendPlayers(null);
}
HashMap<AdaptedPlayer, Long> sendingNowAntiSpam = new HashMap<>();
HashMap<QueuePlayer, Integer> sendingAttempts = new HashMap<>();
final HashMap<AdaptedPlayer, Long> sendingNowAntiSpam = new HashMap<>();
final HashMap<QueuePlayer, Integer> sendingAttempts = new HashMap<>();
@Override
public void sendPlayers(QueueServer queueServer) {
@@ -439,6 +437,7 @@ public class QueueManagerImpl implements QueueManager {
main.getLogger().severe("Could not find ideal server for server/group '"+server.getName()+"'");
continue;
}
server.setLastSentTime(System.currentTimeMillis());
nextPlayer.connect(selected);
}
}
@@ -1,6 +1,5 @@
package us.ajg0702.queue.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
@@ -10,10 +9,10 @@ import java.util.concurrent.TimeUnit;
public class TaskManager {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
ScheduledExecutorService updateExecutor = Executors.newScheduledThreadPool(1);
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
final ScheduledExecutorService updateExecutor = Executors.newScheduledThreadPool(1);
QueueMain main;
final QueueMain main;
public TaskManager(QueueMain main) {
this.main = main;
}
@@ -39,7 +38,6 @@ public class TaskManager {
sendTask = scheduleAtFixedRate(
main.getQueueManager()::sendPlayers,
0L,
(long) (main.getConfig().getDouble("wait-time")*1000L),
TimeUnit.MILLISECONDS
);
@@ -53,21 +51,18 @@ public class TaskManager {
messageTask = scheduleAtFixedRate(
main.getQueueManager()::sendMessages,
0L,
main.getConfig().getInt("message-time"),
TimeUnit.SECONDS
);
actionBarTask = scheduleAtFixedRate(
main.getQueueManager()::sendActionBars,
0L,
2L,
TimeUnit.SECONDS
);
queueEventTask = scheduleAtFixedRate(
main.getQueueManager()::sendQueueEvents,
0L,
2L,
TimeUnit.SECONDS
);
@@ -75,7 +70,6 @@ public class TaskManager {
if(main.getConfig().getInt("reload-servers-interval") > 0) {
reloadServerTask = scheduleAtFixedRate(
main.getQueueManager()::reloadServers,
0L,
main.getConfig().getInt("reload-servers-interval"),
TimeUnit.SECONDS
);
@@ -105,8 +99,8 @@ public class TaskManager {
}
}
private ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
return scheduleAtFixedRate(executor, command, initialDelay, period, unit);
private ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long period, TimeUnit unit) {
return scheduleAtFixedRate(executor, command, 0, period, unit);
}
@@ -5,7 +5,6 @@ import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.players.QueuePlayer;
import us.ajg0702.queue.api.queues.QueueServer;
import us.ajg0702.queue.api.server.AdaptedServer;
import us.ajg0702.queue.api.server.AdaptedServerInfo;
import us.ajg0702.queue.api.server.AdaptedServerPing;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.utils.common.GenUtils;
@@ -33,7 +32,7 @@ public class QueueServerImpl implements QueueServer {
private final QueueMain main;
private HashMap<AdaptedServer, AdaptedServerPing> pings = new HashMap<>();
private final HashMap<AdaptedServer, AdaptedServerPing> pings = new HashMap<>();
private final List<AdaptedServer> servers;
@@ -165,7 +164,11 @@ public class QueueServerImpl implements QueueServer {
@Override
public long getLastSentTime() {
return lastSentTime;
return System.currentTimeMillis() - lastSentTime;
}
@Override
public void setLastSentTime(long lastSentTime) {
this.lastSentTime = lastSentTime;
}
@Override
@@ -4,7 +4,8 @@ import us.ajg0702.queue.api.AliasManager;
import us.ajg0702.utils.common.Config;
public class FreeAliasManager implements AliasManager {
Config config;
@SuppressWarnings("unused")
final Config config;
public FreeAliasManager(Config config) {
this.config = config;
}
@@ -2,6 +2,7 @@ package us.ajg0702.queue.platforms.velocity;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import us.ajg0702.queue.api.PlatformMethods;
import us.ajg0702.queue.api.commands.ICommandSender;
import us.ajg0702.queue.api.players.AdaptedPlayer;
@@ -13,8 +14,8 @@ import java.util.logging.Logger;
public class PlatformMethodImpl implements PlatformMethods {
ProxyServer proxyServer;
Logger logger;
final ProxyServer proxyServer;
final Logger logger;
public PlatformMethodImpl(ProxyServer proxyServer, Logger logger) {
this.proxyServer = proxyServer;
@@ -25,7 +26,7 @@ public class PlatformMethodImpl implements PlatformMethods {
public void sendJoinQueueChannelMessages(QueueServer queueServer, QueuePlayer queuePlayer) {
AdaptedPlayer player = queuePlayer.getPlayer();
if(player == null) return;
player.sendMessage(Component.text());
}
@Override
@@ -32,12 +32,12 @@ import java.util.logging.Logger;
)
public class VelocityQueue {
ProxyServer proxyServer;
Logger logger;
final ProxyServer proxyServer;
final Logger logger;
QueueMain main;
File dataFolder;
final File dataFolder;
@Inject
public VelocityQueue(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataFolder) {
@@ -8,8 +8,8 @@ import java.util.List;
public class VelocityCommand implements RawCommand {
QueueMain main;
BaseCommand command;
final QueueMain main;
final BaseCommand command;
public VelocityCommand(QueueMain main, BaseCommand command) {
this.main = main;
@@ -2,13 +2,13 @@ package us.ajg0702.queue.platforms.velocity.commands;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import us.ajg0702.queue.api.commands.ICommandSender;
public class VelocitySender implements ICommandSender {
CommandSource handle;
final CommandSource handle;
public VelocitySender(CommandSource handle) {
this.handle = handle;
@@ -25,7 +25,7 @@ public class VelocitySender implements ICommandSender {
}
@Override
public void sendMessage(Component message) {
public void sendMessage(@NotNull Component message) {
handle.sendMessage(message);
}
@@ -6,6 +6,7 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.jetbrains.annotations.NotNull;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;
@@ -14,7 +15,7 @@ import java.util.UUID;
public class VelocityPlayer implements AdaptedPlayer, Audience {
Player handle;
final Player handle;
public VelocityPlayer(Player player) {
handle = player;
@@ -26,13 +27,13 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
}
@Override
public void sendMessage(Component message) {
public void sendMessage(@NotNull Component message) {
if(PlainTextComponentSerializer.plainText().serialize(message).isEmpty()) return;
handle.sendMessage(message);
}
@Override
public void sendActionBar(Component message) {
public void sendActionBar(@NotNull Component message) {
handle.sendActionBar(message);
}
@@ -49,7 +50,7 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
@Override
public String getServerName() {
Optional<ServerConnection> serverConnection = handle.getCurrentServer();
if(!serverConnection.isPresent()) return "none";
if(serverConnection.isEmpty()) return "none";
ServerConnection connection = serverConnection.get();
return connection.getServerInfo().getName();
}
@@ -38,7 +38,7 @@ public class ServerBuilderImpl implements ServerBuilder {
@Override
public AdaptedServer getServer(String name) {
Optional<RegisteredServer> serverOptional = proxyServer.getServer(name);
if(serverOptional.isPresent()) return null;
if(serverOptional.isEmpty()) return null;
return new VelocityServer(serverOptional.get());
}
@@ -5,8 +5,6 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import us.ajg0702.queue.api.server.AdaptedServerPing;
import java.util.Optional;
public class VelocityServerPing implements AdaptedServerPing {
private final ServerPing handle;
@@ -26,16 +24,12 @@ public class VelocityServerPing implements AdaptedServerPing {
@Override
public int getPlayerCount() {
Optional<ServerPing.Players> players = handle.getPlayers();
if(!players.isPresent()) return 0;
return players.get().getOnline();
return handle.getPlayers().map(ServerPing.Players::getOnline).orElse(0);
}
@Override
public int getMaxPlayers() {
Optional<ServerPing.Players> players = handle.getPlayers();
if(!players.isPresent()) return 0;
return players.get().getMax();
return handle.getPlayers().map(ServerPing.Players::getMax).orElse(0);
}
@Override