2018-07-31 18:03:32 +02:00
package world.bentobox.bentobox ;
2017-05-20 23:09:53 +02:00
2024-01-05 05:18:41 +01:00
import java.nio.file.Files ;
import java.nio.file.Path ;
2019-06-09 08:50:11 +02:00
import java.util.List ;
2019-05-15 20:16:41 +02:00
import java.util.Optional ;
2019-02-13 11:03:26 +01:00
import org.apache.commons.lang.exception.ExceptionUtils ;
2018-07-23 01:17:34 +02:00
import org.bukkit.Bukkit ;
2023-06-27 07:08:49 +02:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.server.ServerCommandEvent ;
2019-01-26 22:22:07 +01:00
import org.bukkit.generator.ChunkGenerator ;
2019-02-16 10:48:39 +01:00
import org.bukkit.plugin.PluginManager ;
2017-05-20 23:09:53 +02:00
import org.bukkit.plugin.java.JavaPlugin ;
2019-10-14 06:02:25 +02:00
import org.bukkit.scheduler.BukkitTask ;
2019-01-18 15:12:06 +01:00
import org.eclipse.jdt.annotation.NonNull ;
import org.eclipse.jdt.annotation.Nullable ;
2019-05-15 20:16:41 +02:00
2018-08-06 15:19:06 +02:00
import world.bentobox.bentobox.api.configuration.Config ;
2018-07-31 18:03:32 +02:00
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent ;
2019-01-03 18:12:32 +01:00
import world.bentobox.bentobox.api.localization.TextVariables ;
2018-07-31 18:03:32 +02:00
import world.bentobox.bentobox.api.user.Notifier ;
2019-01-03 18:12:32 +01:00
import world.bentobox.bentobox.api.user.User ;
2018-08-05 05:43:38 +02:00
import world.bentobox.bentobox.commands.BentoBoxCommand ;
2019-09-08 16:20:48 +02:00
import world.bentobox.bentobox.database.DatabaseSetup ;
2023-12-28 02:30:20 +01:00
import world.bentobox.bentobox.hooks.ItemsAdderHook ;
2019-07-05 01:54:05 +02:00
import world.bentobox.bentobox.hooks.MultiverseCoreHook ;
2022-10-19 10:27:12 +02:00
import world.bentobox.bentobox.hooks.MyWorldsHook ;
2024-03-10 18:40:26 +01:00
import world.bentobox.bentobox.hooks.MythicMobsHook ;
2023-12-24 13:24:21 +01:00
import world.bentobox.bentobox.hooks.SlimefunHook ;
2019-07-05 01:54:05 +02:00
import world.bentobox.bentobox.hooks.VaultHook ;
2019-05-31 10:56:03 +02:00
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook ;
2019-10-03 22:34:03 +02:00
import world.bentobox.bentobox.listeners.BannedCommands ;
2018-07-31 18:03:32 +02:00
import world.bentobox.bentobox.listeners.BlockEndDragon ;
2018-08-23 05:46:24 +02:00
import world.bentobox.bentobox.listeners.DeathListener ;
2018-07-31 18:03:32 +02:00
import world.bentobox.bentobox.listeners.JoinLeaveListener ;
2019-02-17 13:32:05 +01:00
import world.bentobox.bentobox.listeners.PanelListenerManager ;
2023-09-17 00:55:52 +02:00
import world.bentobox.bentobox.listeners.PrimaryIslandListener ;
2022-12-29 19:01:25 +01:00
import world.bentobox.bentobox.listeners.StandardSpawnProtectionListener ;
2022-09-30 20:33:17 +02:00
import world.bentobox.bentobox.listeners.teleports.EntityTeleportListener ;
2022-09-30 00:26:31 +02:00
import world.bentobox.bentobox.listeners.teleports.PlayerTeleportListener ;
2022-01-22 22:14:57 +01:00
import world.bentobox.bentobox.managers.AddonsManager ;
import world.bentobox.bentobox.managers.BlueprintsManager ;
import world.bentobox.bentobox.managers.CommandsManager ;
import world.bentobox.bentobox.managers.FlagsManager ;
import world.bentobox.bentobox.managers.HooksManager ;
import world.bentobox.bentobox.managers.IslandDeletionManager ;
import world.bentobox.bentobox.managers.IslandWorldManager ;
import world.bentobox.bentobox.managers.IslandsManager ;
import world.bentobox.bentobox.managers.LocalesManager ;
import world.bentobox.bentobox.managers.PlaceholdersManager ;
import world.bentobox.bentobox.managers.PlayersManager ;
import world.bentobox.bentobox.managers.RanksManager ;
import world.bentobox.bentobox.managers.WebManager ;
2018-09-15 12:17:58 +02:00
import world.bentobox.bentobox.util.heads.HeadGetter ;
2018-12-31 14:22:57 +01:00
import world.bentobox.bentobox.versions.ServerCompatibility ;
2017-05-20 23:09:53 +02:00
/ * *
2018-07-29 22:21:46 +02:00
* Main BentoBox class
2018-07-31 18:14:57 +02:00
* @author tastybento , Poslovitch
2017-05-20 23:09:53 +02:00
* /
2023-06-27 07:08:49 +02:00
public class BentoBox extends JavaPlugin implements Listener {
2019-07-04 09:22:59 +02:00
2018-07-29 22:21:46 +02:00
private static BentoBox instance ;
2017-10-23 04:08:34 +02:00
2017-05-20 23:09:53 +02:00
// Databases
private PlayersManager playersManager ;
private IslandsManager islandsManager ;
2017-06-12 01:30:34 +02:00
2017-12-11 21:55:42 +01:00
// Managers
private CommandsManager commandsManager ;
2017-12-22 13:22:33 +01:00
private LocalesManager localesManager ;
2017-12-28 14:49:27 +01:00
private AddonsManager addonsManager ;
2018-01-01 01:41:19 +01:00
private FlagsManager flagsManager ;
2018-05-21 01:09:57 +02:00
private IslandWorldManager islandWorldManager ;
2019-04-14 14:55:24 +02:00
private BlueprintsManager blueprintsManager ;
2018-10-30 14:53:19 +01:00
private HooksManager hooksManager ;
2018-11-02 15:37:24 +01:00
private PlaceholdersManager placeholdersManager ;
2019-01-18 15:12:06 +01:00
private IslandDeletionManager islandDeletionManager ;
2019-02-12 16:24:51 +01:00
private WebManager webManager ;
2018-01-07 00:23:01 +01:00
// Settings
2018-03-01 14:25:09 +01:00
private Settings settings ;
2018-01-07 00:23:01 +01:00
2018-03-01 14:25:09 +01:00
// Notifier
private Notifier notifier ;
2017-10-22 04:53:07 +02:00
2018-04-01 03:34:49 +02:00
private HeadGetter headGetter ;
2018-07-13 06:25:07 +02:00
private boolean isLoaded ;
2019-01-18 15:12:06 +01:00
// Metrics
@Nullable
private BStats metrics ;
2019-01-13 02:12:30 +01:00
2019-07-19 06:55:23 +02:00
private Config < Settings > configObject ;
2019-10-14 06:02:25 +02:00
private BukkitTask blueprintLoadingTask ;
2020-04-21 03:37:42 +02:00
private boolean shutdown ;
2017-05-20 23:09:53 +02:00
@Override
public void onEnable ( ) {
2019-05-08 00:29:02 +02:00
if ( ! ServerCompatibility . getInstance ( ) . checkCompatibility ( ) . isCanLaunch ( ) ) {
2018-12-31 14:22:57 +01:00
// The server's most likely incompatible.
2019-03-26 16:14:09 +01:00
// Show a warning
2019-04-17 22:58:17 +02:00
logWarning ( " ************ Disclaimer ************** " ) ;
logWarning ( " BentoBox may not be compatible with this server! " ) ;
2019-06-09 08:50:11 +02:00
logWarning ( " BentoBox is tested only on the following Spigot versions: " ) ;
List < String > versions = ServerCompatibility . ServerVersion . getVersions ( ServerCompatibility . Compatibility . COMPATIBLE , ServerCompatibility . Compatibility . SUPPORTED )
2021-09-20 03:29:19 +02:00
. stream ( ) . map ( ServerCompatibility . ServerVersion : : toString ) . toList ( ) ;
2019-06-09 08:50:11 +02:00
logWarning ( String . join ( " , " , versions ) ) ;
2019-04-17 22:58:17 +02:00
logWarning ( " ************************************** " ) ;
2018-12-31 14:22:57 +01:00
}
2018-07-13 06:25:07 +02:00
// Not loaded
2018-07-18 03:32:28 +02:00
isLoaded = false ;
2018-07-03 11:20:52 +02:00
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
2019-05-12 11:48:56 +02:00
final long loadStart = System . currentTimeMillis ( ) ;
2018-07-03 11:20:52 +02:00
2018-01-07 23:43:37 +01:00
// Save the default config from config.yml
saveDefaultConfig ( ) ;
2018-02-07 06:31:19 +01:00
setInstance ( this ) ;
2018-07-06 06:10:47 +02:00
// Load Flags
2018-08-16 13:49:44 +02:00
flagsManager = new FlagsManager ( this ) ;
2018-07-06 06:10:47 +02:00
2019-02-06 16:46:17 +01:00
if ( ! loadSettings ( ) ) {
// We're aborting the load.
2018-10-30 23:16:13 +01:00
return ;
}
2019-02-06 16:46:17 +01:00
// Saving the config now.
2019-05-04 07:29:03 +02:00
saveConfig ( ) ;
2019-02-06 16:46:17 +01:00
2018-04-01 00:33:48 +02:00
// Start Database managers
2018-01-07 00:23:01 +01:00
playersManager = new PlayersManager ( this ) ;
2018-04-01 00:33:48 +02:00
// Check if this plugin is now disabled (due to bad database handling)
if ( ! this . isEnabled ( ) ) {
return ;
}
2018-01-07 00:23:01 +01:00
islandsManager = new IslandsManager ( this ) ;
2018-04-01 03:34:49 +02:00
// Start head getter
headGetter = new HeadGetter ( this ) ;
2018-07-03 03:51:18 +02:00
2018-03-01 14:25:09 +01:00
// Load Notifier
notifier = new Notifier ( ) ;
2018-05-26 22:08:35 +02:00
// Set up command manager
2018-01-07 00:23:01 +01:00
commandsManager = new CommandsManager ( ) ;
2018-08-05 05:43:38 +02:00
// Load BentoBox commands
new BentoBoxCommand ( ) ;
// Start Island Worlds Manager
2018-11-10 11:04:48 +01:00
islandWorldManager = new IslandWorldManager ( this ) ;
2019-05-15 20:16:41 +02:00
// Load blueprints manager
2019-04-14 14:55:24 +02:00
blueprintsManager = new BlueprintsManager ( this ) ;
2018-08-02 17:11:46 +02:00
// Locales manager must be loaded before addons
2018-11-10 11:04:48 +01:00
localesManager = new LocalesManager ( this ) ;
2018-08-02 17:11:46 +02:00
2019-01-26 15:29:18 +01:00
// Load hooks
hooksManager = new HooksManager ( this ) ;
2018-08-02 17:11:46 +02:00
// Load addons. Addons may load worlds, so they must go before islands are loaded.
2018-11-10 11:04:48 +01:00
addonsManager = new AddonsManager ( this ) ;
2018-08-02 17:11:46 +02:00
addonsManager . loadAddons ( ) ;
2019-05-04 07:29:03 +02:00
2019-05-12 11:48:56 +02:00
final long loadTime = System . currentTimeMillis ( ) - loadStart ;
2023-11-10 19:54:30 +01:00
Bukkit . getScheduler ( ) . runTask ( instance , ( ) - > {
try {
completeSetup ( loadTime ) ;
} catch ( Exception e ) {
fireCriticalError ( e . getMessage ( ) , " " ) ;
e . printStackTrace ( ) ;
}
} ) ;
2020-12-19 19:28:46 +01:00
}
2019-05-04 22:56:55 +02:00
2020-12-19 19:28:46 +01:00
private void completeSetup ( long loadTime ) {
final long enableStart = System . currentTimeMillis ( ) ;
2022-01-08 04:08:15 +01:00
hooksManager . registerHook ( new VaultHook ( ) ) ;
2024-03-10 18:40:26 +01:00
// MythicMobs
hooksManager . registerHook ( new MythicMobsHook ( ) ) ;
2020-12-19 19:28:46 +01:00
hooksManager . registerHook ( new PlaceholderAPIHook ( ) ) ;
// Setup the Placeholders manager
placeholdersManager = new PlaceholdersManager ( this ) ;
2019-05-04 22:56:55 +02:00
2020-12-19 19:28:46 +01:00
// Enable addons
addonsManager . enableAddons ( ) ;
2019-05-04 22:56:55 +02:00
2020-12-19 19:28:46 +01:00
// Register default gamemode placeholders
addonsManager . getGameModeAddons ( ) . forEach ( placeholdersManager : : registerDefaultPlaceholders ) ;
2018-08-02 17:11:46 +02:00
2020-12-19 19:28:46 +01:00
// Register Listeners
registerListeners ( ) ;
// Load islands from database - need to wait until all the worlds are loaded
try {
islandsManager . load ( ) ;
} catch ( Exception e ) {
fireCriticalError ( e . getMessage ( ) , " Could not load islands! " ) ;
return ;
}
2018-08-02 17:11:46 +02:00
2020-12-19 19:28:46 +01:00
// Save islands & players data every X minutes
Bukkit . getScheduler ( ) . runTaskTimer ( instance , ( ) - > {
if ( ! playersManager . isSaveTaskRunning ( ) ) {
playersManager . saveAll ( true ) ;
} else {
getLogger ( ) . warning ( " Tried to start a player data save task while the previous auto save was still running! " ) ;
2019-09-08 16:20:48 +02:00
}
2020-12-19 19:28:46 +01:00
if ( ! islandsManager . isSaveTaskRunning ( ) ) {
islandsManager . saveAll ( true ) ;
} else {
getLogger ( ) . warning ( " Tried to start a island data save task while the previous auto save was still running! " ) ;
}
} , getSettings ( ) . getDatabaseBackupPeriod ( ) * 20 * 60L , getSettings ( ) . getDatabaseBackupPeriod ( ) * 20 * 60L ) ;
// Make sure all flag listeners are registered.
flagsManager . registerListeners ( ) ;
// Load metrics
metrics = new BStats ( this ) ;
metrics . registerMetrics ( ) ;
// Register Multiverse hook - MV loads AFTER BentoBox
// Make sure all worlds are already registered to Multiverse.
hooksManager . registerHook ( new MultiverseCoreHook ( ) ) ;
2022-10-19 10:27:12 +02:00
hooksManager . registerHook ( new MyWorldsHook ( ) ) ;
2023-06-27 07:08:49 +02:00
islandWorldManager . registerWorldsToMultiverse ( true ) ;
2020-12-19 19:28:46 +01:00
2023-12-24 13:24:21 +01:00
// Register Slimefun
hooksManager . registerHook ( new SlimefunHook ( ) ) ;
2023-12-28 02:30:20 +01:00
// Register ItemsAdder
hooksManager . registerHook ( new ItemsAdderHook ( this ) ) ;
2022-07-06 19:39:15 +02:00
// TODO: re-enable after implementation
//hooksManager.registerHook(new DynmapHook());
2021-03-19 23:18:44 +01:00
// TODO: re-enable after rework
//hooksManager.registerHook(new LangUtilsHook());
2020-12-19 19:28:46 +01:00
webManager = new WebManager ( this ) ;
final long enableTime = System . currentTimeMillis ( ) - enableStart ;
// Show banner
User . getInstance ( Bukkit . getConsoleSender ( ) ) . sendMessage ( " successfully-loaded " ,
TextVariables . VERSION , instance . getDescription ( ) . getVersion ( ) ,
" [time] " , String . valueOf ( loadTime + enableTime ) ) ;
// Poll for blueprints loading to be finished - async so could be a completely variable time
blueprintLoadingTask = Bukkit . getScheduler ( ) . runTaskTimer ( instance , ( ) - > {
if ( getBlueprintsManager ( ) . isBlueprintsLoaded ( ) ) {
blueprintLoadingTask . cancel ( ) ;
// Tell all addons that everything is loaded
isLoaded = true ;
this . addonsManager . allLoaded ( ) ;
2023-08-16 02:25:26 +02:00
// Run ready commands
settings . getReadyCommands ( ) . forEach ( cmd - > Bukkit . getServer ( ) . dispatchCommand ( getServer ( ) . getConsoleSender ( ) , cmd ) ) ;
2020-12-19 19:28:46 +01:00
// Fire plugin ready event - this should go last after everything else
Bukkit . getPluginManager ( ) . callEvent ( new BentoBoxReadyEvent ( ) ) ;
instance . log ( " All blueprints loaded. " ) ;
}
} , 0L , 1L ) ;
if ( getSettings ( ) . getDatabaseType ( ) . equals ( DatabaseSetup . DatabaseType . YAML ) ) {
logWarning ( " *** You're still using YAML database ! *** " ) ;
logWarning ( " This database type is being deprecated from BentoBox as some official addons encountered difficulties supporting it correctly. " ) ;
logWarning ( " You should switch ASAP to an alternative database type. Please refer to the comments in BentoBox's config.yml. " ) ;
logWarning ( " There is NO guarantee YAML database will remain properly supported in the following updates, and its usage should as such be considered a non-viable situation. " ) ;
logWarning ( " *** *** *** *** *** *** *** *** *** *** *** " ) ;
}
}
private void fireCriticalError ( String message , String error ) {
2021-08-30 03:17:38 +02:00
logError ( " *****************CRITICAL ERROR!****************** " ) ;
2020-12-19 19:28:46 +01:00
logError ( message ) ;
logError ( error + " Disabling BentoBox... " ) ;
logError ( " ************************************************* " ) ;
// Stop all addons
if ( addonsManager ! = null ) {
addonsManager . disableAddons ( ) ;
}
// Do not save players or islands, just shutdown
shutdown = true ;
instance . setEnabled ( false ) ;
2017-05-20 23:09:53 +02:00
}
2017-05-24 17:10:49 +02:00
2018-02-11 17:18:50 +01:00
/ * *
2019-02-14 11:08:54 +01:00
* Registers listeners .
2018-02-11 17:18:50 +01:00
* /
2017-12-11 20:15:48 +01:00
private void registerListeners ( ) {
2019-02-16 10:48:39 +01:00
PluginManager manager = getServer ( ) . getPluginManager ( ) ;
// Player join events
manager . registerEvents ( new JoinLeaveListener ( this ) , this ) ;
2018-02-11 17:18:50 +01:00
// Panel listener manager
2019-02-16 10:48:39 +01:00
manager . registerEvents ( new PanelListenerManager ( ) , this ) ;
2019-02-16 11:09:34 +01:00
// Standard Nether/End spawns protection
manager . registerEvents ( new StandardSpawnProtectionListener ( this ) , this ) ;
2022-09-30 00:26:31 +02:00
// Player portals
manager . registerEvents ( new PlayerTeleportListener ( this ) , this ) ;
2022-09-30 20:33:17 +02:00
// Entity portals
manager . registerEvents ( new EntityTeleportListener ( this ) , this ) ;
2018-05-25 21:19:46 +02:00
// End dragon blocking
2019-02-16 10:48:39 +01:00
manager . registerEvents ( new BlockEndDragon ( this ) , this ) ;
2018-07-12 06:55:00 +02:00
// Banned visitor commands
2019-10-03 22:34:03 +02:00
manager . registerEvents ( new BannedCommands ( this ) , this ) ;
2018-08-23 05:46:24 +02:00
// Death counter
2019-02-16 10:48:39 +01:00
manager . registerEvents ( new DeathListener ( this ) , this ) ;
2023-06-27 07:08:49 +02:00
// MV unregister
manager . registerEvents ( this , this ) ;
2019-02-16 10:48:39 +01:00
// Island Delete Manager
2019-01-13 10:09:35 +01:00
islandDeletionManager = new IslandDeletionManager ( this ) ;
2019-02-16 10:48:39 +01:00
manager . registerEvents ( islandDeletionManager , this ) ;
2023-09-17 00:55:52 +02:00
// Primary Island Listener
manager . registerEvents ( new PrimaryIslandListener ( this ) , this ) ;
2017-07-07 07:00:21 +02:00
}
2017-05-20 23:09:53 +02:00
@Override
2017-12-28 15:29:32 +01:00
public void onDisable ( ) {
2020-11-01 22:58:29 +01:00
// Stop all async database tasks
shutdown = true ;
2018-04-01 00:33:48 +02:00
if ( addonsManager ! = null ) {
addonsManager . disableAddons ( ) ;
}
2017-05-20 23:09:53 +02:00
// Save data
2018-04-01 00:33:48 +02:00
if ( playersManager ! = null ) {
playersManager . shutdown ( ) ;
}
if ( islandsManager ! = null ) {
islandsManager . shutdown ( ) ;
}
2023-06-27 07:08:49 +02:00
}
@EventHandler
public void onServerStop ( ServerCommandEvent e ) {
2023-10-15 22:57:48 +02:00
/ * This is no longer needed as with https : //github.com/Multiverse/Multiverse-Core/releases/tag/4.3.12 (or maybe earlier) the issue
* is fixed where the generator was not remembered across reboots .
* /
/ *
2023-06-27 07:08:49 +02:00
if ( islandWorldManager ! = null & & ( e . getCommand ( ) . equalsIgnoreCase ( " stop " ) | | e . getCommand ( ) . equalsIgnoreCase ( " restart " ) ) ) {
// Unregister any MV worlds if () {
2023-10-15 22:57:48 +02:00
//islandWorldManager.registerWorldsToMultiverse(false);
} * /
2017-05-20 23:09:53 +02:00
}
2017-05-24 17:10:49 +02:00
2017-05-20 23:09:53 +02:00
/ * *
2021-01-24 23:14:31 +01:00
* Returns the player manager
* @return the player manager
* @see # getPlayersManager ( )
2017-05-20 23:09:53 +02:00
* /
2021-01-24 23:14:31 +01:00
public PlayersManager getPlayers ( ) {
2017-05-20 23:09:53 +02:00
return playersManager ;
}
2017-05-24 17:10:49 +02:00
2017-05-20 23:09:53 +02:00
/ * *
2021-01-24 23:14:31 +01:00
* Returns the player manager
* @return the player manager
* @see # getPlayers ( )
2021-03-21 22:08:21 +01:00
* @since 1 . 16 . 0
2017-05-20 23:09:53 +02:00
* /
2021-01-24 23:14:31 +01:00
public PlayersManager getPlayersManager ( ) {
2021-09-20 03:29:19 +02:00
return getPlayers ( ) ;
2021-01-24 23:14:31 +01:00
}
/ * *
* Returns the island manager
* @return the island manager
* @see # getIslandsManager ( )
* /
public IslandsManager getIslands ( ) {
return islandsManager ;
}
/ * *
* Returns the island manager
* @return the island manager
* @see # getIslands ( )
2021-03-21 22:08:21 +01:00
* @since 1 . 16 . 0
2021-01-24 23:14:31 +01:00
* /
public IslandsManager getIslandsManager ( ) {
2021-09-20 03:29:19 +02:00
return getIslands ( ) ;
2017-05-20 23:09:53 +02:00
}
2017-06-11 01:08:21 +02:00
2018-07-29 22:21:46 +02:00
private static void setInstance ( BentoBox plugin ) {
BentoBox . instance = plugin ;
2018-02-07 06:31:19 +01:00
}
2018-02-09 05:08:46 +01:00
2018-07-29 22:21:46 +02:00
public static BentoBox getInstance ( ) {
2018-03-11 20:08:19 +01:00
return instance ;
2017-06-11 01:08:21 +02:00
}
2018-01-01 01:41:19 +01:00
/ * *
* @return the Commands manager
* /
2017-12-11 21:55:42 +01:00
public CommandsManager getCommandsManager ( ) {
return commandsManager ;
}
2018-01-01 01:41:19 +01:00
/ * *
* @return the Locales manager
* /
2017-12-22 13:22:33 +01:00
public LocalesManager getLocalesManager ( ) {
return localesManager ;
}
2018-01-01 01:41:19 +01:00
/ * *
* @return the Addons manager
* /
public AddonsManager getAddonsManager ( ) {
return addonsManager ;
}
/ * *
* @return the Flags manager
* /
public FlagsManager getFlagsManager ( ) {
return flagsManager ;
}
2018-01-07 00:23:01 +01:00
/ * *
2018-03-01 14:25:09 +01:00
* @return the ranksManager
2024-01-08 12:50:26 +01:00
* @deprecated Just use { @code RanksManager . getInstance ( ) }
2018-01-07 00:23:01 +01:00
* /
2024-01-08 12:50:26 +01:00
@Deprecated ( since = " 2.0.0 " )
2018-03-01 14:25:09 +01:00
public RanksManager getRanksManager ( ) {
2024-01-08 12:50:26 +01:00
return RanksManager . getInstance ( ) ;
2018-01-07 00:23:01 +01:00
}
/ * *
* @return the Island World Manager
* /
2018-05-25 21:19:46 +02:00
public IslandWorldManager getIWM ( ) {
2018-01-07 00:23:01 +01:00
return islandWorldManager ;
}
2018-01-28 21:47:17 +01:00
/ * *
2018-03-01 14:25:09 +01:00
* @return the settings
2018-01-28 21:47:17 +01:00
* /
2018-03-01 14:25:09 +01:00
public Settings getSettings ( ) {
return settings ;
2018-01-28 21:47:17 +01:00
}
2019-02-06 16:46:17 +01:00
/ * *
* Loads the settings from the config file .
* If it fails , it can shut the plugin down .
* @return { @code true } if it loaded successfully .
* @since 1 . 3 . 0
* /
public boolean loadSettings ( ) {
log ( " Loading Settings from config.yml... " ) ;
// Load settings from config.yml. This will check if there are any issues with it too.
2019-07-19 06:55:23 +02:00
if ( configObject = = null ) configObject = new Config < > ( this , Settings . class ) ;
settings = configObject . loadConfigObject ( ) ;
2019-02-06 16:46:17 +01:00
if ( settings = = null ) {
// Settings did not load correctly. Disable plugin.
logError ( " Settings did not load correctly - disabling plugin - please check config.yml " ) ;
getPluginLoader ( ) . disablePlugin ( this ) ;
return false ;
}
2024-01-04 09:09:44 +01:00
2024-01-08 12:50:26 +01:00
log ( " Saving default panels... " ) ;
2024-01-05 05:18:41 +01:00
if ( ! Files . exists ( Path . of ( this . getDataFolder ( ) . getPath ( ) , " panels " , " island_creation_panel.yml " ) ) ) {
log ( " Saving default island_creation_panel... " ) ;
this . saveResource ( " panels/island_creation_panel.yml " , false ) ;
}
if ( ! Files . exists ( Path . of ( this . getDataFolder ( ) . getPath ( ) , " panels " , " language_panel.yml " ) ) ) {
log ( " Saving default language_panel... " ) ;
this . saveResource ( " panels/language_panel.yml " , false ) ;
}
2019-02-06 16:46:17 +01:00
return true ;
}
2019-05-04 07:29:03 +02:00
@Override
public void saveConfig ( ) {
2019-07-19 06:55:23 +02:00
if ( settings ! = null ) configObject . saveConfigObject ( settings ) ;
2019-05-04 07:29:03 +02:00
}
2018-03-01 14:25:09 +01:00
/ * *
* @return the notifier
* /
public Notifier getNotifier ( ) {
return notifier ;
}
2018-04-01 03:34:49 +02:00
/ * *
* @return the headGetter
* /
public HeadGetter getHeadGetter ( ) {
return headGetter ;
}
2018-07-03 03:51:18 +02:00
2018-04-28 06:02:15 +02:00
public void log ( String string ) {
getLogger ( ) . info ( ( ) - > string ) ;
}
2018-07-03 03:51:18 +02:00
2018-07-14 20:14:51 +02:00
public void logDebug ( Object object ) {
getLogger ( ) . info ( ( ) - > " DEBUG: " + object ) ;
}
2018-04-28 06:02:15 +02:00
public void logError ( String error ) {
getLogger ( ) . severe ( ( ) - > error ) ;
}
2018-07-03 03:51:18 +02:00
2019-02-13 11:03:26 +01:00
/ * *
* Logs the stacktrace of a Throwable that was thrown by an error .
* It should be used preferably instead of { @link Throwable # printStackTrace ( ) } as it does not risk exposing sensitive information .
* @param throwable the Throwable that was thrown by an error .
* @since 1 . 3 . 0
* /
public void logStacktrace ( @NonNull Throwable throwable ) {
logError ( ExceptionUtils . getStackTrace ( throwable ) ) ;
}
2018-04-28 06:02:15 +02:00
public void logWarning ( String warning ) {
2019-01-22 14:18:06 +01:00
getLogger ( ) . warning ( ( ) - > warning ) ;
2018-04-28 06:02:15 +02:00
}
2018-05-19 08:08:18 +02:00
2019-04-14 14:55:24 +02:00
/ * *
* Returns the instance of the { @link BlueprintsManager } .
* @return the { @link BlueprintsManager } .
* @since 1 . 5 . 0
* /
public BlueprintsManager getBlueprintsManager ( ) {
return blueprintsManager ;
}
2018-07-13 06:25:07 +02:00
/ * *
2018-11-10 10:03:15 +01:00
* Returns whether BentoBox is fully loaded or not .
* This basically means that all managers are instantiated and can therefore be safely accessed .
* @return whether BentoBox is fully loaded or not .
2018-07-13 06:25:07 +02:00
* /
public boolean isLoaded ( ) {
return isLoaded ;
}
2018-10-30 14:53:19 +01:00
/ * *
* @return the HooksManager
* /
public HooksManager getHooks ( ) {
return hooksManager ;
}
2018-10-30 15:35:27 +01:00
/ * *
* Convenience method to get the VaultHook .
* @return the Vault hook
* /
public Optional < VaultHook > getVault ( ) {
return Optional . ofNullable ( ( VaultHook ) hooksManager . getHook ( " Vault " ) . orElse ( null ) ) ;
}
2018-11-02 15:44:25 +01:00
/ * *
* @return the PlaceholdersManager .
* /
public PlaceholdersManager getPlaceholdersManager ( ) {
return placeholdersManager ;
}
2019-01-13 02:12:30 +01:00
/ * *
* @return the islandDeletionManager
2019-01-18 15:12:06 +01:00
* @since 1 . 1
2019-01-13 02:12:30 +01:00
* /
2019-01-13 10:09:35 +01:00
public IslandDeletionManager getIslandDeletionManager ( ) {
2019-01-13 02:12:30 +01:00
return islandDeletionManager ;
}
2019-01-18 15:12:06 +01:00
/ * *
* @return an optional of the Bstats instance
* @since 1 . 1
* /
@NonNull
public Optional < BStats > getMetrics ( ) {
return Optional . ofNullable ( metrics ) ;
}
2019-01-26 22:22:07 +01:00
2019-04-21 10:28:48 +02:00
/ * *
* @return the { @link WebManager } .
* @since 1 . 5 . 0
* /
public WebManager getWebManager ( ) {
return webManager ;
}
2019-02-06 16:46:17 +01:00
// Overriding default JavaPlugin methods
2019-01-26 22:22:07 +01:00
/ * ( non - Javadoc )
* @see org . bukkit . plugin . java . JavaPlugin # getDefaultWorldGenerator ( java . lang . String , java . lang . String )
* /
@Override
2019-04-14 14:55:24 +02:00
public ChunkGenerator getDefaultWorldGenerator ( @NonNull String worldName , String id ) {
2019-01-26 22:22:07 +01:00
return addonsManager . getDefaultWorldGenerator ( worldName , id ) ;
}
2019-02-06 16:46:17 +01:00
/ * ( non - Javadoc )
* @see org . bukkit . plugin . java . JavaPlugin # reloadConfig ( )
* /
@Override
public void reloadConfig ( ) {
loadSettings ( ) ;
}
2020-04-21 03:37:42 +02:00
/ * *
* Check if plug has shutdown . Used to close databases that are running async .
* @return true if plugin has shutdown
* @since 1 . 13 . 0
* /
public boolean isShutdown ( ) {
return shutdown ;
}
2017-05-20 23:09:53 +02:00
}