From 22d985f0b469f9c7689d18656f8a7c24ff9f1d85 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 22 Oct 2020 15:50:31 +0200 Subject: [PATCH] Added option to send title and chat message when a player reached the max level of a job Closes #971 --- .../com/gamingmesh/jobs/PlayerManager.java | 25 +++++++++++-------- .../jobs/commands/JobsCommands.java | 8 ++++-- .../gamingmesh/jobs/commands/list/quests.java | 4 +-- .../jobs/config/GeneralConfigManager.java | 5 +++- .../jobs/config/LanguageManager.java | 6 ++++- .../com/gamingmesh/jobs/container/Job.java | 6 ++--- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 3969259c..d9cb1c41 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -43,6 +43,7 @@ import org.bukkit.inventory.meta.FireworkMeta; import com.gamingmesh.jobs.CMILib.Version; import com.gamingmesh.jobs.CMILib.ActionBarManager; import com.gamingmesh.jobs.CMILib.CMIReflections; +import com.gamingmesh.jobs.CMILib.TitleMessageManager; import com.gamingmesh.jobs.api.JobsJoinEvent; import com.gamingmesh.jobs.api.JobsLeaveEvent; import com.gamingmesh.jobs.api.JobsLevelUpEvent; @@ -583,11 +584,8 @@ public class PlayerManager { try { if (Jobs.getGCManager().SoundLevelupUse) { Sound sound = levelUpEvent.getSound(); - if (sound != null) { - if (player != null) - player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch()); - } else - Jobs.consoleMsg("[Jobs] Can't find sound by name: " + levelUpEvent.getTitleChangeSound().name() + ". Please update it"); + if (player != null) + player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch()); } } catch (Exception e) { } @@ -714,12 +712,9 @@ public class PlayerManager { try { if (Jobs.getGCManager().SoundTitleChangeUse) { Sound sound = levelUpEvent.getTitleChangeSound(); - if (sound != null) { - if (player != null) - player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(), - levelUpEvent.getTitleChangePitch()); - } else - Jobs.consoleMsg("[Jobs] Can't find sound by name: " + levelUpEvent.getTitleChangeSound().name() + ". Please update it"); + if (player != null) + player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(), + levelUpEvent.getTitleChangePitch()); } } catch (Exception e) { } @@ -744,10 +739,18 @@ public class PlayerManager { } } } + jPlayer.reloadHonorific(); Jobs.getPermissionHandler().recalculatePermissions(jPlayer); performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel); Jobs.getSignUtil().updateAllSign(job); + + if (Jobs.getGCManager().titleMessageMaxLevelReached && prog.getLevel() == jPlayer.getMaxJobLevelAllowed(prog.getJob())) { + TitleMessageManager.send(jPlayer.getPlayer(), Jobs.getLanguage().getMessage("message.max-level-reached.title", + "%jobname%", prog.getJob().getNameWithColor()), + Jobs.getLanguage().getMessage("message.max-level-reached.subtitle", "%jobname%", prog.getJob().getNameWithColor()), 20, 40, 20); + jPlayer.getPlayer().sendMessage(Jobs.getLanguage().getMessage("message.max-level-reached.chat", "%jobname%", prog.getJob().getNameWithColor())); + } } /** diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 08130a83..15753cb0 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -408,14 +408,18 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public String jobStatsMessage(JobProgression jobProg) { + boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); + String path = "command.stats.output." + (isMaxLevelReached ? "max-level" + : "message"); + Title title = Jobs.gettitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()); - String message = Jobs.getLanguage().getMessage("command.stats.output", + String message = Jobs.getLanguage().getMessage(path, "%joblevel%", jobProg.getLevel(), "%jobname%", jobProg.getJob().getNameWithColor(), "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, "%jobmaxxp%", jobProg.getMaxExperience(), "%titlename%", title == null ? "Unknown" : title.getName()); - return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message; + return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message; } public String jobProgressMessage(double max, double current) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 1c78b9b4..d3ca38c8 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -100,9 +100,7 @@ public class quests implements Cmd { .replace("[time]", TimeManage.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); if (current.contains("[desc]")) { - for (String one : q.getQuest().getDescription()) { - hoverList.add(one); - } + q.getQuest().getDescription().forEach(hoverList::add); } else { hoverList.add(current); } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 2ee4d570..5f52c0d0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -103,7 +103,7 @@ public class GeneralConfigManager { BossBarEnabled, BossBarShowOnEachAction, BossBarsMessageByDefault, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse, DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled, LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, - payForEachVTradeItem; + payForEachVTradeItem, titleMessageMaxLevelReached; public ItemStack guiBackButton, guiNextButton, guiFiller; @@ -864,6 +864,9 @@ public class GeneralConfigManager { LevelChangeChat = c.get("ShowChatMessage.OnLevelChange", true); EmptyServerAccountChat = c.get("ShowChatMessage.OnEmptyServerAccount", true); + c.addComment("SendTitleMessageWhenMaxLevelReached", "Send title and chat message when a player reached the maximum level in a job."); + titleMessageMaxLevelReached = c.get("SendTitleMessageWhenMaxLevelReached", false); + c.addComment("Sounds", "Sounds", "Extra sounds on some events", "All sounds can be found in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html"); SoundLevelupUse = c.get("Sounds.LevelUp.use", true); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 2742f5ad..1e2d3273 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -293,7 +293,8 @@ public class LanguageManager { c.get("command.stats.help.args", "[playername]"); Jobs.getGCManager().getCommandArgs().put("stats", Arrays.asList("[playername]")); c.get("command.stats.error.nojob", "Please join a job first."); - c.get("command.stats.output", "Level %joblevel% for %jobname%: %jobxp%/%jobmaxxp% xp"); + c.get("command.stats.output.message", "Level %joblevel% for %jobname%: %jobxp%/%jobmaxxp% xp"); + c.get("command.stats.output.max-level", " &cMax level - %jobname%"); c.get("command.stats.bossBarOutput", "Lvl %joblevel% %jobname%: %jobxp%/%jobmaxxp% xp%gain%"); c.get("command.stats.bossBarGain", " &7(&f%gain%&7)"); @@ -631,6 +632,9 @@ public class LanguageManager { c.get("message.skillup.broadcast", "%playername% has been promoted to a %titlename% %jobname%."); c.get("message.skillup.nobroadcast", "Congratulations, you have been promoted to a %titlename% %jobname%."); + c.get("message.max-level-reached.title", "&2Max level reached"); + c.get("message.max-level-reached.subtitle", "&2in %jobname%!"); + c.get("message.max-level-reached.chat", "&cYou have reached the maximum level in %jobname%!"); c.get("message.levelup.broadcast", "%playername% is now a level %joblevel% %jobname%."); c.get("message.levelup.nobroadcast", "You are now level %joblevel% %jobname%."); diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index 2f9184ba..e312ef7a 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -350,12 +350,12 @@ public class Job { } public int getMaxLevel(JobsPlayer player) { - return player == null ? getMaxLevel() : player.getMaxJobLevelAllowed(this); + return player == null ? maxLevel : player.getMaxJobLevelAllowed(this); } public int getMaxLevel(CommandSender sender) { if (sender == null) - return getMaxLevel(); + return maxLevel; if (sender instanceof Player) { JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender); @@ -363,7 +363,7 @@ public class Job { return player.getMaxJobLevelAllowed(this); } - return getMaxLevel() > getVipMaxLevel() ? getMaxLevel() : getVipMaxLevel(); + return maxLevel > vipmaxLevel ? maxLevel : vipmaxLevel; } /**