mcMMO.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. package com.gmail.nossr50;
  2. import com.gmail.nossr50.chat.ChatManager;
  3. import com.gmail.nossr50.commands.CommandManager;
  4. import com.gmail.nossr50.config.*;
  5. import com.gmail.nossr50.config.experience.ExperienceConfig;
  6. import com.gmail.nossr50.config.mods.ArmorConfigManager;
  7. import com.gmail.nossr50.config.mods.BlockConfigManager;
  8. import com.gmail.nossr50.config.mods.EntityConfigManager;
  9. import com.gmail.nossr50.config.mods.ToolConfigManager;
  10. import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
  11. import com.gmail.nossr50.config.skills.repair.RepairConfigManager;
  12. import com.gmail.nossr50.config.skills.salvage.SalvageConfigManager;
  13. import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
  14. import com.gmail.nossr50.config.treasure.TreasureConfig;
  15. import com.gmail.nossr50.database.DatabaseManager;
  16. import com.gmail.nossr50.database.DatabaseManagerFactory;
  17. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  18. import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll;
  19. import com.gmail.nossr50.listeners.*;
  20. import com.gmail.nossr50.party.PartyManager;
  21. import com.gmail.nossr50.runnables.SaveTimerTask;
  22. import com.gmail.nossr50.runnables.backups.CleanBackupsTask;
  23. import com.gmail.nossr50.runnables.commands.NotifySquelchReminderTask;
  24. import com.gmail.nossr50.runnables.database.UserPurgeTask;
  25. import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
  26. import com.gmail.nossr50.runnables.player.ClearRegisteredXPGainTask;
  27. import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
  28. import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask;
  29. import com.gmail.nossr50.skills.alchemy.Alchemy;
  30. import com.gmail.nossr50.skills.child.ChildConfig;
  31. import com.gmail.nossr50.skills.repair.repairables.Repairable;
  32. import com.gmail.nossr50.skills.repair.repairables.RepairableManager;
  33. import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager;
  34. import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
  35. import com.gmail.nossr50.skills.salvage.salvageables.SalvageableManager;
  36. import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager;
  37. import com.gmail.nossr50.util.*;
  38. import com.gmail.nossr50.util.blockmeta.ChunkManager;
  39. import com.gmail.nossr50.util.blockmeta.ChunkManagerFactory;
  40. import com.gmail.nossr50.util.commands.CommandRegistrationManager;
  41. import com.gmail.nossr50.util.compat.CompatibilityManager;
  42. import com.gmail.nossr50.util.experience.FormulaManager;
  43. import com.gmail.nossr50.util.platform.PlatformManager;
  44. import com.gmail.nossr50.util.platform.ServerSoftwareType;
  45. import com.gmail.nossr50.util.player.PlayerLevelUtils;
  46. import com.gmail.nossr50.util.player.UserManager;
  47. import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
  48. import com.gmail.nossr50.util.skills.RankUtils;
  49. import com.gmail.nossr50.util.skills.SkillTools;
  50. import com.gmail.nossr50.util.skills.SmeltingTracker;
  51. import com.gmail.nossr50.util.upgrade.UpgradeManager;
  52. import com.gmail.nossr50.worldguard.WorldGuardManager;
  53. import net.kyori.adventure.platform.bukkit.BukkitAudiences;
  54. import net.shatteredlands.shatt.backup.ZipLibrary;
  55. import org.bstats.bukkit.Metrics;
  56. import org.bstats.charts.SimplePie;
  57. import org.bukkit.Bukkit;
  58. import org.bukkit.entity.Player;
  59. import org.bukkit.event.HandlerList;
  60. import org.bukkit.metadata.FixedMetadataValue;
  61. import org.bukkit.plugin.PluginManager;
  62. import org.bukkit.plugin.java.JavaPlugin;
  63. import org.jetbrains.annotations.NotNull;
  64. import org.jetbrains.annotations.Nullable;
  65. import java.io.File;
  66. import java.io.IOException;
  67. import java.io.InputStream;
  68. import java.io.InputStreamReader;
  69. import java.nio.charset.StandardCharsets;
  70. import java.util.ArrayList;
  71. import java.util.List;
  72. public class mcMMO extends JavaPlugin {
  73. /* Managers */
  74. private static PlatformManager platformManager;
  75. private static ChunkManager placeStore;
  76. private static RepairableManager repairableManager;
  77. private static SalvageableManager salvageableManager;
  78. private static ModManager modManager;
  79. private static DatabaseManager databaseManager;
  80. private static FormulaManager formulaManager;
  81. private static UpgradeManager upgradeManager;
  82. private static MaterialMapStore materialMapStore;
  83. private static PlayerLevelUtils playerLevelUtils;
  84. private static SmeltingTracker smeltingTracker;
  85. private static TransientMetadataTools transientMetadataTools;
  86. private static ChatManager chatManager;
  87. private static CommandManager commandManager; //ACF
  88. private static TransientEntityTracker transientEntityTracker;
  89. private @NotNull SkillTools skillTools;
  90. private static boolean serverShutdownExecuted = false;
  91. /* Adventure */
  92. private static BukkitAudiences audiences;
  93. /* Blacklist */
  94. private static WorldBlacklist worldBlacklist;
  95. /* File Paths */
  96. private static String mainDirectory;
  97. private static String localesDirectory;
  98. private static String flatFileDirectory;
  99. private static String usersFile;
  100. private static String modDirectory;
  101. public static mcMMO p;
  102. // Jar Stuff
  103. public static File mcmmo;
  104. /* Plugin Checks */
  105. private static boolean healthBarPluginEnabled;
  106. private static boolean projectKorraEnabled;
  107. // API checks
  108. private static boolean serverAPIOutdated = false;
  109. // Config Validation Check
  110. public boolean noErrorsInConfigFiles = true;
  111. // XP Event Check
  112. private boolean xpEventEnabled;
  113. private static boolean isRetroModeEnabled;
  114. /* Metadata Values */
  115. public static final String REPLANT_META_KEY = "mcMMO: Recently Replanted";
  116. public static final String EXPLOSION_FROM_RUPTURE = "mcMMO: Rupture Explosion";
  117. public static final String RUPTURE_META_KEY = "mcMMO: RuptureTask";
  118. public static final String FISH_HOOK_REF_METAKEY = "mcMMO: Fish Hook Tracker";
  119. public static final String DODGE_TRACKER = "mcMMO: Dodge Tracker";
  120. public static final String CUSTOM_DAMAGE_METAKEY = "mcMMO: Custom Damage";
  121. public static final String travelingBlock = "mcMMO: Traveling Block";
  122. public static final String blockMetadataKey = "mcMMO: Piston Tracking";
  123. public static final String tntMetadataKey = "mcMMO: Tracked TNT";
  124. public static final String customNameKey = "mcMMO: Custom Name";
  125. public static final String customVisibleKey = "mcMMO: Name Visibility";
  126. public static final String droppedItemKey = "mcMMO: Tracked Item";
  127. public static final String infiniteArrowKey = "mcMMO: Infinite Arrow";
  128. public static final String trackedArrow = "mcMMO: Tracked Arrow";
  129. public static final String bowForceKey = "mcMMO: Bow Force";
  130. public static final String arrowDistanceKey = "mcMMO: Arrow Distance";
  131. public static final String BONUS_DROPS_METAKEY = "mcMMO: Double Drops";
  132. public static final String disarmedItemKey = "mcMMO: Disarmed Item";
  133. public static final String playerDataKey = "mcMMO: Player Data";
  134. public static final String databaseCommandKey = "mcMMO: Processing Database Command";
  135. public static FixedMetadataValue metadataValue;
  136. private long purgeTime = 2630000000L;
  137. private GeneralConfig generalConfig;
  138. private AdvancedConfig advancedConfig;
  139. // private RepairConfig repairConfig;
  140. // private SalvageConfig salvageConfig;
  141. // private PersistentDataConfig persistentDataConfig;
  142. // private ChatConfig chatConfig;
  143. // private CoreSkillsConfig coreSkillsConfig;
  144. // private RankConfig rankConfig;
  145. // private TreasureConfig treasureConfig;
  146. // private FishingTreasureConfig fishingTreasureConfig;
  147. // private SoundConfig soundConfig;
  148. public mcMMO() {
  149. p = this;
  150. }
  151. /**
  152. * Things to be run when the plugin is enabled.
  153. */
  154. @Override
  155. public void onEnable() {
  156. try {
  157. generalConfig = new GeneralConfig(getDataFolder()); //Load before skillTools
  158. skillTools = new SkillTools(this); //Load after general config
  159. //Init configs
  160. advancedConfig = new AdvancedConfig(getDataFolder());
  161. //Store this value so other plugins can check it
  162. isRetroModeEnabled = generalConfig.getIsRetroMode();
  163. //Platform Manager
  164. platformManager = new PlatformManager();
  165. //Filter out any debug messages (if debug/verbose logging is not enabled)
  166. getLogger().setFilter(new LogFilter(this));
  167. metadataValue = new FixedMetadataValue(this, true);
  168. PluginManager pluginManager = getServer().getPluginManager();
  169. healthBarPluginEnabled = pluginManager.getPlugin("HealthBar") != null;
  170. projectKorraEnabled = pluginManager.getPlugin("ProjectKorra") != null;
  171. upgradeManager = new UpgradeManager();
  172. setupFilePaths();
  173. modManager = new ModManager();
  174. //Init Material Maps
  175. materialMapStore = new MaterialMapStore();
  176. loadConfigFiles();
  177. if (!noErrorsInConfigFiles) {
  178. return;
  179. }
  180. if (getServer().getName().equals("Cauldron") || getServer().getName().equals("MCPC+")) {
  181. checkModConfigs();
  182. }
  183. if(projectKorraEnabled) {
  184. getLogger().info("ProjectKorra was detected, this can cause some issues with weakness potions and combat skills for mcMMO");
  185. }
  186. if (healthBarPluginEnabled) {
  187. getLogger().info("HealthBar plugin found, mcMMO's healthbars are automatically disabled.");
  188. }
  189. if (pluginManager.getPlugin("NoCheatPlus") != null && pluginManager.getPlugin("CompatNoCheatPlus") == null) {
  190. getLogger().warning("NoCheatPlus plugin found, but CompatNoCheatPlus was not found!");
  191. getLogger().warning("mcMMO will not work properly alongside NoCheatPlus without CompatNoCheatPlus");
  192. }
  193. // One month in milliseconds
  194. this.purgeTime = 2630000000L * generalConfig.getOldUsersCutoff();
  195. databaseManager = DatabaseManagerFactory.getDatabaseManager(mcMMO.getUsersFilePath(), getLogger(), purgeTime, mcMMO.p.getAdvancedConfig().getStartingLevel());
  196. //Check for the newer API and tell them what to do if its missing
  197. checkForOutdatedAPI();
  198. if(serverAPIOutdated)
  199. {
  200. Bukkit
  201. .getScheduler()
  202. .scheduleSyncRepeatingTask(this,
  203. () -> getLogger().severe("You are running an outdated version of "+platformManager.getServerSoftware()+", mcMMO will not work unless you update to a newer version!"),
  204. 20, 20*60*30);
  205. if(platformManager.getServerSoftware() == ServerSoftwareType.CRAFT_BUKKIT)
  206. {
  207. Bukkit.getScheduler()
  208. .scheduleSyncRepeatingTask(this,
  209. () -> getLogger().severe("We have detected you are using incompatible server software, our best guess is that you are using CraftBukkit. mcMMO requires Spigot or Paper, if you are not using CraftBukkit, you will still need to update your custom server software before mcMMO will work."),
  210. 20, 20*60*30);
  211. }
  212. } else {
  213. registerEvents();
  214. registerCoreSkills();
  215. registerCustomRecipes();
  216. PartyManager.loadParties();
  217. formulaManager = new FormulaManager();
  218. for (Player player : getServer().getOnlinePlayers()) {
  219. new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
  220. }
  221. debug("Version " + getDescription().getVersion() + " is enabled!");
  222. scheduleTasks();
  223. CommandRegistrationManager.registerCommands();
  224. placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
  225. if (generalConfig.getPTPCommandWorldPermissions()) {
  226. Permissions.generateWorldTeleportPermissions();
  227. }
  228. //Populate Ranked Skill Maps (DO THIS LAST)
  229. RankUtils.populateRanks();
  230. }
  231. //If anonymous statistics are enabled then use them
  232. Metrics metrics;
  233. if(generalConfig.getIsMetricsEnabled()) {
  234. metrics = new Metrics(this, 3894);
  235. metrics.addCustomChart(new SimplePie("version", () -> getDescription().getVersion()));
  236. if(generalConfig.getIsRetroMode())
  237. metrics.addCustomChart(new SimplePie("leveling_system", () -> "Retro"));
  238. else
  239. metrics.addCustomChart(new SimplePie("leveling_system", () -> "Standard"));
  240. }
  241. }
  242. catch (Throwable t) {
  243. getLogger().severe("There was an error while enabling mcMMO!");
  244. if (!(t instanceof ExceptionInInitializerError)) {
  245. t.printStackTrace();
  246. }
  247. else {
  248. getLogger().info("Please do not replace the mcMMO jar while the server is running.");
  249. }
  250. getServer().getPluginManager().disablePlugin(this);
  251. //Fixes #4438 - Don't initialize things if we are going to disable mcMMO anyway
  252. return;
  253. }
  254. //Init player level values
  255. playerLevelUtils = new PlayerLevelUtils();
  256. //Init the blacklist
  257. worldBlacklist = new WorldBlacklist(this);
  258. //Init smelting tracker
  259. smeltingTracker = new SmeltingTracker();
  260. //Set up Adventure's audiences
  261. audiences = BukkitAudiences.create(this);
  262. transientMetadataTools = new TransientMetadataTools(this);
  263. chatManager = new ChatManager(this);
  264. commandManager = new CommandManager(this);
  265. transientEntityTracker = new TransientEntityTracker();
  266. setServerShutdown(false); //Reset flag, used to make decisions about async saves
  267. }
  268. public static PlayerLevelUtils getPlayerLevelUtils() {
  269. return playerLevelUtils;
  270. }
  271. public static MaterialMapStore getMaterialMapStore() {
  272. return materialMapStore;
  273. }
  274. private void checkForOutdatedAPI() {
  275. try {
  276. Class<?> checkForClass = Class.forName("org.bukkit.event.block.BlockDropItemEvent");
  277. checkForClass.getMethod("getItems");
  278. Class.forName("net.md_5.bungee.api.chat.BaseComponent");
  279. } catch (ClassNotFoundException | NoSuchMethodException e) {
  280. serverAPIOutdated = true;
  281. String software = platformManager.getServerSoftwareStr();
  282. getLogger().severe("You are running an older version of " + software + " that is not compatible with mcMMO, update your server software!");
  283. }
  284. }
  285. @Override
  286. public void onLoad()
  287. {
  288. if(getServer().getPluginManager().getPlugin("WorldGuard") != null) {
  289. WorldGuardManager.getInstance().registerFlags();
  290. }
  291. }
  292. /**
  293. * Things to be run when the plugin is disabled.
  294. */
  295. @Override
  296. public void onDisable() {
  297. setServerShutdown(true);
  298. //TODO: Write code to catch unfinished async save tasks, for now we just hope they finish in time, which they should in most cases
  299. mcMMO.p.getLogger().info("Server shutdown has been executed, saving and cleaning up data...");
  300. try {
  301. UserManager.saveAll(); // Make sure to save player information if the server shuts down
  302. UserManager.clearAll();
  303. Alchemy.finishAllBrews(); // Finish all partially complete AlchemyBrewTasks to prevent vanilla brewing continuation on restart
  304. PartyManager.saveParties(); // Save our parties
  305. //TODO: Needed?
  306. if(generalConfig.getScoreboardsEnabled())
  307. ScoreboardManager.teardownAll();
  308. formulaManager.saveFormula();
  309. placeStore.closeAll();
  310. }
  311. catch (Exception e) {
  312. e.printStackTrace();
  313. }
  314. if (generalConfig.getBackupsEnabled()) {
  315. // Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
  316. try {
  317. ZipLibrary.mcMMOBackup();
  318. }
  319. catch (IOException e) {
  320. getLogger().severe(e.toString());
  321. }
  322. catch(NoClassDefFoundError e) {
  323. getLogger().severe("Backup class not found!");
  324. getLogger().info("Please do not replace the mcMMO jar while the server is running.");
  325. }
  326. catch (Throwable e) {
  327. getLogger().severe(e.toString());
  328. }
  329. }
  330. debug("Canceling all tasks...");
  331. getServer().getScheduler().cancelTasks(this); // This removes our tasks
  332. debug("Unregister all events...");
  333. HandlerList.unregisterAll(this); // Cancel event registrations
  334. databaseManager.onDisable();
  335. debug("Was disabled."); // How informative!
  336. }
  337. public static String getMainDirectory() {
  338. return mainDirectory;
  339. }
  340. public static String getLocalesDirectory() {
  341. return localesDirectory;
  342. }
  343. public static String getFlatFileDirectory() {
  344. return flatFileDirectory;
  345. }
  346. public static String getUsersFilePath() {
  347. return usersFile;
  348. }
  349. public static String getModDirectory() {
  350. return modDirectory;
  351. }
  352. public boolean isXPEventEnabled() {
  353. return xpEventEnabled;
  354. }
  355. public void setXPEventEnabled(boolean enabled) {
  356. this.xpEventEnabled = enabled;
  357. }
  358. public void toggleXpEventEnabled() {
  359. xpEventEnabled = !xpEventEnabled;
  360. }
  361. public void debug(String message) {
  362. getLogger().info("[Debug] " + message);
  363. }
  364. public static FormulaManager getFormulaManager() {
  365. return formulaManager;
  366. }
  367. public static ChunkManager getPlaceStore() {
  368. return placeStore;
  369. }
  370. public static RepairableManager getRepairableManager() {
  371. return repairableManager;
  372. }
  373. public static SalvageableManager getSalvageableManager() {
  374. return salvageableManager;
  375. }
  376. public static DatabaseManager getDatabaseManager() {
  377. return databaseManager;
  378. }
  379. public static ModManager getModManager() {
  380. return modManager;
  381. }
  382. public static UpgradeManager getUpgradeManager() {
  383. return upgradeManager;
  384. }
  385. public static CompatibilityManager getCompatibilityManager() {
  386. return platformManager.getCompatibilityManager();
  387. }
  388. @Deprecated
  389. public static void setDatabaseManager(DatabaseManager databaseManager) {
  390. mcMMO.databaseManager = databaseManager;
  391. }
  392. public static boolean isHealthBarPluginEnabled() {
  393. return healthBarPluginEnabled;
  394. }
  395. /**
  396. * Setup the various storage file paths
  397. */
  398. private void setupFilePaths() {
  399. mcmmo = getFile();
  400. mainDirectory = getDataFolder().getPath() + File.separator;
  401. localesDirectory = mainDirectory + "locales" + File.separator;
  402. flatFileDirectory = mainDirectory + "flatfile" + File.separator;
  403. usersFile = flatFileDirectory + "mcmmo.users";
  404. modDirectory = mainDirectory + "mods" + File.separator;
  405. fixFilePaths();
  406. }
  407. private void fixFilePaths() {
  408. File oldFlatfilePath = new File(mainDirectory + "FlatFileStuff" + File.separator);
  409. File oldModPath = new File(mainDirectory + "ModConfigs" + File.separator);
  410. if (oldFlatfilePath.exists()) {
  411. if (!oldFlatfilePath.renameTo(new File(flatFileDirectory))) {
  412. getLogger().warning("Failed to rename FlatFileStuff to flatfile!");
  413. }
  414. }
  415. if (oldModPath.exists()) {
  416. if (!oldModPath.renameTo(new File(modDirectory))) {
  417. getLogger().warning("Failed to rename ModConfigs to mods!");
  418. }
  419. }
  420. File oldArmorFile = new File(modDirectory + "armor.yml");
  421. File oldBlocksFile = new File(modDirectory + "blocks.yml");
  422. File oldEntitiesFile = new File(modDirectory + "entities.yml");
  423. File oldToolsFile = new File(modDirectory + "tools.yml");
  424. if (oldArmorFile.exists()) {
  425. if (!oldArmorFile.renameTo(new File(modDirectory + "armor.default.yml"))) {
  426. getLogger().warning("Failed to rename armor.yml to armor.default.yml!");
  427. }
  428. }
  429. if (oldBlocksFile.exists()) {
  430. if (!oldBlocksFile.renameTo(new File(modDirectory + "blocks.default.yml"))) {
  431. getLogger().warning("Failed to rename blocks.yml to blocks.default.yml!");
  432. }
  433. }
  434. if (oldEntitiesFile.exists()) {
  435. if (!oldEntitiesFile.renameTo(new File(modDirectory + "entities.default.yml"))) {
  436. getLogger().warning("Failed to rename entities.yml to entities.default.yml!");
  437. }
  438. }
  439. if (oldToolsFile.exists()) {
  440. if (!oldToolsFile.renameTo(new File(modDirectory + "tools.default.yml"))) {
  441. getLogger().warning("Failed to rename tools.yml to tools.default.yml!");
  442. }
  443. }
  444. File currentFlatfilePath = new File(flatFileDirectory);
  445. currentFlatfilePath.mkdirs();
  446. File localesDirectoryPath = new File(localesDirectory);
  447. localesDirectoryPath.mkdirs();
  448. }
  449. private void loadConfigFiles() {
  450. // Force the loading of config files
  451. TreasureConfig.getInstance();
  452. FishingTreasureConfig.getInstance();
  453. HiddenConfig.getInstance();
  454. mcMMO.p.getAdvancedConfig();
  455. PotionConfig.getInstance();
  456. CoreSkillsConfig.getInstance();
  457. SoundConfig.getInstance();
  458. RankConfig.getInstance();
  459. new ChildConfig();
  460. List<Repairable> repairables = new ArrayList<>();
  461. if (generalConfig.getToolModsEnabled()) {
  462. new ToolConfigManager(this);
  463. }
  464. if (generalConfig.getArmorModsEnabled()) {
  465. new ArmorConfigManager(this);
  466. }
  467. if (generalConfig.getBlockModsEnabled()) {
  468. new BlockConfigManager(this);
  469. }
  470. if (generalConfig.getEntityModsEnabled()) {
  471. new EntityConfigManager(this);
  472. }
  473. // Load repair configs, make manager, and register them at this time
  474. repairables.addAll(new RepairConfigManager(this).getLoadedRepairables());
  475. repairables.addAll(modManager.getLoadedRepairables());
  476. repairableManager = new SimpleRepairableManager(repairables.size());
  477. repairableManager.registerRepairables(repairables);
  478. // Load salvage configs, make manager and register them at this time
  479. SalvageConfigManager sManager = new SalvageConfigManager(this);
  480. List<Salvageable> salvageables = new ArrayList<>(sManager.getLoadedSalvageables());
  481. salvageableManager = new SimpleSalvageableManager(salvageables.size());
  482. salvageableManager.registerSalvageables(salvageables);
  483. }
  484. private void registerEvents() {
  485. PluginManager pluginManager = getServer().getPluginManager();
  486. // Register events
  487. pluginManager.registerEvents(new PlayerListener(this), this);
  488. pluginManager.registerEvents(new BlockListener(this), this);
  489. pluginManager.registerEvents(new EntityListener(this), this);
  490. pluginManager.registerEvents(new InventoryListener(this), this);
  491. pluginManager.registerEvents(new SelfListener(this), this);
  492. pluginManager.registerEvents(new WorldListener(this), this);
  493. pluginManager.registerEvents(new ChunkListener(), this);
  494. // pluginManager.registerEvents(new CommandListener(this), this);
  495. }
  496. /**
  497. * Registers core skills
  498. * This enables the skills in the new skill system
  499. */
  500. private void registerCoreSkills() {
  501. /*
  502. * Acrobatics skills
  503. */
  504. InteractionManager.initMaps(); //Init maps
  505. if(CoreSkillsConfig.getInstance().isPrimarySkillEnabled(PrimarySkillType.ACROBATICS))
  506. {
  507. getLogger().info("Enabling Acrobatics Skills");
  508. //TODO: Should do this differently
  509. Roll roll = new Roll();
  510. CoreSkillsConfig.getInstance().isSkillEnabled(roll);
  511. InteractionManager.registerSubSkill(new Roll());
  512. }
  513. }
  514. private void registerCustomRecipes() {
  515. getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
  516. if (generalConfig.getChimaeraEnabled()) {
  517. getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe());
  518. }
  519. }, 40);
  520. }
  521. private void scheduleTasks() {
  522. // Periodic save timer (Saves every 10 minutes by default)
  523. long second = 20;
  524. long minute = second * 60;
  525. long saveIntervalTicks = Math.max(minute, generalConfig.getSaveInterval() * minute);
  526. new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
  527. // Cleanup the backups folder
  528. new CleanBackupsTask().runTaskAsynchronously(mcMMO.p);
  529. // Old & Powerless User remover
  530. long purgeIntervalTicks = generalConfig.getPurgeInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
  531. if (purgeIntervalTicks == 0) {
  532. new UserPurgeTask().runTaskLaterAsynchronously(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
  533. }
  534. else if (purgeIntervalTicks > 0) {
  535. new UserPurgeTask().runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks);
  536. }
  537. // Automatically remove old members from parties
  538. long kickIntervalTicks = generalConfig.getAutoPartyKickInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
  539. if (kickIntervalTicks == 0) {
  540. new PartyAutoKickTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
  541. }
  542. else if (kickIntervalTicks > 0) {
  543. new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
  544. }
  545. // Update power level tag scoreboards
  546. new PowerLevelUpdatingTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
  547. // Clear the registered XP data so players can earn XP again
  548. if (ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) {
  549. new ClearRegisteredXPGainTask().runTaskTimer(this, 60, 60);
  550. }
  551. if(mcMMO.p.getAdvancedConfig().allowPlayerTips())
  552. {
  553. new NotifySquelchReminderTask().runTaskTimer(this, 60, ((20 * 60) * 60));
  554. }
  555. }
  556. private void checkModConfigs() {
  557. if (!generalConfig.getToolModsEnabled()) {
  558. getLogger().warning("Cauldron implementation found, but the custom tool config for mcMMO is disabled!");
  559. getLogger().info("To enable, set Mods.Tool_Mods_Enabled to TRUE in config.yml.");
  560. }
  561. if (!generalConfig.getArmorModsEnabled()) {
  562. getLogger().warning("Cauldron implementation found, but the custom armor config for mcMMO is disabled!");
  563. getLogger().info("To enable, set Mods.Armor_Mods_Enabled to TRUE in config.yml.");
  564. }
  565. if (!generalConfig.getBlockModsEnabled()) {
  566. getLogger().warning("Cauldron implementation found, but the custom block config for mcMMO is disabled!");
  567. getLogger().info("To enable, set Mods.Block_Mods_Enabled to TRUE in config.yml.");
  568. }
  569. if (!generalConfig.getEntityModsEnabled()) {
  570. getLogger().warning("Cauldron implementation found, but the custom entity config for mcMMO is disabled!");
  571. getLogger().info("To enable, set Mods.Entity_Mods_Enabled to TRUE in config.yml.");
  572. }
  573. }
  574. public @Nullable InputStreamReader getResourceAsReader(@NotNull String fileName) {
  575. InputStream in = getResource(fileName);
  576. return in == null ? null : new InputStreamReader(in, StandardCharsets.UTF_8);
  577. }
  578. /**
  579. * Checks if this plugin is using retro mode
  580. * Retro mode is a 0-1000 skill system
  581. * Standard mode is scaled for 1-100
  582. * @return true if retro mode is enabled
  583. */
  584. public static boolean isRetroModeEnabled() {
  585. return isRetroModeEnabled;
  586. }
  587. public static WorldBlacklist getWorldBlacklist() {
  588. return worldBlacklist;
  589. }
  590. public static PlatformManager getPlatformManager() {
  591. return platformManager;
  592. }
  593. public static SmeltingTracker getSmeltingTracker() {
  594. return smeltingTracker;
  595. }
  596. public static BukkitAudiences getAudiences() {
  597. return audiences;
  598. }
  599. public static boolean isProjectKorraEnabled() {
  600. return projectKorraEnabled;
  601. }
  602. public static TransientMetadataTools getTransientMetadataTools() {
  603. return transientMetadataTools;
  604. }
  605. public ChatManager getChatManager() {
  606. return chatManager;
  607. }
  608. public CommandManager getCommandManager() {
  609. return commandManager;
  610. }
  611. public static TransientEntityTracker getTransientEntityTracker() {
  612. return transientEntityTracker;
  613. }
  614. public static synchronized boolean isServerShutdownExecuted() {
  615. return serverShutdownExecuted;
  616. }
  617. private static synchronized void setServerShutdown(boolean bool) {
  618. serverShutdownExecuted = bool;
  619. }
  620. public long getPurgeTime() {
  621. return purgeTime;
  622. }
  623. public @NotNull SkillTools getSkillTools() {
  624. return skillTools;
  625. }
  626. public @NotNull GeneralConfig getGeneralConfig() {
  627. return generalConfig;
  628. }
  629. public @NotNull AdvancedConfig getAdvancedConfig() {
  630. return advancedConfig;
  631. }
  632. }