2015-01-15 20:56:13 +01:00
|
|
|
package com.sekwah.advancedportals;
|
|
|
|
|
|
|
|
import com.sekwah.advancedportals.DataCollector.DataCollector;
|
2015-06-28 21:37:00 +02:00
|
|
|
import com.sekwah.advancedportals.compat.bukkit.NMS;
|
2015-01-15 20:56:13 +01:00
|
|
|
import com.sekwah.advancedportals.destinations.Destination;
|
|
|
|
import com.sekwah.advancedportals.metrics.Metrics;
|
2015-02-08 14:08:50 +01:00
|
|
|
import com.sekwah.advancedportals.portals.Portal;
|
2015-01-15 23:16:16 +01:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2015-01-15 20:56:13 +01:00
|
|
|
|
|
|
|
public class AdvancedPortalsPlugin extends JavaPlugin {
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
public NMS nmsAccess;
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2015-02-09 20:50:10 +01:00
|
|
|
public boolean useCustomPrefix = false;
|
|
|
|
|
|
|
|
public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]";
|
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
public void onEnable() {
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
try {
|
|
|
|
Metrics metrics = new Metrics(this);
|
|
|
|
metrics.start();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Failed to submit the stats :-(
|
|
|
|
}
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2015-08-18 01:03:56 +02:00
|
|
|
this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!");
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
String packageName = getServer().getClass().getPackage().getName();
|
|
|
|
String[] packageSplit = packageName.split("\\.");
|
|
|
|
String version = packageSplit[packageSplit.length - 1];
|
|
|
|
|
|
|
|
try {
|
2015-06-28 21:37:00 +02:00
|
|
|
Class<?> nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version);
|
2015-01-15 20:56:13 +01:00
|
|
|
if(NMS.class.isAssignableFrom(nmsClass)){
|
|
|
|
this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance();
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
System.out.println("Something went wrong, please notify the author and tell them this version v:" + version);
|
|
|
|
this.setEnabled(false);
|
|
|
|
}
|
|
|
|
} catch (ClassNotFoundException e) {
|
2015-03-24 21:53:16 +01:00
|
|
|
System.out.println("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version);
|
2015-01-15 20:56:13 +01:00
|
|
|
this.setEnabled(false);
|
2015-06-28 21:37:00 +02:00
|
|
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException |
|
|
|
|
NoSuchMethodException | SecurityException e) {
|
2015-01-15 20:56:13 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-06-28 21:37:00 +02:00
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
new Assets(this);
|
|
|
|
|
|
|
|
// Opens a channel that messages bungeeCord
|
|
|
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
|
|
|
|
|
|
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
|
|
|
|
// only copy the file if it doesnt exist!
|
|
|
|
ConfigAccessor config = new ConfigAccessor(this, "Config.yml");
|
|
|
|
config.saveDefaultConfig();
|
2015-02-09 20:50:10 +01:00
|
|
|
|
|
|
|
this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix");
|
|
|
|
if(useCustomPrefix){
|
|
|
|
this.customPrefix = config.getConfig().getString("CustomPrefix");
|
|
|
|
}
|
|
|
|
|
2016-03-01 14:59:48 +01:00
|
|
|
ConfigAccessor portalConfig = new ConfigAccessor(this, "Portals.yml");
|
|
|
|
portalConfig.saveDefaultConfig();
|
2015-01-15 20:56:13 +01:00
|
|
|
|
2016-03-01 14:59:48 +01:00
|
|
|
ConfigAccessor destinationConfig = new ConfigAccessor(this, "Destinations.yml");
|
|
|
|
destinationConfig.saveDefaultConfig();
|
2015-01-15 20:56:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Loads the portal and destination editors
|
|
|
|
new Portal(this);
|
|
|
|
new Destination(this);
|
|
|
|
|
|
|
|
new DataCollector(this);
|
|
|
|
|
|
|
|
// These register the commands
|
|
|
|
new AdvancedPortalsCommand(this);
|
|
|
|
new DestinationCommand(this);
|
|
|
|
new WarpCommand(this);
|
|
|
|
|
|
|
|
|
|
|
|
// These register the listeners
|
|
|
|
new Listeners(this);
|
|
|
|
|
|
|
|
new FlowStopper(this);
|
|
|
|
new PortalProtect(this);
|
|
|
|
new PortalPlacer(this);
|
|
|
|
|
|
|
|
Selection.LoadData(this);
|
|
|
|
|
|
|
|
DataCollector.setupMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onDisable() {
|
2015-01-15 23:16:16 +01:00
|
|
|
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
|
2015-01-15 20:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|