mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-24 22:11:18 -04:00
Remove primary server getters
This commit is contained in:
parent
ff486728a9
commit
c84f36209d
5 changed files with 0 additions and 154 deletions
fabric-lifecycle-events-v1/src/main
java/net/fabricmc/fabric
api/event/lifecycle/v1
impl/lifecycle
resources
|
@ -65,42 +65,6 @@ public final class ServerLifecycleEvents {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the currently running primary server.
|
||||
*
|
||||
* <p><b>Use of this method is highly discouraged and not recommended since there is no real restriction on whether the game engine could run multiple servers concurrently.</b>
|
||||
* One should attempt to obtain the server instance from a {@link ServerWorld server world} or via other means.
|
||||
*
|
||||
* <p>The server instance returned SHOULD NOT be cached! Call the method every time you need the server.
|
||||
*
|
||||
* @return the currently running server
|
||||
* @throws IllegalStateException if the server is not available
|
||||
*/
|
||||
@Deprecated
|
||||
public static MinecraftServer getPrimaryServer() {
|
||||
final MinecraftServer server = ServerLifecycleInternals.getServer();
|
||||
|
||||
if (server != null) {
|
||||
return server;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Server was not available");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the primary server is available.
|
||||
* The server may not always be available on a {@link net.fabricmc.api.EnvType#CLIENT client}, so it is advised to verify this is {@code true} before calling {@link ServerLifecycleEvents#getPrimaryServer()}
|
||||
*
|
||||
* <p><b>Use of this method is highly discouraged and not recommended since there is no real restriction on whether the game engine could run multiple servers concurrently.</b>
|
||||
* One should attempt to obtain the server instance from a {@link ServerWorld server world} or via other means.
|
||||
*
|
||||
* @return true if the server is available.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isPrimaryServerAvailable() {
|
||||
return ServerLifecycleInternals.getServer() != null;
|
||||
}
|
||||
|
||||
public interface LifecycleCallback {
|
||||
void onChangeLifecycle(MinecraftServer server);
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.lifecycle;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
public final class DedicatedServerLifecycleInternals extends ServerLifecycleInternals implements DedicatedServerModInitializer {
|
||||
public DedicatedServerLifecycleInternals() {
|
||||
// On a dedicated server, the game instance is the server
|
||||
super(() -> (MinecraftServer) FabricLoader.getInstance().getGameInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.lifecycle;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public abstract class ServerLifecycleInternals {
|
||||
private static Supplier<MinecraftServer> serverSupplier;
|
||||
|
||||
/* @Nullable */
|
||||
public static MinecraftServer getServer() {
|
||||
return serverSupplier.get();
|
||||
}
|
||||
|
||||
protected ServerLifecycleInternals(Supplier<MinecraftServer> supplier) {
|
||||
serverSupplier = supplier;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.impl.lifecycle.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.impl.lifecycle.ServerLifecycleInternals;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class IntegratedServerLifecycleInternals extends ServerLifecycleInternals implements ClientModInitializer {
|
||||
public IntegratedServerLifecycleInternals() {
|
||||
// On an a client, the server is in the client
|
||||
super(() -> {
|
||||
// Get the client
|
||||
final MinecraftClient client = (MinecraftClient) FabricLoader.getInstance().getGameInstance();
|
||||
|
||||
// And return the client's integrated server
|
||||
return client.getServer();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
}
|
||||
}
|
|
@ -18,14 +18,6 @@
|
|||
"mixins": [
|
||||
"fabric-lifecycle-events-v1.mixins.json"
|
||||
],
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"net.fabricmc.fabric.impl.lifecycle.client.IntegratedServerLifecycleInternals"
|
||||
],
|
||||
"server": [
|
||||
"net.fabricmc.fabric.impl.lifecycle.DedicatedServerLifecycleInternals"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabric-api-base": "*"
|
||||
|
|
Loading…
Add table
Reference in a new issue