use of com.palmergames.bukkit.towny.tasks.OnPlayerLogin in project Towny by TownyAdvanced.
the class Towny method onEnable.
@Override
public void onEnable() {
Bukkit.getLogger().info("==================== Towny ========================");
townyUniverse = TownyUniverse.getInstance();
// Setup static classes
BukkitTools.initialize(this);
TownyTimerHandler.initialize(this);
TownyEconomyHandler.initialize(this);
TownyFormatter.initialize();
PlayerCacheUtil.initialize(this);
TownyPerms.initialize(this);
InviteHandler.initialize(this);
try {
// Load the foundation of Towny, containing config, locales, database.
loadFoundation(false);
// Check for plugins that we use or we develop.
// N.B. Includes the hook for TownyChat
checkPlugins();
// Make sure the timers are stopped for a reset, then started.
cycleTimers();
// Reset the player cache.
resetCache();
// Check for plugin updates if the Minecraft version is still supported.
if (isMinecraftVersionStillSupported())
TownyUpdateChecker.checkForUpdates(this);
// Initialize SpawnUtil only after the Translation class has figured out a language.
// N.B. Important that localization loaded correctly for this step.
SpawnUtil.initialize(this);
// Setup bukkit command interfaces
registerSpecialCommands();
registerCommands();
// Add custom metrics charts.
addMetricsCharts();
} catch (TownyInitException tie) {
addError(tie.getError());
getLogger().log(Level.SEVERE, tie.getMessage(), tie);
}
// NOTE: Runs regardless if Towny errors out!
// Important for safe mode.
adventure = BukkitAudiences.create(this);
// If we aren't going to enter safe mode, do the following:
if (!isError() && TownySettings.isTownyUpdating(getVersion())) {
printChangelogToConsole();
// Update config with new version.
TownySettings.setLastRunVersion(getVersion());
// Save database.
townyUniverse.getDataSource().saveAll();
// cleanup() updates SQL schema for any changes.
townyUniverse.getDataSource().cleanup();
}
// Hence, these if checks.
if (!isError(TownyInitException.TownyError.MAIN_CONFIG) && !isError(TownyInitException.TownyError.PERMISSIONS)) {
// Register all child permissions for ranks
TownyPerms.registerPermissionNodes();
}
registerEvents();
Bukkit.getLogger().info("=============================================================");
if (isError()) {
plugin.getLogger().warning("[WARNING] - ***** SAFE MODE ***** " + version);
} else {
plugin.getLogger().info("Version: " + version + " - Plugin Enabled");
}
Bukkit.getLogger().info("=============================================================");
if (!isError()) {
// Re login anyone online. (In case of plugin reloading)
for (Player player : BukkitTools.getOnlinePlayers()) if (player != null) {
// Test and kick any players with invalid names.
if (player.getName().contains(" ")) {
player.kickPlayer("Invalid name!");
return;
}
// Perform login code in it's own thread to update Towny data.
if (BukkitTools.scheduleSyncDelayedTask(new OnPlayerLogin(this, player), 0L) == -1) {
TownyMessaging.sendErrorMsg("Could not schedule OnLogin.");
}
}
}
}
Aggregations