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

160 lines
5.2 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;
2021-01-24 04:05:58 +01:00
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
2019-05-31 05:04:48 +02:00
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
2020-07-16 11:58:06 +02:00
import java.util.HashMap;
2021-01-24 04:05:58 +01:00
import java.util.Map;
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;
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);
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);
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()) {
2019-05-31 05:04:48 +02:00
player.removeMetadata("hasWarped", this);
player.removeMetadata("lavaWarped", this);
}
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().warning( "Advanced bungee features disabled for Advanced Portals as bungee isn't enabled on the server (spigot.yml)" );
return false;
}
} catch(NullPointerException e) {
2020-07-02 03:39:23 +02:00
return false;
}
2020-07-02 03:39:23 +02:00
return true;
}
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;
}
}