Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.hollowcube.minestom.extensions;

import net.minestom.server.Auth;
import net.minestom.server.MinecraftServer;
import net.minestom.server.extensions.ExtensionManager;
import net.minestom.server.utils.validate.Check;
Expand All @@ -11,12 +12,32 @@
public final class ExtensionBootstrap {
private static ExtensionManager extensions = null;

/**
* Initialises the server with offline-mode authentication.
*
* @return the bootstrap to {@link #start(String, int)} once setup is done
*/
public static @NotNull ExtensionBootstrap init() {
return new ExtensionBootstrap(MinecraftServer.init());
return init(new Auth.Offline());
}

/**
* Initialises the server with the given authentication mode.
*
* <p>The {@link Auth} is bound to the {@code ServerProcess} by {@link MinecraftServer#init(Auth)}
* and cannot be swapped afterwards, so a server that sits behind a Velocity proxy has to pass
* {@link Auth.Velocity} here - there is no way to switch it on later.
*
* @param auth how incoming connections are authenticated, e.g. {@link Auth.Velocity} for a
* server behind a Velocity proxy
* @return the bootstrap to {@link #start(String, int)} once setup is done
*/
public static @NotNull ExtensionBootstrap init(@NotNull Auth auth) {
return new ExtensionBootstrap(MinecraftServer.init(auth));
}

public static @NotNull ExtensionManager getExtensionManager() {
Check.notNull(extensions, "ExtensionBootstrap has not been initialized yet!");

Check warning on line 40 in minestom-extensions/src/main/java/net/hollowcube/minestom/extensions/ExtensionBootstrap.java

View workflow job for this annotation

GitHub Actions / build / Build (macos-latest)

[removal] notNull(@org.jetbrains.annotations.Nullable Object,String) in Check has been deprecated and marked for removal
return extensions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.hollowcube.minestom.extensions;

import net.minestom.server.Auth;
import net.minestom.server.MinecraftServer;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;

/**
* Pins that {@link ExtensionBootstrap} hands the caller's {@link Auth} to
* {@link MinecraftServer#init(Auth)}.
*
* <p>This is the whole point of the {@code init(Auth)} overload and it cannot be worked around from
* the outside: the {@code ServerProcess} keeps the {@link Auth} it was built with, so a bootstrap
* that silently called {@code MinecraftServer.init()} would leave every server behind a Velocity
* proxy on offline-mode authentication with no way to correct it afterwards.
*/
class ExtensionBootstrapAuthTest {

@Test
@DisplayName("init(Auth) binds the given auth to the server process")
void initWithAuthBindsGivenAuth() {
Auth.Velocity velocity = new Auth.Velocity("a-velocity-secret");

ExtensionBootstrap.init(velocity);

assertSame(velocity, MinecraftServer.process().auth());
}

@Test
@DisplayName("init() keeps defaulting to offline mode")
void initWithoutAuthDefaultsToOffline() {
ExtensionBootstrap.init();

assertInstanceOf(Auth.Offline.class, MinecraftServer.process().auth());
}
}
Loading