Skip to content

Commit

Permalink
Fix some small deprecations/IDE warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Nov 25, 2024
1 parent e30f948 commit 48c6dea
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/earthmc/queue/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void sendNext() {
player.sendMessage(Component.text("You have been sent to " + formattedName + ".", NamedTextColor.GREEN));
failedAttempts = 0;
sendProgressMessages(queue);
plugin.logger().info(player.getUsername() + " has been sent to " + formattedName + " via queue.");
plugin.logger().info("{} has been sent to {} via queue.", player.getUsername(), formattedName);
} else {
player.sendMessage(Component.text("Unable to connect you to " + formattedName + ".", NamedTextColor.RED));

Expand All @@ -134,7 +134,7 @@ public void sendNext() {
player.sendMessage(Component.text("Reason: ", reason.colorIfAbsent(NamedTextColor.RED).color()).append(reason));
}
}).exceptionally(e -> {
plugin.logger().error("An exception occurred while trying to send " + player.getUsername() + " to " + formattedName, e);
plugin.logger().error("An exception occurred while trying to send {} to {}", player.getUsername(), formattedName, e);
player.sendMessage(Component.text("Unable to connect you to " + formattedName + ".", NamedTextColor.RED));
player.sendMessage(Component.text("Attempting to re-queue you...", NamedTextColor.RED));
toSend.queue(this);
Expand Down Expand Up @@ -199,7 +199,7 @@ public void enqueue(QueuedPlayer player, boolean confirmation) {
return;
} else {
player.sendMessage(Component.text("You have been removed from the queue for " + player.queue().getServerFormatted() + ".", NamedTextColor.RED));
plugin.logger().info(player.name() + " has been removed from the queue, because they joined the queue for another.");
plugin.logger().info("{} has been removed from the queue, because they joined the queue for another.", player.name());
player.queue().remove(player);
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/net/earthmc/queue/QueuePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.gson.Gson;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
Expand Down Expand Up @@ -46,6 +46,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

Expand All @@ -70,10 +71,10 @@ public QueuePlugin(ProxyServer proxy, CommandManager commandManager, Logger logg
this.logger = logger;
this.pluginFolderPath = pluginFolderPath;

commandManager.register("joinqueue", new JoinCommand(this));
commandManager.register("leavequeue", new LeaveCommand());
commandManager.register(PauseCommand.createCommand(this));
commandManager.register("queue", new QueueCommand(this));
commandManager.register(buildMeta("joinqueue"), new JoinCommand(this));
commandManager.register(buildMeta("leavequeue"), new LeaveCommand());
commandManager.register(buildMeta("pausequeue"), PauseCommand.createCommand(this));
commandManager.register(buildMeta("queue"), new QueueCommand(this));
}

@Subscribe
Expand Down Expand Up @@ -189,7 +190,7 @@ public void onServerConnect(ServerConnectedEvent event) {
processAutoQueue(event, player);
}

@Subscribe(order = PostOrder.LATE)
@Subscribe
public void onChooseInitialServer(PlayerChooseInitialServerEvent event) {
final RegisteredServer initial = event.getInitialServer().orElse(null);

Expand All @@ -202,8 +203,9 @@ public void onChooseInitialServer(PlayerChooseInitialServerEvent event) {
return;

QueuedPlayer player = queued(event.getPlayer());
if (player.loadFuture() != null && player.getLastJoinedServer().isEmpty())
player.loadFuture().join(); // We want to ensure that player data is loaded so that we can get their last server
final CompletableFuture<Void> loadFuture = player.loadFuture();
if (loadFuture != null && player.getLastJoinedServer().isEmpty())
loadFuture.join(); // We want to ensure that player data is loaded so that we can get their last server

final String target = validateAutoQueueTarget(event.getPlayer(), player.getLastJoinedServer().orElse(config.autoQueueSettings().defaultTarget()));

Expand All @@ -215,7 +217,7 @@ public void onChooseInitialServer(PlayerChooseInitialServerEvent event) {
return;

event.setInitialServer(queue.getServer());
logger.info(event.getPlayer().getUsername() + " has been sent to " + queue.getServerFormatted() + " via autoqueue.");
logger.info("{} has been sent to {} via autoqueue.", event.getPlayer().getUsername(), queue.getServerFormatted());
}

public void processAutoQueue(ServerConnectedEvent event, QueuedPlayer player) {
Expand Down Expand Up @@ -387,4 +389,8 @@ public void savePausedQueues() {
}

private record PausedQueue(String server, Instant unpauseTime, String reason) {}

private CommandMeta buildMeta(String alias) {
return this.proxy.getCommandManager().metaBuilder(alias).plugin(this).build();
}
}
2 changes: 0 additions & 2 deletions src/main/java/net/earthmc/queue/commands/QueueCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import net.earthmc.queue.QueuedPlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/earthmc/queue/object/Ratio.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Ratio(Map<T, Integer> ratios) {
}
}

@SuppressWarnings("unchecked")
public Ratio(List<SubQueue> subQueues) {
for (SubQueue subQueue : subQueues) {
this.options.add(new Option<>((T) subQueue, subQueue.maxSends));
Expand Down Expand Up @@ -83,7 +84,7 @@ public T next(boolean dry, @NotNull Predicate<T> predicate, @Nullable T defaultV
// return the first matching predicate (if any). Otherwise, just return the default value.
// This fixes edge cases where players can get stuck in a sub queue if their sub queue has reached max uses
// and none of the other sub queues have any players in them. Unit tested at 'testRatioWithMatchingPredicate'
if (predicateMatches.size() > 0)
if (!predicateMatches.isEmpty())
return predicateMatches.get(0).value;
else
return defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CompletableFuture<Void> savePlayer(@NotNull QueuedPlayer player) {
properties.store(os, null);
}
} catch (IOException e) {
plugin.logger().error("An error occurred when saving data for " + player.uuid(), e);
plugin.logger().error("An error occurred when saving data for {}", player.uuid(), e);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/earthmc/queue/storage/SQLStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public CompletableFuture<Void> loadPlayer(@NotNull QueuedPlayer player) {
}
}
} catch (SQLException e) {
plugin.logger().error("while loading data for player " + player.name(), e);
plugin.logger().error("while loading data for player {}", player.name(), e);
}
});
}
Expand All @@ -94,7 +94,7 @@ public CompletableFuture<Void> savePlayer(@NotNull QueuedPlayer player) {

ps.execute();
} catch (SQLException e) {
plugin.logger().error("while saving data for player " + player.name(), e);
plugin.logger().error("while saving data for player {}", player.name(), e);
}
});
}
Expand Down

0 comments on commit 48c6dea

Please sign in to comment.