diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 8c870977..52a9ac6e 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -69,7 +69,7 @@ import net.coreprotect.CoreProtectAPI; public class Jobs { public static Jobs instance = new Jobs(); // public static JobsPlugin plugin = new JobsPlugin(); - private static PlayerManager pManager = new PlayerManager(); + private static PlayerManager pManager = null; private static JobsCommands cManager = null; private static Language lManager = null; private static LanguageManager lmManager = null; @@ -180,6 +180,10 @@ public class Jobs { return pManager; } + public static void setPlayerManager(JobsPlugin jobsPlugin) { + pManager = new PlayerManager (jobsPlugin); + } + public static void setRestrictedBlockManager(JobsPlugin plugin) { RBManager = new RestrictedBlockManager(plugin); } diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index c6887d3d..ba7ab173 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -94,6 +94,8 @@ public class JobsPlugin extends JavaPlugin { Jobs.setPermissionHandler(new PermissionHandler(this)); + Jobs.setPlayerManager(this); + Jobs.setScboard(this); Jobs.setLanguage(this); Jobs.setGUIManager(this); diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 26db1c79..066eb9d3 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -58,6 +58,11 @@ public class PlayerManager { private PointsData PointsDatabase = new PointsData(); private HashMap PlayerMap = new HashMap(); + JobsPlugin plugin; + + public PlayerManager(JobsPlugin plugin) { + this.plugin = plugin; + } public PointsData getPointsData() { return PointsDatabase; @@ -108,6 +113,7 @@ public class PlayerManager { JobsPlayer.loadLogFromDao(jPlayer); players.put(player.getName().toLowerCase(), jPlayer); } + AutoJoinJobs(player); jPlayer.onConnect(); jPlayer.reloadHonorific(); Jobs.getPermissionHandler().recalculatePermissions(jPlayer); @@ -804,4 +810,28 @@ public class PlayerManager { return new BoostMultiplier(Fmoney, Fpoints, Fexp); } + + public void AutoJoinJobs(final Player player) { + if (player == null) + return; + // ignoring OP players for obvious reasons + if (player.isOp()) + return; + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + if (!player.isOnline()) + return; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) + return; + for (Job one : Jobs.getJobs()) { + JobProgression cur = jPlayer.getJobProgression(one); + if (cur == null && player.hasPermission("jobs.autojoin." + one.getName().toLowerCase())) { + Jobs.getPlayerManager().joinJob(jPlayer, one); + } + } + return; + } + }, Jobs.getGCManager().AutoJobJoinDelay * 20L); + } } diff --git a/com/gamingmesh/jobs/config/GeneralConfigManager.java b/com/gamingmesh/jobs/config/GeneralConfigManager.java index 17454bcc..5534ff6c 100644 --- a/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -120,6 +120,7 @@ public class GeneralConfigManager { public boolean UseTaxes; public boolean TransferToServerAccount; public boolean TakeFromPlayersPayment; + public int AutoJobJoinDelay; //BossBar public boolean BossBarEnabled; @@ -402,6 +403,12 @@ public class GeneralConfigManager { "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); saveOnDisconnect = c.get("save-on-disconnect", false); + c.getW().addComment("Optimizations.AutoJobJoinDelay", "Delay in seconds to perform auto join job if used after player joins server", + "If you using offline server, try to keep it slightly more than your login plugin gives time to enter password", + "For player to auto join job add permission node jobs.autojoin.[jobname]", + "Op players are ignored"); + AutoJobJoinDelay = c.get("Optimizations.AutoJobJoinDelay", 15); + c.getW().addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", "Theroticali this should work without issues, but if you havving some, just disable",