2019-12-01 22:52:07 +00:00
|
|
|
/*
|
2020-04-15 19:39:21 +00:00
|
|
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
2019-12-01 22:52:07 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.platform.bungeecord;
|
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
import net.md_5.bungee.api.config.ListenerInfo;
|
2019-12-01 22:52:07 +00:00
|
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
|
|
|
import net.md_5.bungee.config.Configuration;
|
|
|
|
import net.md_5.bungee.config.ConfigurationProvider;
|
|
|
|
import net.md_5.bungee.config.YamlConfiguration;
|
2019-12-21 17:53:19 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2019-12-01 22:52:07 +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;
|
2020-06-10 22:58:29 +00:00
|
|
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
2020-05-23 21:50:04 +00:00
|
|
|
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
|
|
|
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
2020-06-10 22:58:29 +00:00
|
|
|
import org.geysermc.connector.utils.FileUtils;
|
2020-03-17 16:43:09 +00:00
|
|
|
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
|
2020-04-19 23:08:14 +00:00
|
|
|
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-04-27 20:45:14 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2019-12-01 22:52:07 +00:00
|
|
|
import java.util.UUID;
|
2019-12-02 14:45:51 +00:00
|
|
|
import java.util.logging.Level;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-29 20:01:53 +00:00
|
|
|
public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
private GeyserBungeeCommandManager geyserCommandManager;
|
2019-12-01 22:52:07 +00:00
|
|
|
private GeyserBungeeConfiguration geyserConfig;
|
|
|
|
private GeyserBungeeLogger geyserLogger;
|
2020-05-23 21:50:04 +00:00
|
|
|
private IGeyserPingPassthrough geyserBungeePingPassthrough;
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
private GeyserConnector connector;
|
|
|
|
|
2019-12-01 22:52:07 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
if (!getDataFolder().exists())
|
|
|
|
getDataFolder().mkdir();
|
|
|
|
|
|
|
|
Configuration configuration = null;
|
2019-12-02 16:54:07 +00:00
|
|
|
try {
|
2020-06-10 22:58:29 +00:00
|
|
|
if (!getDataFolder().exists())
|
|
|
|
getDataFolder().mkdir();
|
|
|
|
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
|
|
|
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserBungeeConfiguration.class);
|
2019-12-02 16:54:07 +00:00
|
|
|
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
2020-06-10 22:58:29 +00:00
|
|
|
} catch (IOException ex) {
|
|
|
|
getLogger().log(Level.WARNING, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
|
|
|
ex.printStackTrace();
|
2019-12-02 16:54:07 +00:00
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-27 20:45:14 +00:00
|
|
|
if (getProxy().getConfig().getListeners().size() == 1) {
|
|
|
|
ListenerInfo listener = getProxy().getConfig().getListeners().toArray(new ListenerInfo[0])[0];
|
|
|
|
|
|
|
|
InetSocketAddress javaAddr = listener.getHost();
|
|
|
|
|
|
|
|
// 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-05-09 03:58:29 +00:00
|
|
|
if (!javaAddr.getHostString().equals("0.0.0.0") && !javaAddr.getHostString().equals("")) {
|
2020-06-10 22:58:29 +00:00
|
|
|
this.geyserConfig.getRemote().setAddress(javaAddr.getHostString());
|
2020-04-27 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 22:58:29 +00:00
|
|
|
this.geyserConfig.getRemote().setPort(javaAddr.getPort());
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode());
|
2020-05-21 03:43:22 +00:00
|
|
|
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2020-06-10 22:58:29 +00:00
|
|
|
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && getProxy().getPluginManager().getPlugin("floodgate-bungee") == null) {
|
|
|
|
geyserLogger.severe("Auth type set to Floodgate but Floodgate not found! Disabling...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
geyserConfig.loadFloodgate(this, configuration);
|
2020-05-03 20:30:20 +00:00
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this);
|
2019-12-01 22:52:07 +00:00
|
|
|
|
2020-04-19 23:08:14 +00:00
|
|
|
this.geyserCommandManager = new GeyserBungeeCommandManager(connector);
|
|
|
|
|
2020-05-23 21:50:04 +00:00
|
|
|
if (geyserConfig.isLegacyPingPassthrough()) {
|
|
|
|
this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
|
|
|
} else {
|
|
|
|
this.geyserBungeePingPassthrough = new GeyserBungeePingPassthrough(getProxy());
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:43:09 +00:00
|
|
|
this.getProxy().getPluginManager().registerCommand(this, new GeyserBungeeCommandExecutor(connector));
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2020-03-17 16:43:09 +00:00
|
|
|
connector.shutdown();
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserBungeeConfiguration getGeyserConfig() {
|
|
|
|
return geyserConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeyserBungeeLogger 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 geyserBungeePingPassthrough;
|
|
|
|
}
|
2019-12-01 22:52:07 +00:00
|
|
|
}
|