ViaLoader/src/main/java/net/raphimc/vialoader/ViaLoader.java

82 lines
3.3 KiB
Java
Raw Normal View History

2023-01-11 20:52:23 +01:00
/*
2023-05-28 19:19:59 +02:00
* This file is part of ViaLoader - https://github.com/RaphiMC/ViaLoader
2024-01-01 02:31:00 +01:00
* Copyright (C) 2020-2024 RK_01/RaphiMC and contributors
2023-01-11 20:52:23 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-05-28 19:19:59 +02:00
package net.raphimc.vialoader;
2023-01-04 01:01:32 +01:00
import com.viaversion.viaversion.ViaManagerImpl;
import com.viaversion.viaversion.api.Via;
2023-01-11 20:52:23 +01:00
import com.viaversion.viaversion.api.platform.ViaInjector;
import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
2023-01-04 01:01:32 +01:00
import com.viaversion.viaversion.commands.ViaCommandHandler;
import com.viaversion.viaversion.protocol.ProtocolManagerImpl;
2023-05-28 19:19:59 +02:00
import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl;
import net.raphimc.vialoader.impl.viaversion.VLCommandHandler;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
import net.raphimc.vialoader.util.JLoggerToSLF4J;
2023-01-04 01:01:32 +01:00
import org.slf4j.LoggerFactory;
import java.util.function.Supplier;
import java.util.logging.Level;
2023-01-04 01:01:32 +01:00
import java.util.logging.Logger;
2023-05-28 19:19:59 +02:00
public class ViaLoader {
2023-01-04 01:01:32 +01:00
2023-01-04 03:33:44 +01:00
public static final String VERSION = "${version}";
2023-05-28 19:19:59 +02:00
private static final Logger LOGGER = new JLoggerToSLF4J(LoggerFactory.getLogger("ViaLoader"));
2023-01-04 01:01:32 +01:00
@SuppressWarnings("ReassignedVariable")
2023-02-20 15:34:13 +01:00
public static void init(ViaPlatform<?> platform, ViaPlatformLoader loader, ViaInjector injector, ViaCommandHandler commandHandler, final Supplier<?>... platformSuppliers) {
2023-01-04 01:01:32 +01:00
if (platform == null) platform = new ViaVersionPlatformImpl(null);
2023-05-28 19:19:59 +02:00
if (loader == null) loader = new VLLoader();
if (injector == null) injector = new VLInjector();
if (commandHandler == null) commandHandler = new VLCommandHandler();
2023-01-04 01:01:32 +01:00
Via.init(ViaManagerImpl.builder()
.platform(platform)
.loader(loader)
.injector(injector)
.commandHandler(commandHandler)
.build());
2024-02-13 23:30:03 +01:00
Via.getConfig().reload();
2023-02-20 15:35:04 +01:00
if (platformSuppliers != null) {
Via.getManager().addEnableListener(() -> {
2023-02-20 15:34:13 +01:00
for (Supplier<?> additionalPlatformSupplier : platformSuppliers) {
try {
additionalPlatformSupplier.get();
} catch (Throwable e) {
2023-02-20 15:34:13 +01:00
LOGGER.log(Level.SEVERE, "Platform failed to load", e);
}
}
2023-02-20 15:35:04 +01:00
});
}
2023-01-04 01:01:32 +01:00
final ViaManagerImpl viaManager = (ViaManagerImpl) Via.getManager();
viaManager.init();
viaManager.onServerLoaded();
2023-01-04 01:01:32 +01:00
Via.getManager().getProtocolManager().setMaxProtocolPathSize(Integer.MAX_VALUE);
Via.getManager().getProtocolManager().setMaxPathDeltaIncrease(-1);
((ProtocolManagerImpl) Via.getManager().getProtocolManager()).refreshVersions();
}
}