mirror of
https://github.com/Zrips/Jobs.git
synced 2025-04-14 08:05:41 +02:00
Properly use titles for jobs by their job name
This commit is contained in:
parent
3a46bfb491
commit
068b71ad2d
@ -418,10 +418,18 @@ public class PlayerManager {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// LevelUp event
|
// LevelUp event
|
||||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel), Jobs
|
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(
|
||||||
.gettitleManager().getTitleForLevel(prog.getLevel()), Jobs.getGCManager().SoundLevelupSound
|
jPlayer,
|
||||||
.toUpperCase(), Jobs.getGCManager().SoundLevelupVolume, Jobs.getGCManager().SoundLevelupPitch, Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
|
job.getName(),
|
||||||
Jobs.getGCManager().SoundTitleChangeVolume, Jobs.getGCManager().SoundTitleChangePitch);
|
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);
|
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||||
// If event is canceled, dont do anything
|
// If event is canceled, dont do anything
|
||||||
if (levelUpEvent.isCancelled())
|
if (levelUpEvent.isCancelled())
|
||||||
@ -469,7 +477,7 @@ public class PlayerManager {
|
|||||||
|
|
||||||
if (Jobs.getGCManager().SoundTitleChangeUse) {
|
if (Jobs.getGCManager().SoundTitleChangeUse) {
|
||||||
Sound sound = levelUpEvent.getTitleChangeSound();
|
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(),
|
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
|
||||||
levelUpEvent.getTitleChangePitch());
|
levelUpEvent.getTitleChangePitch());
|
||||||
else
|
else
|
||||||
|
@ -15,12 +15,12 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
|
|||||||
private Title OldTitle;
|
private Title OldTitle;
|
||||||
private Title NewTitle;
|
private Title NewTitle;
|
||||||
private int level;
|
private int level;
|
||||||
private Sound soundLevelupSound;
|
private Sound soundLevelupSound = Sound.values()[0];
|
||||||
private int soundLevelupVolume = 1;
|
private int soundLevelupVolume = 1;
|
||||||
private int soundLevelupPitch = 3;
|
private int soundLevelupPitch = 3;
|
||||||
private Sound soundTitleChangeSound;
|
private Sound soundTitleChangeSound = Sound.values()[0];
|
||||||
private int soundTitleChangeVolume;
|
private int soundTitleChangeVolume = 1;
|
||||||
private int soundTitleChangePitch;
|
private int soundTitleChangePitch = 3;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume,
|
public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume,
|
||||||
|
@ -1,184 +1,184 @@
|
|||||||
package com.gamingmesh.jobs.config;
|
package com.gamingmesh.jobs.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.container.LocaleReader;
|
import com.gamingmesh.jobs.container.LocaleReader;
|
||||||
import com.gamingmesh.jobs.container.Title;
|
import com.gamingmesh.jobs.container.Title;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
|
||||||
public class TitleManager {
|
public class TitleManager {
|
||||||
|
|
||||||
protected List<Title> titles = new ArrayList<Title>();
|
protected List<Title> titles = new ArrayList<Title>();
|
||||||
|
|
||||||
private Jobs plugin;
|
private Jobs plugin;
|
||||||
|
|
||||||
public TitleManager(Jobs plugin) {
|
public TitleManager(Jobs plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to return the title for a given level
|
* Function to return the title for a given level
|
||||||
* @return the correct title
|
* @return the correct title
|
||||||
* @return null if no title matches
|
* @return null if no title matches
|
||||||
*/
|
*/
|
||||||
public Title getTitleForLevel(int level) {
|
public Title getTitle(int level, String jobName) {
|
||||||
Title title = null;
|
Title title = null;
|
||||||
for (Title t : titles) {
|
for (Title t : titles) {
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
if (t.getLevelReq() <= level) {
|
if (t.getLevelReq() <= level && (t.getJobName() == null || t.getJobName().equalsIgnoreCase(jobName))) {
|
||||||
title = t;
|
title = t;
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
title = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to load the title configuration
|
* Method to load the title configuration
|
||||||
*
|
*
|
||||||
* loads from Jobs/titleConfig.yml
|
* loads from Jobs/titleConfig.yml
|
||||||
*/
|
*/
|
||||||
synchronized void load() {
|
synchronized void load() {
|
||||||
this.titles.clear();
|
this.titles.clear();
|
||||||
|
|
||||||
File f = new File(plugin.getDataFolder(), "titleConfig.yml");
|
File f = new File(plugin.getDataFolder(), "titleConfig.yml");
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||||
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
|
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
|
||||||
|
|
||||||
LocaleReader c = new LocaleReader(config, writer);
|
LocaleReader c = new LocaleReader(config, writer);
|
||||||
|
|
||||||
StringBuilder header = new StringBuilder()
|
StringBuilder header = new StringBuilder()
|
||||||
.append("Title configuration")
|
.append("Title configuration")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("Stores the titles people gain at certain levels.")
|
.append("Stores the titles people gain at certain levels.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("Each title requres to have a name, short name (used when the player has more than")
|
.append("Each title requres to have a name, short name (used when the player has more than")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("1 job) the colour of the title and the level requrirement to attain the title.")
|
.append("1 job) the colour of the title and the level requrirement to attain the title.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("It is recommended but not required to have a title at level 0.")
|
.append("It is recommended but not required to have a title at level 0.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("Titles are completely optional.")
|
.append("Titles are completely optional.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("Posible variable are {level} to add current jobs level.")
|
.append("Posible variable are {level} to add current jobs level.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append("Optionaly you can set different titles based by job.")
|
.append("Optionaly you can set different titles based by job.")
|
||||||
.append(System.getProperty("line.separator"))
|
.append(System.getProperty("line.separator"))
|
||||||
.append(" JobName: Miner");
|
.append(" JobName: Miner");
|
||||||
c.getC().options().header(header.toString());
|
c.getC().options().header(header.toString());
|
||||||
c.getC().options().copyDefaults(true);
|
c.getC().options().copyDefaults(true);
|
||||||
|
|
||||||
ConfigurationSection titleSection = c.getC().getConfigurationSection("Titles");
|
ConfigurationSection titleSection = c.getC().getConfigurationSection("Titles");
|
||||||
if (titleSection == null) {
|
if (titleSection == null) {
|
||||||
titleSection = c.getC().createSection("Titles");
|
titleSection = c.getC().createSection("Titles");
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Novice.Name", "N"),
|
c.get("Titles.Novice.Name", "N"),
|
||||||
c.get("Titles.Novice.ShortName", "N"),
|
c.get("Titles.Novice.ShortName", "N"),
|
||||||
ChatColor.matchColor(c.get("Titles.Novice.ChatColour", "YELLOW")),
|
ChatColor.matchColor(c.get("Titles.Novice.ChatColour", "YELLOW")),
|
||||||
c.get("Titles.Novice.levelReq", 0),
|
c.get("Titles.Novice.levelReq", 0),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Apprentice.Name", "A"),
|
c.get("Titles.Apprentice.Name", "A"),
|
||||||
c.get("Titles.Apprentice.ShortName", "A"),
|
c.get("Titles.Apprentice.ShortName", "A"),
|
||||||
ChatColor.matchColor(c.get("Titles.Apprentice.ChatColour", "WHITE")),
|
ChatColor.matchColor(c.get("Titles.Apprentice.ChatColour", "WHITE")),
|
||||||
c.get("Titles.Apprentice.levelReq", 25),
|
c.get("Titles.Apprentice.levelReq", 25),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Initiate.Name", "I"),
|
c.get("Titles.Initiate.Name", "I"),
|
||||||
c.get("Titles.Initiate.ShortName", "I"),
|
c.get("Titles.Initiate.ShortName", "I"),
|
||||||
ChatColor.matchColor(c.get("Titles.Initiate.ChatColour", "GOLD")),
|
ChatColor.matchColor(c.get("Titles.Initiate.ChatColour", "GOLD")),
|
||||||
c.get("Titles.Initiate.levelReq", 50),
|
c.get("Titles.Initiate.levelReq", 50),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Journeyman.Name", "J"),
|
c.get("Titles.Journeyman.Name", "J"),
|
||||||
c.get("Titles.Journeyman.ShortName", "J"),
|
c.get("Titles.Journeyman.ShortName", "J"),
|
||||||
ChatColor.matchColor(c.get("Titles.Journeyman.ChatColour", "DARK_GREEN")),
|
ChatColor.matchColor(c.get("Titles.Journeyman.ChatColour", "DARK_GREEN")),
|
||||||
c.get("Titles.Journeyman.levelReq", 75),
|
c.get("Titles.Journeyman.levelReq", 75),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Adept.Name", "Ad"),
|
c.get("Titles.Adept.Name", "Ad"),
|
||||||
c.get("Titles.Adept.ShortName", "Ad"),
|
c.get("Titles.Adept.ShortName", "Ad"),
|
||||||
ChatColor.matchColor(c.get("Titles.Adept.ChatColour", "DARK_PURPLE")),
|
ChatColor.matchColor(c.get("Titles.Adept.ChatColour", "DARK_PURPLE")),
|
||||||
c.get("Titles.Adept.levelReq", 100),
|
c.get("Titles.Adept.levelReq", 100),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Master.Name", "M"),
|
c.get("Titles.Master.Name", "M"),
|
||||||
c.get("Titles.Master.ShortName", "M"),
|
c.get("Titles.Master.ShortName", "M"),
|
||||||
ChatColor.matchColor(c.get("Titles.Master.ChatColour", "GRAY")),
|
ChatColor.matchColor(c.get("Titles.Master.ChatColour", "GRAY")),
|
||||||
c.get("Titles.Master.levelReq", 125),
|
c.get("Titles.Master.levelReq", 125),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Grandmaster.Name", "GM"),
|
c.get("Titles.Grandmaster.Name", "GM"),
|
||||||
c.get("Titles.Grandmaster.ShortName", "GM"),
|
c.get("Titles.Grandmaster.ShortName", "GM"),
|
||||||
ChatColor.matchColor(c.get("Titles.Grandmaster.ChatColour", "DARK_GRAY")),
|
ChatColor.matchColor(c.get("Titles.Grandmaster.ChatColour", "DARK_GRAY")),
|
||||||
c.get("Titles.Grandmaster.levelReq", 150),
|
c.get("Titles.Grandmaster.levelReq", 150),
|
||||||
null));
|
null));
|
||||||
|
|
||||||
this.titles.add(new Title(
|
this.titles.add(new Title(
|
||||||
c.get("Titles.Legendary.Name", "L"),
|
c.get("Titles.Legendary.Name", "L"),
|
||||||
c.get("Titles.Legendary.ShortName", "L"),
|
c.get("Titles.Legendary.ShortName", "L"),
|
||||||
ChatColor.matchColor(c.get("Titles.Legendary.ChatColour", "BLACK")),
|
ChatColor.matchColor(c.get("Titles.Legendary.ChatColour", "BLACK")),
|
||||||
c.get("Titles.Legendary.levelReq", 200),
|
c.get("Titles.Legendary.levelReq", 200),
|
||||||
null));
|
null));
|
||||||
try {
|
try {
|
||||||
c.getC().save(f);
|
c.getC().save(f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
for (String titleKey : titleSection.getKeys(false)) {
|
for (String titleKey : titleSection.getKeys(false)) {
|
||||||
String jobName = null;
|
String jobName = null;
|
||||||
String titleName = titleSection.getString(titleKey + ".Name");
|
String titleName = titleSection.getString(titleKey + ".Name");
|
||||||
String titleShortName = titleSection.getString(titleKey + ".ShortName");
|
String titleShortName = titleSection.getString(titleKey + ".ShortName");
|
||||||
ChatColor titleColor = ChatColor.matchColor(titleSection.getString(titleKey + ".ChatColour", ""));
|
ChatColor titleColor = ChatColor.matchColor(titleSection.getString(titleKey + ".ChatColour", ""));
|
||||||
int levelReq = titleSection.getInt(titleKey + ".levelReq", -1);
|
int levelReq = titleSection.getInt(titleKey + ".levelReq", -1);
|
||||||
|
|
||||||
if (titleSection.isString(titleKey + ".JobName")) {
|
if (titleSection.isString(titleKey + ".JobName")) {
|
||||||
jobName = titleSection.getString(titleKey + ".JobName");
|
jobName = titleSection.getString(titleKey + ".JobName");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (titleName == null) {
|
if (titleName == null) {
|
||||||
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!");
|
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (titleShortName == null) {
|
if (titleShortName == null) {
|
||||||
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ShortName property. Skipping!");
|
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ShortName property. Skipping!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (titleColor == null) {
|
if (titleColor == null) {
|
||||||
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ChatColour property. Skipping!");
|
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ChatColour property. Skipping!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (levelReq <= -1) {
|
if (levelReq <= -1) {
|
||||||
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid levelReq property. Skipping!");
|
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid levelReq property. Skipping!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.titles.add(new Title(titleName, titleShortName, titleColor, levelReq, jobName));
|
this.titles.add(new Title(titleName, titleShortName, titleColor, levelReq, jobName));
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded " + titles.size() + " titles!");
|
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded " + titles.size() + " titles!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,7 +520,7 @@ public class JobsPlayer {
|
|||||||
builder.append(Jobs.getGCManager().getModifyChatSeparator());
|
builder.append(Jobs.getGCManager().getModifyChatSeparator());
|
||||||
gotTitle = false;
|
gotTitle = false;
|
||||||
}
|
}
|
||||||
Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel());
|
Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName());
|
||||||
|
|
||||||
if (numJobs == 1) {
|
if (numJobs == 1) {
|
||||||
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
|
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user