Advanced-Portals/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsPlugin.java

190 lines
6.8 KiB
Java
Raw Normal View History

package com.sekwah.advancedportals.bukkit;
2020-06-18 04:37:06 +02:00
import com.sekwah.advancedportals.bukkit.config.ConfigAccessor;
import com.sekwah.advancedportals.bukkit.config.ConfigHelper;
import com.sekwah.advancedportals.bukkit.destinations.Destination;
import com.sekwah.advancedportals.bukkit.destinations.DestinationCommand;
import com.sekwah.advancedportals.bukkit.effects.WarpEffects;
import com.sekwah.advancedportals.bukkit.listeners.*;
import com.sekwah.advancedportals.bukkit.metrics.Metrics;
import com.sekwah.advancedportals.bukkit.portals.Portal;
2020-12-30 03:49:45 +01:00
import com.sekwah.advancedportals.bungee.BungeeMessages;
import org.bukkit.Bukkit;
2021-01-24 04:05:58 +01:00
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
2019-05-31 05:04:48 +02:00
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
2020-07-16 11:58:06 +02:00
import java.util.HashMap;
2021-01-24 04:05:58 +01:00
import java.util.Map;
import java.util.Objects;
2020-07-16 11:58:06 +02:00
public class AdvancedPortalsPlugin extends JavaPlugin {
private Settings settings;
2016-03-29 13:38:03 +02:00
2021-01-24 04:05:58 +01:00
protected boolean isProxyPluginEnabled = false;
2020-07-02 03:39:23 +02:00
2021-01-24 04:05:58 +01:00
protected boolean forceRegisterProxyChannels = false;
protected boolean disableProxyWarning = false;
private boolean worldEditActive = false;
2021-01-24 04:05:58 +01:00
protected static final Map<String, String> PLAYER_DESTI_MAP = new HashMap<>();
2016-03-29 13:38:03 +02:00
2021-01-24 04:05:58 +01:00
@Override
public void onEnable() {
2016-03-29 13:38:03 +02:00
saveDefaultConfig();
/*Metrics metrics = */
new Metrics(this, 4814);
2017-06-13 02:32:28 +02:00
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
ConfigHelper configHelper = new ConfigHelper(config.getConfig());
2020-06-18 04:37:06 +02:00
configHelper.update();
2020-06-18 04:37:06 +02:00
config.saveConfig();
2020-06-18 04:37:06 +02:00
2021-01-24 04:05:58 +01:00
FileConfiguration pluginConfig = config.getConfig();
forceRegisterProxyChannels = pluginConfig.getBoolean(ConfigHelper.FORCE_ENABLE_PROXY_SUPPORT, false);
disableProxyWarning = pluginConfig.getBoolean(ConfigHelper.DISABLE_PROXY_WARNING, false);
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
portalConfig.saveDefaultConfig();
2016-05-11 12:42:54 +02:00
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
destinationConfig.saveDefaultConfig();
2016-05-11 12:42:54 +02:00
this.settings = new Settings(this);
2016-05-11 12:42:54 +02:00
// Loads the portal and destination editors
2021-01-24 04:05:58 +01:00
Portal.init(this);
Destination.init(this);
2016-05-11 12:42:54 +02:00
this.registerCommands();
2016-05-11 12:42:54 +02:00
new WarpEffects(this);
2016-05-11 12:42:54 +02:00
this.addListeners();
this.setupDataCollector();
2016-05-11 12:42:54 +02:00
this.setupBungee();
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
2019-05-31 05:04:48 +02:00
for (Player player:
this.getServer().getOnlinePlayers()) {
player.removeMetadata(Listeners.HAS_WARPED, this);
player.removeMetadata(Listeners.LAVA_WARPED, this);
2019-05-31 05:04:48 +02:00
}
2016-03-29 13:38:03 +02:00
if (settings.enabledWorldEditIntegration() && Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
worldEditActive = true;
}
2016-03-29 13:38:03 +02:00
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
// only copy the file if it doesnt exist!
}
private void registerCommands() {
new PluginMessages(this);
new AdvancedPortalsCommand(this);
new DestinationCommand(this);
}
private void addListeners() {
new Listeners(this);
new FlowStopper(this);
new PortalProtect(this);
new PortalPlacer(this);
}
private void setupDataCollector() {
2017-07-20 16:28:00 +02:00
Selection.loadData(this);
}
private void setupBungee() {
2020-07-02 03:39:23 +02:00
// Enables very basic bungee support if not setup right
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
2021-01-24 04:05:58 +01:00
if(forceRegisterProxyChannels || this.checkIfBungee()) {
2020-07-02 03:39:23 +02:00
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
2020-01-20 16:45:55 +01:00
2020-12-30 03:49:45 +01:00
this.getServer().getMessenger().registerOutgoingPluginChannel(this, BungeeMessages.CHANNEL_NAME);
this.getServer().getMessenger().registerIncomingPluginChannel(this, BungeeMessages.CHANNEL_NAME, new PluginMessageReceiver(this));
2021-01-24 04:05:58 +01:00
isProxyPluginEnabled = true;
2020-07-02 03:39:23 +02:00
}
else {
2021-01-24 04:05:58 +01:00
isProxyPluginEnabled = false;
2020-07-02 03:39:23 +02:00
}
}
2021-01-24 04:05:58 +01:00
public Map<String, String> getPlayerDestiMap() {
return PLAYER_DESTI_MAP;
}
public boolean isProxyPluginEnabled() {
return isProxyPluginEnabled;
}
2020-07-02 03:39:23 +02:00
private boolean checkIfBungee()
{
// we check if the server is Spigot/Paper (because of the spigot.yml file)
try {
Class.forName("org.spigotmc.SpigotConfig");
} catch (ClassNotFoundException e) {
2020-07-02 03:39:23 +02:00
this.getServer().getConsoleSender().sendMessage( "\u00A7ePossibly unsupported version for bungee messages detected, channels won't be enabled." );
2021-01-24 04:05:58 +01:00
getLogger().info("If you believe this shouldn't be the case please contact us on discord https://discord.sekwah.com/");
2020-07-02 03:39:23 +02:00
return false;
}
2021-01-24 04:05:58 +01:00
try {
ConfigurationSection configSelection = getServer().spigot().getConfig().getConfigurationSection("settings");
if (configSelection != null && configSelection.getBoolean("bungeecord") ) {
getLogger().info( "Bungee detected. Enabling proxy features." );
return true;
}
} catch(NoSuchMethodError | NullPointerException e) {
if(!disableProxyWarning) getLogger().info("BungeeCord config not detected, ignoring settings");
}
// Will be valid if paperspigot is being used. Otherwise catch.
try {
YamlConfiguration config = getServer().spigot().getPaperConfig();
if(Objects.equals(config.get("velocity-support.enabled"),true)
|| Objects.equals(config.get("proxies.velocity.enabled"),true)) {
getLogger().info( "Modern forwarding detected. Enabling proxy features." );
return true;
2021-01-24 04:05:58 +01:00
}
} catch(NoSuchMethodError | NullPointerException e) {
if(!disableProxyWarning) getLogger().info("Paper config not detected, ignoring paper settings");
2020-07-02 03:39:23 +02:00
}
if(!disableProxyWarning) getLogger().warning( "Proxy features disabled for Advanced Portals as bungee isn't enabled on the server (spigot.yml)." +
"If you are using Paper proxies.velocity.enabled (config/paper-global.yml) or settings.velocity-support.enabled (paper.yml) may not be enabled " );
return false;
}
2016-03-29 13:38:03 +02:00
2021-01-24 04:05:58 +01:00
@Override
2016-03-29 13:38:03 +02:00
public void onDisable() {
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
}
public Settings getSettings() {
return settings;
}
public boolean isWorldEditActive() {
return worldEditActive;
}
}