/** * Broadcasts level up about a player * * @param jPlayer * @param job */ public void performLevelUp(JobsPlayer jPlayer, Job job) { Player player = plugin.getServer().getPlayer(jPlayer.getName()); JobProgression prog = jPlayer.getJobProgression(job); if (prog == null) return; String message; if (plugin.getJobsConfiguration().isBroadcastingLevelups()) { message = plugin.getMessageConfig().getMessage("level-up-broadcast"); } else { message = plugin.getMessageConfig().getMessage("level-up-no-broadcast"); } message = message.replace("%jobname%", job.getName()); message = message.replace("%jobcolour%", job.getChatColour().toString()); if (prog.getTitle() != null) { message = message.replace("%titlename%", prog.getTitle().getName()); message = message.replace("%titlecolour%", prog.getTitle().getChatColor().toString()); } message = message.replace("%playername%", jPlayer.getName()); if (player == null) { message = message.replace("%playerdisplayname%", jPlayer.getName()); } else { message = message.replace("%playerdisplayname%", player.getDisplayName()); } message = message.replace("%joblevel%", "" + prog.getLevel()); for (String line : message.split("\n")) { if (plugin.getJobsConfiguration().isBroadcastingLevelups()) { plugin.getServer().broadcastMessage(line); } else if (player != null) { player.sendMessage(line); } } Title levelTitle = plugin.getJobsConfiguration().getTitleForLevel(prog.getLevel()); if (levelTitle != null && !levelTitle.equals(prog.getTitle())) { // user would skill up if (plugin.getJobsConfiguration().isBroadcastingSkillups()) { message = plugin.getMessageConfig().getMessage("skill-up-broadcast"); } else { message = plugin.getMessageConfig().getMessage("skill-up-no-broadcast"); } message = message.replace("%playername%", jPlayer.getName()); message = message.replace("%titlecolour%", levelTitle.getChatColor().toString()); message = message.replace("%titlename%", levelTitle.getName()); message = message.replace("%jobcolour%", job.getChatColour().toString()); message = message.replace("%jobname%", job.getName()); for (String line : message.split("\n")) { if (plugin.getJobsConfiguration().isBroadcastingLevelups()) { plugin.getServer().broadcastMessage(line); } else if (player != null) { player.sendMessage(line); } } } prog.setTitle(levelTitle); jPlayer.reloadHonorific(); jPlayer.recalculatePermissions(); }
/** * Demote player in their job * * @param jPlayer * @param job - the job * @param levels - number of levels to demote */ public void demoteJob(JobsPlayer jPlayer, Job job, int levels) { synchronized (jPlayer.saveLock) { jPlayer.demoteJob(job, levels); jPlayer.save(plugin.getJobsCore().getJobsDAO()); } Player player = plugin.getServer().getPlayer(jPlayer.getName()); if (player != null) { String message = plugin.getMessageConfig().getMessage("demote-target"); message = message.replace("%jobcolour%", job.getChatColour().toString()); message = message.replace("%jobname%", job.getName()); message = message.replace("%levelslost%", Integer.valueOf(levels).toString()); for (String line : message.split("\n")) { player.sendMessage(line); } } }
/** * Removes experience to the player * * @param jPlayer * @param job - the job * @param experience - experience gained */ public void removeExperience(JobsPlayer jPlayer, Job job, double experience) { synchronized (jPlayer.saveLock) { JobProgression prog = jPlayer.getJobProgression(job); if (prog == null) return; prog.addExperience(-experience); jPlayer.save(plugin.getJobsCore().getJobsDAO()); } Player player = plugin.getServer().getPlayer(jPlayer.getName()); if (player != null) { String message = plugin.getMessageConfig().getMessage("removexp-target"); message = message.replace("%jobcolour%", job.getChatColour().toString()); message = message.replace("%jobname%", job.getName()); message = message.replace("%expgained%", Double.valueOf(experience).toString()); for (String line : message.split("\n")) { player.sendMessage(line); } } }
/** * Causes player to leave their job * * @param jPlayer * @param job */ public void leaveJob(JobsPlayer jPlayer, Job job) { synchronized (jPlayer.saveLock) { if (!jPlayer.isInJob(job)) return; // let the user leave the job if (!jPlayer.leaveJob(job)) return; plugin.getJobsCore().getJobsDAO().quitJob(jPlayer, job); plugin.getJobsCore().leaveSlot(job); } Player player = plugin.getServer().getPlayer(jPlayer.getName()); if (player != null) { String message = plugin.getMessageConfig().getMessage("leave-job-success"); message = message.replace("%jobcolour%", job.getChatColour().toString()); message = message.replace("%jobname%", job.getName()); for (String line : message.split("\n")) { player.sendMessage(line); } } }
/** * Transfers player job * * @param jPlayer * @param oldjob - the old job * @param newjob - the new job */ public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) { synchronized (jPlayer.saveLock) { if (!jPlayer.transferJob(oldjob, newjob)) return; JobsDAO dao = plugin.getJobsCore().getJobsDAO(); dao.quitJob(jPlayer, oldjob); dao.joinJob(jPlayer, newjob); jPlayer.save(dao); } Player player = plugin.getServer().getPlayer(jPlayer.getName()); if (player != null) { String message = plugin.getMessageConfig().getMessage("transfer-target"); message = message.replace("%oldjobcolour%", oldjob.getChatColour().toString()); message = message.replace("%oldjobname%", oldjob.getName()); message = message.replace("%newjobcolour%", newjob.getChatColour().toString()); message = message.replace("%newjobname%", newjob.getName()); for (String line : message.split("\n")) { player.sendMessage(line); } } }