2019-07-08 19:13:31 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-07-08 19:13:31 +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 19:13:31 +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 19:13:31 +00:00
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2020-05-26 14:05:25 +00:00
|
|
|
package org.geysermc.platform.spigot;
|
2019-07-08 19:13:31 +00:00
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
2021-05-01 04:30:01 +00:00
|
|
|
import com.viaversion.viaversion.api.Via;
|
|
|
|
import com.viaversion.viaversion.api.data.MappingData;
|
|
|
|
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
|
|
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
2020-04-27 20:45:14 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2019-12-01 21:16:52 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2020-11-14 23:49:56 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2019-12-01 21:16:52 +00:00
|
|
|
import org.geysermc.connector.GeyserConnector;
|
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;
|
2021-07-28 23:44:09 +00:00
|
|
|
import org.geysermc.connector.common.AuthType;
|
2020-06-10 22:58:29 +00:00
|
|
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
2020-06-27 15:36:48 +00:00
|
|
|
import org.geysermc.connector.dump.BootstrapDumpInfo;
|
2020-04-29 20:01:53 +00:00
|
|
|
import org.geysermc.connector.network.translators.world.WorldManager;
|
2020-05-23 21:50:04 +00:00
|
|
|
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
|
|
|
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
2020-06-21 23:22:59 +00:00
|
|
|
import org.geysermc.connector.utils.FileUtils;
|
2020-07-05 23:35:51 +00:00
|
|
|
import org.geysermc.connector.utils.LanguageUtils;
|
2021-02-04 00:54:12 +00:00
|
|
|
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
|
2020-05-26 14:05:25 +00:00
|
|
|
import org.geysermc.platform.spigot.command.GeyserSpigotCommandExecutor;
|
|
|
|
import org.geysermc.platform.spigot.command.GeyserSpigotCommandManager;
|
2020-10-29 22:30:52 +00:00
|
|
|
import org.geysermc.platform.spigot.command.SpigotCommandSender;
|
2021-09-10 01:20:25 +00:00
|
|
|
import org.geysermc.platform.spigot.world.GeyserPistonListener;
|
2021-01-09 21:45:32 +00:00
|
|
|
import org.geysermc.platform.spigot.world.GeyserSpigot1_11CraftingListener;
|
2020-05-26 14:05:25 +00:00
|
|
|
import org.geysermc.platform.spigot.world.GeyserSpigotBlockPlaceListener;
|
2020-11-20 19:56:39 +00:00
|
|
|
import org.geysermc.platform.spigot.world.manager.*;
|
2019-07-08 19:13:31 +00:00
|
|
|
|
2020-06-10 22:58:29 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2021-07-31 16:52:49 +00:00
|
|
|
import java.net.SocketAddress;
|
2020-06-20 17:54:40 +00:00
|
|
|
import java.nio.file.Path;
|
2020-11-20 19:56:39 +00:00
|
|
|
import java.util.List;
|
2019-12-01 21:16:52 +00:00
|
|
|
import java.util.UUID;
|
2020-06-10 22:58:29 +00:00
|
|
|
import java.util.logging.Level;
|
2019-08-02 20:15:32 +00:00
|
|
|
|
2020-05-26 14:05:25 +00:00
|
|
|
public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|
|
|
private GeyserSpigotCommandManager geyserCommandManager;
|
|
|
|
private GeyserSpigotConfiguration geyserConfig;
|
2021-07-31 16:52:49 +00:00
|
|
|
private GeyserSpigotInjector geyserInjector;
|
2020-05-26 14:05:25 +00:00
|
|
|
private GeyserSpigotLogger geyserLogger;
|
2020-05-26 14:11:28 +00:00
|
|
|
private IGeyserPingPassthrough geyserSpigotPingPassthrough;
|
2020-05-26 14:05:25 +00:00
|
|
|
private GeyserSpigotWorldManager geyserWorldManager;
|
2019-08-02 20:15:32 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
private GeyserConnector connector;
|
|
|
|
|
2021-02-04 00:54:35 +00:00
|
|
|
/**
|
|
|
|
* The Minecraft server version, formatted as <code>1.#.#</code>
|
|
|
|
*/
|
|
|
|
private String minecraftVersion;
|
|
|
|
|
2019-12-01 21:16:52 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2020-06-10 22:58:29 +00:00
|
|
|
// This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed
|
|
|
|
try {
|
2020-06-11 20:39:29 +00:00
|
|
|
if (!getDataFolder().exists()) {
|
2020-06-10 22:58:29 +00:00
|
|
|
getDataFolder().mkdir();
|
2020-06-11 20:39:29 +00:00
|
|
|
}
|
2020-06-10 22:58:29 +00:00
|
|
|
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
2020-06-11 20:39:29 +00:00
|
|
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpigotConfiguration.class);
|
2020-06-10 22:58:29 +00:00
|
|
|
} catch (IOException ex) {
|
2020-07-05 23:35:51 +00:00
|
|
|
getLogger().log(Level.WARNING, LanguageUtils.getLocaleStringLog("geyser.config.failed"), ex);
|
2020-06-10 22:58:29 +00:00
|
|
|
ex.printStackTrace();
|
2019-12-01 21:16:52 +00:00
|
|
|
}
|
2019-08-06 01:59:54 +00:00
|
|
|
|
2021-05-23 19:55:01 +00:00
|
|
|
try {
|
|
|
|
// Required for the Cloudburst Network dependency to initialize.
|
|
|
|
Class.forName("io.netty.channel.kqueue.KQueue");
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
// While we could support these older versions, the downside is not having KQueue working at all
|
|
|
|
// And since there are alternative ways to get Geyser working for these aging platforms, it's not worth it.
|
|
|
|
getLogger().severe("*********************************************");
|
|
|
|
getLogger().severe("");
|
|
|
|
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_server.header"));
|
|
|
|
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_server.message", "1.12.2"));
|
|
|
|
getLogger().severe("");
|
|
|
|
getLogger().severe("*********************************************");
|
|
|
|
|
|
|
|
Bukkit.getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-16 17:45:52 +00:00
|
|
|
// By default this should be localhost but may need to be changed in some circumstances
|
|
|
|
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
|
2020-08-19 17:14:17 +00:00
|
|
|
geyserConfig.setAutoconfiguredRemote(true);
|
|
|
|
// Don't use localhost if not listening on all interfaces
|
|
|
|
if (!Bukkit.getIp().equals("0.0.0.0") && !Bukkit.getIp().equals("")) {
|
|
|
|
geyserConfig.getRemote().setAddress(Bukkit.getIp());
|
|
|
|
}
|
2020-08-16 17:45:52 +00:00
|
|
|
geyserConfig.getRemote().setPort(Bukkit.getPort());
|
2020-04-27 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 20:09:40 +00:00
|
|
|
if (geyserConfig.getBedrock().isCloneRemotePort()) {
|
|
|
|
geyserConfig.getBedrock().setPort(Bukkit.getPort());
|
|
|
|
}
|
|
|
|
|
2020-05-26 14:05:25 +00:00
|
|
|
this.geyserLogger = new GeyserSpigotLogger(getLogger(), geyserConfig.isDebugMode());
|
2020-05-21 14:29:32 +00:00
|
|
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2021-06-06 23:01:16 +00:00
|
|
|
// Remove this in like a year
|
|
|
|
if (Bukkit.getPluginManager().getPlugin("floodgate-bukkit") != null) {
|
|
|
|
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.outdated", "https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/master/"));
|
|
|
|
this.getPluginLoader().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-28 23:44:09 +00:00
|
|
|
if (geyserConfig.getRemote().getAuthType() == AuthType.FLOODGATE && Bukkit.getPluginManager().getPlugin("floodgate") == null) {
|
2020-07-05 23:35:51 +00:00
|
|
|
geyserLogger.severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.not_installed") + " " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.floodgate.disabling"));
|
2020-06-10 22:58:29 +00:00
|
|
|
this.getPluginLoader().disablePlugin(this);
|
|
|
|
return;
|
2020-09-28 01:08:31 +00:00
|
|
|
} else if (geyserConfig.isAutoconfiguredRemote() && Bukkit.getPluginManager().getPlugin("floodgate") != null) {
|
2020-08-19 17:14:17 +00:00
|
|
|
// Floodgate installed means that the user wants Floodgate authentication
|
|
|
|
geyserLogger.debug("Auto-setting to Floodgate authentication.");
|
2021-07-28 23:44:09 +00:00
|
|
|
geyserConfig.getRemote().setAuthType(AuthType.FLOODGATE);
|
2020-06-10 22:58:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 20:30:20 +00:00
|
|
|
geyserConfig.loadFloodgate(this);
|
|
|
|
|
2021-02-04 00:54:35 +00:00
|
|
|
// Turn "(MC: 1.16.4)" into 1.16.4.
|
|
|
|
this.minecraftVersion = Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0];
|
|
|
|
|
2020-05-26 14:05:25 +00:00
|
|
|
this.connector = GeyserConnector.start(PlatformType.SPIGOT, this);
|
2019-09-22 22:08:12 +00:00
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
if (geyserConfig.isLegacyPingPassthrough()) {
|
2020-05-26 14:11:28 +00:00
|
|
|
this.geyserSpigotPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
2020-05-23 21:50:04 +00:00
|
|
|
} else {
|
2020-05-26 14:11:28 +00:00
|
|
|
this.geyserSpigotPingPassthrough = new GeyserSpigotPingPassthrough(geyserLogger);
|
2020-05-23 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
2021-06-21 01:42:22 +00:00
|
|
|
this.geyserCommandManager = new GeyserSpigotCommandManager(connector);
|
2020-05-10 02:37:18 +00:00
|
|
|
|
2021-04-24 19:18:41 +00:00
|
|
|
boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
2020-11-02 19:28:31 +00:00
|
|
|
if (isViaVersion) {
|
2021-05-01 04:30:01 +00:00
|
|
|
try {
|
|
|
|
// Ensure that we have the latest 4.0.0 changes and not an older ViaVersion version
|
|
|
|
Class.forName("com.viaversion.viaversion.api.ViaManager");
|
|
|
|
} catch (ClassNotFoundException e) {
|
2020-11-02 19:28:31 +00:00
|
|
|
geyserLogger.warning(LanguageUtils.getLocaleStringLog("geyser.bootstrap.viaversion.too_old",
|
2021-06-07 18:56:29 +00:00
|
|
|
"https://ci.viaversion.com/job/ViaVersion/"));
|
2020-11-02 19:28:31 +00:00
|
|
|
isViaVersion = false;
|
2021-05-01 04:30:01 +00:00
|
|
|
if (this.geyserConfig.isDebugMode()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-11-02 19:28:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-10 02:37:18 +00:00
|
|
|
// Used to determine if Block.getBlockData() is present.
|
|
|
|
boolean isLegacy = !isCompatible(Bukkit.getServer().getVersion(), "1.13.0");
|
|
|
|
if (isLegacy)
|
2020-09-03 23:00:36 +00:00
|
|
|
geyserLogger.debug("Legacy version of Minecraft (1.12.2 or older) detected; falling back to ViaVersion for block state retrieval.");
|
2020-05-10 02:37:18 +00:00
|
|
|
|
2021-01-09 21:45:32 +00:00
|
|
|
boolean isPre1_12 = !isCompatible(Bukkit.getServer().getVersion(), "1.12.0");
|
2020-10-29 22:30:52 +00:00
|
|
|
// Set if we need to use a different method for getting a player's locale
|
2021-01-09 21:45:32 +00:00
|
|
|
SpigotCommandSender.setUseLegacyLocaleMethod(isPre1_12);
|
2020-10-29 22:30:52 +00:00
|
|
|
|
2021-07-31 16:52:49 +00:00
|
|
|
// We want to do this late in the server startup process to allow plugins such as ViaVersion and ProtocolLib
|
|
|
|
// To do their job injecting, then connect into *that*
|
|
|
|
this.geyserInjector = new GeyserSpigotInjector(isViaVersion);
|
|
|
|
this.geyserInjector.initializeLocalChannel(this);
|
|
|
|
|
2021-07-31 17:54:51 +00:00
|
|
|
if (Boolean.parseBoolean(System.getProperty("Geyser.UseDirectAdapters", "true"))) {
|
2020-11-20 19:56:39 +00:00
|
|
|
try {
|
|
|
|
String name = Bukkit.getServer().getClass().getPackage().getName();
|
|
|
|
String nmsVersion = name.substring(name.lastIndexOf('.') + 1);
|
|
|
|
SpigotAdapters.registerWorldAdapter(nmsVersion);
|
|
|
|
if (isViaVersion && isViaVersionNeeded()) {
|
|
|
|
if (isLegacy) {
|
|
|
|
// Pre-1.13
|
2020-12-28 05:29:27 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigot1_12NativeWorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
} else {
|
|
|
|
// Post-1.13
|
2021-05-20 02:24:11 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigotLegacyNativeWorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No ViaVersion
|
2021-05-20 02:24:11 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigotNativeWorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
geyserLogger.debug("Using NMS adapter: " + this.geyserWorldManager.getClass() + ", " + nmsVersion);
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (geyserConfig.isDebugMode()) {
|
|
|
|
geyserLogger.debug("Error while attempting to find NMS adapter. Most likely, this can be safely ignored. :)");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-31 17:54:51 +00:00
|
|
|
geyserLogger.debug("Not using NMS adapter as it is disabled via system property.");
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
if (this.geyserWorldManager == null) {
|
|
|
|
// No NMS adapter
|
|
|
|
if (isLegacy && isViaVersion) {
|
|
|
|
// Use ViaVersion for converting pre-1.13 block states
|
2020-12-28 05:29:27 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigot1_12WorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
} else if (isLegacy) {
|
|
|
|
// Not sure how this happens - without ViaVersion, we don't know any block states, so just assume everything is air
|
2020-12-28 05:29:27 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigotFallbackWorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
} else {
|
|
|
|
// Post-1.13
|
2021-05-20 02:24:11 +00:00
|
|
|
this.geyserWorldManager = new GeyserSpigotWorldManager(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
geyserLogger.debug("Using default world manager: " + this.geyserWorldManager.getClass());
|
|
|
|
}
|
|
|
|
GeyserSpigotBlockPlaceListener blockPlaceListener = new GeyserSpigotBlockPlaceListener(connector, this.geyserWorldManager);
|
2020-05-10 20:25:28 +00:00
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(blockPlaceListener, this);
|
2020-04-19 23:08:14 +00:00
|
|
|
|
2021-09-10 01:20:25 +00:00
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new GeyserPistonListener(connector, this.geyserWorldManager), this);
|
|
|
|
|
2021-01-09 21:45:32 +00:00
|
|
|
if (isPre1_12) {
|
|
|
|
// Register events needed to send all recipes to the client
|
2021-03-08 21:57:31 +00:00
|
|
|
Bukkit.getServer().getPluginManager().registerEvents(new GeyserSpigot1_11CraftingListener(connector), this);
|
2021-01-09 21:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 14:05:25 +00:00
|
|
|
this.getCommand("geyser").setExecutor(new GeyserSpigotCommandExecutor(connector));
|
2019-12-01 21:16:52 +00:00
|
|
|
}
|
2019-10-02 20:45:29 +00:00
|
|
|
|
2019-12-01 21:16:52 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2020-11-20 19:56:39 +00:00
|
|
|
if (connector != null) {
|
2020-06-10 22:58:29 +00:00
|
|
|
connector.shutdown();
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
2021-07-31 16:52:49 +00:00
|
|
|
if (geyserInjector != null) {
|
|
|
|
geyserInjector.shutdown();
|
|
|
|
}
|
2019-12-01 21:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-26 14:05:25 +00:00
|
|
|
public GeyserSpigotConfiguration getGeyserConfig() {
|
2019-12-01 21:16:52 +00:00
|
|
|
return geyserConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-26 14:05:25 +00:00
|
|
|
public GeyserSpigotLogger getGeyserLogger() {
|
2019-12-01 21:16:52 +00:00
|
|
|
return geyserLogger;
|
|
|
|
}
|
2020-04-19 23:08:14 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public CommandManager getGeyserCommandManager() {
|
|
|
|
return this.geyserCommandManager;
|
|
|
|
}
|
2020-04-29 20:01:53 +00:00
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
@Override
|
|
|
|
public IGeyserPingPassthrough getGeyserPingPassthrough() {
|
2020-05-26 14:11:28 +00:00
|
|
|
return geyserSpigotPingPassthrough;
|
2020-05-23 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
@Override
|
|
|
|
public WorldManager getWorldManager() {
|
|
|
|
return this.geyserWorldManager;
|
|
|
|
}
|
2020-05-10 02:37:18 +00:00
|
|
|
|
2020-06-20 17:54:40 +00:00
|
|
|
@Override
|
|
|
|
public Path getConfigFolder() {
|
|
|
|
return getDataFolder().toPath();
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
@Override
|
|
|
|
public BootstrapDumpInfo getDumpInfo() {
|
|
|
|
return new GeyserSpigotDumpInfo();
|
|
|
|
}
|
|
|
|
|
2021-02-04 00:54:35 +00:00
|
|
|
@Override
|
|
|
|
public String getMinecraftServerVersion() {
|
|
|
|
return this.minecraftVersion;
|
|
|
|
}
|
|
|
|
|
2021-07-31 16:52:49 +00:00
|
|
|
@Override
|
|
|
|
public SocketAddress getSocketAddress() {
|
|
|
|
return this.geyserInjector.getServerSocketAddress();
|
|
|
|
}
|
|
|
|
|
2020-05-10 02:37:18 +00:00
|
|
|
public boolean isCompatible(String version, String whichVersion) {
|
|
|
|
int[] currentVersion = parseVersion(version);
|
|
|
|
int[] otherVersion = parseVersion(whichVersion);
|
|
|
|
int length = Math.max(currentVersion.length, otherVersion.length);
|
|
|
|
for (int index = 0; index < length; index = index + 1) {
|
|
|
|
int self = (index < currentVersion.length) ? currentVersion[index] : 0;
|
|
|
|
int other = (index < otherVersion.length) ? otherVersion[index] : 0;
|
|
|
|
|
|
|
|
if (self != other) {
|
|
|
|
return (self - other) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int[] parseVersion(String versionParam) {
|
|
|
|
versionParam = (versionParam == null) ? "" : versionParam;
|
|
|
|
if (versionParam.contains("(MC: ")) {
|
|
|
|
versionParam = versionParam.split("\\(MC: ")[1];
|
|
|
|
versionParam = versionParam.split("\\)")[0];
|
|
|
|
}
|
|
|
|
String[] stringArray = versionParam.split("[_.-]");
|
|
|
|
int[] temp = new int[stringArray.length];
|
|
|
|
for (int index = 0; index <= (stringArray.length - 1); index = index + 1) {
|
|
|
|
String t = stringArray[index].replaceAll("\\D", "");
|
|
|
|
try {
|
|
|
|
temp[index] = Integer.parseInt(t);
|
2020-11-20 19:56:39 +00:00
|
|
|
} catch (NumberFormatException ex) {
|
2020-05-10 02:37:18 +00:00
|
|
|
temp[index] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
}
|
2020-06-20 17:54:40 +00:00
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
/**
|
|
|
|
* @return the server version before ViaVersion finishes initializing
|
|
|
|
*/
|
|
|
|
public ProtocolVersion getServerProtocolVersion() {
|
2021-02-04 00:54:35 +00:00
|
|
|
return ProtocolVersion.getClosest(this.minecraftVersion);
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function should not run unless ViaVersion is installed on the server.
|
|
|
|
*
|
|
|
|
* @return true if there is any block mappings difference between the server and client.
|
|
|
|
*/
|
|
|
|
private boolean isViaVersionNeeded() {
|
|
|
|
ProtocolVersion serverVersion = getServerProtocolVersion();
|
2021-04-24 19:18:41 +00:00
|
|
|
List<ProtocolPathEntry> protocolList = Via.getManager().getProtocolManager().getProtocolPath(MinecraftConstants.PROTOCOL_VERSION,
|
2020-11-20 19:56:39 +00:00
|
|
|
serverVersion.getVersion());
|
|
|
|
if (protocolList == null) {
|
|
|
|
// No translation needed!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int i = protocolList.size() - 1; i >= 0; i--) {
|
2021-04-24 19:18:41 +00:00
|
|
|
MappingData mappingData = protocolList.get(i).getProtocol().getMappingData();
|
2020-11-20 19:56:39 +00:00
|
|
|
if (mappingData != null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// All mapping data is null, which means client and server block states are the same
|
|
|
|
return false;
|
2020-06-27 15:36:48 +00:00
|
|
|
}
|
2019-09-29 18:05:41 +00:00
|
|
|
}
|