2015-01-15 20:56:13 +01:00
|
|
|
package com.sekwah.advancedportals;
|
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
import com.sekwah.advancedportals.compat.CraftBukkit;
|
2017-06-10 09:21:14 +02:00
|
|
|
import com.sekwah.advancedportals.destinations.Destination;
|
|
|
|
import com.sekwah.advancedportals.destinations.DestinationCommand;
|
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.*;
|
2017-06-13 02:32:28 +02:00
|
|
|
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;
|
|
|
|
|
2017-06-13 02:32:28 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-01-15 20:56:13 +01:00
|
|
|
public class AdvancedPortalsPlugin extends JavaPlugin {
|
2015-01-15 23:16:16 +01:00
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
public CraftBukkit compat = null;
|
2017-04-20 04:31:25 +02:00
|
|
|
private Settings settings;
|
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];
|
|
|
|
|
2017-06-12 15:53:27 +02:00
|
|
|
saveDefaultConfig();
|
|
|
|
|
2017-06-13 02:32:28 +02:00
|
|
|
try {
|
|
|
|
Metrics metrics = new Metrics(this);
|
|
|
|
metrics.start();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Failed to submit the stats :-(
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
try {
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2016-08-03 05:30:59 +02:00
|
|
|
this.compat = new CraftBukkit(this, version);
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
|
|
|
|
portalConfig.saveDefaultConfig();
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
|
|
|
|
destinationConfig.saveDefaultConfig();
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
this.settings = new Settings(this);
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
// Loads the portal and destination editors
|
|
|
|
new Portal(this);
|
|
|
|
new Destination(this);
|
2016-05-11 12:42:54 +02:00
|
|
|
|
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
this.registerCommands();
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2016-08-03 00:47:26 +02:00
|
|
|
new WarpEffects(this);
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
this.addListeners();
|
|
|
|
this.setupDataCollector();
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
this.setupBungee();
|
2016-08-03 00:47:26 +02:00
|
|
|
|
|
|
|
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();
|
2016-08-03 00:47:26 +02:00
|
|
|
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);
|
2016-08-03 00:47:26 +02:00
|
|
|
} catch (IllegalArgumentException |
|
2016-08-03 05:30:59 +02:00
|
|
|
NoSuchFieldException | SecurityException | NoSuchMethodException e) {
|
2016-03-29 13:38:03 +02:00
|
|
|
e.printStackTrace();
|
2016-08-03 00:47:26 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// thanks to the new config accessor code the config.saveDefaultConfig(); will now
|
|
|
|
// only copy the file if it doesnt exist!
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
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() {
|
|
|
|
Selection.LoadData(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupBungee() {
|
|
|
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
|
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
|
|
|
|
}
|
|
|
|
|
2016-03-29 13:38:03 +02:00
|
|
|
|
|
|
|
public void onDisable() {
|
|
|
|
this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-20 04:31:25 +02:00
|
|
|
public Settings getSettings() {
|
|
|
|
return settings;
|
|
|
|
}
|
2015-01-15 20:56:13 +01:00
|
|
|
}
|