Added nullability checks on configuraton values

This commit is contained in:
4drian3d 2022-02-13 19:01:33 -05:00
parent 9a67b10ab1
commit 60cb957b19

View File

@ -1,21 +1,24 @@
package com.glyart.authmevelocity.proxy.config; package com.glyart.authmevelocity.proxy.config;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import com.moandjiezana.toml.Toml; import com.moandjiezana.toml.Toml;
import org.jetbrains.annotations.NotNull;
public final class AuthMeConfig { public final class AuthMeConfig {
private final List<String> authServers; private final List<String> authServers;
private final ServerOnLogin serverOnLogin; private final ServerOnLogin serverOnLogin;
private final Commands commands; private final Commands commands;
private final EnsureAuthServer ensure; private final EnsureAuthServer ensure;
public AuthMeConfig(Toml toml){ public AuthMeConfig(@NotNull Toml toml){
this.authServers = toml.getList("authServers"); this.authServers = Objects.requireNonNull(toml.getList("authServers"), "the list of auth servers is not available, please check your configuration for any failure");
this.serverOnLogin = toml.getTable("SendOnLogin").to(ServerOnLogin.class); this.serverOnLogin = Objects.requireNonNull(toml.getTable("SendOnLogin"), "SendOnLogin options are not available, check your configuration").to(ServerOnLogin.class);
this.commands = toml.getTable("Commands").to(Commands.class); this.commands = Objects.requireNonNull(toml.getTable("Commands"), "Commands options are not available, check your configuration").to(Commands.class);
this.ensure = toml.getTable("EnsureAuthServer").to(EnsureAuthServer.class); this.ensure = Objects.requireNonNull(toml.getTable("EnsureAuthServer"), "EnsureAuthServer options are not available, check your configuration").to(EnsureAuthServer.class);
} }
public static class ServerOnLogin { public static class ServerOnLogin {
@ -26,7 +29,7 @@ public final class AuthMeConfig {
return this.sendToServerOnLogin; return this.sendToServerOnLogin;
} }
public List<String> getTeleportServers(){ public @NotNull List<String> getTeleportServers(){
return this.teleportServers; return this.teleportServers;
} }
} }
@ -35,11 +38,11 @@ public final class AuthMeConfig {
private Set<String> allowedCommands; private Set<String> allowedCommands;
private String blockedCommandMessage; private String blockedCommandMessage;
public Set<String> getAllowedCommands(){ public @NotNull Set<String> getAllowedCommands(){
return this.allowedCommands; return this.allowedCommands;
} }
public String getBlockedMessage() { public @NotNull String getBlockedMessage() {
return this.blockedCommandMessage; return this.blockedCommandMessage;
} }
} }
@ -52,25 +55,25 @@ public final class AuthMeConfig {
return this.ensureFirstServerIsAuthServer; return this.ensureFirstServerIsAuthServer;
} }
public String getDisconnectMessage(){ public @NotNull String getDisconnectMessage(){
return this.disconnectMessage; return this.disconnectMessage;
} }
} }
public Commands getCommandsConfig(){ public @NotNull Commands getCommandsConfig(){
return this.commands; return this.commands;
} }
public ServerOnLogin getToServerOptions(){ public @NotNull ServerOnLogin getToServerOptions(){
return this.serverOnLogin; return this.serverOnLogin;
} }
public EnsureAuthServer getEnsureOptions(){ public @NotNull EnsureAuthServer getEnsureOptions(){
return this.ensure; return this.ensure;
} }
public List<String> getAuthServers(){ public @NotNull List<String> getAuthServers(){
return this.authServers; return this.authServers;
} }
} }