Skip to content

Commit

Permalink
misc: Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Nov 23, 2022
1 parent 0a5e51b commit f1db3fe
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 39 deletions.
Expand Up @@ -11,6 +11,7 @@
import me.dreamerzero.kickredirect.enums.CheckMode;
import me.dreamerzero.kickredirect.enums.SendMode;

@SuppressWarnings("CanBeFinal")
public class Configuration {
private Configuration(){}
public static ConfigurationContainer<Config> loadMainConfig(final KickRedirect plugin){
Expand Down Expand Up @@ -50,14 +51,15 @@ public static ConfigurationContainer<Messages> loadMessages(final KickRedirect p
messages = node.get(Messages.class);
node.set(Messages.class, messages);
loader.save(node);
} catch (ConfigurateException exception){
} catch (ConfigurateException exception) {
plugin.getLogger().error("Could not load messages.conf file", exception);
return null;
}
return new ConfigurationContainer<>(messages, Messages.class, loader, plugin.getLogger());
}

@ConfigSerializable
@SuppressWarnings({"CanBeFinal", "FieldMayBeFinal"})
public static class Config implements ConfigSection {
@Comment("Sets the list of available servers to forward to the player\nDepending on the configuration of sendMode it will be sent to one server or another")
private String[] serversToRedirect = {"lobby1", "lobby2"};
Expand Down Expand Up @@ -114,6 +116,7 @@ public void debug(boolean bool) {
}
}

@SuppressWarnings("FieldMayBeFinal")
@ConfigSerializable
public static class Messages implements ConfigSection {
@Comment("Sets the message to send if no server is found to which to send the player")
Expand Down Expand Up @@ -151,6 +154,7 @@ public Debug debug() {
return this.debugMessages;
}

@SuppressWarnings("FieldMayBeFinal")
@ConfigSerializable
public static class Reload {
@Comment("Message to send in plugin reload start")
Expand All @@ -175,6 +179,7 @@ public String failedReload() {
}
}

@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
@ConfigSerializable
public static class Debug {
private String redirectResult = "----- INITIAL DEBUG ----- "+
Expand Down Expand Up @@ -203,5 +208,5 @@ public String finalResult() {
}
}

static interface ConfigSection {}
interface ConfigSection {}
}
@@ -1,7 +1,5 @@
package me.dreamerzero.kickredirect.configuration;

import java.util.function.Consumer;

import org.slf4j.Logger;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
Expand Down Expand Up @@ -31,16 +29,11 @@ public void reload() {
this.safeReload();
}

public void setValues(Consumer<C> consumer) {
consumer.accept(this.config);
this.safeReload();
}

public C get() {
return this.config;
}

private final void safeReload() {
private void safeReload() {
C newConfig = null;
try {
final CommentedConfigurationNode node = loader.load();
Expand Down
Expand Up @@ -2,5 +2,5 @@

public enum CheckMode {
WHITELIST,
BLACKLIST;
BLACKLIST
}
Expand Up @@ -4,5 +4,5 @@ public enum KickStep {
REPEATED_ATTEMPT,
NULL_SERVER,
AVAILABLE_SERVER,
DISALLOWED_REASON;
DISALLOWED_REASON
}
Expand Up @@ -7,6 +7,7 @@
import com.velocitypowered.api.proxy.server.RegisteredServer;

import net.kyori.adventure.builder.AbstractBuilder;
import org.jetbrains.annotations.NotNull;

public class RequestBuilder implements AbstractBuilder<ConnectionRequestBuilder> {
private RegisteredServer server;
Expand All @@ -33,7 +34,7 @@ public RequestBuilder result(boolean result) {
}

@Override
public ConnectionRequestBuilder build() {
public @NotNull ConnectionRequestBuilder build() {
return new ConnectionRequestBuilder() {

@Override
Expand Down
Expand Up @@ -26,7 +26,5 @@ public ServerKickResult result(Component component) {
}
};

public ServerKickResult result(Component component) {
return null;
}
public abstract ServerKickResult result(Component component);
}
Expand Up @@ -8,6 +8,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import me.dreamerzero.kickredirect.utils.DebugInfo;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -162,7 +163,7 @@ void issue5() {
.containsKey(bundle.getPlayer().getUniqueId())
.extracting(a -> a.get(bundle.getPlayer().getUniqueId()))
.isNotNull()
.extracting(a -> a.step())
.extracting(DebugInfo::step)
.isEqualTo(KickStep.REPEATED_ATTEMPT);
}
}
Expand Up @@ -32,9 +32,9 @@
import net.kyori.adventure.text.Component;

public class TestProxyServer implements ProxyServer {
private PluginManager pManager;
private EventManager eManager;
private CommandManager cManager;
private final PluginManager pManager;
private final EventManager eManager;
private final CommandManager cManager;
private final Map<String, RegisteredServer> servers = Map.of(
"lobby1", new TestRegisteredServer(5).name("lobby1"),
"lobby2", new TestRegisteredServer(0).name("lobby2"));
Expand All @@ -57,7 +57,7 @@ public ResourcePackInfo.Builder createResourcePackBuilder(String arg0) {

@Override
public Collection<Player> getAllPlayers() {
return Set.<Player>of();
return Set.of();
}

@Override
Expand Down Expand Up @@ -87,12 +87,7 @@ public ProxyConfig getConfiguration() {

@Override
public ConsoleCommandSource getConsoleCommandSource() {
return new ConsoleCommandSource(){
@Override
public Tristate getPermissionValue(String arg0) {
return Tristate.TRUE;
}
};
return st -> Tristate.TRUE;
}

@Override
Expand Down Expand Up @@ -124,7 +119,7 @@ public PluginManager getPluginManager() {
public Scheduler getScheduler() {
return new Scheduler(){
@Override
public TaskBuilder buildTask(Object plugin, Runnable consumer) {
public TaskBuilder buildTask(@NotNull Object plugin, @NotNull Runnable consumer) {
return new TaskBuilder() {

@Override
Expand Down Expand Up @@ -156,12 +151,12 @@ public ScheduledTask schedule() {
}

@Override
public TaskBuilder buildTask(Object plugin, Consumer<ScheduledTask> consumer) {
public TaskBuilder buildTask(@NotNull Object plugin, @NotNull Consumer<ScheduledTask> consumer) {
return null;
}

@Override
public Collection<ScheduledTask> tasksByPlugin(Object plugin) {
public @NotNull Collection<ScheduledTask> tasksByPlugin(@NotNull Object plugin) {
return Collections.emptyList();
}
};
Expand All @@ -179,12 +174,12 @@ public ProxyVersion getVersion() {

@Override
public Collection<Player> matchPlayer(String arg0) {
return Set.<Player>of();
return Set.of();
}

@Override
public Collection<RegisteredServer> matchServer(String arg0) {
return Set.<RegisteredServer>of();
return Set.of();
}

@Override
Expand Down
@@ -1,10 +1,7 @@
package me.dreamerzero.kickredirect.listener.objects;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.CompletableFuture;

import com.velocitypowered.api.proxy.Player;
Expand All @@ -30,9 +27,7 @@ public TestRegisteredServer(int playerCount) {
}

public TestRegisteredServer(Player... players) {
for(Player player : players) {
PLAYERS.add(player);
}
PLAYERS.addAll(Arrays.asList(players));
}

public TestRegisteredServer(String name) {
Expand Down

0 comments on commit f1db3fe

Please sign in to comment.