2015-08-21 15:10:08 +02:00
|
|
|
/**
|
|
|
|
* Jobs Plugin for Bukkit
|
|
|
|
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.gamingmesh.jobs;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2015-11-27 15:34:19 +01:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2015-08-21 15:10:08 +02:00
|
|
|
import net.coreprotect.CoreProtect;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
import com.gamingmesh.jobs.listeners.JobsListener;
|
|
|
|
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
|
|
|
|
import com.gamingmesh.jobs.listeners.McMMOlistener;
|
2015-11-26 14:10:26 +01:00
|
|
|
import com.gamingmesh.jobs.listeners.MythicMobsListener;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.ActionBar;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.TabComplete;
|
|
|
|
import com.gamingmesh.jobs.config.YmlMaker;
|
|
|
|
|
|
|
|
public class JobsPlugin extends JavaPlugin {
|
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
2015-09-17 17:28:23 +02:00
|
|
|
public void onEnable() {
|
2015-11-27 15:34:19 +01:00
|
|
|
|
|
|
|
String packageName = getServer().getClass().getPackage().getName();
|
|
|
|
|
|
|
|
String[] packageSplit = packageName.split("\\.");
|
|
|
|
String version = packageSplit[packageSplit.length - 1].split("(?<=\\G.{4})")[0];
|
|
|
|
try {
|
|
|
|
Class<?> nmsClass;
|
|
|
|
nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version);
|
|
|
|
if (NMS.class.isAssignableFrom(nmsClass)) {
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setNms((NMS) nmsClass.getConstructor().newInstance());
|
2015-11-27 15:34:19 +01:00
|
|
|
} else {
|
|
|
|
System.out.println("Something went wrong, please note down version and contact author v:" + version);
|
|
|
|
this.setEnabled(false);
|
|
|
|
}
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + version);
|
|
|
|
this.setEnabled(false);
|
2016-03-01 16:06:03 +01:00
|
|
|
return;
|
2015-11-27 15:34:19 +01:00
|
|
|
} catch (InstantiationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
this.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setActionBar(new ActionBar());
|
|
|
|
|
|
|
|
// OfflinePlayerList.fillList();
|
2015-09-17 17:28:23 +02:00
|
|
|
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
|
|
|
jobConfig.saveDefaultConfig();
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
YmlMaker jobSigns = new YmlMaker(this, "Signs.yml");
|
|
|
|
jobSigns.saveDefaultConfig();
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml");
|
|
|
|
jobSchedule.saveDefaultConfig();
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
|
|
|
|
jobShopItems.saveDefaultConfig();
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
Jobs.setPermissionHandler(new PermissionHandler(this));
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.setScboard(this);
|
|
|
|
Jobs.setLanguage(this);
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setGUIManager(this);
|
2016-01-09 13:58:33 +01:00
|
|
|
Jobs.setExplore();
|
2016-01-06 14:40:27 +01:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setBBManager(this);
|
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
Jobs.setPluginLogger(getLogger());
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
Jobs.setDataFolder(getDataFolder());
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setGCManager(this);
|
|
|
|
Jobs.setConfigManager(this);
|
|
|
|
|
|
|
|
Jobs.setCommandManager(this);
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
getCommand("jobs").setExecutor(Jobs.getCommandManager());
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
this.getCommand("jobs").setTabCompleter(new TabComplete());
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
try {
|
|
|
|
Jobs.startup();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
// register the listeners
|
|
|
|
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
|
|
|
|
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
if (McMMOlistener.CheckmcMMO())
|
|
|
|
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setMythicManager(this);
|
|
|
|
if (Jobs.getMythicManager().Check() && Jobs.getGCManager().MythicMobsEnabled) {
|
2015-11-26 14:10:26 +01:00
|
|
|
getServer().getPluginManager().registerEvents(new MythicMobsListener(this), this);
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
2015-11-26 14:10:26 +01:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().useBlockProtection)
|
2015-09-17 17:28:23 +02:00
|
|
|
getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this);
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
// register economy
|
|
|
|
Bukkit.getScheduler().runTask(this, new HookEconomyTask(this));
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
if (getServer().getPluginManager().getPlugin("CoreProtect") != null) {
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.setCoreProtectApi(((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI());
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 17:28:23 +02:00
|
|
|
// all loaded properly.
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().useGlobalBoostScheduler)
|
|
|
|
Jobs.getScheduleManager().scheduler();
|
|
|
|
Jobs.getScheduleManager().DateUpdater();
|
2015-09-17 17:28:23 +02:00
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully.");
|
2015-09-17 17:28:23 +02:00
|
|
|
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
|
|
|
console.sendMessage(message);
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.getLanguage().reload(Jobs.getGCManager().getLocale());
|
|
|
|
|
2016-01-09 13:58:33 +01:00
|
|
|
Jobs.getJobsDAO().loadExplore();
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
Jobs.getCommandManager().fillCommands();
|
2015-09-17 17:28:23 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 09:48:10 +02:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2016-03-30 15:42:36 +02:00
|
|
|
Jobs.getGUIManager().CloseInventories();
|
|
|
|
Jobs.getShopManager().CloseInventories();
|
2016-01-09 13:58:33 +01:00
|
|
|
Jobs.getJobsDAO().saveExplore();
|
2015-09-17 09:48:10 +02:00
|
|
|
Jobs.shutdown();
|
2016-01-04 12:44:18 +01:00
|
|
|
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] &2Plugin has been disabled succesfully.");
|
2015-09-17 09:48:10 +02:00
|
|
|
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
|
|
|
console.sendMessage(message);
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|