2013-03-01 06:52:01 +01:00
package com.gmail.nossr50 ;
2019-01-13 04:08:54 +01:00
import com.gmail.nossr50.config.* ;
2013-05-03 21:26:20 +02:00
import com.gmail.nossr50.config.experience.ExperienceConfig ;
2014-03-03 18:27:45 +01:00
import com.gmail.nossr50.config.mods.ArmorConfigManager ;
import com.gmail.nossr50.config.mods.BlockConfigManager ;
import com.gmail.nossr50.config.mods.EntityConfigManager ;
import com.gmail.nossr50.config.mods.ToolConfigManager ;
2014-02-03 20:52:28 +01:00
import com.gmail.nossr50.config.skills.alchemy.PotionConfig ;
import com.gmail.nossr50.config.skills.repair.RepairConfigManager ;
2013-12-14 14:27:50 +01:00
import com.gmail.nossr50.config.skills.salvage.SalvageConfigManager ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.config.treasure.TreasureConfig ;
import com.gmail.nossr50.database.DatabaseManager ;
2013-06-04 18:14:43 +02:00
import com.gmail.nossr50.database.DatabaseManagerFactory ;
2019-01-13 08:54:53 +01:00
import com.gmail.nossr50.datatypes.skills.PrimarySkillType ;
2019-01-09 04:52:52 +01:00
import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll ;
2018-07-24 04:13:57 +02:00
import com.gmail.nossr50.listeners.* ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.party.PartyManager ;
2014-03-28 23:07:48 +01:00
import com.gmail.nossr50.runnables.CheckDateTask ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.runnables.SaveTimerTask ;
2013-11-01 16:07:56 +01:00
import com.gmail.nossr50.runnables.backups.CleanBackupsTask ;
2019-04-05 02:27:17 +02:00
import com.gmail.nossr50.runnables.commands.NotifySquelchReminderTask ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.runnables.database.UserPurgeTask ;
import com.gmail.nossr50.runnables.party.PartyAutoKickTask ;
2013-05-03 21:26:20 +02:00
import com.gmail.nossr50.runnables.player.ClearRegisteredXPGainTask ;
2014-08-01 19:35:36 +02:00
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask ;
2013-09-12 04:42:27 +02:00
import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.runnables.skills.BleedTimerTask ;
2013-11-16 00:21:00 +01:00
import com.gmail.nossr50.skills.alchemy.Alchemy ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.skills.child.ChildConfig ;
2013-10-07 16:23:04 +02:00
import com.gmail.nossr50.skills.repair.repairables.Repairable ;
import com.gmail.nossr50.skills.repair.repairables.RepairableManager ;
2013-10-09 06:10:32 +02:00
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager ;
2013-12-14 14:27:50 +01:00
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable ;
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableManager ;
import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager ;
2018-07-24 04:13:57 +02:00
import com.gmail.nossr50.util.* ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager ;
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory ;
import com.gmail.nossr50.util.commands.CommandRegistrationManager ;
2020-04-25 05:21:21 +02:00
import com.gmail.nossr50.util.compat.CompatibilityManager ;
2013-09-10 15:28:07 +02:00
import com.gmail.nossr50.util.experience.FormulaManager ;
2020-04-25 05:21:21 +02:00
import com.gmail.nossr50.util.platform.PlatformManager ;
import com.gmail.nossr50.util.platform.ServerSoftwareType ;
2019-05-04 00:04:40 +02:00
import com.gmail.nossr50.util.player.PlayerLevelUtils ;
2013-03-01 06:52:01 +01:00
import com.gmail.nossr50.util.player.UserManager ;
2013-09-12 04:42:27 +02:00
import com.gmail.nossr50.util.scoreboards.ScoreboardManager ;
2019-01-20 03:51:18 +01:00
import com.gmail.nossr50.util.skills.RankUtils ;
2020-07-24 05:59:34 +02:00
import com.gmail.nossr50.util.skills.SmeltingTracker ;
2014-07-23 02:01:26 +02:00
import com.gmail.nossr50.util.upgrade.UpgradeManager ;
2019-01-23 22:55:35 +01:00
import com.gmail.nossr50.worldguard.WorldGuardManager ;
2017-05-14 17:36:31 +02:00
import com.google.common.base.Charsets ;
2020-09-24 16:08:24 +02:00
import net.kyori.adventure.platform.bukkit.BukkitAudiences ;
2013-09-10 15:28:07 +02:00
import net.shatteredlands.shatt.backup.ZipLibrary ;
2019-01-16 20:05:43 +01:00
import org.bstats.bukkit.Metrics ;
2019-04-17 20:51:13 +02:00
import org.bukkit.Bukkit ;
2018-07-24 04:13:57 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.event.HandlerList ;
import org.bukkit.metadata.FixedMetadataValue ;
import org.bukkit.plugin.PluginManager ;
import org.bukkit.plugin.java.JavaPlugin ;
import java.io.File ;
import java.io.IOException ;
import java.io.InputStream ;
import java.io.InputStreamReader ;
import java.util.ArrayList ;
import java.util.List ;
2013-09-10 15:28:07 +02:00
2013-03-01 06:52:01 +01:00
public class mcMMO extends JavaPlugin {
2013-04-25 15:27:48 +02:00
/* Managers */
2020-04-25 05:21:21 +02:00
private static PlatformManager platformManager ;
2013-12-14 14:27:50 +01:00
private static ChunkManager placeStore ;
private static RepairableManager repairableManager ;
private static SalvageableManager salvageableManager ;
private static ModManager modManager ;
private static DatabaseManager databaseManager ;
private static FormulaManager formulaManager ;
private static HolidayManager holidayManager ;
2014-07-23 02:01:26 +02:00
private static UpgradeManager upgradeManager ;
2019-04-23 17:20:00 +02:00
private static MaterialMapStore materialMapStore ;
2019-05-04 00:04:40 +02:00
private static PlayerLevelUtils playerLevelUtils ;
2020-07-24 05:59:34 +02:00
private static SmeltingTracker smeltingTracker ;
2013-03-01 06:52:01 +01:00
2020-09-24 16:08:24 +02:00
/* Adventure */
private static BukkitAudiences audiences ;
2019-01-22 18:16:02 +01:00
/* Blacklist */
private static WorldBlacklist worldBlacklist ;
2013-04-25 15:27:48 +02:00
/* File Paths */
2013-03-01 06:52:01 +01:00
private static String mainDirectory ;
2019-04-30 08:31:33 +02:00
private static String localesDirectory ;
2013-03-01 06:52:01 +01:00
private static String flatFileDirectory ;
private static String usersFile ;
private static String modDirectory ;
2013-04-25 15:27:48 +02:00
public static mcMMO p ;
// Jar Stuff
public static File mcmmo ;
2013-04-30 21:07:29 +02:00
/* Plugin Checks */
2013-09-29 23:57:13 +02:00
private static boolean healthBarPluginEnabled ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
// API checks
private static boolean serverAPIOutdated = false ;
2013-08-10 19:33:21 +02:00
// Config Validation Check
public boolean noErrorsInConfigFiles = true ;
2013-03-01 06:52:01 +01:00
// XP Event Check
2013-04-25 15:27:48 +02:00
private boolean xpEventEnabled ;
2013-03-01 06:52:01 +01:00
2019-01-20 09:46:33 +01:00
private static boolean isRetroModeEnabled ;
2018-12-29 14:24:55 +01:00
2013-04-30 21:07:29 +02:00
/* Metadata Values */
2020-02-20 00:58:53 +01:00
public final static String REPLANT_META_KEY = " mcMMO: Recently Replanted " ;
2019-03-18 10:40:19 +01:00
public static final String FISH_HOOK_REF_METAKEY = " mcMMO: Fish Hook Tracker " ;
2019-09-18 03:59:44 +02:00
public static final String DODGE_TRACKER = " mcMMO: Dodge Tracker " ;
2019-03-24 06:57:44 +01:00
public static final String CUSTOM_DAMAGE_METAKEY = " mcMMO: Custom Damage " ;
2019-07-02 08:50:30 +02:00
public static final String COTW_TEMPORARY_SUMMON = " mcMMO: COTW Entity " ;
2013-04-02 14:41:51 +02:00
public final static String entityMetadataKey = " mcMMO: Spawned Entity " ;
public final static String blockMetadataKey = " mcMMO: Piston Tracking " ;
public final static String tntMetadataKey = " mcMMO: Tracked TNT " ;
2017-02-22 06:00:27 +01:00
public final static String funfettiMetadataKey = " mcMMO: Funfetti " ;
2013-04-05 04:11:11 +02:00
public final static String customNameKey = " mcMMO: Custom Name " ;
public final static String customVisibleKey = " mcMMO: Name Visibility " ;
2013-04-17 15:19:50 +02:00
public final static String droppedItemKey = " mcMMO: Tracked Item " ;
2013-05-15 04:43:13 +02:00
public final static String infiniteArrowKey = " mcMMO: Infinite Arrow " ;
2019-06-18 22:06:26 +02:00
public final static String trackedArrow = " mcMMO: Tracked Arrow " ;
2013-05-15 07:19:14 +02:00
public final static String bowForceKey = " mcMMO: Bow Force " ;
2013-05-15 14:35:12 +02:00
public final static String arrowDistanceKey = " mcMMO: Arrow Distance " ;
2019-05-15 01:14:01 +02:00
public final static String BONUS_DROPS_METAKEY = " mcMMO: Double Drops " ;
2019-01-09 04:52:52 +01:00
//public final static String customDamageKey = "mcMMO: Custom Damage";
2013-12-02 00:43:17 +01:00
public final static String disarmedItemKey = " mcMMO: Disarmed Item " ;
2014-02-07 18:50:04 +01:00
public final static String playerDataKey = " mcMMO: Player Data " ;
2014-04-06 14:41:40 +02:00
public final static String greenThumbDataKey = " mcMMO: Green Thumb " ;
2014-08-20 00:11:56 +02:00
public final static String databaseCommandKey = " mcMMO: Processing Database Command " ;
2015-01-10 12:31:13 +01:00
public final static String bredMetadataKey = " mcMMO: Bred Animal " ;
2013-04-02 14:41:51 +02:00
public static FixedMetadataValue metadataValue ;
2013-03-01 06:52:01 +01:00
2020-05-01 23:43:48 +02:00
public mcMMO ( ) {
p = this ;
}
2013-03-01 06:52:01 +01:00
/ * *
* Things to be run when the plugin is enabled .
* /
@Override
public void onEnable ( ) {
try {
2020-04-25 05:21:21 +02:00
//Platform Manager
platformManager = new PlatformManager ( ) ;
2013-03-01 06:52:01 +01:00
getLogger ( ) . setFilter ( new LogFilter ( this ) ) ;
metadataValue = new FixedMetadataValue ( this , true ) ;
2014-02-27 16:56:21 +01:00
PluginManager pluginManager = getServer ( ) . getPluginManager ( ) ;
healthBarPluginEnabled = pluginManager . getPlugin ( " HealthBar " ) ! = null ;
2013-10-31 13:15:19 +01:00
2014-07-23 02:01:26 +02:00
upgradeManager = new UpgradeManager ( ) ;
2013-03-01 06:52:01 +01:00
setupFilePaths ( ) ;
2013-10-04 15:41:01 +02:00
2014-02-03 20:48:43 +01:00
modManager = new ModManager ( ) ;
2020-03-04 01:37:13 +01:00
//Init Material Maps
materialMapStore = new MaterialMapStore ( ) ;
2013-03-01 06:52:01 +01:00
loadConfigFiles ( ) ;
2013-08-10 19:33:21 +02:00
if ( ! noErrorsInConfigFiles ) {
return ;
}
2019-01-15 07:48:37 +01:00
//Store this value so other plugins can check it
isRetroModeEnabled = Config . getInstance ( ) . getIsRetroMode ( ) ;
2014-06-14 20:34:35 +02:00
if ( getServer ( ) . getName ( ) . equals ( " Cauldron " ) | | getServer ( ) . getName ( ) . equals ( " MCPC+ " ) ) {
2013-10-04 15:41:01 +02:00
checkModConfigs ( ) ;
}
2013-09-22 14:39:20 +02:00
2013-09-29 23:57:13 +02:00
if ( healthBarPluginEnabled ) {
2013-09-22 14:39:20 +02:00
getLogger ( ) . info ( " HealthBar plugin found, mcMMO's healthbars are automatically disabled. " ) ;
}
2013-04-29 06:29:38 +02:00
2014-02-27 16:56:21 +01:00
if ( pluginManager . getPlugin ( " NoCheatPlus " ) ! = null & & pluginManager . getPlugin ( " CompatNoCheatPlus " ) = = null ) {
2013-10-19 00:27:07 +02:00
getLogger ( ) . warning ( " NoCheatPlus plugin found, but CompatNoCheatPlus was not found! " ) ;
getLogger ( ) . warning ( " mcMMO will not work properly alongside NoCheatPlus without CompatNoCheatPlus " ) ;
}
2013-06-04 18:14:43 +02:00
databaseManager = DatabaseManagerFactory . getDatabaseManager ( ) ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
//Check for the newer API and tell them what to do if its missing
checkForOutdatedAPI ( ) ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
if ( serverAPIOutdated )
{
Bukkit
. getScheduler ( )
. scheduleSyncRepeatingTask ( this ,
2020-04-25 05:21:21 +02:00
( ) - > getLogger ( ) . severe ( " You are running an outdated version of " + platformManager . getServerSoftware ( ) + " , mcMMO will not work unless you update to a newer version! " ) ,
2019-04-17 20:51:13 +02:00
20 , 20 * 60 * 30 ) ;
2013-04-02 19:47:52 +02:00
2020-04-25 05:21:21 +02:00
if ( platformManager . getServerSoftware ( ) = = ServerSoftwareType . CRAFT_BUKKIT )
2019-04-17 20:51:13 +02:00
{
Bukkit . getScheduler ( )
. scheduleSyncRepeatingTask ( this ,
( ) - > 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. " ) ,
20 , 20 * 60 * 30 ) ;
}
} else {
registerEvents ( ) ;
registerCoreSkills ( ) ;
registerCustomRecipes ( ) ;
2013-05-20 15:38:30 +02:00
2019-04-17 20:51:13 +02:00
PartyManager . loadParties ( ) ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
formulaManager = new FormulaManager ( ) ;
holidayManager = new HolidayManager ( ) ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
for ( Player player : getServer ( ) . getOnlinePlayers ( ) ) {
new PlayerProfileLoadingTask ( player ) . runTaskLaterAsynchronously ( mcMMO . p , 1 ) ; // 1 Tick delay to ensure the player is marked as online before we begin loading
}
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
debug ( " Version " + getDescription ( ) . getVersion ( ) + " is enabled! " ) ;
2013-03-01 06:52:01 +01:00
2019-04-17 20:51:13 +02:00
scheduleTasks ( ) ;
CommandRegistrationManager . registerCommands ( ) ;
2019-01-16 20:05:43 +01:00
2019-04-17 20:51:13 +02:00
placeStore = ChunkManagerFactory . getChunkManager ( ) ; // Get our ChunkletManager
2019-01-20 03:51:18 +01:00
2019-04-17 20:51:13 +02:00
if ( Config . getInstance ( ) . getPTPCommandWorldPermissions ( ) ) {
Permissions . generateWorldTeleportPermissions ( ) ;
}
//Populate Ranked Skill Maps (DO THIS LAST)
RankUtils . populateRanks ( ) ;
}
2019-01-16 20:05:43 +01:00
2019-04-17 20:51:13 +02:00
//If anonymous statistics are enabled then use them
2019-01-16 20:05:43 +01:00
Metrics metrics ;
if ( Config . getInstance ( ) . getIsMetricsEnabled ( ) ) {
metrics = new Metrics ( this ) ;
metrics . addCustomChart ( new Metrics . SimplePie ( " version " , ( ) - > getDescription ( ) . getVersion ( ) ) ) ;
if ( Config . getInstance ( ) . getIsRetroMode ( ) )
metrics . addCustomChart ( new Metrics . SimplePie ( " scaling " , ( ) - > " Standard " ) ) ;
else
metrics . addCustomChart ( new Metrics . SimplePie ( " scaling " , ( ) - > " Retro " ) ) ;
}
2013-03-01 06:52:01 +01:00
}
catch ( Throwable t ) {
getLogger ( ) . severe ( " There was an error while enabling mcMMO! " ) ;
if ( ! ( t instanceof ExceptionInInitializerError ) ) {
t . printStackTrace ( ) ;
}
else {
getLogger ( ) . info ( " Please do not replace the mcMMO jar while the server is running. " ) ;
}
2013-03-10 20:07:07 +01:00
getServer ( ) . getPluginManager ( ) . disablePlugin ( this ) ;
2013-03-01 06:52:01 +01:00
}
2019-01-22 18:16:02 +01:00
2019-05-04 00:04:40 +02:00
//Init player level values
playerLevelUtils = new PlayerLevelUtils ( ) ;
2019-01-22 18:16:02 +01:00
//Init the blacklist
worldBlacklist = new WorldBlacklist ( this ) ;
2020-07-24 05:59:34 +02:00
//Init smelting tracker
smeltingTracker = new SmeltingTracker ( ) ;
2020-09-24 16:08:24 +02:00
audiences = BukkitAudiences . create ( this ) ;
2013-03-01 06:52:01 +01:00
}
2019-05-04 00:04:40 +02:00
public static PlayerLevelUtils getPlayerLevelUtils ( ) {
return playerLevelUtils ;
}
2019-04-23 17:20:00 +02:00
public static MaterialMapStore getMaterialMapStore ( ) {
return materialMapStore ;
}
2019-04-17 20:51:13 +02:00
private void checkForOutdatedAPI ( ) {
try {
Class < ? > checkForClass = Class . forName ( " org.bukkit.event.block.BlockDropItemEvent " ) ;
2020-07-13 21:31:30 +02:00
checkForClass . getMethod ( " getItems " ) ;
Class . forName ( " net.md_5.bungee.api.chat.BaseComponent " ) ;
2019-04-17 20:51:13 +02:00
} catch ( ClassNotFoundException | NoSuchMethodException e ) {
serverAPIOutdated = true ;
2020-04-25 05:21:21 +02:00
String software = platformManager . getServerSoftwareStr ( ) ;
2019-04-17 20:51:13 +02:00
getLogger ( ) . severe ( " You are running an older version of " + software + " that is not compatible with mcMMO, update your server software! " ) ;
}
}
2019-01-23 02:59:45 +01:00
@Override
public void onLoad ( )
{
2019-06-25 02:32:05 +02:00
if ( getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldGuard " ) ! = null ) {
2019-06-25 08:25:15 +02:00
WorldGuardManager . getInstance ( ) . registerFlags ( ) ;
2019-06-25 02:32:05 +02:00
}
2019-01-23 02:59:45 +01:00
}
2013-03-01 06:52:01 +01:00
/ * *
* Things to be run when the plugin is disabled .
* /
@Override
public void onDisable ( ) {
try {
2013-04-02 14:29:38 +02:00
UserManager . saveAll ( ) ; // Make sure to save player information if the server shuts down
2014-06-04 05:52:22 +02:00
UserManager . clearAll ( ) ;
2019-06-06 06:11:44 +02:00
Alchemy . finishAllBrews ( ) ; // Finish all partially complete AlchemyBrewTasks to prevent vanilla brewing continuation on restart
2013-04-02 14:29:38 +02:00
PartyManager . saveParties ( ) ; // Save our parties
2019-01-18 23:20:31 +01:00
//TODO: Needed?
if ( Config . getInstance ( ) . getScoreboardsEnabled ( ) )
ScoreboardManager . teardownAll ( ) ;
2013-05-20 15:38:30 +02:00
formulaManager . saveFormula ( ) ;
2014-01-12 12:08:47 +01:00
holidayManager . saveAnniversaryFiles ( ) ;
2013-04-02 14:29:38 +02:00
placeStore . saveAll ( ) ; // Save our metadata
placeStore . cleanUp ( ) ; // Cleanup empty metadata stores
2013-03-01 06:52:01 +01:00
}
2019-06-25 08:25:15 +02:00
2019-06-06 08:50:39 +02:00
catch ( Exception e ) { e . printStackTrace ( ) ; }
2013-03-01 06:52:01 +01:00
2014-01-18 16:58:49 +01:00
debug ( " Canceling all tasks... " ) ;
2013-03-01 06:52:01 +01:00
getServer ( ) . getScheduler ( ) . cancelTasks ( this ) ; // This removes our tasks
2014-01-18 16:58:49 +01:00
debug ( " Unregister all events... " ) ;
2013-03-01 06:52:01 +01:00
HandlerList . unregisterAll ( this ) ; // Cancel event registrations
if ( Config . getInstance ( ) . getBackupsEnabled ( ) ) {
// Remove other tasks BEFORE starting the Backup, or we just cancel it straight away.
try {
2013-11-01 16:28:42 +01:00
ZipLibrary . mcMMOBackup ( ) ;
2013-03-01 06:52:01 +01:00
}
catch ( IOException e ) {
getLogger ( ) . severe ( e . toString ( ) ) ;
}
catch ( Throwable e ) {
if ( e instanceof NoClassDefFoundError ) {
getLogger ( ) . severe ( " Backup class not found! " ) ;
getLogger ( ) . info ( " Please do not replace the mcMMO jar while the server is running. " ) ;
}
else {
getLogger ( ) . severe ( e . toString ( ) ) ;
}
}
}
2014-08-01 19:35:36 +02:00
databaseManager . onDisable ( ) ;
2013-04-13 21:53:00 +02:00
debug ( " Was disabled. " ) ; // How informative!
2013-03-01 06:52:01 +01:00
}
public static String getMainDirectory ( ) {
return mainDirectory ;
}
2019-04-30 08:31:33 +02:00
public static String getLocalesDirectory ( ) {
return localesDirectory ;
}
2013-03-01 06:52:01 +01:00
public static String getFlatFileDirectory ( ) {
return flatFileDirectory ;
}
public static String getUsersFilePath ( ) {
return usersFile ;
}
public static String getModDirectory ( ) {
return modDirectory ;
}
public boolean isXPEventEnabled ( ) {
return xpEventEnabled ;
}
public void setXPEventEnabled ( boolean enabled ) {
this . xpEventEnabled = enabled ;
}
public void toggleXpEventEnabled ( ) {
xpEventEnabled = ! xpEventEnabled ;
}
public void debug ( String message ) {
getLogger ( ) . info ( " [Debug] " + message ) ;
}
2013-05-20 15:38:30 +02:00
public static FormulaManager getFormulaManager ( ) {
return formulaManager ;
}
2014-01-12 12:08:47 +01:00
public static HolidayManager getHolidayManager ( ) {
return holidayManager ;
}
2013-04-25 15:16:42 +02:00
public static ChunkManager getPlaceStore ( ) {
return placeStore ;
}
2013-06-04 18:14:43 +02:00
public static RepairableManager getRepairableManager ( ) {
return repairableManager ;
}
2013-12-14 14:27:50 +01:00
public static SalvageableManager getSalvageableManager ( ) {
return salvageableManager ;
}
2013-04-25 15:16:42 +02:00
public static DatabaseManager getDatabaseManager ( ) {
return databaseManager ;
}
2014-02-03 20:48:43 +01:00
public static ModManager getModManager ( ) {
return modManager ;
}
2014-07-23 02:01:26 +02:00
public static UpgradeManager getUpgradeManager ( ) {
return upgradeManager ;
}
2020-04-25 05:21:21 +02:00
public static CompatibilityManager getCompatibilityManager ( ) {
return platformManager . getCompatibilityManager ( ) ;
}
2013-06-04 18:14:43 +02:00
@Deprecated
public static void setDatabaseManager ( DatabaseManager databaseManager ) {
mcMMO . databaseManager = databaseManager ;
2013-04-25 15:16:42 +02:00
}
2013-09-29 23:57:13 +02:00
public static boolean isHealthBarPluginEnabled ( ) {
return healthBarPluginEnabled ;
2013-09-22 14:39:20 +02:00
}
2013-03-01 06:52:01 +01:00
/ * *
* Setup the various storage file paths
* /
private void setupFilePaths ( ) {
mcmmo = getFile ( ) ;
mainDirectory = getDataFolder ( ) . getPath ( ) + File . separator ;
2019-04-30 08:31:33 +02:00
localesDirectory = mainDirectory + " locales " + File . separator ;
2013-10-07 16:33:14 +02:00
flatFileDirectory = mainDirectory + " flatfile " + File . separator ;
2013-03-01 06:52:01 +01:00
usersFile = flatFileDirectory + " mcmmo.users " ;
2013-10-07 16:32:40 +02:00
modDirectory = mainDirectory + " mods " + File . separator ;
2013-10-07 16:43:22 +02:00
fixFilePaths ( ) ;
}
private void fixFilePaths ( ) {
File oldFlatfilePath = new File ( mainDirectory + " FlatFileStuff " + File . separator ) ;
File oldModPath = new File ( mainDirectory + " ModConfigs " + File . separator ) ;
if ( oldFlatfilePath . exists ( ) ) {
2014-01-19 11:49:30 +01:00
if ( ! oldFlatfilePath . renameTo ( new File ( flatFileDirectory ) ) ) {
2014-02-03 20:48:43 +01:00
getLogger ( ) . warning ( " Failed to rename FlatFileStuff to flatfile! " ) ;
2014-01-19 11:49:30 +01:00
}
2013-10-07 16:43:22 +02:00
}
if ( oldModPath . exists ( ) ) {
2014-01-19 11:49:30 +01:00
if ( ! oldModPath . renameTo ( new File ( modDirectory ) ) ) {
2014-02-03 20:48:43 +01:00
getLogger ( ) . warning ( " Failed to rename ModConfigs to mods! " ) ;
}
}
File oldArmorFile = new File ( modDirectory + " armor.yml " ) ;
File oldBlocksFile = new File ( modDirectory + " blocks.yml " ) ;
File oldEntitiesFile = new File ( modDirectory + " entities.yml " ) ;
File oldToolsFile = new File ( modDirectory + " tools.yml " ) ;
if ( oldArmorFile . exists ( ) ) {
if ( ! oldArmorFile . renameTo ( new File ( modDirectory + " armor.default.yml " ) ) ) {
getLogger ( ) . warning ( " Failed to rename armor.yml to armor.default.yml! " ) ;
}
}
if ( oldBlocksFile . exists ( ) ) {
if ( ! oldBlocksFile . renameTo ( new File ( modDirectory + " blocks.default.yml " ) ) ) {
getLogger ( ) . warning ( " Failed to rename blocks.yml to blocks.default.yml! " ) ;
}
}
if ( oldEntitiesFile . exists ( ) ) {
if ( ! oldEntitiesFile . renameTo ( new File ( modDirectory + " entities.default.yml " ) ) ) {
getLogger ( ) . warning ( " Failed to rename entities.yml to entities.default.yml! " ) ;
}
}
if ( oldToolsFile . exists ( ) ) {
if ( ! oldToolsFile . renameTo ( new File ( modDirectory + " tools.default.yml " ) ) ) {
getLogger ( ) . warning ( " Failed to rename tools.yml to tools.default.yml! " ) ;
2014-01-19 11:49:30 +01:00
}
2013-10-07 16:43:22 +02:00
}
2014-02-09 11:28:59 +01:00
File currentFlatfilePath = new File ( flatFileDirectory ) ;
currentFlatfilePath . mkdirs ( ) ;
2019-04-30 08:31:33 +02:00
File localesDirectoryPath = new File ( localesDirectory ) ;
localesDirectoryPath . mkdirs ( ) ;
2013-03-01 06:52:01 +01:00
}
private void loadConfigFiles ( ) {
// Force the loading of config files
TreasureConfig . getInstance ( ) ;
HiddenConfig . getInstance ( ) ;
AdvancedConfig . getInstance ( ) ;
2013-11-16 00:21:00 +01:00
PotionConfig . getInstance ( ) ;
2019-01-09 04:52:52 +01:00
CoreSkillsConfig . getInstance ( ) ;
2019-01-13 04:08:54 +01:00
SoundConfig . getInstance ( ) ;
2019-01-13 08:54:53 +01:00
RankConfig . getInstance ( ) ;
2019-01-09 04:52:52 +01:00
2013-03-01 06:52:01 +01:00
new ChildConfig ( ) ;
2020-07-13 21:31:30 +02:00
List < Repairable > repairables = new ArrayList < > ( ) ;
2013-03-01 06:52:01 +01:00
2013-06-07 19:55:49 +02:00
if ( Config . getInstance ( ) . getToolModsEnabled ( ) ) {
2014-02-03 20:48:43 +01:00
new ToolConfigManager ( this ) ;
2013-03-01 06:52:01 +01:00
}
2013-06-07 19:55:49 +02:00
if ( Config . getInstance ( ) . getArmorModsEnabled ( ) ) {
2014-02-03 20:48:43 +01:00
new ArmorConfigManager ( this ) ;
2013-03-01 06:52:01 +01:00
}
2013-06-07 19:55:49 +02:00
if ( Config . getInstance ( ) . getBlockModsEnabled ( ) ) {
2014-02-03 20:48:43 +01:00
new BlockConfigManager ( this ) ;
2013-03-01 06:52:01 +01:00
}
2013-06-07 19:55:49 +02:00
if ( Config . getInstance ( ) . getEntityModsEnabled ( ) ) {
2014-02-03 20:48:43 +01:00
new EntityConfigManager ( this ) ;
2013-03-01 06:52:01 +01:00
}
// Load repair configs, make manager, and register them at this time
2014-02-03 20:48:43 +01:00
repairables . addAll ( new RepairConfigManager ( this ) . getLoadedRepairables ( ) ) ;
repairables . addAll ( modManager . getLoadedRepairables ( ) ) ;
2013-10-09 06:10:32 +02:00
repairableManager = new SimpleRepairableManager ( repairables . size ( ) ) ;
2013-03-06 15:37:09 +01:00
repairableManager . registerRepairables ( repairables ) ;
2013-12-14 14:27:50 +01:00
// Load salvage configs, make manager and register them at this time
SalvageConfigManager sManager = new SalvageConfigManager ( this ) ;
2020-07-13 21:31:30 +02:00
List < Salvageable > salvageables = new ArrayList < > ( sManager . getLoadedSalvageables ( ) ) ;
2013-12-14 14:27:50 +01:00
salvageableManager = new SimpleSalvageableManager ( salvageables . size ( ) ) ;
salvageableManager . registerSalvageables ( salvageables ) ;
2013-03-01 06:52:01 +01:00
}
private void registerEvents ( ) {
PluginManager pluginManager = getServer ( ) . getPluginManager ( ) ;
// Register events
2013-05-15 21:39:40 +02:00
pluginManager . registerEvents ( new PlayerListener ( this ) , this ) ;
pluginManager . registerEvents ( new BlockListener ( this ) , this ) ;
pluginManager . registerEvents ( new EntityListener ( this ) , this ) ;
pluginManager . registerEvents ( new InventoryListener ( this ) , this ) ;
2019-01-18 21:42:05 +01:00
pluginManager . registerEvents ( new SelfListener ( this ) , this ) ;
2013-05-15 21:39:40 +02:00
pluginManager . registerEvents ( new WorldListener ( this ) , this ) ;
2013-03-01 06:52:01 +01:00
}
2019-01-09 04:52:52 +01:00
/ * *
* Registers core skills
* This enables the skills in the new skill system
* /
private void registerCoreSkills ( ) {
/ *
* Acrobatics skills
* /
2019-06-09 14:53:39 +02:00
InteractionManager . initMaps ( ) ; //Init maps
2019-01-13 08:54:53 +01:00
if ( CoreSkillsConfig . getInstance ( ) . isPrimarySkillEnabled ( PrimarySkillType . ACROBATICS ) )
2019-01-09 04:52:52 +01:00
{
2020-04-29 10:06:53 +02:00
getLogger ( ) . info ( " Enabling Acrobatics Skills " ) ;
2019-01-09 04:52:52 +01:00
//TODO: Should do this differently
Roll roll = new Roll ( ) ;
CoreSkillsConfig . getInstance ( ) . isSkillEnabled ( roll ) ;
InteractionManager . registerSubSkill ( new Roll ( ) ) ;
}
}
2013-03-08 21:46:05 +01:00
private void registerCustomRecipes ( ) {
2018-08-31 05:57:29 +02:00
getServer ( ) . getScheduler ( ) . scheduleSyncDelayedTask ( this , ( ) - > {
if ( Config . getInstance ( ) . getChimaeraEnabled ( ) ) {
getServer ( ) . addRecipe ( ChimaeraWing . getChimaeraWingRecipe ( ) ) ;
}
} , 40 ) ;
2013-03-08 21:46:05 +01:00
}
2013-03-01 06:52:01 +01:00
private void scheduleTasks ( ) {
// Periodic save timer (Saves every 10 minutes by default)
long saveIntervalTicks = Config . getInstance ( ) . getSaveInterval ( ) * 1200 ;
2013-03-20 08:11:16 +01:00
new SaveTimerTask ( ) . runTaskTimer ( this , saveIntervalTicks , saveIntervalTicks ) ;
2013-11-01 17:38:54 +01:00
// Cleanup the backups folder
new CleanBackupsTask ( ) . runTaskAsynchronously ( mcMMO . p ) ;
2019-01-24 00:22:16 +01:00
// Bleed timer (Runs every 0.5 seconds)
2020-07-13 21:31:30 +02:00
new BleedTimerTask ( ) . runTaskTimer ( this , Misc . TICK_CONVERSION_FACTOR , ( Misc . TICK_CONVERSION_FACTOR / 2 ) ) ;
2013-03-01 06:52:01 +01:00
// Old & Powerless User remover
2014-01-19 11:49:30 +01:00
long purgeIntervalTicks = Config . getInstance ( ) . getPurgeInterval ( ) * 60L * 60L * Misc . TICK_CONVERSION_FACTOR ;
2013-03-01 06:52:01 +01:00
2013-04-30 21:19:41 +02:00
if ( purgeIntervalTicks = = 0 ) {
2014-08-04 03:12:41 +02:00
new UserPurgeTask ( ) . runTaskLaterAsynchronously ( this , 2 * Misc . TICK_CONVERSION_FACTOR ) ; // Start 2 seconds after startup.
2013-03-01 06:52:01 +01:00
}
2013-04-30 21:19:41 +02:00
else if ( purgeIntervalTicks > 0 ) {
2014-08-04 03:12:41 +02:00
new UserPurgeTask ( ) . runTaskTimerAsynchronously ( this , purgeIntervalTicks , purgeIntervalTicks ) ;
2013-03-01 06:52:01 +01:00
}
// Automatically remove old members from parties
2014-01-19 11:49:30 +01:00
long kickIntervalTicks = Config . getInstance ( ) . getAutoPartyKickInterval ( ) * 60L * 60L * Misc . TICK_CONVERSION_FACTOR ;
2013-03-01 06:52:01 +01:00
2013-04-30 21:19:41 +02:00
if ( kickIntervalTicks = = 0 ) {
2013-06-13 01:26:09 +02:00
new PartyAutoKickTask ( ) . runTaskLater ( this , 2 * Misc . TICK_CONVERSION_FACTOR ) ; // Start 2 seconds after startup.
2013-03-01 06:52:01 +01:00
}
2013-04-30 21:19:41 +02:00
else if ( kickIntervalTicks > 0 ) {
new PartyAutoKickTask ( ) . runTaskTimer ( this , kickIntervalTicks , kickIntervalTicks ) ;
2013-03-01 06:52:01 +01:00
}
2013-09-12 04:42:27 +02:00
// Update power level tag scoreboards
new PowerLevelUpdatingTask ( ) . runTaskTimer ( this , 2 * Misc . TICK_CONVERSION_FACTOR , 2 * Misc . TICK_CONVERSION_FACTOR ) ;
2014-03-28 23:07:48 +01:00
if ( getHolidayManager ( ) . nearingAprilFirst ( ) ) {
2020-07-13 21:31:30 +02:00
new CheckDateTask ( ) . runTaskTimer ( this , 10L * Misc . TICK_CONVERSION_FACTOR , 60L * 60L * Misc . TICK_CONVERSION_FACTOR ) ;
2014-03-28 23:07:48 +01:00
}
2013-05-03 21:26:20 +02:00
// Clear the registered XP data so players can earn XP again
2014-08-13 17:25:19 +02:00
if ( ExperienceConfig . getInstance ( ) . getDiminishedReturnsEnabled ( ) ) {
2013-10-27 06:44:03 +01:00
new ClearRegisteredXPGainTask ( ) . runTaskTimer ( this , 60 , 60 ) ;
2013-05-03 21:26:20 +02:00
}
2019-04-05 02:27:17 +02:00
if ( AdvancedConfig . getInstance ( ) . allowPlayerTips ( ) )
{
new NotifySquelchReminderTask ( ) . runTaskTimer ( this , 60 , ( ( 20 * 60 ) * 60 ) ) ;
}
2013-03-01 06:52:01 +01:00
}
2013-10-04 15:41:01 +02:00
private void checkModConfigs ( ) {
if ( ! Config . getInstance ( ) . getToolModsEnabled ( ) ) {
2014-06-14 20:34:35 +02:00
getLogger ( ) . warning ( " Cauldron implementation found, but the custom tool config for mcMMO is disabled! " ) ;
2013-10-04 15:41:01 +02:00
getLogger ( ) . info ( " To enable, set Mods.Tool_Mods_Enabled to TRUE in config.yml. " ) ;
}
if ( ! Config . getInstance ( ) . getArmorModsEnabled ( ) ) {
2014-06-14 20:34:35 +02:00
getLogger ( ) . warning ( " Cauldron implementation found, but the custom armor config for mcMMO is disabled! " ) ;
2013-10-04 15:41:01 +02:00
getLogger ( ) . info ( " To enable, set Mods.Armor_Mods_Enabled to TRUE in config.yml. " ) ;
}
if ( ! Config . getInstance ( ) . getBlockModsEnabled ( ) ) {
2014-06-14 20:34:35 +02:00
getLogger ( ) . warning ( " Cauldron implementation found, but the custom block config for mcMMO is disabled! " ) ;
2013-10-04 15:41:01 +02:00
getLogger ( ) . info ( " To enable, set Mods.Block_Mods_Enabled to TRUE in config.yml. " ) ;
}
if ( ! Config . getInstance ( ) . getEntityModsEnabled ( ) ) {
2014-06-14 20:34:35 +02:00
getLogger ( ) . warning ( " Cauldron implementation found, but the custom entity config for mcMMO is disabled! " ) ;
2013-10-04 15:41:01 +02:00
getLogger ( ) . info ( " To enable, set Mods.Entity_Mods_Enabled to TRUE in config.yml. " ) ;
}
}
2017-05-14 17:36:31 +02:00
public InputStreamReader getResourceAsReader ( String fileName ) {
InputStream in = getResource ( fileName ) ;
return in = = null ? null : new InputStreamReader ( in , Charsets . UTF_8 ) ;
}
2019-01-15 07:48:37 +01:00
/ * *
* Checks if this plugin is using retro mode
* Retro mode is a 0 - 1000 skill system
* Standard mode is scaled for 1 - 100
* @return true if retro mode is enabled
* /
2019-01-20 09:46:33 +01:00
public static boolean isRetroModeEnabled ( ) {
2019-01-15 07:48:37 +01:00
return isRetroModeEnabled ;
}
2019-01-22 18:16:02 +01:00
public static WorldBlacklist getWorldBlacklist ( ) {
return worldBlacklist ;
}
2020-04-25 05:21:21 +02:00
public static PlatformManager getPlatformManager ( ) {
return platformManager ;
}
2020-07-24 05:59:34 +02:00
public static SmeltingTracker getSmeltingTracker ( ) {
return smeltingTracker ;
}
2020-09-24 16:08:24 +02:00
public static BukkitAudiences getAudiences ( ) {
return audiences ;
}
2013-03-01 06:52:01 +01:00
}