2019-07-08 17:55:14 +00:00
|
|
|
/*
|
2020-01-09 03:05:42 +00:00
|
|
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2019-07-08 17:55:14 +00:00
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector;
|
|
|
|
|
2020-09-17 00:08:26 +00:00
|
|
|
import com.fasterxml.jackson.core.JsonParser;
|
2020-05-25 01:07:05 +00:00
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2020-07-31 23:47:23 +00:00
|
|
|
import com.nukkitx.network.raknet.RakNetConstants;
|
2019-07-08 23:35:32 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.BedrockServer;
|
2019-07-08 19:19:41 +00:00
|
|
|
import lombok.Getter;
|
2020-06-19 12:50:10 +00:00
|
|
|
import lombok.Setter;
|
2020-11-14 23:49:56 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2020-04-29 20:01:53 +00:00
|
|
|
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
2020-04-19 23:08:14 +00:00
|
|
|
import org.geysermc.connector.command.CommandManager;
|
2020-07-20 23:02:18 +00:00
|
|
|
import org.geysermc.connector.common.AuthType;
|
2020-06-10 22:58:29 +00:00
|
|
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
2019-08-06 01:59:54 +00:00
|
|
|
import org.geysermc.connector.metrics.Metrics;
|
2019-07-10 06:34:10 +00:00
|
|
|
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
2019-12-21 17:35:48 +00:00
|
|
|
import org.geysermc.connector.network.remote.RemoteServer;
|
2019-10-16 18:55:05 +00:00
|
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.BiomeTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
|
|
|
|
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
|
2020-07-03 00:10:43 +00:00
|
|
|
import org.geysermc.connector.network.translators.effect.EffectRegistry;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
|
|
|
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
2020-07-07 07:44:39 +00:00
|
|
|
import org.geysermc.connector.network.translators.item.PotionMixRegistry;
|
2020-08-25 02:14:44 +00:00
|
|
|
import org.geysermc.connector.network.translators.item.RecipeRegistry;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.sound.SoundHandlerRegistry;
|
2020-07-03 00:10:43 +00:00
|
|
|
import org.geysermc.connector.network.translators.sound.SoundRegistry;
|
2020-04-29 20:01:53 +00:00
|
|
|
import org.geysermc.connector.network.translators.world.WorldManager;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
|
|
|
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
|
2020-11-20 19:56:39 +00:00
|
|
|
import org.geysermc.connector.network.translators.collision.CollisionTranslator;
|
2020-05-23 21:02:51 +00:00
|
|
|
import org.geysermc.connector.utils.DimensionUtils;
|
2020-07-20 23:02:18 +00:00
|
|
|
import org.geysermc.connector.utils.LanguageUtils;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.utils.LocaleUtils;
|
2020-09-17 00:08:26 +00:00
|
|
|
import org.geysermc.connector.utils.ResourcePack;
|
2019-07-08 17:55:14 +00:00
|
|
|
|
2020-07-25 17:42:43 +00:00
|
|
|
import javax.naming.directory.Attribute;
|
|
|
|
import javax.naming.directory.InitialDirContext;
|
2020-08-16 17:45:52 +00:00
|
|
|
import java.net.InetAddress;
|
2019-07-08 23:35:32 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2020-08-16 17:45:52 +00:00
|
|
|
import java.net.UnknownHostException;
|
2019-09-15 23:46:05 +00:00
|
|
|
import java.text.DecimalFormat;
|
2020-07-07 01:11:34 +00:00
|
|
|
import java.util.ArrayList;
|
2020-10-13 01:17:15 +00:00
|
|
|
import java.util.HashMap;
|
2020-07-07 01:11:34 +00:00
|
|
|
import java.util.List;
|
2020-10-13 01:17:15 +00:00
|
|
|
import java.util.Map;
|
2020-04-06 13:33:36 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2019-07-08 17:55:14 +00:00
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
2019-07-21 23:52:30 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2019-07-08 17:55:14 +00:00
|
|
|
|
2019-08-09 01:42:55 +00:00
|
|
|
@Getter
|
2019-12-21 17:35:48 +00:00
|
|
|
public class GeyserConnector {
|
2019-07-08 17:55:14 +00:00
|
|
|
|
2020-09-17 00:08:26 +00:00
|
|
|
public static final ObjectMapper JSON_MAPPER = new ObjectMapper().enable(JsonParser.Feature.IGNORE_UNDEFINED).enable(JsonParser.Feature.ALLOW_COMMENTS).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
2020-05-25 01:07:05 +00:00
|
|
|
|
2019-09-21 16:00:13 +00:00
|
|
|
public static final String NAME = "Geyser";
|
2020-06-23 01:21:42 +00:00
|
|
|
public static final String VERSION = "DEV"; // A fallback for running in IDEs
|
2019-07-08 17:55:14 +00:00
|
|
|
|
2020-07-25 17:42:43 +00:00
|
|
|
private static final String IP_REGEX = "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b";
|
|
|
|
|
2020-07-07 01:11:34 +00:00
|
|
|
private final List<GeyserSession> players = new ArrayList<>();
|
2019-08-09 01:42:55 +00:00
|
|
|
|
2019-07-08 17:55:14 +00:00
|
|
|
private static GeyserConnector instance;
|
|
|
|
|
2019-12-21 17:35:48 +00:00
|
|
|
private RemoteServer remoteServer;
|
2020-06-19 12:50:10 +00:00
|
|
|
@Setter
|
2020-01-04 05:58:58 +00:00
|
|
|
private AuthType authType;
|
2019-07-08 19:19:41 +00:00
|
|
|
|
|
|
|
private boolean shuttingDown = false;
|
|
|
|
|
2019-07-08 17:55:14 +00:00
|
|
|
private final ScheduledExecutorService generalThreadPool;
|
2019-07-21 23:52:30 +00:00
|
|
|
|
2019-12-21 17:38:45 +00:00
|
|
|
private BedrockServer bedrockServer;
|
2019-12-21 17:53:19 +00:00
|
|
|
private PlatformType platformType;
|
2020-04-29 20:01:53 +00:00
|
|
|
private GeyserBootstrap bootstrap;
|
2019-12-21 17:38:45 +00:00
|
|
|
|
2019-08-09 01:42:55 +00:00
|
|
|
private Metrics metrics;
|
2019-08-06 01:59:54 +00:00
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
|
2019-09-15 23:46:05 +00:00
|
|
|
long startupTime = System.currentTimeMillis();
|
2019-09-14 23:21:55 +00:00
|
|
|
|
2019-07-08 17:55:14 +00:00
|
|
|
instance = this;
|
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.bootstrap = bootstrap;
|
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
GeyserLogger logger = bootstrap.getGeyserLogger();
|
|
|
|
GeyserConfiguration config = bootstrap.getGeyserConfig();
|
2020-03-17 16:43:09 +00:00
|
|
|
|
2019-12-21 17:53:19 +00:00
|
|
|
this.platformType = platformType;
|
2019-07-13 19:00:51 +00:00
|
|
|
|
|
|
|
logger.info("******************************************");
|
2019-07-08 17:55:14 +00:00
|
|
|
logger.info("");
|
2020-07-05 23:35:51 +00:00
|
|
|
logger.info(LanguageUtils.getLocaleStringLog("geyser.core.load", NAME, VERSION));
|
2019-07-08 17:55:14 +00:00
|
|
|
logger.info("");
|
|
|
|
logger.info("******************************************");
|
|
|
|
|
2019-09-22 22:15:27 +00:00
|
|
|
this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool());
|
2019-09-22 22:08:12 +00:00
|
|
|
|
2019-07-21 21:18:20 +00:00
|
|
|
logger.setDebug(config.isDebugMode());
|
|
|
|
|
2020-05-25 01:07:05 +00:00
|
|
|
PacketTranslatorRegistry.init();
|
|
|
|
|
|
|
|
/* Initialize translators and registries */
|
|
|
|
BiomeTranslator.init();
|
|
|
|
BlockTranslator.init();
|
|
|
|
BlockEntityTranslator.init();
|
|
|
|
EffectRegistry.init();
|
|
|
|
EntityIdentifierRegistry.init();
|
|
|
|
ItemRegistry.init();
|
|
|
|
ItemTranslator.init();
|
2020-11-20 19:56:39 +00:00
|
|
|
CollisionTranslator.init();
|
2020-05-25 01:07:05 +00:00
|
|
|
LocaleUtils.init();
|
2020-07-07 07:44:39 +00:00
|
|
|
PotionMixRegistry.init();
|
2020-08-25 02:14:44 +00:00
|
|
|
RecipeRegistry.init();
|
2020-05-25 01:07:05 +00:00
|
|
|
SoundRegistry.init();
|
|
|
|
SoundHandlerRegistry.init();
|
2019-07-11 22:39:28 +00:00
|
|
|
|
2020-09-17 00:08:26 +00:00
|
|
|
ResourcePack.loadPacks();
|
|
|
|
|
2020-08-16 17:45:52 +00:00
|
|
|
if (platformType != PlatformType.STANDALONE && config.getRemote().getAddress().equals("auto")) {
|
|
|
|
// Set the remote address to localhost since that is where we are always connecting
|
|
|
|
try {
|
|
|
|
config.getRemote().setAddress(InetAddress.getLocalHost().getHostAddress());
|
|
|
|
} catch (UnknownHostException ex) {
|
|
|
|
logger.debug("Unknown host when trying to find localhost.");
|
|
|
|
if (config.isDebugMode()) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-05-19 03:27:35 +00:00
|
|
|
}
|
2020-07-25 17:42:43 +00:00
|
|
|
String remoteAddress = config.getRemote().getAddress();
|
|
|
|
int remotePort = config.getRemote().getPort();
|
|
|
|
// Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry.
|
|
|
|
if ((config.isLegacyPingPassthrough() || platformType == PlatformType.STANDALONE) && !remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
|
|
|
|
try {
|
|
|
|
// Searches for a server address and a port from a SRV record of the specified host name
|
|
|
|
InitialDirContext ctx = new InitialDirContext();
|
|
|
|
Attribute attr = ctx.getAttributes("dns:///_minecraft._tcp." + remoteAddress, new String[]{"SRV"}).get("SRV");
|
|
|
|
// size > 0 = SRV entry found
|
2020-07-25 22:21:13 +00:00
|
|
|
if (attr != null && attr.size() > 0) {
|
2020-07-25 17:42:43 +00:00
|
|
|
String[] record = ((String) attr.get(0)).split(" ");
|
|
|
|
// Overwrites the existing address and port with that from the SRV record.
|
|
|
|
config.getRemote().setAddress(remoteAddress = record[3]);
|
|
|
|
config.getRemote().setPort(remotePort = Integer.parseInt(record[2]));
|
|
|
|
logger.debug("Found SRV record \"" + remoteAddress + ":" + remotePort + "\"");
|
|
|
|
}
|
2020-08-28 18:36:24 +00:00
|
|
|
} catch (Exception | NoClassDefFoundError ex) { // Check for a NoClassDefFoundError to prevent Android crashes
|
2020-07-28 22:47:08 +00:00
|
|
|
logger.debug("Exception while trying to find an SRV record for the remote host.");
|
|
|
|
if (config.isDebugMode())
|
|
|
|
ex.printStackTrace(); // Otherwise we can get a stack trace for any domain that doesn't have an SRV record
|
2020-07-25 17:42:43 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 03:27:35 +00:00
|
|
|
|
2020-07-25 17:42:43 +00:00
|
|
|
remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort);
|
2019-11-30 12:34:45 +00:00
|
|
|
authType = AuthType.getByName(config.getRemote().getAuthType());
|
2019-07-08 23:35:32 +00:00
|
|
|
|
2020-11-12 00:28:45 +00:00
|
|
|
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
|
2020-05-23 21:02:51 +00:00
|
|
|
|
2020-07-31 23:47:23 +00:00
|
|
|
// https://github.com/GeyserMC/Geyser/issues/957
|
|
|
|
RakNetConstants.MAXIMUM_MTU_SIZE = (short) config.getMtu();
|
|
|
|
logger.debug("Setting MTU to " + config.getMtu());
|
|
|
|
|
2019-12-21 17:38:45 +00:00
|
|
|
bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort()));
|
2019-07-10 06:34:10 +00:00
|
|
|
bedrockServer.setHandler(new ConnectorServerEventHandler(this));
|
2019-07-08 23:35:32 +00:00
|
|
|
bedrockServer.bind().whenComplete((avoid, throwable) -> {
|
|
|
|
if (throwable == null) {
|
2020-07-05 23:35:51 +00:00
|
|
|
logger.info(LanguageUtils.getLocaleStringLog("geyser.core.start", config.getBedrock().getAddress(), String.valueOf(config.getBedrock().getPort())));
|
2019-07-08 23:35:32 +00:00
|
|
|
} else {
|
2020-08-21 17:01:50 +00:00
|
|
|
logger.severe(LanguageUtils.getLocaleStringLog("geyser.core.fail", config.getBedrock().getAddress(), String.valueOf(config.getBedrock().getPort())));
|
2019-07-08 23:35:32 +00:00
|
|
|
throwable.printStackTrace();
|
|
|
|
}
|
|
|
|
}).join();
|
2019-08-09 21:09:47 +00:00
|
|
|
|
2019-09-21 16:00:13 +00:00
|
|
|
if (config.getMetrics().isEnabled()) {
|
2019-12-21 17:35:48 +00:00
|
|
|
metrics = new Metrics(this, "GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger(""));
|
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size));
|
2020-10-13 01:17:15 +00:00
|
|
|
// Prevent unwanted words best we can
|
2020-10-13 01:28:54 +00:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> AuthType.getByName(config.getRemote().getAuthType()).toString().toLowerCase()));
|
2019-12-21 17:53:19 +00:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName));
|
2020-10-13 01:17:15 +00:00
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("defaultLocale", LanguageUtils::getDefaultLocale));
|
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("version", () -> GeyserConnector.VERSION));
|
|
|
|
metrics.addCustomChart(new Metrics.AdvancedPie("playerPlatform", () -> {
|
|
|
|
Map<String, Integer> valueMap = new HashMap<>();
|
|
|
|
for (GeyserSession session : players) {
|
|
|
|
if (session == null) continue;
|
|
|
|
if (session.getClientData() == null) continue;
|
|
|
|
String os = session.getClientData().getDeviceOS().toString();
|
|
|
|
if (!valueMap.containsKey(os)) {
|
|
|
|
valueMap.put(os, 1);
|
|
|
|
} else {
|
|
|
|
valueMap.put(os, valueMap.get(os) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return valueMap;
|
|
|
|
}));
|
|
|
|
metrics.addCustomChart(new Metrics.AdvancedPie("playerVersion", () -> {
|
|
|
|
Map<String, Integer> valueMap = new HashMap<>();
|
|
|
|
for (GeyserSession session : players) {
|
|
|
|
if (session == null) continue;
|
|
|
|
if (session.getClientData() == null) continue;
|
|
|
|
String version = session.getClientData().getGameVersion();
|
|
|
|
if (!valueMap.containsKey(version)) {
|
|
|
|
valueMap.put(version, 1);
|
|
|
|
} else {
|
|
|
|
valueMap.put(version, valueMap.get(version) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return valueMap;
|
|
|
|
}));
|
2019-09-21 16:00:13 +00:00
|
|
|
}
|
2019-09-15 23:46:05 +00:00
|
|
|
|
2020-07-03 00:10:43 +00:00
|
|
|
boolean isGui = false;
|
|
|
|
// This will check if we are in standalone and get the 'useGui' variable from there
|
|
|
|
if (platformType == PlatformType.STANDALONE) {
|
|
|
|
try {
|
|
|
|
Class<?> cls = Class.forName("org.geysermc.platform.standalone.GeyserStandaloneBootstrap");
|
|
|
|
isGui = (boolean) cls.getMethod("isUseGui").invoke(cls.cast(bootstrap));
|
2020-07-08 22:44:10 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.debug("Failed detecting if standalone is using a GUI; if this is a GeyserConnect instance this can be safely ignored.");
|
|
|
|
}
|
2020-07-03 00:10:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-15 23:46:05 +00:00
|
|
|
double completeTime = (System.currentTimeMillis() - startupTime) / 1000D;
|
2020-07-05 23:35:51 +00:00
|
|
|
String message = LanguageUtils.getLocaleStringLog("geyser.core.finish.done", new DecimalFormat("#.###").format(completeTime)) + " ";
|
2020-07-03 00:10:43 +00:00
|
|
|
if (isGui) {
|
2020-07-05 23:35:51 +00:00
|
|
|
message += LanguageUtils.getLocaleStringLog("geyser.core.finish.gui");
|
2020-07-03 00:10:43 +00:00
|
|
|
} else {
|
2020-07-05 23:35:51 +00:00
|
|
|
message += LanguageUtils.getLocaleStringLog("geyser.core.finish.console");
|
2020-07-03 00:10:43 +00:00
|
|
|
}
|
|
|
|
logger.info(message);
|
2020-08-23 15:34:09 +00:00
|
|
|
|
|
|
|
if (platformType == PlatformType.STANDALONE) {
|
|
|
|
logger.warning(LanguageUtils.getLocaleStringLog("geyser.core.movement_warn"));
|
|
|
|
}
|
2019-07-08 17:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void shutdown() {
|
2020-07-05 23:35:51 +00:00
|
|
|
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown"));
|
2019-07-08 17:55:14 +00:00
|
|
|
shuttingDown = true;
|
|
|
|
|
2020-04-06 13:33:36 +00:00
|
|
|
if (players.size() >= 1) {
|
2020-07-05 23:35:51 +00:00
|
|
|
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.kick.log", players.size()));
|
2020-04-06 13:33:36 +00:00
|
|
|
|
2020-07-10 14:43:30 +00:00
|
|
|
// Make a copy to prevent ConcurrentModificationException
|
|
|
|
final List<GeyserSession> tmpPlayers = new ArrayList<>(players);
|
|
|
|
for (GeyserSession playerSession : tmpPlayers) {
|
2020-10-29 22:30:52 +00:00
|
|
|
playerSession.disconnect(LanguageUtils.getPlayerLocaleString("geyser.core.shutdown.kick.message", playerSession.getLocale()));
|
2020-04-06 13:33:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// Simulate a long-running Job
|
|
|
|
try {
|
|
|
|
while (true) {
|
|
|
|
if (players.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeUnit.MILLISECONDS.sleep(100);
|
|
|
|
}
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
throw new IllegalStateException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Block and wait for the future to complete
|
|
|
|
try {
|
|
|
|
future.get();
|
2020-07-05 23:35:51 +00:00
|
|
|
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.kick.done"));
|
2020-04-06 13:33:36 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
// Quietly fail
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 17:55:14 +00:00
|
|
|
generalThreadPool.shutdown();
|
2019-12-21 17:38:45 +00:00
|
|
|
bedrockServer.close();
|
2020-03-17 16:43:09 +00:00
|
|
|
players.clear();
|
|
|
|
remoteServer = null;
|
|
|
|
authType = null;
|
2020-04-19 23:08:14 +00:00
|
|
|
this.getCommandManager().getCommands().clear();
|
2020-04-06 13:33:36 +00:00
|
|
|
|
2020-07-05 23:35:51 +00:00
|
|
|
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.done"));
|
2019-07-08 17:55:14 +00:00
|
|
|
}
|
2019-08-06 01:59:54 +00:00
|
|
|
|
2019-10-16 18:55:05 +00:00
|
|
|
public void addPlayer(GeyserSession player) {
|
2020-07-07 01:11:34 +00:00
|
|
|
players.add(player);
|
2019-08-09 01:42:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 18:55:05 +00:00
|
|
|
public void removePlayer(GeyserSession player) {
|
2020-07-07 01:11:34 +00:00
|
|
|
players.remove(player);
|
2019-08-09 01:42:55 +00:00
|
|
|
}
|
2019-12-01 21:16:52 +00:00
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
public static GeyserConnector start(PlatformType platformType, GeyserBootstrap bootstrap) {
|
2020-03-17 16:43:09 +00:00
|
|
|
return new GeyserConnector(platformType, bootstrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
|
|
|
shutdown();
|
|
|
|
bootstrap.onEnable();
|
|
|
|
}
|
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
public GeyserLogger getLogger() {
|
2020-03-17 16:43:09 +00:00
|
|
|
return bootstrap.getGeyserLogger();
|
2019-12-01 21:16:52 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
public GeyserConfiguration getConfig() {
|
2020-03-17 16:43:09 +00:00
|
|
|
return bootstrap.getGeyserConfig();
|
2019-12-01 21:16:52 +00:00
|
|
|
}
|
2019-12-21 17:35:48 +00:00
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
public CommandManager getCommandManager() {
|
2020-04-29 20:01:53 +00:00
|
|
|
return bootstrap.getGeyserCommandManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorldManager getWorldManager() {
|
|
|
|
return bootstrap.getWorldManager();
|
2020-04-19 23:08:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 18:36:24 +00:00
|
|
|
/**
|
2020-10-07 22:51:36 +00:00
|
|
|
* Whether to use XML reflections in the jar or manually find the reflections.
|
|
|
|
* Will return true if the version number is not 'DEV' and the platform is not Fabric.
|
|
|
|
* On Fabric - it complains about being unable to create a default XMLReader.
|
|
|
|
* On other platforms this should only be true in compiled jars.
|
2020-08-28 18:36:24 +00:00
|
|
|
*
|
2020-10-07 22:51:36 +00:00
|
|
|
* @return whether to use XML reflections
|
2020-08-28 18:36:24 +00:00
|
|
|
*/
|
2020-10-07 22:51:36 +00:00
|
|
|
public boolean useXmlReflections() {
|
2020-08-28 18:36:24 +00:00
|
|
|
//noinspection ConstantConditions
|
2020-10-07 22:51:36 +00:00
|
|
|
return !this.getPlatformType().equals(PlatformType.FABRIC) && !"DEV".equals(GeyserConnector.VERSION);
|
2020-08-28 18:36:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 17:35:48 +00:00
|
|
|
public static GeyserConnector getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
2019-07-08 17:55:14 +00:00
|
|
|
}
|