1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-11 11:51:54 +01:00

Call expgainevent before payment and don't continue if event is

canceled, set it to 0 and let it to do its thing.
Optimize for boost permission check on each action. Calculate only every
one minute if needed.
Try to create points table every time, to avoid missing table.
This commit is contained in:
Zrips 2016-06-12 15:42:33 +03:00
parent 5bc42e209f
commit a8466e5e2f
17 changed files with 201 additions and 200 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
@ -149,9 +150,8 @@ public class GuiManager {
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
// money exp boost // money exp boost
Player dude = Bukkit.getServer().getPlayer(player.getUniqueId()); Double MoneyBoost = JPlayer.getBoost(job.getName(), BoostType.MONEY);
Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job); Double ExpBoost = JPlayer.getBoost(job.getName(), BoostType.EXP);
Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job);
int level = 1; int level = 1;
JobProgression prog = JPlayer.getJobProgression(job); JobProgression prog = JPlayer.getJobProgression(job);

View File

@ -735,7 +735,9 @@ public class Jobs {
if (income != 0D || points != 0D) { if (income != 0D || points != 0D) {
BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID()), Jobs.getNoneJob()); // jPlayer
BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(jPlayer, Jobs.getNoneJob());
// Calculate income // Calculate income
@ -825,7 +827,7 @@ public class Jobs {
} }
} }
BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID()), prog.getJob()); BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob());
if (multiplier != 0.0) if (multiplier != 0.0)
FinalBoost = new BoostMultiplier(FinalBoost.getMoneyBoost() + multiplier, FinalBoost = new BoostMultiplier(FinalBoost.getMoneyBoost() + multiplier,
@ -903,19 +905,22 @@ public class Jobs {
} else if (Jobs.getGCManager().BossBarEnabled && !Jobs.getGCManager().BossBarShowOnEachAction) } else if (Jobs.getGCManager().BossBarEnabled && !Jobs.getGCManager().BossBarShowOnEachAction)
jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); jPlayer.getUpdateBossBarFor().add(prog.getJob().getName());
// JobsPayment event
JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount);
Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent);
// If event is canceled, don't do anything
if (JobsExpGainEvent.isCancelled())
expAmount = 0D;
else
expAmount = JobsExpGainEvent.getExp();
Jobs.getEconomy().pay(jPlayer, amount, pointAmount, expAmount); Jobs.getEconomy().pay(jPlayer, amount, pointAmount, expAmount);
int oldLevel = prog.getLevel(); int oldLevel = prog.getLevel();
if (Jobs.getGCManager().LoggingUse) if (Jobs.getGCManager().LoggingUse)
Loging.recordToLog(jPlayer, info, amount, expAmount); Loging.recordToLog(jPlayer, info, amount, expAmount);
// JobsPayment event if (prog.addExperience(expAmount))
JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount);
Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent);
// If event is canceled, don't do anything
if (JobsExpGainEvent.isCancelled())
continue;
if (prog.addExperience(JobsExpGainEvent.getExp()))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
} }
} }

View File

