135 lines
5.1 KiB
Java
135 lines
5.1 KiB
Java
package fi.flexplex.connect;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.Properties;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import fi.flexplex.connect.util.FileChangeListener;
|
|
|
|
public final class FlexConnect extends JavaPlugin {
|
|
|
|
private String token = "";
|
|
private FlexPlexGraphQLApi flexPlexGraphQLApi;
|
|
|
|
public String getToken() {
|
|
return this.token;
|
|
}
|
|
|
|
public FlexPlexGraphQLApi getFlexPlexGraphQLApi() {
|
|
return this.flexPlexGraphQLApi;
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
|
|
// Plugin own configs
|
|
this.saveDefaultConfig();
|
|
this.token = this.getConfig().getString("token");
|
|
if (this.token.equals("default")) {
|
|
this.getLogger().warning("Token for FlexPlex server network has not been set into plugins config file. Please request token from FlexPlex staff members if you don't already have one!");
|
|
}
|
|
|
|
// GraphQL Api
|
|
this.flexPlexGraphQLApi = new FlexPlexGraphQLApi(this, "https://api.flexplex.fi/graphql");
|
|
|
|
boolean configsModified = false;
|
|
|
|
// Check online mode
|
|
if (this.getServer().getOnlineMode()) {
|
|
final Properties properties = new Properties();
|
|
try {
|
|
properties.load(new FileInputStream("server.properties"));
|
|
properties.setProperty("online-mode", "false");
|
|
properties.store(new FileOutputStream("server.properties"), null);
|
|
} catch (final IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
this.getLogger().warning("Automatic changes has been made to server.properties file.");
|
|
configsModified = true;
|
|
}
|
|
|
|
// Check paper config
|
|
boolean paperConfigModified = false;
|
|
final YamlConfiguration paperConfig = this.getServer().spigot().getPaperConfig();
|
|
|
|
// Legacy paper configs (1.18 or older)
|
|
if (paperConfig.contains("settings.velocity-support.enabled")) {
|
|
if (!paperConfig.getBoolean("settings.velocity-support.enabled")) {
|
|
paperConfig.set("settings.velocity-support.enabled", true);
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
if (paperConfig.contains("settings.velocity-support.online-mode")) {
|
|
if (!paperConfig.getBoolean("settings.velocity-support.online-mode")) {
|
|
paperConfig.set("settings.velocity-support.online-mode", true);
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
if (paperConfig.contains("settings.velocity-support.secret")) {
|
|
if (!paperConfig.getString("settings.velocity-support.secret").equals("flexplex")) {
|
|
paperConfig.set("settings.velocity-support.secret", "flexplex");
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
|
|
// Current paper configurations 1.19+
|
|
if (paperConfig.contains("proxies.velocity.enabled")) {
|
|
if (!paperConfig.getBoolean("proxies.velocity.enabled")) {
|
|
paperConfig.set("proxies.velocity.enabled", true);
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
if (paperConfig.contains("proxies.velocity.online-mode")) {
|
|
if (!paperConfig.getBoolean("proxies.velocity.online-mode")) {
|
|
paperConfig.set("proxies.velocity.online-mode", true);
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
if (paperConfig.contains("proxies.velocity.secret")) {
|
|
if (!paperConfig.getString("proxies.velocity.secret").equals("flexplex")) {
|
|
paperConfig.set("proxies.velocity.secret", "flexplex");
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
|
|
// In both configurations
|
|
if (paperConfig.contains("settings.unsupported-settings.perform-username-validation")) {
|
|
if (paperConfig.getBoolean("settings.unsupported-settings.perform-username-validation")) {
|
|
paperConfig.set("settings.unsupported-settings.perform-username-validation", false);
|
|
paperConfigModified = true;
|
|
}
|
|
}
|
|
|
|
if (paperConfigModified) {
|
|
try {
|
|
paperConfig.save("paper.yml");
|
|
} catch (final IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
this.getLogger().warning("Automatic changes has been made to paper.yml config file.");
|
|
configsModified = true;
|
|
}
|
|
|
|
// Actions if configs were modified
|
|
if (configsModified) {
|
|
this.getLogger().warning("Changes has been made to config files. Server will now shutdown automatically.");
|
|
this.getServer().shutdown();
|
|
return;
|
|
}
|
|
|
|
// Register listener
|
|
this.getServer().getPluginManager().registerEvents(new FlexConnectListener(this), this);
|
|
|
|
// Register file change listener
|
|
new FileChangeListener(this, "ops.json", "whitelist.json");
|
|
|
|
// Update whitelists for flexplex api
|
|
this.flexPlexGraphQLApi.updateWhitelist();
|
|
}
|
|
|
|
}
|