mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-27 23:45:44 +00:00
Initial port to 1.18
Co-authored-by: David Quintana <[email protected]> Co-authored-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
be0a6819ac
commit
40a174310d
538 files changed
+3322
-9030
No files matched your search
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.server;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeI18n;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LanguageHook
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final Pattern PATTERN = Pattern.compile("%(\\d+\\$)?[\\d\\.]*[df]");
|
||||
private static List<Map<String, String>> capturedTables = new ArrayList<>(2);
|
||||
private static Map<String, String> modTable;
|
||||
/**
|
||||
* Loads lang files on the server
|
||||
*/
|
||||
public static void captureLanguageMap(Map<String, String> table)
|
||||
{
|
||||
capturedTables.add(table);
|
||||
if (modTable != null) {
|
||||
capturedTables.forEach(t->t.putAll(modTable));
|
||||
}
|
||||
}
|
||||
|
||||
// The below is based on client side net.minecraft.client.resources.Locale code
|
||||
private static void loadLocaleData(final List<Resource> allResources) {
|
||||
allResources.stream().map(Resource::getInputStream).forEach(LanguageHook::loadLocaleData);
|
||||
}
|
||||
|
||||
private static void loadLocaleData(final InputStream inputstream) {
|
||||
try
|
||||
{
|
||||
JsonElement jsonelement = GSON.fromJson(new InputStreamReader(inputstream, StandardCharsets.UTF_8), JsonElement.class);
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(jsonelement, "strings");
|
||||
|
||||
jsonobject.entrySet().forEach(entry -> {
|
||||
String s = PATTERN.matcher(GsonHelper.convertToString(entry.getValue(), entry.getKey())).replaceAll("%$1s");
|
||||
modTable.put(entry.getKey(), s);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(inputstream);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadLanguage(String langName, MinecraftServer server) {
|
||||
String langFile = String.format("lang/%s.json", langName);
|
||||
ResourceManager resourceManager = server.getServerResources().getResourceManager();
|
||||
resourceManager.getNamespaces().forEach(namespace -> {
|
||||
try {
|
||||
ResourceLocation langResource = new ResourceLocation(namespace, langFile);
|
||||
loadLocaleData(resourceManager.getResources(langResource));
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
} catch (Exception exception) {
|
||||
LOGGER.warn("Skipped language file: {}:{}", namespace, langFile, exception);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void loadForgeAndMCLangs() {
|
||||
modTable = new HashMap<>(5000);
|
||||
final InputStream mc = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/minecraft/lang/en_us.json");
|
||||
final InputStream forge = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/forge/lang/en_us.json");
|
||||
loadLocaleData(mc);
|
||||
loadLocaleData(forge);
|
||||
capturedTables.forEach(t->t.putAll(modTable));
|
||||
ForgeI18n.loadLanguageData(modTable);
|
||||
}
|
||||
|
||||
static void loadLanguagesOnServer(MinecraftServer server) {
|
||||
modTable = new HashMap<>(5000);
|
||||
// Possible multi-language server support?
|
||||
for (String lang : Arrays.asList("en_us")) {
|
||||
loadLanguage(lang, server);
|
||||
}
|
||||
capturedTables.forEach(t->t.putAll(modTable));
|
||||
ForgeI18n.loadLanguageData(modTable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.server;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.server.packs.repository.PackSource;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.common.util.LogicalSidedProvider;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
import net.minecraftforge.fml.ModLoadingWarning;
|
||||
import net.minecraftforge.network.ConnectionType;
|
||||
import net.minecraftforge.network.NetworkConstants;
|
||||
import net.minecraftforge.network.ServerStatusPing;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.forgespi.locating.IModFile;
|
||||
import net.minecraftforge.resource.PathResourcePack;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.fml.loading.FileUtils;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
|
||||
public class ServerLifecycleHooks
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Marker SERVERHOOKS = MarkerManager.getMarker("SERVERHOOKS");
|
||||
private static final LevelResource SERVERCONFIG = new LevelResource("serverconfig");
|
||||
private static volatile CountDownLatch exitLatch = null;
|
||||
private static MinecraftServer currentServer;
|
||||
|
||||
private static Path getServerConfigPath(final MinecraftServer server)
|
||||
{
|
||||
final Path serverConfig = server.getWorldPath(SERVERCONFIG);
|
||||
FileUtils.getOrCreateDirectory(serverConfig, "serverconfig");
|
||||
return serverConfig;
|
||||
}
|
||||
|
||||
public static boolean handleServerAboutToStart(final MinecraftServer server)
|
||||
{
|
||||
currentServer = server;
|
||||
currentServer.getStatus().setForgeData(new ServerStatusPing()); //gathers NetworkRegistry data
|
||||
// on the dedi server we need to force the stuff to setup properly
|
||||
LogicalSidedProvider.setServer(()->server);
|
||||
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
|
||||
return !MinecraftForge.EVENT_BUS.post(new ServerAboutToStartEvent(server));
|
||||
}
|
||||
|
||||
public static boolean handleServerStarting(final MinecraftServer server)
|
||||
{
|
||||
DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, ()->()->LanguageHook.loadLanguagesOnServer(server));
|
||||
return !MinecraftForge.EVENT_BUS.post(new ServerStartingEvent(server));
|
||||
}
|
||||
|
||||
public static void handleServerStarted(final MinecraftServer server)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new ServerStartedEvent(server));
|
||||
allowLogins.set(true);
|
||||
}
|
||||
|
||||
public static void handleServerStopping(final MinecraftServer server)
|
||||
{
|
||||
allowLogins.set(false);
|
||||
MinecraftForge.EVENT_BUS.post(new ServerStoppingEvent(server));
|
||||
}
|
||||
|
||||
public static void expectServerStopped()
|
||||
{
|
||||
exitLatch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
public static void handleServerStopped(final MinecraftServer server)
|
||||
{
|
||||
if (!server.isDedicatedServer()) GameData.revertToFrozen();
|
||||
MinecraftForge.EVENT_BUS.post(new ServerStoppedEvent(server));
|
||||
currentServer = null;
|
||||
LogicalSidedProvider.setServer(null);
|
||||
CountDownLatch latch = exitLatch;
|
||||
|
||||
if (latch != null)
|
||||
{
|
||||
latch.countDown();
|
||||
exitLatch = null;
|
||||
}
|
||||
ConfigTracker.INSTANCE.unloadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
|
||||
}
|
||||
|
||||
public static MinecraftServer getCurrentServer()
|
||||
{
|
||||
return currentServer;
|
||||
}
|
||||
private static AtomicBoolean allowLogins = new AtomicBoolean(false);
|
||||
|
||||
public static boolean handleServerLogin(final ClientIntentionPacket packet, final Connection manager) {
|
||||
if (!allowLogins.get())
|
||||
{
|
||||
TextComponent text = new TextComponent("Server is still starting! Please wait before reconnecting.");
|
||||
LOGGER.info(SERVERHOOKS,"Disconnecting Player (server is still starting): {}", text.getContents());
|
||||
manager.send(new ClientboundLoginDisconnectPacket(text));
|
||||
manager.disconnect(text);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (packet.getIntention() == ConnectionProtocol.LOGIN) {
|
||||
final ConnectionType connectionType = ConnectionType.forVersionFlag(packet.getFMLVersion());
|
||||
final int versionNumber = connectionType.getFMLVersionNumber(packet.getFMLVersion());
|
||||
|
||||
if (connectionType == ConnectionType.MODDED && versionNumber != NetworkConstants.FMLNETVERSION) {
|
||||
rejectConnection(manager, connectionType, "This modded server is not impl compatible with your modded client. Please verify your Forge version closely matches the server. Got net version "+ versionNumber + " this server is net version "+ NetworkConstants.FMLNETVERSION);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (connectionType == ConnectionType.VANILLA && !NetworkRegistry.acceptsVanillaClientConnections()) {
|
||||
rejectConnection(manager, connectionType, "This server has mods that require Forge to be installed on the client. Contact your server admin for more details.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (packet.getIntention() == ConnectionProtocol.STATUS) return true;
|
||||
|
||||
NetworkHooks.registerServerLoginChannel(manager, packet);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void rejectConnection(final Connection manager, ConnectionType type, String message) {
|
||||
manager.setProtocol(ConnectionProtocol.LOGIN);
|
||||
LOGGER.info(SERVERHOOKS, "Disconnecting {} connection attempt: {}", type, message);
|
||||
TextComponent text = new TextComponent(message);
|
||||
manager.send(new ClientboundLoginDisconnectPacket(text));
|
||||
manager.disconnect(text);
|
||||
}
|
||||
|
||||
public static void handleExit(int retVal)
|
||||
{
|
||||
System.exit(retVal);
|
||||
}
|
||||
|
||||
//INTERNAL MODDERS DO NOT USE
|
||||
public static RepositorySource buildPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks) {
|
||||
return (packList, factory) -> serverPackFinder(modResourcePacks, packList, factory);
|
||||
}
|
||||
|
||||
private static void serverPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks, Consumer<Pack> consumer, Pack.PackConstructor factory) {
|
||||
for (Entry<IModFile, ? extends PathResourcePack> e : modResourcePacks.entrySet())
|
||||
{
|
||||
IModInfo mod = e.getKey().getModInfos().get(0);
|
||||
if (Objects.equals(mod.getModId(), "minecraft")) continue; // skip the minecraft "mod"
|
||||
final String name = "mod:" + mod.getModId();
|
||||
final Pack packInfo = Pack.create(name, false, e::getValue, factory, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
if (packInfo == null) {
|
||||
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
||||
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
|
||||
continue;
|
||||
}
|
||||
LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
|
||||
consumer.accept(packInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/** @deprecated For removal in 1.18, superseded by {@code /execute in <dim> run tp <targets>} */
|
||||
@Deprecated(forRemoval = true, since = "1.17.1")
|
||||
public class CommandSetDimension
|
||||
{
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.setdim.invalid.entity"));
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("setdimension")
|
||||
.requires(cs->cs.hasPermission(2)) //permission
|
||||
.then(Commands.argument("targets", EntityArgument.entities())
|
||||
.then(Commands.argument("dim", DimensionArgument.dimension())
|
||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||
.executes(ctx -> execute(ctx, EntityArgument.getOptionalEntities(ctx, "targets"), DimensionArgument.getDimension(ctx, "dim"), BlockPosArgument.getSpawnablePos(ctx, "pos")))
|
||||
)
|
||||
.executes(ctx -> execute(ctx, EntityArgument.getOptionalEntities(ctx, "targets"), DimensionArgument.getDimension(ctx, "dim"), new BlockPos(ctx.getSource().getPosition())))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<CommandSourceStack> ctx, Collection<? extends Entity> entities, ServerLevel dim, BlockPos pos) throws CommandSyntaxException
|
||||
{
|
||||
entities.removeIf(e -> !canEntityTeleport(e));
|
||||
if (entities.isEmpty())
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
String cmdTarget = "@s";
|
||||
String posTarget = "~ ~ ~";
|
||||
for (ParsedCommandNode<CommandSourceStack> parsed : ctx.getNodes())
|
||||
{
|
||||
if (parsed.getNode() instanceof ArgumentCommandNode)
|
||||
{
|
||||
if ("targets".equals(parsed.getNode().getName()))
|
||||
{
|
||||
cmdTarget = parsed.getRange().get(ctx.getInput());
|
||||
}
|
||||
else if ("pos".equals(parsed.getNode().getName()))
|
||||
{
|
||||
posTarget = parsed.getRange().get(ctx.getInput());
|
||||
}
|
||||
}
|
||||
}
|
||||
final String dimName = dim.dimension().location().toString();
|
||||
final String finalCmdTarget = cmdTarget;
|
||||
final String finalPosTarget = posTarget;
|
||||
Component suggestion = new TranslatableComponent("/execute in %s run tp %s %s", dimName, cmdTarget, finalPosTarget)
|
||||
.withStyle((style) -> style.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/execute in " + dimName + " run tp " + finalCmdTarget + " " + finalPosTarget)));
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.setdim.deprecated", suggestion), true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static boolean canEntityTeleport(Entity entity)
|
||||
{
|
||||
// use vanilla portal logic from BlockPortal#onEntityCollision
|
||||
return !entity.isPassenger() && !entity.isVehicle() && entity.canChangeDimensions();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
|
||||
public class CommandDimensions
|
||||
class DimensionsCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
+1
-1
@@ -49,7 +49,7 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
class CommandEntity
|
||||
class EntityCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
@@ -29,13 +29,12 @@ public class ForgeCommand
|
||||
{
|
||||
dispatcher.register(
|
||||
LiteralArgumentBuilder.<CommandSourceStack>literal("forge")
|
||||
.then(CommandTps.register())
|
||||
.then(CommandTrack.register())
|
||||
.then(CommandEntity.register())
|
||||
.then(CommandGenerate.register())
|
||||
.then(CommandDimensions.register())
|
||||
.then(CommandSetDimension.register())
|
||||
.then(CommandModList.register())
|
||||
.then(TPSCommand.register())
|
||||
.then(TrackCommand.register())
|
||||
.then(EntityCommand.register())
|
||||
.then(GenerateCommand.register())
|
||||
.then(DimensionsCommand.register())
|
||||
.then(ModListCommand.register())
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.WorldWorkerManager;
|
||||
|
||||
class CommandGenerate
|
||||
class GenerateCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
+1
-1
@@ -26,7 +26,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandModList {
|
||||
class ModListCommand {
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("mods")
|
||||
+1
-1
@@ -30,7 +30,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
class CommandTps
|
||||
class TPSCommand
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
|
||||
private static final long[] UNLOADED = new long[] {0};
|
||||
@@ -26,8 +26,8 @@ import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.fmllegacy.network.ConnectionType;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkHooks;
|
||||
import net.minecraftforge.network.ConnectionType;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class TextComponentHelper
|
||||
{
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.server.timings.ForgeTimings;
|
||||
import net.minecraftforge.server.timings.TimeTracker;
|
||||
|
||||
class CommandTrack
|
||||
class TrackCommand
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMAT = new DecimalFormat("#####0.00");
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.server.loading;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.logging.CrashReportExtender;
|
||||
import net.minecraftforge.common.util.LogicalSidedProvider;
|
||||
import net.minecraftforge.server.LanguageHook;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
|
||||
public class ServerModLoader
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static boolean hasErrors = false;
|
||||
|
||||
public static void load() {
|
||||
LogicalSidedProvider.setServer(()-> {
|
||||
throw new IllegalStateException("Unable to access server yet");
|
||||
});
|
||||
LanguageHook.loadForgeAndMCLangs();
|
||||
try {
|
||||
ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ()->{});
|
||||
ModLoader.get().loadMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ()->{});
|
||||
ModLoader.get().finishMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ()->{});
|
||||
} catch (LoadingFailedException error) {
|
||||
ServerModLoader.hasErrors = true;
|
||||
// In case its not loaded properly
|
||||
LanguageHook.loadForgeAndMCLangs();
|
||||
CrashReportExtender.dumpModLoadingCrashReport(LOGGER, error, new File("."));
|
||||
throw error;
|
||||
}
|
||||
List<ModLoadingWarning> warnings = ModLoader.get().getWarnings();
|
||||
if (!warnings.isEmpty()) {
|
||||
LOGGER.warn(LOADING, "Mods loaded with {} warnings", warnings.size());
|
||||
warnings.forEach(warning -> LOGGER.warn(LOADING, warning.formatToString()));
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.start();
|
||||
}
|
||||
|
||||
public static boolean hasErrors() {
|
||||
return ServerModLoader.hasErrors;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package net.minecraftforge.server.permission;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import net.minecraftforge.server.permission.context.IContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
Reference in new issue
Block a user