@ -38,6 +38,7 @@ import com.gamingmesh.jobs.api.JobsJoinEvent;
import com.gamingmesh.jobs.api.JobsLeaveEvent; import com.gamingmesh.jobs.api.JobsLeaveEvent;
import com.gamingmesh.jobs.api.JobsLevelUpEvent; import com.gamingmesh.jobs.api.JobsLevelUpEvent;
import com.gamingmesh.jobs.container.BoostMultiplier; import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobCommands; import com.gamingmesh.jobs.container.JobCommands;
import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobItems;
@ -230,7 +231,7 @@ public class PlayerManager {
Job job = Jobs.getJob(jobdata.getJobName()); Job job = Jobs.getJob(jobdata.getJobName());
if (job == null) if (job == null)
continue; continue;
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1, -1); JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
jPlayer.progression.add(jobProgression); jPlayer.progression.add(jobProgression);
jPlayer.reloadMaxExperience(); jPlayer.reloadMaxExperience();
jPlayer.reloadLimits(); jPlayer.reloadLimits();
@ -570,76 +571,9 @@ public class PlayerManager {
return false; return false;
} }
/**
* Get job money boost
* @param player
* @param job
* @return double of boost
*/
public Double GetMoneyBoost(Player player, Job job) {
Double Boost = 1.0;
if (player != null && job.getName() != null) {
if (Perm.hasPermission(player, "jobs.boost." + job.getName() + ".money") ||
Perm.hasPermission(player, "jobs.boost." + job.getName() + ".all") ||
Perm.hasPermission(player, "jobs.boost.all.all") ||
Perm.hasPermission(player, "jobs.boost.all.money")) {
Boost = Jobs.getGCManager().BoostMoney;
}
}
return Boost;
}
public double GetMoneyBoostInPerc(Player player, Job job) { public double GetBoostInPerc(JobsPlayer player, Job job, BoostType type) {
double Boost = GetMoneyBoost(player, job) * 100.0 - 100.0; double Boost = player.getBoost(job.getName(), type) * 100.0 - 100.0;
return Boost;
}
/**
* Get job point boost
* @param player
* @param job
* @return double of boost
*/
public Double GetPointBoost(Player player, Job job) {
Double Boost = 1.0;
if (player != null && job.getName() != null) {
if (Perm.hasPermission(player, "jobs.boost." + job.getName() + ".points") ||
Perm.hasPermission(player, "jobs.boost." + job.getName() + ".all") ||
Perm.hasPermission(player, "jobs.boost.all.all") ||
Perm.hasPermission(player, "jobs.boost.all.points")) {
Boost = Jobs.getGCManager().BoostPoints;
}
}
return Boost;
}
public double GetPointBoostInPerc(Player player, Job job) {
double Boost = GetPointBoost(player, job) * 100.0 - 100.0;
return Boost;
}
/**
* Get job exp boost
* @param player
* @param job
* @return double of boost
*/
public Double GetExpBoost(Player player, Job job) {
Double Boost = 1.0;
if (player == null || job.getName() == null)
return 1.0;
if (Perm.hasPermission(player, "jobs.boost." + job.getName() + ".exp") ||
Perm.hasPermission(player, "jobs.boost." + job.getName() + ".all") ||
Perm.hasPermission(player, "jobs.boost.all.all") ||
Perm.hasPermission(player, "jobs.boost.all.exp")) {
Boost = Jobs.getGCManager().BoostExp;
}
return Boost;
}
public double GetExpBoostInPerc(Player player, Job job) {
double Boost = GetExpBoost(player, job) * 100.0 - 100.0;
return Boost; return Boost;
} }
@ -732,16 +666,16 @@ public class PlayerManager {
return new BoostMultiplier(0D, 0D, 0D); return new BoostMultiplier(0D, 0D, 0D);
} }
public BoostMultiplier getFinalBonus(Player player, Job prog) { public BoostMultiplier getFinalBonus(JobsPlayer player, Job prog) {
BoostMultiplier multiplier = new BoostMultiplier(0D, 0D, 0D); BoostMultiplier multiplier = new BoostMultiplier(0D, 0D, 0D);
if (player == null || prog == null) if (player == null || prog == null)
return multiplier; return multiplier;
double PMoneyBoost = Jobs.getPlayerManager().GetMoneyBoostInPerc(player, prog); double PMoneyBoost = Jobs.getPlayerManager().GetBoostInPerc(player, prog, BoostType.MONEY);
PMoneyBoost = (int) (PMoneyBoost * 100D) / 100D; PMoneyBoost = (int) (PMoneyBoost * 100D) / 100D;
double PPointBoost = Jobs.getPlayerManager().GetPointBoostInPerc(player, prog); double PPointBoost = Jobs.getPlayerManager().GetBoostInPerc(player, prog, BoostType.POINTS);
PPointBoost = (int) (PPointBoost * 100D) / 100D; PPointBoost = (int) (PPointBoost * 100D) / 100D;
double PExpBoost = Jobs.getPlayerManager().GetExpBoostInPerc(player, prog); double PExpBoost = Jobs.getPlayerManager().GetBoostInPerc(player, prog, BoostType.EXP);
PExpBoost = (int) (PExpBoost * 100D) / 100D; PExpBoost = (int) (PExpBoost * 100D) / 100D;
double GMoneyBoost = prog.getMoneyBoost() * 100.0 - 100.0; double GMoneyBoost = prog.getMoneyBoost() * 100.0 - 100.0;
@ -755,7 +689,7 @@ public class PlayerManager {
if (!Jobs.getGCManager().useDynamicPayment) if (!Jobs.getGCManager().useDynamicPayment)
DBoost = 0.0; DBoost = 0.0;
BoostMultiplier itemboost = Jobs.getPlayerManager().getItemBoost(player, prog); BoostMultiplier itemboost = Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog);
double IMoneyBoost = itemboost.getMoneyBoost() * 100.0 - 100.0; double IMoneyBoost = itemboost.getMoneyBoost() * 100.0 - 100.0;
IMoneyBoost = (int) (IMoneyBoost * 100D) / 100D; IMoneyBoost = (int) (IMoneyBoost * 100D) / 100D;
@ -764,7 +698,7 @@ public class PlayerManager {
double IExpBoost = itemboost.getExpBoost() * 100.0 - 100.0; double IExpBoost = itemboost.getExpBoost() * 100.0 - 100.0;
IExpBoost = (int) (IExpBoost * 100D) / 100D; IExpBoost = (int) (IExpBoost * 100D) / 100D;
double RBoost = Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player) * 100.0 - 100.0; double RBoost = Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer()) * 100.0 - 100.0;
RBoost = (int) (RBoost * 100D) / 100D; RBoost = (int) (RBoost * 100D) / 100D;
double Fmoney = (int) ((IMoneyBoost + DBoost + GMoneyBoost + PMoneyBoost + RBoost) * 100) / 100D; double Fmoney = (int) ((IMoneyBoost + DBoost + GMoneyBoost + PMoneyBoost + RBoost) * 100) / 100D;

View File

@ -30,6 +30,10 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
return this.points; return this.points;
} }
public void setPoints(double amount) {
this.points = amount;
}
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

