123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- package com.gmail.nossr50;
- import com.gmail.nossr50.datatypes.PlayerProfile;
- import com.gmail.nossr50.commands.skills.*;
- import com.gmail.nossr50.commands.spout.*;
- import com.gmail.nossr50.commands.mc.*;
- import com.gmail.nossr50.commands.party.*;
- import com.gmail.nossr50.commands.general.*;
- import com.gmail.nossr50.config.Config;
- import com.gmail.nossr50.config.HiddenConfig;
- import com.gmail.nossr50.config.RepairConfigManager;
- import com.gmail.nossr50.config.SpoutConfig;
- import com.gmail.nossr50.config.TreasuresConfig;
- import com.gmail.nossr50.config.mods.CustomBlocksConfig;
- import com.gmail.nossr50.config.mods.CustomArmorConfig;
- import com.gmail.nossr50.config.mods.CustomToolsConfig;
- import com.gmail.nossr50.runnables.*;
- import com.gmail.nossr50.skills.repair.RepairManager;
- import com.gmail.nossr50.skills.repair.RepairManagerFactory;
- import com.gmail.nossr50.skills.repair.Repairable;
- import com.gmail.nossr50.util.Database;
- import com.gmail.nossr50.util.Leaderboard;
- import com.gmail.nossr50.util.Metrics;
- import com.gmail.nossr50.util.Metrics.Graph;
- import com.gmail.nossr50.util.Users;
- import com.gmail.nossr50.util.blockmeta.ChunkletManager;
- import com.gmail.nossr50.util.blockmeta.ChunkletManagerFactory;
- import com.gmail.nossr50.listeners.BlockListener;
- import com.gmail.nossr50.listeners.EntityListener;
- import com.gmail.nossr50.listeners.HardcoreListener;
- import com.gmail.nossr50.listeners.PlayerListener;
- import com.gmail.nossr50.listeners.WorldListener;
- import com.gmail.nossr50.locale.LocaleLoader;
- import net.shatteredlands.shatt.backup.ZipLibrary;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.scheduler.BukkitScheduler;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- public class mcMMO extends JavaPlugin {
- private final PlayerListener playerListener = new PlayerListener(this);
- private final BlockListener blockListener = new BlockListener(this);
- private final EntityListener entityListener = new EntityListener(this);
- private final WorldListener worldListener = new WorldListener();
- private final HardcoreListener hardcoreListener = new HardcoreListener();
- public HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
- public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();
- public static File versionFile;
- public static Database database;
- public static mcMMO p;
- public static ChunkletManager placeStore;
- public static RepairManager repairManager;
- /* Jar Stuff */
- public File mcmmo;
- //File Paths
- public String mainDirectory, flatFileDirectory, usersFile, leaderboardDirectory, modDirectory;
- /**
- * Things to be run when the plugin is enabled.
- */
- public void onEnable() {
- p = this;
- setupFilePaths();
- //Force the loading of config files
- Config configInstance = Config.getInstance();
- TreasuresConfig.getInstance();
- HiddenConfig.getInstance();
- SpoutConfig.getInstance().load();
- List<Repairable> repairables = new ArrayList<Repairable>();
- if (configInstance.getToolModsEnabled()) {
- CustomToolsConfig.getInstance().load();
- repairables.addAll(CustomToolsConfig.getInstance().getLoadedRepairables());
- }
- if (configInstance.getArmorModsEnabled()) {
- CustomArmorConfig.getInstance().load();
- repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
- }
- if (configInstance.getBlockModsEnabled()) {
- CustomBlocksConfig.getInstance().load();
- }
- //Load repair configs, make manager, and register them at this time
- RepairConfigManager rManager = new RepairConfigManager(this);
- repairables.addAll(rManager.getLoadedRepairables());
- repairManager = RepairManagerFactory.getRepairManager(repairables.size());
- repairManager.registerRepairables(repairables);
- if (!configInstance.getUseMySQL()) {
- Users.loadUsers();
- }
- PluginManager pm = getServer().getPluginManager();
- //Register events
- pm.registerEvents(playerListener, this);
- pm.registerEvents(blockListener, this);
- pm.registerEvents(entityListener, this);
- pm.registerEvents(worldListener, this);
- if (configInstance.getHardcoreEnabled()) {
- pm.registerEvents(hardcoreListener, this);
- }
- PluginDescriptionFile pdfFile = getDescription();
- //Setup the leaderboards
- if (configInstance.getUseMySQL()) {
- database = new Database(this);
- database.createStructure();
- }
- else {
- Leaderboard.makeLeaderboards();
- }
- for (Player player : getServer().getOnlinePlayers()) {
- Users.addUser(player); //In case of reload add all users back into PlayerProfile
- }
- System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
- BukkitScheduler scheduler = getServer().getScheduler();
- //Schedule Spout Activation 1 second after start-up
- scheduler.scheduleSyncDelayedTask(this, new SpoutStart(this), 20);
- //Periodic save timer (Saves every 10 minutes)
- scheduler.scheduleSyncRepeatingTask(this, new SaveTimer(this), 0, configInstance.getSaveInterval() * 1200);
- //Regen & Cooldown timer (Runs every second)
- scheduler.scheduleSyncRepeatingTask(this, new SkillMonitor(this), 0, 20);
- //Bleed timer (Runs every two seconds)
- scheduler.scheduleSyncRepeatingTask(this, new BleedTimer(), 0, 40);
- registerCommands();
- if (configInstance.getStatsTrackingEnabled()) {
- try {
- Metrics metrics = new Metrics(this);
- Graph graph = metrics.createGraph("Percentage of servers using timings");
- if (pm.useTimings()) {
- graph.addPlotter(new Metrics.Plotter("Enabled") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- else {
- graph.addPlotter(new Metrics.Plotter("Disabled") {
- @Override
- public int getValue() {
- return 1;
- }
- });
- }
- metrics.start();
- }
- catch (IOException e) {
- System.out.println("Failed to submit stats.");
- }
- }
- // Get our ChunkletManager
- placeStore = ChunkletManagerFactory.getChunkletManager();
- }
- /**
- * Setup the various storage file paths
- */
- public void setupFilePaths() {
- mcmmo = getFile();
- mainDirectory = getDataFolder().getPath() + File.separator;
- flatFileDirectory = mainDirectory + "FlatFileStuff" + File.separator;
- usersFile = flatFileDirectory + "mcmmo.users";
- leaderboardDirectory = flatFileDirectory + "Leaderboards" + File.separator;
- modDirectory = mainDirectory + "ModConfigs" + File.separator;
- }
- /**
- * Get profile of the player.
- * </br>
- * This function is designed for API usage.
- *
- * @param player Player whose profile to get
- * @return the PlayerProfile object
- */
- public PlayerProfile getPlayerProfile(Player player) {
- return Users.getProfile(player);
- }
- /**
- * Get profile of the player by name.
- * </br>
- * This function is designed for API usage.
- *
- * @param playerName Name of player whose profile to get
- * @return the PlayerProfile object
- */
- public PlayerProfile getPlayerProfileByName(String playerName) {
- return Users.getProfileByName(playerName);
- }
- /**
- * Get profile of the offline player.
- * </br>
- * This function is designed for API usage.
- *
- * @param player Offline player whose profile to get
- * @return the PlayerProfile object
- */
- public PlayerProfile getOfflinePlayerProfile(OfflinePlayer player) {
- return Users.getProfile(player);
- }
- /**
- * Things to be run when the plugin is disabled.
- */
- public void onDisable() {
- //Make sure to save player information if the server shuts down
- for (PlayerProfile x : Users.getProfiles().values()) {
- x.save();
- }
- getServer().getScheduler().cancelTasks(this); //This removes our tasks
- //Save our metadata
- placeStore.saveAll();
- //Cleanup empty metadata stores
- placeStore.cleanUp();
- //Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
- try {
- ZipLibrary.mcMMObackup();
- }
- catch (IOException e) {
- getLogger().severe(e.toString());
- }
- System.out.println("mcMMO was disabled."); //How informative!
- }
- /**
- * Register the commands.
- */
- private void registerCommands() {
- //Register aliases with the aliasmap (used in the playercommandpreprocessevent to ugly alias them to actual commands)
- //Skills commands
- aliasMap.put(LocaleLoader.getString("Acrobatics.SkillName").toLowerCase(), "acrobatics");
- aliasMap.put(LocaleLoader.getString("Archery.SkillName").toLowerCase(), "archery");
- aliasMap.put(LocaleLoader.getString("Axes.SkillName").toLowerCase(), "axes");
- aliasMap.put(LocaleLoader.getString("Excavation.SkillName").toLowerCase(), "excavation");
- aliasMap.put(LocaleLoader.getString("Fishing.SkillName").toLowerCase(), "fishing");
- aliasMap.put(LocaleLoader.getString("Herbalism.SkillName").toLowerCase(), "herbalism");
- aliasMap.put(LocaleLoader.getString("Mining.SkillName").toLowerCase(), "mining");
- aliasMap.put(LocaleLoader.getString("Repair.SkillName").toLowerCase(), "repair");
- aliasMap.put(LocaleLoader.getString("Swords.SkillName").toLowerCase(), "swords");
- aliasMap.put(LocaleLoader.getString("Taming.SkillName").toLowerCase(), "taming");
- aliasMap.put(LocaleLoader.getString("Unarmed.SkillName").toLowerCase(), "unarmed");
- aliasMap.put(LocaleLoader.getString("Woodcutting.SkillName").toLowerCase(), "woodcutting");
- //Register commands
- //Skills commands
- getCommand("acrobatics").setExecutor(new AcrobaticsCommand());
- getCommand("archery").setExecutor(new ArcheryCommand());
- getCommand("axes").setExecutor(new AxesCommand());
- getCommand("excavation").setExecutor(new ExcavationCommand());
- getCommand("fishing").setExecutor(new FishingCommand());
- getCommand("herbalism").setExecutor(new HerbalismCommand());
- getCommand("mining").setExecutor(new MiningCommand());
- getCommand("repair").setExecutor(new RepairCommand());
- getCommand("swords").setExecutor(new SwordsCommand());
- getCommand("taming").setExecutor(new TamingCommand());
- getCommand("unarmed").setExecutor(new UnarmedCommand());
- getCommand("woodcutting").setExecutor(new WoodcuttingCommand());
- Config configInstance = Config.getInstance();
- //mc* commands
- if (configInstance.getCommandMCRemoveEnabled()) {
- getCommand("mcremove").setExecutor(new McremoveCommand(this));
- }
- if (configInstance.getCommandMCAbilityEnabled()) {
- getCommand("mcability").setExecutor(new McabilityCommand());
- }
- if (configInstance.getCommandMCCEnabled()) {
- getCommand("mcc").setExecutor(new MccCommand());
- }
- if (configInstance.getCommandMCGodEnabled()) {
- getCommand("mcgod").setExecutor(new McgodCommand());
- }
- if (configInstance.getCommandmcMMOEnabled()) {
- getCommand("mcmmo").setExecutor(new McmmoCommand());
- }
- if (configInstance.getCommandMCRefreshEnabled()) {
- getCommand("mcrefresh").setExecutor(new McrefreshCommand(this));
- }
- if (configInstance.getCommandMCTopEnabled()) {
- getCommand("mctop").setExecutor(new MctopCommand());
- }
- if (configInstance.getCommandMCStatsEnabled()) {
- getCommand("mcstats").setExecutor(new McstatsCommand());
- }
- //Party commands
- if (configInstance.getCommandAcceptEnabled()) {
- getCommand("accept").setExecutor(new AcceptCommand(this));
- }
- if (configInstance.getCommandAdminChatAEnabled()) {
- getCommand("a").setExecutor(new ACommand(this));
- }
- if (configInstance.getCommandInviteEnabled()) {
- getCommand("invite").setExecutor(new InviteCommand(this));
- }
- if (configInstance.getCommandPartyEnabled()) {
- getCommand("party").setExecutor(new PartyCommand(this));
- }
- if (configInstance.getCommandPartyChatPEnabled()) {
- getCommand("p").setExecutor(new PCommand(this));
- }
- if (configInstance.getCommandPTPEnabled()) {
- getCommand("ptp").setExecutor(new PtpCommand(this));
- }
- //Other commands
- if (configInstance.getCommandAddXPEnabled()) {
- getCommand("addxp").setExecutor(new AddxpCommand(this));
- }
- if (configInstance.getCommandAddLevelsEnabled()) {
- getCommand("addlevels").setExecutor(new AddlevelsCommand(this));
- }
- if (configInstance.getCommandMmoeditEnabled()) {
- getCommand("mmoedit").setExecutor(new MmoeditCommand(this));
- }
- if (configInstance.getCommandInspectEnabled()) {
- getCommand("inspect").setExecutor(new InspectCommand(this));
- }
- if (configInstance.getCommandXPRateEnabled()) {
- getCommand("xprate").setExecutor(new XprateCommand(this));
- }
- getCommand("mmoupdate").setExecutor(new MmoupdateCommand(this));
- //Spout commands
- if (configInstance.getCommandXPLockEnabled()) {
- getCommand("xplock").setExecutor(new XplockCommand());
- }
- getCommand("mchud").setExecutor(new MchudCommand(this));
- }
- /*
- * Boilerplate Custom Config Stuff (Treasures)
- */
- private FileConfiguration treasuresConfig = null;
- private File treasuresConfigFile = null;
- /**
- * Reload the Treasures.yml file.
- */
- public void reloadTreasuresConfig() {
- if (treasuresConfigFile == null) {
- treasuresConfigFile = new File(getDataFolder(), "treasures.yml");
- }
- treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile);
- if (isInJar("treasures.yml")) {
- InputStream defConfigStream = getResource("treasures.yml");
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- treasuresConfig.setDefaults(defConfig);
- }
- }
- /**
- * Get the Treasures config information.
- *
- * @return the configuration object for treasures.yml
- */
- public FileConfiguration getTreasuresConfig() {
- if (treasuresConfig == null) {
- reloadTreasuresConfig();
- }
- return treasuresConfig;
- }
- /**
- * Save the Treasures config informtion.
- */
- public void saveTreasuresConfig() {
- if (treasuresConfig == null || treasuresConfigFile == null) {
- return;
- }
- try {
- treasuresConfig.save(treasuresConfigFile);
- }
- catch (IOException ex) {
- getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString());
- }
- }
- /*
- * Boilerplate Custom Config Stuff (Tools)
- */
- private FileConfiguration toolsConfig = null;
- private File toolsConfigFile = null;
- /**
- * Reload the Tools.yml file.
- */
- public void reloadToolsConfig() {
- if (toolsConfigFile == null) {
- toolsConfigFile = new File(modDirectory, "tools.yml");
- }
- toolsConfig = YamlConfiguration.loadConfiguration(toolsConfigFile);
- if (isInJar("tools.yml")) {
- InputStream defConfigStream = getResource("tools.yml");
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- toolsConfig.setDefaults(defConfig);
- }
- }
- /**
- * Get the Tools config information.
- *
- * @return the configuration object for tools.yml
- */
- public FileConfiguration getToolsConfig() {
- if (toolsConfig == null) {
- reloadToolsConfig();
- }
- return toolsConfig;
- }
- /**
- * Save the Tools config informtion.
- */
- public void saveToolsConfig() {
- if (toolsConfig == null || toolsConfigFile == null) {
- return;
- }
- try {
- toolsConfig.save(toolsConfigFile);
- }
- catch (IOException ex) {
- getLogger().severe("Could not save config to " + toolsConfigFile + ex.toString());
- }
- }
- /*
- * Boilerplate Custom Config Stuff (Armor)
- */
- private FileConfiguration armorConfig = null;
- private File armorConfigFile = null;
- /**
- * Reload the Armor.yml file.
- */
- public void reloadArmorConfig() {
- if (armorConfigFile == null) {
- armorConfigFile = new File(modDirectory, "armor.yml");
- }
- armorConfig = YamlConfiguration.loadConfiguration(armorConfigFile);
- if (isInJar("armor.yml")) {
- InputStream defConfigStream = getResource("armor.yml");
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- armorConfig.setDefaults(defConfig);
- }
- }
- /**
- * Get the Armor config information.
- *
- * @return the configuration object for armor.yml
- */
- public FileConfiguration getArmorConfig() {
- if (armorConfig == null) {
- reloadArmorConfig();
- }
- return armorConfig;
- }
- /**
- * Save the Armor config informtion.
- */
- public void saveArmorConfig() {
- if (armorConfig == null || armorConfigFile == null) {
- return;
- }
- try {
- armorConfig.save(armorConfigFile);
- }
- catch (IOException ex) {
- getLogger().severe("Could not save config to " + armorConfigFile + ex.toString());
- }
- }
- /*
- * Boilerplate Custom Config Stuff (Blocks)
- */
- private FileConfiguration blocksConfig = null;
- private File blocksConfigFile = null;
- /**
- * Reload the Blocks.yml file.
- */
- public void reloadBlocksConfig() {
- if (blocksConfigFile == null) {
- blocksConfigFile = new File(modDirectory, "blocks.yml");
- }
- blocksConfig = YamlConfiguration.loadConfiguration(blocksConfigFile);
- if (isInJar("blocks.yml")) {
- InputStream defConfigStream = getResource("blocks.yml");
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- blocksConfig.setDefaults(defConfig);
- }
- }
- /**
- * Get the Blocks config information.
- *
- * @return the configuration object for blocks.yml
- */
- public FileConfiguration getBlocksConfig() {
- if (blocksConfig == null) {
- reloadBlocksConfig();
- }
- return blocksConfig;
- }
- /**
- * Save the Blocks config informtion.
- */
- public void saveBlocksConfig() {
- if (blocksConfig == null || blocksConfigFile == null) {
- return;
- }
- try {
- blocksConfig.save(blocksConfigFile);
- }
- catch (IOException ex) {
- getLogger().severe("Could not save config to " + blocksConfigFile + ex.toString());
- }
- }
- /*
- * Boilerplate Custom Config Stuff (Spout)
- */
- private FileConfiguration spoutConfig = null;
- private File spoutConfigFile = null;
- /**
- * Reload the Spout.yml file.
- */
- public void reloadSpoutConfig() {
- if (spoutConfigFile == null) {
- spoutConfigFile = new File(modDirectory, "spout.yml");
- }
- spoutConfig = YamlConfiguration.loadConfiguration(spoutConfigFile);
- if (isInJar("spout.yml")) {
- InputStream defConfigStream = getResource("spout.yml");
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- spoutConfig.setDefaults(defConfig);
- }
- }
- /**
- * Get the Spout config information.
- *
- * @return the configuration object for spout.yml
- */
- public FileConfiguration getSpoutConfig() {
- if (spoutConfig == null) {
- reloadSpoutConfig();
- }
- return spoutConfig;
- }
- /**
- * Save the Spout config informtion.
- */
- public void saveSpoutConfig() {
- if (spoutConfig == null || spoutConfigFile == null) {
- return;
- }
- try {
- spoutConfig.save(spoutConfigFile);
- }
- catch (IOException ex) {
- getLogger().severe("Could not save config to " + spoutConfigFile + ex.toString());
- }
- }
- public boolean isInJar(String resource) {
- InputStream iStream = getResource(resource);
- return iStream != null;
- }
- }
|