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

135 lines
4.6 KiB
Java
Raw Normal View History

package com.sekwah.advancedportals.bukkit;
import com.sekwah.advancedportals.bukkit.compat.CraftBukkit;
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;
2019-05-31 05:04:48 +02:00
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class AdvancedPortalsPlugin extends JavaPlugin {
public CraftBukkit compat = null;
private Settings settings;
2016-03-29 13:38:03 +02:00
2020-01-20 16:45:55 +01:00
public String channelName = "mc:advancedportals";
// public HashMap<OfflinePlayer, String> PlayerDestiMap = new HashMap<>();
2016-03-29 13:38:03 +02:00
public void onEnable() {
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1];
saveDefaultConfig();
Metrics metrics = new Metrics(this);
2017-06-13 02:32:28 +02:00
2016-03-29 13:38:03 +02:00
try {
2016-05-11 12:42:54 +02:00
this.compat = new CraftBukkit(this, version);
2016-05-11 12:42:54 +02:00
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
2020-06-18 04:37:06 +02:00
ConfigHelper configHelper = new ConfigHelper(config.getConfig());
configHelper.update();
config.saveConfig();
// TODO reenable and finish but probably focus on the recode first
/*if(config.getConfig().getBoolean("DisableGatewayBeam", true)) {
new PacketInjector(this, version);
}*/
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
new Portal(this);
new Destination(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!");
2016-05-11 12:42:54 +02:00
2016-03-29 13:38:03 +02:00
} catch (ClassNotFoundException e) {
2017-05-13 19:19:08 +02:00
e.printStackTrace();
this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version);
2017-05-13 19:19:08 +02:00
this.getLogger().warning("Along with the above stacktrace");
2016-03-29 13:38:03 +02:00
this.setEnabled(false);
} catch (IllegalArgumentException |
NoSuchFieldException | SecurityException | NoSuchMethodException e) {
2016-03-29 13:38:03 +02:00
e.printStackTrace();
this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version);
this.getLogger().warning("Along with the above stacktrace");
this.setEnabled(false);
2016-03-29 13:38:03 +02:00
}
2019-05-31 05:04:48 +02:00
for (Player player:
this.getServer().getOnlinePlayers()) {
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() {
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
2020-01-20 16:45:55 +01:00
this.getServer().getMessenger().registerOutgoingPluginChannel(this, channelName);
this.getServer().getMessenger().registerIncomingPluginChannel(this, channelName, new PluginMessageReceiver(this));
}
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;
}
}