View File

@ -426,9 +426,7 @@ public class JobsCommands implements CommandExecutor {
public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) { public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) {
// money exp boost // money exp boost
Player dude = Bukkit.getServer().getPlayer(player.getPlayerUUID()); BoostMultiplier finalBoost = Jobs.getPlayerManager().getFinalBonus(player, job);
BoostMultiplier finalBoost = Jobs.getPlayerManager().getFinalBonus(dude, job);
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();

View File

@ -7,7 +7,9 @@ import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.BoostMultiplier; import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
public class bonus implements Cmd { public class bonus implements Cmd {
@ -33,12 +35,17 @@ public class bonus implements Cmd {
return true; return true;
} }
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return false;
// sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", job.getChatColor() + job.getName())); // sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", job.getChatColor() + job.getName()));
double PMoneyBoost = Jobs.getPlayerManager().GetMoneyBoostInPerc(player, job); double PMoneyBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.MONEY);
PMoneyBoost = (int) (PMoneyBoost * 100D) / 100D; PMoneyBoost = (int) (PMoneyBoost * 100D) / 100D;
double PPointBoost = Jobs.getPlayerManager().GetPointBoostInPerc(player, job); double PPointBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.POINTS);
PPointBoost = (int) (PPointBoost * 100D) / 100D; PPointBoost = (int) (PPointBoost * 100D) / 100D;
double PExpBoost = Jobs.getPlayerManager().GetExpBoostInPerc(player, job); double PExpBoost = Jobs.getPlayerManager().GetBoostInPerc(jPlayer, job, BoostType.EXP);
PExpBoost = (int) (PExpBoost * 100D) / 100D; PExpBoost = (int) (PExpBoost * 100D) / 100D;
double GMoneyBoost = job.getMoneyBoost() * 100.0 - 100.0; double GMoneyBoost = job.getMoneyBoost() * 100.0 - 100.0;

View File

