1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-03 14:58:34 +01:00

Properly use titles for jobs by their job name

This commit is contained in:
Zrips 2016-10-01 13:23:30 +03:00
parent 3a46bfb491
commit 068b71ad2d
4 changed files with 202 additions and 194 deletions

View File

@ -418,10 +418,18 @@ public class PlayerManager {
return;
// LevelUp event
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel), Jobs
.gettitleManager().getTitleForLevel(prog.getLevel()), Jobs.getGCManager().SoundLevelupSound
.toUpperCase(), Jobs.getGCManager().SoundLevelupVolume, Jobs.getGCManager().SoundLevelupPitch, Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
Jobs.getGCManager().SoundTitleChangeVolume, Jobs.getGCManager().SoundTitleChangePitch);
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(
jPlayer,
job.getName(),
prog.getLevel(),
Jobs.gettitleManager().getTitle(oldLevel, prog.getJob().getName()),
Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
Jobs.getGCManager().SoundLevelupSound.toUpperCase(),
Jobs.getGCManager().SoundLevelupVolume,
Jobs.getGCManager().SoundLevelupPitch,
Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
Jobs.getGCManager().SoundTitleChangeVolume,
Jobs.getGCManager().SoundTitleChangePitch);
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
// If event is canceled, dont do anything
if (levelUpEvent.isCancelled())
@ -469,7 +477,7 @@ public class PlayerManager {
if (Jobs.getGCManager().SoundTitleChangeUse) {
Sound sound = levelUpEvent.getTitleChangeSound();
if (sound != null && player != null)
if (sound != null && player != null && player.getLocation() != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
levelUpEvent.getTitleChangePitch());
else

View File

@ -15,12 +15,12 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
private Title OldTitle;
private Title NewTitle;
private int level;
private Sound soundLevelupSound;
private Sound soundLevelupSound = Sound.values()[0];
private int soundLevelupVolume = 1;
private int soundLevelupPitch = 3;
private Sound soundTitleChangeSound;
private int soundTitleChangeVolume;
private int soundTitleChangePitch;
private Sound soundTitleChangeSound = Sound.values()[0];
private int soundTitleChangeVolume = 1;
private int soundTitleChangePitch = 3;
private boolean cancelled;
public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume,

View File

@ -29,15 +29,15 @@ public class TitleManager {
* @return the correct title
* @return null if no title matches
*/
public Title getTitleForLevel(int level) {
public Title getTitle(int level, String jobName) {
Title title = null;
for (Title t : titles) {
if (title == null) {
if (t.getLevelReq() <= level) {
if (t.getLevelReq() <= level && (t.getJobName() == null || t.getJobName().equalsIgnoreCase(jobName))) {
title = t;
}
} else {
if (t.getLevelReq() <= level && t.getLevelReq() > title.getLevelReq()) {
if (t.getLevelReq() <= level && t.getLevelReq() > title.getLevelReq() && (t.getJobName() == null || t.getJobName().equalsIgnoreCase(jobName))) {
title = t;
}
}

View File

@ -520,7 +520,7 @@ public class JobsPlayer {
builder.append(Jobs.getGCManager().getModifyChatSeparator());
gotTitle = false;
}
Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel());
Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName());
if (numJobs == 1) {
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {