2020-01-20 11:55:18 +01:00
|
|
|
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;
|
2020-01-20 11:55:18 +01:00
|
|
|
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;
|
2015-01-15 23:16:16 +01:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
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
|
|
|
|
2020-01-20 16:45:55 +01:00
|
|
|
public String channelName = "mc:advancedportals";
|
|
|
|
|
|
|
|
// public HashMap<OfflinePlayer, String> PlayerDestiMap = new HashMap<>();
|
2020-01-20 11:55:18 +01:00
|
|
|
|
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();
|
|
|
|
|
2019-06-03 03:55:44 +02:00
|
|
|
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
|
|
|
|
2016-08-03 05:30:59 +02:00
|
|
|
this.compat = new CraftBukkit(this, version);
|
2016-05-11 12:42:54 +02:00
|
|
|
|
2018-10-18 04:27:10 +02:00
|
|
|
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
|
2017-07-12 14:27:22 +02:00
|
|
|
|
2020-06-18 04:37:06 +02:00
|
|
|
ConfigHelper configHelper = new ConfigHelper(config.getConfig());
|
|
|
|
|
|
|
|
configHelper.update();
|
|
|
|
|
|
|
|
config.saveConfig();
|
|
|
|
|
2019-05-25 03:31:38 +02:00
|
|
|
// TODO reenable and finish but probably focus on the recode first
|
|
|
|
/*if(config.getConfig().getBoolean("DisableGatewayBeam", true)) {
|
2018-10-18 04:27:10 +02:00
|
|
|
new PacketInjector(this, version);
|
2019-05-25 03:31:38 +02:00
|
|
|
}*/
|
2017-07-12 14:27:22 +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
|
|
|
|
2017-07-12 14:27:22 +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
|
|
|
}
|
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!
|
|
|
|
}
|
|
|
|
|
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() {
|
2017-07-20 16:28:00 +02:00
|
|
|
Selection.loadData(this);
|
2017-04-20 04:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2017-04-20 04:31:25 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|