@ -33,6 +33,7 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.container.BoostType;
import com.gamingmesh.jobs.container.LocaleReader; import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.container.Schedule; import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.dao.JobsDAOMySQL; import com.gamingmesh.jobs.dao.JobsDAOMySQL;
@ -109,11 +110,11 @@ public class GeneralConfigManager {
useGlobalBoostScheduler, JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin; useGlobalBoostScheduler, JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin;
public Integer levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume, public Integer levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume,
SoundTitleChangePitch, ToplistInScoreboardInterval; SoundTitleChangePitch, ToplistInScoreboardInterval;
public double BoostExp;
public double MinimumOveralPaymentLimit; public double MinimumOveralPaymentLimit;
public double MinimumOveralPointsLimit; public double MinimumOveralPointsLimit;
public double BoostMoney;
public double BoostPoints; public HashMap <BoostType, Double> Boost = new HashMap <BoostType, Double>();
public double DynamicPaymentMaxPenalty; public double DynamicPaymentMaxPenalty;
public double DynamicPaymentMaxBonus; public double DynamicPaymentMaxBonus;
public double TaxesAmount; public double TaxesAmount;
@ -734,9 +735,9 @@ public class GeneralConfigManager {
"Use: jobs.boost.[jobname].money or jobs.boost.[jobname].exp or jobs.boost.[jobname].points or jobs.boost.[jobname].all for all of them with specific jobs name.", "Use: jobs.boost.[jobname].money or jobs.boost.[jobname].exp or jobs.boost.[jobname].points or jobs.boost.[jobname].all for all of them with specific jobs name.",
"Use: jobs.boost.all.money or jobs.boost.all.exp or jobs.boost.all.points or jobs.boost.all.all to get boost for all jobs", "Use: jobs.boost.all.money or jobs.boost.all.exp or jobs.boost.all.points or jobs.boost.all.all to get boost for all jobs",
"1.25 means that player will get 25% more than others, you can set less than 1 to get less from anothers"); "1.25 means that player will get 25% more than others, you can set less than 1 to get less from anothers");
BoostExp = c.get("boost.exp", 1.00); Boost.put(BoostType.EXP, c.get("boost.exp", 1.00));
BoostMoney = c.get("boost.money", 1.00); Boost.put(BoostType.MONEY, c.get("boost.money", 1.00));
BoostPoints = c.get("boost.points", 1.00); Boost.put(BoostType.POINTS, c.get("boost.points", 1.00));
c.getW().addComment("old-job", "Old job save", "Players can leave job and return later with some level loss during that", c.getW().addComment("old-job", "Old job save", "Players can leave job and return later with some level loss during that",
"You can fix players level if hes job level is at max level"); "You can fix players level if hes job level is at max level");

View File

@ -32,3 +32,5 @@
/ShopItem.class /ShopItem.class
/LocaleReader.class /LocaleReader.class
/BoostMultiplier.class /BoostMultiplier.class
/BoostCounter.class
/BoostType.class

View File

@ -0,0 +1,33 @@
package com.gamingmesh.jobs.container;
public class BoostCounter {
BoostType type;
double boost;
Long calculatedon;
public BoostCounter(BoostType type, double boost, Long calculatedon) {
this.type = type;
this.boost = boost;
this.calculatedon = calculatedon;
}
public BoostType getType() {
return this.type;
}
public long getTime() {
return this.calculatedon;
}
public double getBoost() {
return this.boost;
}
public void setTime(long time) {
this.calculatedon = time;
}
public void setBoost(double boost) {
this.boost = boost;
}
}

View File

