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

105 lines
3.7 KiB
Java
Raw Normal View History

package com.sekwah.advancedportals;
import com.sekwah.advancedportals.DataCollector.DataCollector;
import com.sekwah.advancedportals.compat.bukkit.NMS;
2016-08-02 03:53:56 +02:00
import com.sekwah.advancedportals.destinations.*;
2016-03-01 21:18:52 +01:00
import com.sekwah.advancedportals.effects.WarpEffects;
2016-07-31 05:35:24 +02:00
import com.sekwah.advancedportals.listeners.*;
import com.sekwah.advancedportals.metrics.Metrics;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
public class AdvancedPortalsPlugin extends JavaPlugin {
2016-03-29 13:38:03 +02:00
public NMS nmsAccess;
public void onEnable() {
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
String packageName = getServer().getClass().getPackage().getName();
String[] packageSplit = packageName.split("\\.");
String version = packageSplit[packageSplit.length - 1];
try {
Class<?> nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version);
if (NMS.class.isAssignableFrom(nmsClass)) {
this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance();
2016-05-11 12:42:54 +02:00
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
portalConfig.saveDefaultConfig();
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
destinationConfig.saveDefaultConfig();
new Assets(this);
// Opens a channel that messages bungeeCord
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
// Loads the portal and destination editors
new Portal(this);
new Destination(this);
new DataCollector(this);
// These register the commands
new PluginMessages(this);
2016-05-11 12:42:54 +02:00
new AdvancedPortalsCommand(this);
new DestinationCommand(this);
new WarpEffects(this);
// These register the listeners
new Listeners(this);
new FlowStopper(this);
new PortalProtect(this);
new PortalPlacer(this);
Selection.LoadData(this);
DataCollector.setupMetrics();
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
2016-03-29 13:38:03 +02:00
} else {
2016-05-11 12:42:54 +02:00
this.getLogger().warning("Something went wrong, please notify the author and tell them this version v:" + version);
2016-03-29 13:38:03 +02:00
this.setEnabled(false);
}
} catch (ClassNotFoundException e) {
2016-05-11 12:42:54 +02:00
this.getLogger().warning("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version);
2016-03-29 13:38:03 +02:00
this.setEnabled(false);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException |
NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
saveDefaultConfig();
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
// only copy the file if it doesnt exist!
}
public void onDisable() {
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
}
}