2019-12-21 22:19:04 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-12-21 22:19:04 +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:
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.platform.sponge;
|
2019-12-21 22:18:34 +00:00
|
|
|
|
|
|
|
import com.google.inject.Inject;
|
2020-11-14 23:49:56 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.GeyserBootstrap;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.command.CommandManager;
|
|
|
|
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
|
|
|
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
|
|
|
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
|
|
|
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.util.FileUtils;
|
|
|
|
import org.geysermc.geyser.text.GeyserLocale;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.platform.sponge.command.GeyserSpongeCommandExecutor;
|
|
|
|
import org.geysermc.geyser.platform.sponge.command.GeyserSpongeCommandManager;
|
2019-12-21 22:18:34 +00:00
|
|
|
import org.slf4j.Logger;
|
2020-03-17 16:43:09 +00:00
|
|
|
import org.spongepowered.api.Sponge;
|
2019-12-21 22:18:34 +00:00
|
|
|
import org.spongepowered.api.config.ConfigDir;
|
|
|
|
import org.spongepowered.api.event.Listener;
|
|
|
|
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
|
|
|
import org.spongepowered.api.event.game.state.GameStoppedEvent;
|
|
|
|
import org.spongepowered.api.plugin.Plugin;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-04-27 20:45:14 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2020-06-20 17:54:40 +00:00
|
|
|
import java.nio.file.Path;
|
2019-12-21 22:18:34 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
@Plugin(id = "geyser", name = GeyserImpl.NAME + "-Sponge", version = GeyserImpl.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
2020-04-29 20:01:53 +00:00
|
|
|
public class GeyserSpongePlugin implements GeyserBootstrap {
|
2019-12-21 22:18:34 +00:00
|
|
|
|
|
|
|
@Inject
|
|
|
|
private Logger logger;
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@ConfigDir(sharedRoot = false)
|
|
|
|
private File configDir;
|
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
private GeyserSpongeCommandManager geyserCommandManager;
|
2019-12-21 22:18:34 +00:00
|
|
|
private GeyserSpongeConfiguration geyserConfig;
|
|
|
|
private GeyserSpongeLogger geyserLogger;
|
2020-05-23 21:50:04 +00:00
|
|
|
private IGeyserPingPassthrough geyserSpongePingPassthrough;
|
2019-12-21 22:18:34 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
private GeyserImpl geyser;
|
2020-03-17 16:43:09 +00:00
|
|
|
|
2019-12-21 22:18:34 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
if (!configDir.exists())
|
|
|
|
configDir.mkdirs();
|
|
|
|
|
|
|
|
File configFile = null;
|
|
|
|
try {
|
|
|
|
configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (file) -> file.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
|
|
|
} catch (IOException ex) {
|
2021-11-20 23:29:46 +00:00
|
|
|
logger.warn(GeyserLocale.getLocaleStringLog("geyser.config.failed"));
|
2019-12-21 22:18:34 +00:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-08-28 15:47:52 +00:00
|
|
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpongeConfiguration.class);
|
2019-12-21 22:18:34 +00:00
|
|
|
} catch (IOException ex) {
|
2021-11-20 23:29:46 +00:00
|
|
|
logger.warn(GeyserLocale.getLocaleStringLog("geyser.config.failed"));
|
2019-12-21 22:18:34 +00:00
|
|
|
ex.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
if (Sponge.getServer().getBoundAddress().isPresent()) {
|
|
|
|
InetSocketAddress javaAddr = Sponge.getServer().getBoundAddress().get();
|
|
|
|
|
|
|
|
// Don't change the ip if its listening on all interfaces
|
|
|
|
// By default this should be 127.0.0.1 but may need to be changed in some circumstances
|
2020-08-16 17:45:52 +00:00
|
|
|
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
|
2020-08-19 17:14:17 +00:00
|
|
|
this.geyserConfig.setAutoconfiguredRemote(true);
|
2020-08-28 15:47:52 +00:00
|
|
|
geyserConfig.getRemote().setPort(javaAddr.getPort());
|
2020-04-27 20:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-17 01:09:18 +00:00
|
|
|
if (geyserConfig.getBedrock().isCloneRemotePort()) {
|
2020-08-28 15:47:52 +00:00
|
|
|
geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort());
|
2020-07-30 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 22:18:34 +00:00
|
|
|
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
|
2020-05-21 03:43:22 +00:00
|
|
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyser = GeyserImpl.start(PlatformType.SPONGE, this);
|
2019-12-21 22:18:34 +00:00
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
if (geyserConfig.isLegacyPingPassthrough()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyserSpongePingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
2020-05-23 21:50:04 +00:00
|
|
|
} else {
|
|
|
|
this.geyserSpongePingPassthrough = new GeyserSpongePingPassthrough();
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), geyser);
|
|
|
|
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(geyser), "geyser");
|
2019-12-21 22:18:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2021-11-20 21:34:30 +00:00
|
|
|
geyser.shutdown();
|
2019-12-21 22:18:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserSpongeConfiguration getGeyserConfig() {
|
|
|
|
return geyserConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserSpongeLogger getGeyserLogger() {
|
|
|
|
return geyserLogger;
|
|
|
|
}
|
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
@Override
|
|
|
|
public CommandManager getGeyserCommandManager() {
|
|
|
|
return this.geyserCommandManager;
|
|
|
|
}
|
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
@Override
|
|
|
|
public IGeyserPingPassthrough getGeyserPingPassthrough() {
|
|
|
|
return geyserSpongePingPassthrough;
|
|
|
|
}
|
|
|
|
|
2020-06-20 17:54:40 +00:00
|
|
|
@Override
|
|
|
|
public Path getConfigFolder() {
|
|
|
|
return configDir.toPath();
|
|
|
|
}
|
|
|
|
|
2019-12-21 22:18:34 +00:00
|
|
|
@Listener
|
|
|
|
public void onServerStart(GameStartedServerEvent event) {
|
|
|
|
onEnable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Listener
|
|
|
|
public void onServerStop(GameStoppedEvent event) {
|
|
|
|
onDisable();
|
|
|
|
}
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BootstrapDumpInfo getDumpInfo() {
|
|
|
|
return new GeyserSpongeDumpInfo();
|
|
|
|
}
|
2021-02-04 00:54:35 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getMinecraftServerVersion() {
|
|
|
|
return Sponge.getPlatform().getMinecraftVersion().getName();
|
|
|
|
}
|
2019-12-21 22:18:34 +00:00
|
|
|
}
|