Skip to content

Instantly share code, notes, and snippets.

@TheGlitch76
Created July 3, 2019 18:59
Show Gist options
  • Save TheGlitch76/066991b146fb41fe1a77cc55600e0294 to your computer and use it in GitHub Desktop.
Save TheGlitch76/066991b146fb41fe1a77cc55600e0294 to your computer and use it in GitHub Desktop.
fabric-loader for nukkit
/*
* Copyright 2016 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.loader.game;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.launch.common.FabricLauncherBase;
import net.fabricmc.loader.util.Arguments;
import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class NukkitGameProvider implements GameProvider {
static class VersionData {
public String id;
public String name;
}
private String entrypoint;
private Arguments arguments;
private Path gameJar;
private VersionData versionData;
@Override
public String getGameId() {
if (versionData != null) {
String id = versionData.id;
if (id == null) {
id = versionData.name;
}
if (id != null) {
return "nukkit-" + id.replaceAll("[^a-zA-Z0-9.]+", "-");
}
}
String filename = gameJar.getFileName().toString();
if (filename.lastIndexOf('-') >= 0) {
filename = filename.substring(0, filename.lastIndexOf('-'));
}
return "nukkit-" + filename;
}
@Override
public String getGameName() {
if (versionData != null && versionData.name != null) {
return "Nukkit " + versionData.name;
}
return "Nukkit";
}
@Override
public String getEntrypoint() {
return entrypoint;
}
@Override
public Path getLaunchDirectory() {
if (arguments == null) {
return new File(".").toPath();
}
return FabricLauncherBase.getLaunchDirectory(arguments).toPath();
}
@Override
public boolean isObfuscated() {
return false;
}
@Override
public boolean requiresUrlClassLoader() {
return false;
}
@Override
public List<Path> getGameContextJars() {
List<Path> list = new ArrayList<>();
list.add(gameJar);
return list;
}
@Override
public boolean locateGame(EnvType envType, ClassLoader loader) {
List<String> entrypointClasses = new ArrayList<>();
entrypointClasses.add("cn.nukkit.Nukkit");
Optional<GameProviderHelper.EntrypointResult> entrypointResult = GameProviderHelper.findFirstClass(loader, entrypointClasses);
if (!entrypointResult.isPresent()) {
return false;
}
entrypoint = entrypointResult.get().entrypointName;
gameJar = entrypointResult.get().entrypointPath;
// realmsJar = GameProviderHelper.getSource(loader, "realmsVersion").orElse(null);
//hasModLoader = GameProviderHelper.getSource(loader, "ModLoader.class").isPresent();
versionData = null;
return true;
}
@Override
public void acceptArguments(String... argStrs) {
this.arguments = new Arguments();
arguments.parse(argStrs);
//todo impl
//FabricLauncherBase.processArgumentMap(arguments, EnvType.SERVER);
}
@Override
public void launch(ClassLoader loader) {
String targetClass = entrypoint;
try {
Class<?> c = ((ClassLoader) loader).loadClass(targetClass);
Method m = c.getMethod("main", String[].class);
m.invoke(null, (Object) arguments.toArray());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
this is here in case anybody wants to actually modify the entire toolchain (unlikely) to support a underused server software
- add the gameprovider
- register it
- compile
- download the fabric-installer
- run the installer to get fabric-server-launch.jar
- copy the contents of the compiled fabric-loader.jar inside fabric-server-loader.jar
- delete the ASM package from nukkit
- add apache commons io to the fabric-server-loader.jar
- run fabric-server-loader.jar
- ???
-profit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment