mirror of https://github.com/Zrips/Jobs.git
Call JobsLevelUpEvent when promoting or adding levels to players
Fixes #1168
This commit is contained in:
parent
e40bea99ee
commit
c81489f862
|
@ -11,4 +11,4 @@ assignees: ''
|
|||
|
||||
**Detailed information what should do**
|
||||
|
||||
<-- Maybe a config example if related -->
|
||||
<!-- Maybe a config example if related -->
|
||||
|
|
|
@ -522,6 +522,7 @@ public class Jobs extends JavaPlugin {
|
|||
Map<Integer, Map<String, Log>> playersLogs = dao.getAllLogs();
|
||||
Map<Integer, ArchivedJobs> playersArchives = dao.getAllArchivedJobs();
|
||||
Map<Integer, PaymentData> playersLimits = dao.loadPlayerLimits();
|
||||
|
||||
for (Iterator<PlayerInfo> it = temp.values().iterator(); it.hasNext();) {
|
||||
PlayerInfo one = it.next();
|
||||
int id = one.getID();
|
||||
|
|
|
@ -378,7 +378,7 @@ public class Placeholder {
|
|||
try {
|
||||
int id = Integer.parseInt(value);
|
||||
if (id > 0)
|
||||
return user.getJobProgression().get(id - 1);
|
||||
return user.progression.get(id - 1);
|
||||
} catch (IndexOutOfBoundsException | NumberFormatException e) {
|
||||
Job job = Jobs.getJob(value);
|
||||
if (job != null)
|
||||
|
@ -459,12 +459,12 @@ public class Placeholder {
|
|||
case user_displayhonorific:
|
||||
return user.getDisplayHonorific();
|
||||
case user_joinedjobcount:
|
||||
return Integer.toString(user.getJobProgression().size());
|
||||
return Integer.toString(user.progression.size());
|
||||
case user_archived_jobs:
|
||||
return Integer.toString(user.getArchivedJobs().getArchivedJobs().size());
|
||||
case user_jobs:
|
||||
String jobNames = "";
|
||||
for (JobProgression prog : user.getJobProgression()) {
|
||||
for (JobProgression prog : user.progression) {
|
||||
if (!jobNames.isEmpty()) {
|
||||
jobNames += ", ";
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ public class Placeholder {
|
|||
return convert(false);
|
||||
|
||||
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
|
||||
short playerMaxJobs = (short) user.getJobProgression().size();
|
||||
short playerMaxJobs = (short) user.progression.size();
|
||||
return convert(confMaxJobs > 0 && playerMaxJobs >= confMaxJobs
|
||||
&& !Jobs.getPlayerManager().getJobsLimit(user, playerMaxJobs));
|
||||
|
||||
|
|
|
@ -504,6 +504,7 @@ public class PlayerManager {
|
|||
return false;
|
||||
|
||||
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
|
||||
|
||||
// let the user leave the job
|
||||
if (!jPlayer.leaveJob(job))
|
||||
return false;
|
||||
|
@ -678,8 +679,10 @@ public class PlayerManager {
|
|||
Jobs.getGCManager().SoundTitleChangeSound,
|
||||
Jobs.getGCManager().SoundTitleChangeVolume,
|
||||
Jobs.getGCManager().SoundTitleChangePitch);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||
// If event is canceled, dont do anything
|
||||
|
||||
// If event is cancelled, don't do anything
|
||||
if (levelUpEvent.isCancelled())
|
||||
return;
|
||||
|
||||
|
@ -822,12 +825,12 @@ public class PlayerManager {
|
|||
command = split[1];
|
||||
command = command.replace("[playerName]", player.getName());
|
||||
command = command.replace("[job]", job.getName());
|
||||
}
|
||||
|
||||
if (split[0].equalsIgnoreCase("player:")) {
|
||||
player.performCommand(command);
|
||||
} else {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
if (split[0].equalsIgnoreCase("player:")) {
|
||||
player.performCommand(command);
|
||||
} else {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,19 +247,23 @@ public class JobsCommands implements CommandExecutor {
|
|||
message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1));
|
||||
|
||||
if (Jobs.getGCManager().useDynamicPayment) {
|
||||
if ((int) (job.getBonus() * 100) / 100.0 != 0) {
|
||||
if ((int) (job.getBonus() * 100) / 100.0 < 0)
|
||||
int bonus = (int) ((job.getBonus() * 100) / 100.0);
|
||||
|
||||
if (bonus != 0) {
|
||||
if (bonus < 0)
|
||||
message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1));
|
||||
else
|
||||
message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", (int) (job.getBonus() * 100) / 100.0));
|
||||
message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus));
|
||||
}
|
||||
}
|
||||
|
||||
for (ActionType actionType : ActionType.values()) {
|
||||
if (showAllTypes == 1 || type.startsWith(actionType.getName().toLowerCase())) {
|
||||
List<JobInfo> info = job.getJobInfo(actionType);
|
||||
|
||||
if (info != null && !info.isEmpty()) {
|
||||
String m = jobInfoMessage(player, job, actionType);
|
||||
|
||||
if (m.contains("\n"))
|
||||
message.addAll(Arrays.asList(m.split("\n")));
|
||||
else
|
||||
|
@ -425,12 +429,14 @@ public class JobsCommands implements CommandExecutor {
|
|||
*/
|
||||
public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) {
|
||||
int level = jPlayer.getLevelAfterRejoin(jobProg);
|
||||
double exp = jPlayer.getExpAfterRejoin(jobProg, jPlayer.getLevelAfterRejoin(jobProg));
|
||||
double exp = jPlayer.getExpAfterRejoin(jobProg, level);
|
||||
int maxExperience = jobProg.getMaxExperience(level);
|
||||
|
||||
String message = Jobs.getLanguage().getMessage("command.stats.output.message",
|
||||
"%joblevel%", level,
|
||||
"%jobname%", jobProg.getJob().getJobDisplayName(),
|
||||
"%jobxp%", Math.round(exp * 100.0) / 100.0,
|
||||
"%jobmaxxp%", jobProg.getMaxExperience(level));
|
||||
return " " + jobProgressMessage(jobProg.getMaxExperience(level), exp) + " " + message;
|
||||
"%jobmaxxp%", maxExperience);
|
||||
return " " + jobProgressMessage(maxExperience, exp) + " " + message;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
|
||||
import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
|
@ -48,10 +49,9 @@ public class level implements Cmd {
|
|||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
if (job == null && Jobs.getJob(one) != null) {
|
||||
job = Jobs.getJob(one);
|
||||
if (job == null && (job = Jobs.getJob(one)) != null)
|
||||
continue;
|
||||
}
|
||||
|
||||
playerName = one;
|
||||
}
|
||||
|
||||
|
@ -80,12 +80,31 @@ public class level implements Cmd {
|
|||
prog.setLevel(amount);
|
||||
break;
|
||||
case Add:
|
||||
total = (prog.getLevel() + amount);
|
||||
prog.setLevel(total);
|
||||
int oldLevel = prog.getLevel();
|
||||
total = (oldLevel + amount);
|
||||
|
||||
if (prog.setLevel(total)) {
|
||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job, prog.getLevel(),
|
||||
Jobs.getTitleManager().getTitle(oldLevel, prog.getJob().getName()),
|
||||
Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
|
||||
Jobs.getGCManager().SoundLevelupSound,
|
||||
Jobs.getGCManager().SoundLevelupVolume,
|
||||
Jobs.getGCManager().SoundLevelupPitch,
|
||||
Jobs.getGCManager().SoundTitleChangeSound,
|
||||
Jobs.getGCManager().SoundTitleChangeVolume,
|
||||
Jobs.getGCManager().SoundTitleChangePitch);
|
||||
|
||||
plugin.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||
|
||||
// If event is cancelled, don't do anything
|
||||
if (levelUpEvent.isCancelled())
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case Take:
|
||||
total = (prog.getLevel() - amount);
|
||||
prog.setLevel(amount);
|
||||
prog.setLevel(total);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -307,8 +307,7 @@ public class GeneralConfigManager {
|
|||
Jobs.getDBManager().start();
|
||||
|
||||
c.addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number");
|
||||
c.get("save-period", 10);
|
||||
if (c.getInt("save-period") <= 0) {
|
||||
if (c.get("save-period", 10) <= 0) {
|
||||
Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!");
|
||||
c.set("save-period", 10);
|
||||
}
|
||||
|
|
|
@ -158,13 +158,14 @@ public class ScheduleManager {
|
|||
conf.options().copyDefaults(true);
|
||||
conf.options().copyHeader(true);
|
||||
|
||||
if (!conf.isConfigurationSection("Boost"))
|
||||
ConfigurationSection section = conf.getConfigurationSection("Boost");
|
||||
if (section == null)
|
||||
return;
|
||||
|
||||
List<String> sections = new ArrayList<>(conf.getConfigurationSection("Boost").getKeys(false));
|
||||
List<String> sections = new ArrayList<>(section.getKeys(false));
|
||||
|
||||
for (String oneSection : sections) {
|
||||
ConfigurationSection path = conf.getConfigurationSection("Boost." + oneSection);
|
||||
ConfigurationSection path = section.getConfigurationSection(oneSection);
|
||||
|
||||
if (path == null || !path.getBoolean("Enabled") || !path.getString("From", "").contains(":")
|
||||
|| !path.getString("Until", "").contains(":") || !path.isList("Days") || !path.isList("Jobs"))
|
||||
|
@ -181,17 +182,13 @@ public class ScheduleManager {
|
|||
if (path.isList("MessageOnStart"))
|
||||
sched.setMessageOnStart(path.getStringList("MessageOnStart"), path.getString("From"), path.getString("Until"));
|
||||
|
||||
if (path.contains("BroadcastOnStart"))
|
||||
sched.setBroadcastOnStart(path.getBoolean("BroadcastOnStart"));
|
||||
sched.setBroadcastOnStart(path.getBoolean("BroadcastOnStart", true));
|
||||
|
||||
if (path.isList("MessageOnStop"))
|
||||
sched.setMessageOnStop(path.getStringList("MessageOnStop"), path.getString("From"), path.getString("Until"));
|
||||
|
||||
if (path.contains("BroadcastOnStop"))
|
||||
sched.setBroadcastOnStop(path.getBoolean("BroadcastOnStop"));
|
||||
|
||||
if (path.contains("BroadcastInterval"))
|
||||
sched.setBroadcastInterval(path.getInt("BroadcastInterval"));
|
||||
sched.setBroadcastOnStop(path.getBoolean("BroadcastOnStop", true));
|
||||
sched.setBroadcastInterval(path.getInt("BroadcastInterval"));
|
||||
|
||||
if (path.isList("BroadcastMessage"))
|
||||
sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until"));
|
||||
|
|
|
@ -34,8 +34,10 @@ public class BoostMultiplier implements Cloneable {
|
|||
}
|
||||
|
||||
public BoostMultiplier add(double amount) {
|
||||
for (CurrencyType one : CurrencyType.values()) {
|
||||
map.put(one, amount);
|
||||
if (amount > 0) {
|
||||
for (CurrencyType one : CurrencyType.values()) {
|
||||
map.put(one, amount);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -654,7 +654,7 @@ public class Job {
|
|||
|
||||
public boolean isWorldBlackListed(Block block, Entity ent) {
|
||||
if (worldBlacklist.isEmpty())
|
||||
return isReversedWorldBlacklist();
|
||||
return reversedWorldBlacklist;
|
||||
|
||||
if (block != null)
|
||||
return worldBlacklist.contains(block.getWorld().getName()) != reversedWorldBlacklist;
|
||||
|
|
|
@ -137,15 +137,15 @@ public class JobProgression {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the level of this job
|
||||
* @param level - the new level for this job
|
||||
* Sets the level of this job progression
|
||||
*
|
||||
* @param level the new level for this job
|
||||
* @return true if this progression can level up
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
// synchronized (jPlayer.saveLock) {
|
||||
public boolean setLevel(int level) {
|
||||
jPlayer.setSaved(false);
|
||||
this.level = level;
|
||||
reloadMaxExperienceAndCheckLevelUp();
|
||||
// }
|
||||
return reloadMaxExperienceAndCheckLevelUp();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.gamingmesh.jobs.CMILib.ActionBarManager;
|
|||
import com.gamingmesh.jobs.CMILib.CMIChatColor;
|
||||
import com.gamingmesh.jobs.CMILib.CMIMaterial;
|
||||
import com.gamingmesh.jobs.Signs.SignTopType;
|
||||
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||
import com.gamingmesh.jobs.economy.PaymentData;
|
||||
|
@ -665,8 +666,23 @@ public class JobsPlayer {
|
|||
if (prog == null)
|
||||
return;
|
||||
|
||||
if (level != prog.getLevel()) {
|
||||
prog.setLevel(level);
|
||||
int oldLevel = prog.getLevel();
|
||||
|
||||
if (level != oldLevel) {
|
||||
if (prog.setLevel(level)) {
|
||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(this, job, prog.getLevel(),
|
||||
Jobs.getTitleManager().getTitle(oldLevel, prog.getJob().getName()),
|
||||
Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
|
||||
Jobs.getGCManager().SoundLevelupSound,
|
||||
Jobs.getGCManager().SoundLevelupVolume,
|
||||
Jobs.getGCManager().SoundLevelupPitch,
|
||||
Jobs.getGCManager().SoundTitleChangeSound,
|
||||
Jobs.getGCManager().SoundTitleChangeVolume,
|
||||
Jobs.getGCManager().SoundTitleChangePitch);
|
||||
|
||||
plugin.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||
}
|
||||
|
||||
reloadHonorific();
|
||||
reloadLimits();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(this);
|
||||
|
|
|
@ -73,8 +73,8 @@ public class JobsManager {
|
|||
hostname = c.get("mysql.hostname", c.getC().getString("mysql-hostname", "localhost:3306"));
|
||||
database = c.get("mysql.database", c.getC().getString("mysql-database", "minecraft"));
|
||||
prefix = c.get("mysql.table-prefix", c.getC().getString("mysql-table-prefix", "jobs_"));
|
||||
certificate = c.get("mysql.verify-server-certificate", c.getC().getBoolean("verify-server-certificate", false));
|
||||
ssl = c.get("mysql.use-ssl", c.getC().getBoolean("use-ssl", false));
|
||||
certificate = c.get("mysql.verify-server-certificate", c.getC().getBoolean("verify-server-certificate"));
|
||||
ssl = c.get("mysql.use-ssl", c.getC().getBoolean("use-ssl"));
|
||||
autoReconnect = c.get("mysql.auto-reconnect", c.getC().getBoolean("auto-reconnect", true));
|
||||
characterEncoding = c.get("mysql.characterEncoding", "utf8");
|
||||
encoding = c.get("mysql.encoding", "UTF-8");
|
||||
|
|
Loading…
Reference in New Issue