@ -0,0 +1,34 @@
/**
* Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs.container;
public enum BoostType {
MONEY("Money"),
EXP("Exp"),
POINTS("Points");
private String name;
private BoostType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -26,18 +26,12 @@ public class JobProgression {
private double experience; private double experience;
private int level; private int level;
private transient int maxExperience = -1; private transient int maxExperience = -1;
private double MoneyBoost = -1;
private double PointBoost = -1;
private double ExpBoost = -1;
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience, double MoneyBoost, double PointBoost, double ExpBoost) { public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
this.job = job; this.job = job;
this.jPlayer = jPlayer; this.jPlayer = jPlayer;
this.experience = experience; this.experience = experience;
this.level = level; this.level = level;
this.MoneyBoost = MoneyBoost;
this.PointBoost = PointBoost;
this.ExpBoost = ExpBoost;
} }
/** /**
@ -49,36 +43,6 @@ public class JobProgression {
return experience >= maxExperience; return experience >= maxExperience;
} }
/**
* Return the MoneyBoost
* @return the MoneyBoost
*/
public double getMoneyBoost() {
if (this.MoneyBoost == -1)
this.MoneyBoost = JobsPlayer.getMoneyBoost(this.job.getName(), this.jPlayer.getPlayer());
return this.MoneyBoost;
}
/**
* Return the PointBoost
* @return the PointBoost
*/
public double getPointBoost() {
if (this.PointBoost == -1)
this.PointBoost = JobsPlayer.getPointBoost(this.job.getName(), this.jPlayer.getPlayer());
return this.PointBoost;
}
/**
* Return the ExpBoost
* @return the ExpBoost
*/
public double getExpBoost() {
if (this.ExpBoost == -1)
this.ExpBoost = JobsPlayer.getExpBoost(this.job.getName(), this.jPlayer.getPlayer());
return this.ExpBoost;
}
/** /**
* Return the job * Return the job
* @return the job * @return the job

View File

@ -20,6 +20,7 @@ package com.gamingmesh.jobs.container;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -32,6 +33,7 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.dao.JobsDAOData;
import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.Perm; import com.gamingmesh.jobs.stuff.Perm;
public class JobsPlayer { public class JobsPlayer {
@ -40,6 +42,9 @@ public class JobsPlayer {
// progression of the player in each job // progression of the player in each job
private UUID playerUUID; private UUID playerUUID;
public ArrayList<JobProgression> progression = new ArrayList<JobProgression>(); public ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
private HashMap<String, ArrayList<BoostCounter>> boostCounter = new HashMap<String, ArrayList<BoostCounter>>();
// display honorific // display honorific
private String honorific; private String honorific;
// player save status // player save status
@ -87,7 +92,7 @@ public class JobsPlayer {
continue; continue;
// create the progression object // create the progression object
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1, -1); JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
// calculate the max level // calculate the max level
// add the progression level. // add the progression level.
jPlayer.progression.add(jobProgression); jPlayer.progression.add(jobProgression);
@ -118,7 +123,7 @@ public class JobsPlayer {
continue; continue;
// create the progression object // create the progression object
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1, -1); JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
// calculate the max level // calculate the max level
// add the progression level. // add the progression level.
jPlayer.progression.add(jobProgression); jPlayer.progression.add(jobProgression);
@ -200,48 +205,60 @@ public class JobsPlayer {
} }
/** /**
* Get the MoneyBoost * Get the Boost
* @return the MoneyBoost * @return the Boost
*/ */
public static double getMoneyBoost(String JobName, Player player) { public double getBoost(String JobName, BoostType type) {
double MoneyBoost = 1.0;
if (JobName != null) { if (this.player == null)
if (Perm.hasPermission(player, "jobs.boost." + JobName + ".money") || Perm.hasPermission(player, "jobs.boost." + JobName + ".both") || Perm.hasPermission( this.player = Bukkit.getPlayer(this.OffPlayer.getUniqueId());
player, "jobs.boost.all.both") || Perm.hasPermission(player, "jobs.boost.all.money")) {
MoneyBoost = Jobs.getGCManager().BoostMoney; double Boost = 1.0;
if (this.player == null)
return Boost;
long time = System.currentTimeMillis();
if (this.boostCounter.containsKey(JobName)) {
ArrayList<BoostCounter> counterList = boostCounter.get(JobName);
for (BoostCounter counter : counterList) {
if (counter.getType() != type)
continue;
if (time - counter.getTime() > 1000 * 60) {
Boost = getPlayerBoost(JobName, type);
counter.setBoost(Boost);
counter.setTime(time);
return Boost;
} else {
return counter.getBoost();
}
} }
Boost = getPlayerBoost(JobName, type);
counterList.add(new BoostCounter(type, Boost, time));
return Boost;
} }
return MoneyBoost;
Boost = getPlayerBoost(JobName, type);
ArrayList<BoostCounter> counterList = new ArrayList<BoostCounter>();
counterList.add(new BoostCounter(type, Boost, time));
boostCounter.put(JobName, counterList);
return Boost;
} }
/** private Double getPlayerBoost(String JobName, BoostType type) {
* Get the PointBoost double Boost = 1.0;
* @return the PointBoost Debug.D("recalculating for " + JobName);
*/ if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) ||
public static double getPointBoost(String JobName, Player player) { Perm.hasPermission(player, "jobs.boost." + JobName + ".all") ||
double PointBoost = 1.0; Perm.hasPermission(player, "jobs.boost.all.all") ||
if (JobName != null) { Perm.hasPermission(player, "jobs.boost.all." + type.getName().toLowerCase())) {
if (Perm.hasPermission(player, "jobs.boost." + JobName + ".points") || Perm.hasPermission(player, "jobs.boost." + JobName + ".both") || Perm.hasPermission( Boost = Jobs.getGCManager().Boost.get(type);
player, "jobs.boost.all.both") || Perm.hasPermission(player, "jobs.boost.all.money")) {
PointBoost = Jobs.getGCManager().BoostPoints;
}
} }
return PointBoost; return Boost;
}
/**
* Get the ExpBoost
* @return the ExpBoost
*/
public static double getExpBoost(String JobName, Player player) {
Double ExpBoost = 1.0;
if (player == null || JobName == null)
return 1.0;
if (Perm.hasPermission(player, "jobs.boost." + JobName + ".exp") || Perm.hasPermission(player, "jobs.boost." + JobName + ".both") || Perm.hasPermission(player,
"jobs.boost.all.both") || Perm.hasPermission(player, "jobs.boost.all.exp")) {
ExpBoost = Jobs.getGCManager().BoostExp;
}
return ExpBoost;
} }
/** /**
@ -382,7 +399,7 @@ public class JobsPlayer {
Jobs.getJobsDAO().deleteArchive(jPlayer, job); Jobs.getJobsDAO().deleteArchive(jPlayer, job);
} }
progression.add(new JobProgression(job, this, level, exp, -1, -1, -1)); progression.add(new JobProgression(job, this, level, exp));
reloadMaxExperience(); reloadMaxExperience();
reloadLimits(); reloadLimits();
reloadHonorific(); reloadHonorific();

View File

@ -521,6 +521,12 @@ public class JobsDAOMySQL extends JobsDAO {
} }
} }
} }
// Create new points table
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "points` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (SQLException e) {
}
if (rows == 0) { if (rows == 0) {
HashMap<String, String> tempMap = new HashMap<String, String>(); HashMap<String, String> tempMap = new HashMap<String, String>();
@ -664,13 +670,7 @@ public class JobsDAOMySQL extends JobsDAO {
executeSQL("ALTER TABLE `" + getPrefix() + "log` DROP COLUMN `player_uuid`, DROP COLUMN `username`;"); executeSQL("ALTER TABLE `" + getPrefix() + "log` DROP COLUMN `player_uuid`, DROP COLUMN `username`;");
} catch (Exception e) { } catch (Exception e) {
} }
// Create new points table
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "points` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }

View File

@ -29,6 +29,7 @@ import org.bukkit.Bukkit;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.container.PlayerInfo;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.UUIDUtil; import com.gamingmesh.jobs.stuff.UUIDUtil;
public class JobsDAOSQLite extends JobsDAO { public class JobsDAOSQLite extends JobsDAO {
@ -503,6 +504,7 @@ public class JobsDAOSQLite extends JobsDAO {
@Override @Override
protected synchronized void checkUpdate9() throws SQLException { protected synchronized void checkUpdate9() throws SQLException {
Debug.D("checkling 9");
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) { if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to SQLite!"); Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to SQLite!");
@ -527,6 +529,13 @@ public class JobsDAOSQLite extends JobsDAO {
} }
} }
// Create new points table
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "points` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (Exception e) {
}
if (rows != 0) if (rows != 0)
return; return;
@ -788,13 +797,7 @@ public class JobsDAOSQLite extends JobsDAO {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// Create new points table
try {
executeSQL("CREATE TABLE `" + getPrefix()
+ "points` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `userid` int, `totalpoints` double, `currentpoints` double);");
} catch (Exception e) {
e.printStackTrace();
}
} }

View File

@ -167,8 +167,8 @@ public class BufferedEconomy {
if (JobsPaymentEvent.isCancelled()) if (JobsPaymentEvent.isCancelled())
continue; continue;
double newAmount = JobsPaymentEvent.getAmount(); payment.setAmount(JobsPaymentEvent.getAmount());
payment.setAmount(newAmount); payment.setPoints(JobsPaymentEvent.getPoints());
if (Jobs.getGCManager().UseServerAccount) { if (Jobs.getGCManager().UseServerAccount) {
if (!hasMoney) { if (!hasMoney) {
@ -184,7 +184,6 @@ public class BufferedEconomy {
if (Jobs.getGCManager().isEconomyAsync()) if (Jobs.getGCManager().isEconomyAsync())
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i); Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
else else
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
} }
try { try {

View File

@ -251,7 +251,7 @@ public class JobsPaymentListener implements Listener {
if (block == null) if (block == null)
return; return;
if (block.getType().equals(Material.FURNACE) && block.hasMetadata(furnaceOwnerMetadata)) if (block.getType() == Material.FURNACE && block.hasMetadata(furnaceOwnerMetadata))
block.removeMetadata(furnaceOwnerMetadata, plugin); block.removeMetadata(furnaceOwnerMetadata, plugin);
if (Jobs.getGCManager().useBlockProtection) if (Jobs.getGCManager().useBlockProtection)
@ -278,7 +278,7 @@ public class JobsPaymentListener implements Listener {
return; return;
// check if in creative // check if in creative
if (player.getGameMode().equals(GameMode.CREATIVE) && !Jobs.getGCManager().payInCreative()) if (player.getGameMode()== GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
return; return;
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))

View File

@ -1,7 +1,7 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin main: com.gamingmesh.jobs.JobsPlugin
version: 3.4.3 version: 3.4.5
author: phrstbrn author: phrstbrn
depend: [Vault] depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO] softdepend: [CoreProtect, MythicMobs, McMMO]