From 0d94080c743c64949e7716b8b875a2b563d64099 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 20 Nov 2018 12:23:28 -0500 Subject: [PATCH] Remove unneeded null checks --- .../velocitypowered/proxy/VelocityServer.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 2216982a9..ba7a982e9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -72,24 +72,33 @@ public class VelocityServer implements ProxyServer { .registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer()) .create(); - private @MonotonicNonNull ConnectionManager cm; + private ConnectionManager cm; private @MonotonicNonNull VelocityConfiguration configuration; private @MonotonicNonNull NettyHttpClient httpClient; private @MonotonicNonNull KeyPair serverKeyPair; - private @MonotonicNonNull ServerMap servers; + private ServerMap servers; private final VelocityCommandManager commandManager = new VelocityCommandManager(); private final AtomicBoolean shutdownInProgress = new AtomicBoolean(false); private boolean shutdown = false; - private @MonotonicNonNull VelocityPluginManager pluginManager; + private VelocityPluginManager pluginManager; private final Map connectionsByUuid = new ConcurrentHashMap<>(); private final Map connectionsByName = new ConcurrentHashMap<>(); - private @MonotonicNonNull VelocityConsole console; + private VelocityConsole console; private @MonotonicNonNull Ratelimiter ipAttemptLimiter; - private @MonotonicNonNull VelocityEventManager eventManager; - private @MonotonicNonNull VelocityScheduler scheduler; + private VelocityEventManager eventManager; + private VelocityScheduler scheduler; private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar(); + VelocityServer() { + pluginManager = new VelocityPluginManager(this); + eventManager = new VelocityEventManager(pluginManager); + scheduler = new VelocityScheduler(pluginManager); + console = new VelocityConsole(this); + cm = new ConnectionManager(this); + servers = new ServerMap(this); + } + public KeyPair getServerKeyPair() { if (serverKeyPair == null) { throw new AssertionError(); @@ -135,12 +144,6 @@ public class VelocityServer implements ProxyServer { logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion()); serverKeyPair = EncryptionUtils.createRsaKeyPair(1024); - pluginManager = new VelocityPluginManager(this); - eventManager = new VelocityEventManager(pluginManager); - scheduler = new VelocityScheduler(pluginManager); - console = new VelocityConsole(this); - cm = new ConnectionManager(this); - servers = new ServerMap(this); cm.logChannelInformation(); @@ -224,9 +227,6 @@ public class VelocityServer implements ProxyServer { } public Bootstrap initializeGenericBootstrap() { - if (cm == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return this.cm.createWorker(); } @@ -362,66 +362,41 @@ public class VelocityServer implements ProxyServer { @Override public Optional getServer(String name) { - Preconditions.checkNotNull(name, "name"); - if (servers == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return servers.getServer(name); } @Override public Collection getAllServers() { - if (servers == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return servers.getAllServers(); } @Override public RegisteredServer registerServer(ServerInfo server) { - if (servers == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return servers.register(server); } @Override public void unregisterServer(ServerInfo server) { - if (servers == null) { - throw new IllegalStateException("Server did not initialize properly."); - } servers.unregister(server); } @Override public VelocityConsole getConsoleCommandSource() { - if (console == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return console; } @Override public PluginManager getPluginManager() { - if (pluginManager == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return pluginManager; } @Override public EventManager getEventManager() { - if (eventManager == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return eventManager; } @Override public VelocityScheduler getScheduler() { - if (scheduler == null) { - throw new IllegalStateException("Server did not initialize properly."); - } return scheduler; }