1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Slime split protection

This commit is contained in:
Zrips 2015-09-10 13:41:19 +03:00
parent 0dcb81210d
commit 401c6c1c6d
15 changed files with 4190 additions and 3935 deletions

File diff suppressed because it is too large Load Diff

View File

@ -44,10 +44,11 @@ public class PermissionHandler {
if (jPlayer == null)
return;
Player player = (Player) jPlayer.getPlayer();
if (player == null)
Player player = this.plugin.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player == null) {
return;
}
boolean changed = false;

View File

@ -52,39 +52,38 @@ public class PlayerManager {
* Handles join of new player
* @param playername
*/
public void playerJoin(final Player player) {
//synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
players.put(player.getName().toLowerCase(), jPlayer);
public void playerJoin(Player player) {
synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
players.put(player.getName().toLowerCase(), jPlayer);
}
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
}
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
//}
}
/**
* Handles player quit
* @param playername
*/
public void playerQuit(Player player) {
//synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
}
}
}
//}
}
/**

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -18,3 +18,5 @@
/JobsLeaveEvent.class
/NameList.class
/Schedule.class
/Log.class
/LogAmounts.class

View File

@ -34,464 +34,478 @@ import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Perm;
public class JobsPlayer {
// the player the object belongs to
private String userName;
// progression of the player in each job
private UUID playerUUID;
private ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
// display honorific
private String honorific;
// player save status
private volatile boolean isSaved = true;
// player online status
private volatile boolean isOnline = false;
// the player the object belongs to
private String userName;
// progression of the player in each job
private UUID playerUUID;
private ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
// display honorific
private String honorific;
// player save status
private volatile boolean isSaved = true;
// player online status
private volatile boolean isOnline = false;
private OfflinePlayer player = null;
private OfflinePlayer player = null;
private double VipSpawnerMultiplier = -1;
private double VipSpawnerMultiplier = -1;
// save lock
public final Object saveLock = new Object();
// save lock
public final Object saveLock = new Object();
// log
private List<Log> logList = new ArrayList<Log>();
private JobsPlayer(String userName, OfflinePlayer player) {
this.userName = userName;
this.player = player;
private JobsPlayer(String userName, OfflinePlayer player) {
this.userName = userName;
this.player = player;
}
public static JobsPlayer loadFromDao(JobsDAO dao, OfflinePlayer player) {
JobsPlayer jPlayer = new JobsPlayer(player.getName(), player);
jPlayer.playerUUID = player.getUniqueId();
List<JobsDAOData> list = dao.getAllJobs(player);
synchronized (jPlayer.saveLock) {
jPlayer.progression.clear();
for (JobsDAOData jobdata : list) {
if (Jobs.getJob(jobdata.getJobName()) == null)
continue;
// add the job
Job job = Jobs.getJob(jobdata.getJobName());
if (job == null)
continue;
// create the progression object
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1);
// calculate the max level
// add the progression level.
jPlayer.progression.add(jobProgression);
}
jPlayer.reloadMaxExperience();
}
return jPlayer;
}
public List<Log> getLog() {
return this.logList;
}
/**
* Get the player
* @return the player
*/
public OfflinePlayer getPlayer() {
return this.player;
}
public static JobsPlayer loadFromDao(JobsDAO dao, OfflinePlayer player) {
/**
* Get the VipSpawnerMultiplier
* @return the Multiplier
*/
public double getVipSpawnerMultiplier() {
if (!this.player.isOnline())
return 1.0;
if (VipSpawnerMultiplier < 0)
updateVipSpawnerMultiplier();
return this.VipSpawnerMultiplier;
}
JobsPlayer jPlayer = new JobsPlayer(player.getName(), player);
jPlayer.playerUUID = player.getUniqueId();
List<JobsDAOData> list = dao.getAllJobs(player);
//synchronized (jPlayer.saveLock) {
jPlayer.progression.clear();
for (JobsDAOData jobdata : list) {
if (Jobs.getJob(jobdata.getJobName()) == null)
continue;
// add the job
Job job = Jobs.getJob(jobdata.getJobName());
if (job == null)
continue;
public void updateVipSpawnerMultiplier() {
if (Perm.hasPermission(this.player, "jobs.vipspawner"))
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().VIPpayNearSpawnerMultiplier;
else
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().payNearSpawnerMultiplier;
}
// create the progression object
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1);
// calculate the max level
// add the progression level.
jPlayer.progression.add(jobProgression);
/**
* Get the MoneyBoost
* @return the MoneyBoost
*/
public static double getMoneyBoost(String JobName, OfflinePlayer player) {
double MoneyBoost = 1.0;
if (JobName != null) {
if (Perm.hasPermission(player, "jobs.boost." + JobName + ".money") || Perm.hasPermission(player, "jobs.boost." + JobName + ".both") || Perm.hasPermission(
player, "jobs.boost.all.both") || Perm.hasPermission(player, "jobs.boost.all.money")) {
MoneyBoost = ConfigManager.getJobsConfiguration().BoostMoney;
}
}
return MoneyBoost;
}
/**
* Get the MoneyBoost
* @return the MoneyBoost
*/
public static double getExpBoost(String JobName, OfflinePlayer 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 = ConfigManager.getJobsConfiguration().BoostExp;
}
return ExpBoost;
}
/**
* Reloads max experience for this job.
*/
private void reloadMaxExperience() {
for (JobProgression prog : progression) {
prog.reloadMaxExperience();
}
}
/**
* Get the list of job progressions
* @return the list of job progressions
*/
public List<JobProgression> getJobProgression() {
return Collections.unmodifiableList(progression);
}
/**
* Check if have permission
* @return true if have
*/
public boolean havePermission(String perm) {
if (this.isOnline)
return ((Player) player).hasPermission(perm);
return false;
}
/**
* Get the job progression with the certain job
* @return the job progression
*/
public JobProgression getJobProgression(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
return prog;
}
return null;
}
/**
* get the userName
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* get the playerUUID
* @return the playerUUID
*/
public UUID getPlayerUUID() {
return playerUUID;
}
public String getDisplayHonorific() {
return honorific;
}
/**
* Player joins a job
* @param job - the job joined
*/
public boolean joinJob(Job job, JobsPlayer jPlayer) {
synchronized (saveLock) {
if (!isInJob(job)) {
int level = 1;
int exp = 0;
if (Jobs.getJobsDAO().checkArchive(jPlayer, job).size() > 0) {
List<Integer> info = Jobs.getJobsDAO().checkArchive(jPlayer, job);
level = info.get(0);
//exp = info.get(1);
Jobs.getJobsDAO().deleteArchive(jPlayer, job);
}
jPlayer.reloadMaxExperience();
//}
return jPlayer;
}
/**
* Get the player
* @return the player
*/
public OfflinePlayer getPlayer() {
return this.player;
progression.add(new JobProgression(job, this, level, exp, -1, -1));
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
}
return false;
}
}
/**
* Get the VipSpawnerMultiplier
* @return the Multiplier
*/
public double getVipSpawnerMultiplier() {
if (!this.player.isOnline())
return 1.0;
if (VipSpawnerMultiplier < 0)
updateVipSpawnerMultiplier();
return this.VipSpawnerMultiplier;
/**
* Player leaves a job
* @param job - the job left
*/
public boolean leaveJob(Job job) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog != null) {
progression.remove(prog);
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
}
return false;
}
}
public void updateVipSpawnerMultiplier() {
if (Perm.hasPermission(this.player, "jobs.vipspawner"))
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().VIPpayNearSpawnerMultiplier;
else
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().payNearSpawnerMultiplier;
/**
* Leave all jobs
* @return on success
*/
public boolean leaveAllJobs() {
synchronized (saveLock) {
progression.clear();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
;
return true;
}
}
/**
* Get the MoneyBoost
* @return the MoneyBoost
*/
public static double getMoneyBoost(String JobName, OfflinePlayer player) {
double MoneyBoost = 1.0;
if (JobName != null) {
if (Perm.hasPermission(player, "jobs.boost." + JobName + ".money") || Perm.hasPermission(player, "jobs.boost." + JobName + ".both") || Perm.hasPermission(player, "jobs.boost.all.both") || Perm.hasPermission(player, "jobs.boost.all.money")) {
MoneyBoost = ConfigManager.getJobsConfiguration().BoostMoney;
}
}
return MoneyBoost;
/**
* Promotes player in job
* @param job - the job being promoted
* @param levels - number of levels to promote
*/
public void promoteJob(Job job, int levels, JobsPlayer player) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (levels <= 0)
return;
int newLevel = prog.getLevel() + levels;
int maxLevel = job.getMaxLevel();
if (player.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
if (maxLevel > 0 && newLevel > maxLevel) {
newLevel = maxLevel;
}
setLevel(job, newLevel);
}
}
/**
* Get the MoneyBoost
* @return the MoneyBoost
*/
public static double getExpBoost(String JobName, OfflinePlayer 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 = ConfigManager.getJobsConfiguration().BoostExp;
}
return ExpBoost;
/**
* Demotes player in job
* @param job - the job being deomoted
* @param levels - number of levels to demote
*/
public void demoteJob(Job job, int levels) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (levels <= 0)
return;
int newLevel = prog.getLevel() - levels;
if (newLevel < 1) {
newLevel = 1;
}
setLevel(job, newLevel);
}
}
/**
* Reloads max experience for this job.
*/
private void reloadMaxExperience() {
/**
* Sets player to a specific level
* @param job - the job
* @param level - the level
*/
private void setLevel(Job job, int level) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (level != prog.getLevel()) {
prog.setLevel(level);
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
;
}
}
}
/**
* Player leaves a job
* @param oldjob - the old job
* @param newjob - the new job
*/
public boolean transferJob(Job oldjob, Job newjob, JobsPlayer jPlayer) {
synchronized (saveLock) {
if (!isInJob(newjob)) {
for (JobProgression prog : progression) {
prog.reloadMaxExperience();
if (!prog.getJob().equals(oldjob))
continue;
prog.setJob(newjob);
int maxLevel = 0;
if (jPlayer.havePermission("jobs." + newjob.getName() + ".vipmaxlevel"))
maxLevel = newjob.getVipMaxLevel();
else
maxLevel = newjob.getMaxLevel();
if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) {
prog.setLevel(maxLevel);
}
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
;
return true;
}
}
return false;
}
}
/**
* Get the list of job progressions
* @return the list of job progressions
*/
public List<JobProgression> getJobProgression() {
return Collections.unmodifiableList(progression);
/**
* Checks if the player is in this job.
* @param job - the job
* @return true - they are in the job
* @return false - they are not in the job
*/
public boolean isInJob(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
return true;
}
return false;
}
/**
* Check if have permission
* @return true if have
*/
public boolean havePermission(String perm) {
if (this.isOnline)
return ((Player) player).hasPermission(perm);
return false;
}
/**
* Function that reloads your honorific
*/
public void reloadHonorific() {
StringBuilder builder = new StringBuilder();
int numJobs = progression.size();
boolean gotTitle = false;
/**
* Get the job progression with the certain job
* @return the job progression
*/
public JobProgression getJobProgression(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
return prog;
if (numJobs > 0)
for (JobProgression prog : progression) {
DisplayMethod method = prog.getJob().getDisplayMethod();
if (method.equals(DisplayMethod.NONE))
continue;
if (gotTitle) {
builder.append(" ");
gotTitle = false;
}
return null;
}
Title title = ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel(), prog.getJob().getName());
/**
* get the userName
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* get the playerUUID
* @return the playerUUID
*/
public UUID getPlayerUUID() {
return playerUUID;
}
public String getDisplayHonorific() {
return honorific;
}
/**
* Player joins a job
* @param job - the job joined
*/
public boolean joinJob(Job job, JobsPlayer jPlayer) {
synchronized (saveLock) {
if (!isInJob(job)) {
int level = 1;
int exp = 0;
if (Jobs.getJobsDAO().checkArchive(jPlayer, job).size() > 0) {
List<Integer> info = Jobs.getJobsDAO().checkArchive(jPlayer, job);
level = info.get(0);
//exp = info.get(1);
Jobs.getJobsDAO().deleteArchive(jPlayer, job);
}
progression.add(new JobProgression(job, this, level, exp, -1, -1));
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
if (numJobs == 1) {
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
if (title != null) {
String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
return false;
}
}
/**
* Player leaves a job
* @param job - the job left
*/
public boolean leaveJob(Job job) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog != null) {
progression.remove(prog);
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
}
return false;
}
}
/**
* Leave all jobs
* @return on success
*/
public boolean leaveAllJobs() {
synchronized (saveLock) {
progression.clear();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);;
return true;
}
}
/**
* Promotes player in job
* @param job - the job being promoted
* @param levels - number of levels to promote
*/
public void promoteJob(Job job, int levels, JobsPlayer player) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (levels <= 0)
return;
int newLevel = prog.getLevel() + levels;
int maxLevel = job.getMaxLevel();
if (player.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
if (maxLevel > 0 && newLevel > maxLevel) {
newLevel = maxLevel;
}
setLevel(job, newLevel);
}
}
/**
* Demotes player in job
* @param job - the job being deomoted
* @param levels - number of levels to demote
*/
public void demoteJob(Job job, int levels) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (levels <= 0)
return;
int newLevel = prog.getLevel() - levels;
if (newLevel < 1) {
newLevel = 1;
}
setLevel(job, newLevel);
}
}
/**
* Sets player to a specific level
* @param job - the job
* @param level - the level
*/
private void setLevel(Job job, int level) {
synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (level != prog.getLevel()) {
prog.setLevel(level);
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);;
}
}
}
/**
* Player leaves a job
* @param oldjob - the old job
* @param newjob - the new job
*/
public boolean transferJob(Job oldjob, Job newjob, JobsPlayer jPlayer) {
synchronized (saveLock) {
if (!isInJob(newjob)) {
for (JobProgression prog : progression) {
if (!prog.getJob().equals(oldjob))
continue;
prog.setJob(newjob);
int maxLevel = 0;
if (jPlayer.havePermission("jobs." + newjob.getName() + ".vipmaxlevel"))
maxLevel = newjob.getVipMaxLevel();
else
maxLevel = newjob.getMaxLevel();
if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) {
prog.setLevel(maxLevel);
}
reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);;
return true;
}
}
return false;
}
}
/**
* Checks if the player is in this job.
* @param job - the job
* @return true - they are in the job
* @return false - they are not in the job
*/
public boolean isInJob(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
return true;
}
return false;
}
/**
* Function that reloads your honorific
*/
public void reloadHonorific() {
StringBuilder builder = new StringBuilder();
int numJobs = progression.size();
boolean gotTitle = false;
if (numJobs > 0)
for (JobProgression prog : progression) {
DisplayMethod method = prog.getJob().getDisplayMethod();
if (method.equals(DisplayMethod.NONE))
continue;
if (gotTitle) {
builder.append(" ");
gotTitle = false;
}
Title title = ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel(), prog.getJob().getName());
if (numJobs == 1) {
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
if (title != null) {
String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) {
if (gotTitle) {
builder.append(" ");
}
String honorificpart = prog.getJob().getChatColor() + prog.getJob().getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(DisplayMethod.SHORT_TITLE)) {
// add title to honorific
if (title != null) {
String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(DisplayMethod.SHORT_JOB)) {
String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
else {
Job nonejob = Jobs.getNoneJob();
if (nonejob != null) {
DisplayMethod metod = nonejob.getDisplayMethod();
if (metod.equals(DisplayMethod.FULL) || metod.equals(DisplayMethod.TITLE)) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
if (metod.equals(DisplayMethod.SHORT_FULL) || metod.equals(DisplayMethod.SHORT_TITLE) || metod.equals(DisplayMethod.SHORT_JOB)) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
}
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) {
if (gotTitle) {
builder.append(" ");
}
String honorificpart = prog.getJob().getChatColor() + prog.getJob().getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
honorific = builder.toString().trim();
}
/**
* Performs player save
* @param dao
*/
public void save(JobsDAO dao) {
synchronized (saveLock) {
if (!isSaved()) {
dao.save(this);
setSaved(true);
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(
DisplayMethod.SHORT_TITLE)) {
// add title to honorific
if (title != null) {
String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(
DisplayMethod.SHORT_JOB)) {
String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
else {
Job nonejob = Jobs.getNoneJob();
if (nonejob != null) {
DisplayMethod metod = nonejob.getDisplayMethod();
if (metod.equals(DisplayMethod.FULL) || metod.equals(DisplayMethod.TITLE)) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
if (metod.equals(DisplayMethod.SHORT_FULL) || metod.equals(DisplayMethod.SHORT_TITLE) || metod.equals(DisplayMethod.SHORT_JOB)) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
}
}
/**
* Perform connect
*/
public void onConnect() {
isOnline = true;
}
honorific = builder.toString().trim();
}
/**
* Perform disconnect
*
*/
public void onDisconnect() {
isOnline = false;
/**
* Performs player save
* @param dao
*/
public void save(JobsDAO dao) {
synchronized (saveLock) {
if (!isSaved()) {
dao.save(this);
setSaved(true);
}
}
}
/**
* Whether or not player is online
* @return true if online, otherwise false
*/
public boolean isOnline() {
return isOnline;
}
/**
* Perform connect
*/
public void onConnect() {
isOnline = true;
}
public boolean isSaved() {
return isSaved;
}
/**
* Perform disconnect
*
*/
public void onDisconnect() {
isOnline = false;
}
public void setSaved(boolean value) {
isSaved = value;
}
/**
* Whether or not player is online
* @return true if online, otherwise false
*/
public boolean isOnline() {
return isOnline;
}
public boolean isSaved() {
return isSaved;
}
public void setSaved(boolean value) {
isSaved = value;
}
}

View File

@ -39,161 +39,162 @@ import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
public class BufferedEconomy {
private JobsPlugin plugin;
private Economy economy;
private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<BufferedPayment>();
private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>());
private JobsPlugin plugin;
private Economy economy;
private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<BufferedPayment>();
private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>());
private OfflinePlayer ServerAccount = null;
private OfflinePlayer ServerTaxesAccount = null;
private OfflinePlayer ServerAccount = null;
private OfflinePlayer ServerTaxesAccount = null;
PaymentData PaymentData = new PaymentData();
PaymentData PaymentData = new PaymentData();
public BufferedEconomy(JobsPlugin plugin, Economy economy) {
this.plugin = plugin;
this.economy = economy;
}
public BufferedEconomy(JobsPlugin plugin, Economy economy) {
this.plugin = plugin;
this.economy = economy;
}
/**
* Add payment to player's payment buffer
* @param player - player to be paid
* @param amount - amount to be paid
*/
public void pay(JobsPlayer player, double amount, double exp) {
if (amount == 0)
return;
pay(new BufferedPayment(player.getPlayer(), amount, exp));
}
/**
* Add payment to player's payment buffer
* @param player - player to be paid
* @param amount - amount to be paid
*/
public void pay(JobsPlayer player, double amount, double exp) {
if (amount == 0)
return;
pay(new BufferedPayment(player.getPlayer(), amount, exp));
}
/**
* Add payment to player's payment buffer
* @param payment - payment to be paid
*/
public void pay(BufferedPayment payment) {
payments.add(payment);
}
/**
* Add payment to player's payment buffer
* @param payment - payment to be paid
*/
public void pay(BufferedPayment payment) {
payments.add(payment);
}
public String format(double money) {
return economy.format(money);
}
public String format(double money) {
return economy.format(money);
}
/**
* Payout all players the amount they are going to be paid
*/
@SuppressWarnings("deprecation")
public void payAll() {
if (payments.isEmpty())
return;
/**
* Payout all players the amount they are going to be paid
*/
@SuppressWarnings("deprecation")
public void payAll() {
if (payments.isEmpty())
return;
synchronized (paymentCache) {
synchronized (paymentCache) {
Double TotalAmount = 0.0;
Double TaxesAmount = 0.0;
Double TotalAmount = 0.0;
Double TaxesAmount = 0.0;
// combine all payments using paymentCache
while (!payments.isEmpty()) {
BufferedPayment payment = payments.remove();
TotalAmount += payment.getAmount();
// combine all payments using paymentCache
while (!payments.isEmpty()) {
BufferedPayment payment = payments.remove();
TotalAmount += payment.getAmount();
if (ConfigManager.getJobsConfiguration().UseTaxes) {
TaxesAmount += payment.getAmount() * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0);
}
UUID uuid = payment.getOfflinePlayer().getUniqueId();
if (paymentCache.containsKey(uuid)) {
BufferedPayment existing = paymentCache.get(uuid);
double money = payment.getAmount();
double exp = payment.getExp();
if (ConfigManager.getJobsConfiguration().TakeFromPlayersPayment) {
money = money - (money * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0));
}
existing.setAmount(existing.getAmount() + money);
existing.setExp(existing.getExp() + exp);
} else {
double money = payment.getAmount();
if (ConfigManager.getJobsConfiguration().TakeFromPlayersPayment) {
payment.setAmount(money - (money * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0)));
}
paymentCache.put(uuid, payment);
}
}
boolean hasMoney = false;
String ServerAccountname = ConfigManager.getJobsConfiguration().ServerAcountName;
String ServerTaxesAccountname = ConfigManager.getJobsConfiguration().ServertaxesAcountName;
if (this.ServerAccount == null)
this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname);
if (this.ServerTaxesAccount == null)
this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerAccountname);
if (ConfigManager.getJobsConfiguration().UseTaxes && ConfigManager.getJobsConfiguration().TransferToServerAccount && ServerTaxesAccount != null) {
economy.depositPlayer(ServerTaxesAccount, TaxesAmount);
if (ServerTaxesAccount.isOnline()) {
if (!Jobs.actionbartoggle.containsKey(ServerTaxesAccountname) && ConfigManager.getJobsConfiguration().JobsToggleEnabled)
Jobs.actionbartoggle.put(ServerTaxesAccountname, true);
if (Jobs.actionbartoggle.containsKey(ServerTaxesAccountname) && Jobs.actionbartoggle.get(ServerTaxesAccountname)) {
ActionBar.send((Player) ServerTaxesAccount, Language.getMessage("message.taxes").replace("[amount]", String.valueOf((int) (TotalAmount * 100) / 100.0)));
}
}
}
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (economy.hasMoney(ServerAccountname, TotalAmount)) {
hasMoney = true;
economy.withdrawPlayer(ServerAccountname, TotalAmount);
}
}
// Schedule all payments
int i = 0;
for (BufferedPayment payment : paymentCache.values()) {
i++;
// JobsJoin event
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getAmount());
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
// If event is canceled, dont do anything
if (JobsPaymentEvent.isCancelled())
continue;
if (ConfigManager.getJobsConfiguration().isEconomyAsync()) {
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (!hasMoney) {
ActionBar.send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Language.getMessage("economy.error.nomoney"));
continue;
} else
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
} else
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
// Action bar stuff
ActionBar.ShowActionBar(payment);
} else {
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (!hasMoney) {
ActionBar.send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Language.getMessage("economy.error.nomoney"));
continue;
} else
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
} else
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
// Action bar stuff
ActionBar.ShowActionBar(payment);
}
}
// empty payment cache
paymentCache.clear();
if (ConfigManager.getJobsConfiguration().UseTaxes) {
TaxesAmount += payment.getAmount() * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0);
}
UUID uuid = payment.getOfflinePlayer().getUniqueId();
if (paymentCache.containsKey(uuid)) {
BufferedPayment existing = paymentCache.get(uuid);
double money = payment.getAmount();
double exp = payment.getExp();
if (ConfigManager.getJobsConfiguration().TakeFromPlayersPayment) {
money = money - (money * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0));
}
existing.setAmount(existing.getAmount() + money);
existing.setExp(existing.getExp() + exp);
} else {
double money = payment.getAmount();
if (ConfigManager.getJobsConfiguration().TakeFromPlayersPayment) {
payment.setAmount(money - (money * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0)));
}
paymentCache.put(uuid, payment);
}
}
boolean hasMoney = false;
String ServerAccountname = ConfigManager.getJobsConfiguration().ServerAcountName;
String ServerTaxesAccountname = ConfigManager.getJobsConfiguration().ServertaxesAcountName;
if (this.ServerAccount == null)
this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname);
if (this.ServerTaxesAccount == null)
this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerAccountname);
if (ConfigManager.getJobsConfiguration().UseTaxes && ConfigManager.getJobsConfiguration().TransferToServerAccount && ServerTaxesAccount != null) {
economy.depositPlayer(ServerTaxesAccount, TaxesAmount);
if (ServerTaxesAccount.isOnline()) {
if (!Jobs.actionbartoggle.containsKey(ServerTaxesAccountname) && ConfigManager.getJobsConfiguration().JobsToggleEnabled)
Jobs.actionbartoggle.put(ServerTaxesAccountname, true);
if (Jobs.actionbartoggle.containsKey(ServerTaxesAccountname) && Jobs.actionbartoggle.get(ServerTaxesAccountname)) {
ActionBar.send((Player) ServerTaxesAccount, Language.getMessage("message.taxes").replace("[amount]", String.valueOf((int) (TotalAmount * 100)
/ 100.0)));
}
}
}
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (economy.hasMoney(ServerAccountname, TotalAmount)) {
hasMoney = true;
economy.withdrawPlayer(ServerAccountname, TotalAmount);
}
}
// Schedule all payments
int i = 0;
for (BufferedPayment payment : paymentCache.values()) {
i++;
// JobsJoin event
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getAmount());
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
// If event is canceled, dont do anything
if (JobsPaymentEvent.isCancelled())
continue;
if (ConfigManager.getJobsConfiguration().isEconomyAsync()) {
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (!hasMoney) {
ActionBar.send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Language.getMessage("economy.error.nomoney"));
continue;
} else
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
} else
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
// Action bar stuff
ActionBar.ShowActionBar(payment);
} else {
if (ConfigManager.getJobsConfiguration().UseServerAccount) {
if (!hasMoney) {
ActionBar.send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Language.getMessage("economy.error.nomoney"));
continue;
} else
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
} else
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
// Action bar stuff
ActionBar.ShowActionBar(payment);
}
}
// empty payment cache
paymentCache.clear();
}
}
}

View File

@ -2,131 +2,170 @@ package com.gamingmesh.jobs.economy;
public class PaymentData {
Long time = 0L;
Long lastAnnouced = 0L;
Double Payment = 0.0;
public boolean Informed = false;
Long time = 0L;
Long lastAnnouced = 0L;
Double Payment = 0.0;
Double Exp = 0.0;
public boolean Informed = false;
public boolean Reseted = false;
public PaymentData(Long time, Double Payment, Long lastAnnouced, boolean Informed) {
this.time = time;
this.Payment = Payment;
this.lastAnnouced = lastAnnouced;
this.Informed = Informed;
}
public PaymentData() {
}
public Long GetTime() {
return this.time;
}
public Double GetAmount() {
return this.Payment;
}
public Double GetAmountBylimit(int limit) {
if (this.Payment > limit)
return (double) limit;
return (int) (this.Payment * 100) / 100.0;
}
public Long GetLastAnnounced() {
return this.lastAnnouced;
}
public boolean IsAnnounceTime(int time) {
if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis())
return false;
SetAnnouncmentTime();
return true;
}
public void SetAnnouncmentTime() {
this.lastAnnouced = System.currentTimeMillis();
}
public void AddNewAmount(Double Payment) {
this.time = System.currentTimeMillis();
this.Payment = Payment;
}
public void Setinformed() {
this.Informed = true;
}
public void SetNotInformed() {
this.Informed = false;
}
public void AddAmount(Double Payment) {
this.Payment = this.Payment + Payment;
}
public int GetLeftTime(int time) {
int left = 0;
if (this.time + (time * 1000) > System.currentTimeMillis())
left = (int) ((this.time + (time * 1000) - System.currentTimeMillis()) / 1000);
return left;
}
public boolean IsOverMoneyLimit(int limit) {
if (this.Payment < limit)
return false;
return true;
}
public boolean IsOverTimeLimit(int time) {
if (this.time + (time * 1000) > System.currentTimeMillis())
return false;
if (this.Informed)
this.Informed = false;
this.time = System.currentTimeMillis();
this.Payment = 0.0;
return true;
}
public boolean IsReachedLimit(int time, int limit) {
if (IsOverMoneyLimit(limit) && !IsOverTimeLimit(time))
return true;
return false;
}
public int GetLeftsec(int time) {
int lefttime1 = GetLeftTime(time);
int sec = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else
sec = lefttime1;
return sec;
}
public int GetLeftMin(int time) {
int lefttime1 = GetLeftTime(time);
int min = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
} else if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
return min;
}
public int GetLeftHour(int time) {
int lefttime1 = GetLeftTime(time);
int hour = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
}
return hour;
public PaymentData(Long time, Double Payment, Double Exp, Long lastAnnouced, boolean Informed) {
this.time = time;
this.Payment = Payment;
this.Exp = Exp;
this.lastAnnouced = lastAnnouced;
this.Informed = Informed;
}
public PaymentData() {
}
public Long GetTime() {
return this.time;
}
public void setReseted(boolean state) {
this.Reseted = state;
}
public boolean isReseted() {
return this.Reseted;
}
public Double GetAmount() {
return this.Payment;
}
public Double GetAmountBylimit(int limit) {
if (this.Payment > limit)
return (double) limit;
return (int) (this.Payment * 100) / 100.0;
}
public Double GetExpBylimit(int limit) {
if (this.Exp > limit)
return (double) limit;
return (int) (this.Exp * 100) / 100.0;
}
public Long GetLastAnnounced() {
return this.lastAnnouced;
}
public boolean IsAnnounceTime(int time) {
if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis())
return false;
SetAnnouncmentTime();
return true;
}
public void SetAnnouncmentTime() {
this.lastAnnouced = System.currentTimeMillis();
}
public void AddNewAmount(Double Payment) {
this.time = System.currentTimeMillis();
this.Payment = Payment;
}
public void Setinformed() {
this.Informed = true;
}
public void SetNotInformed() {
this.Informed = false;
}
public void AddAmount(Double Payment) {
this.Payment = this.Payment + Payment;
}
public void AddExpAmount(Double Exp) {
this.Exp = this.Exp + Exp;
}
public int GetLeftTime(int time) {
int left = 0;
if (this.time + (time * 1000) > System.currentTimeMillis())
left = (int) ((this.time + (time * 1000) - System.currentTimeMillis()) / 1000);
return left;
}
public boolean IsOverMoneyLimit(int limit) {
if (this.Payment < limit)
return false;
return true;
}
public boolean IsOverExpLimit(int limit) {
if (this.Exp < limit)
return false;
return true;
}
public boolean IsOverTimeLimit(int time) {
if (this.time + (time * 1000) > System.currentTimeMillis())
return false;
if (this.Informed)
this.Informed = false;
this.time = System.currentTimeMillis();
this.Payment = 0.0;
this.Exp = 0.0;
this.Reseted = true;
return true;
}
public boolean IsReachedMoneyLimit(int time, int money) {
if (IsOverTimeLimit(time))
return true;
if (IsOverMoneyLimit(money))
return true;
return false;
}
public boolean IsReachedExpLimit(int time, int exp) {
if (IsOverTimeLimit(time))
return true;
if (IsOverExpLimit(exp))
return true;
return false;
}
public int GetLeftsec(int time) {
int lefttime1 = GetLeftTime(time);
int sec = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else if (lefttime1 < 60)
sec = lefttime1;
} else if (lefttime1 > 60 && lefttime1 < 3600) {
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else
sec = lefttime1;
return sec;
}
public int GetLeftMin(int time) {
int lefttime1 = GetLeftTime(time);
int min = 0;
if (lefttime1 >= 3600) {
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
} else if (lefttime1 > 60 && lefttime1 < 3600)
min = lefttime1 / 60;
return min;
}
public int GetLeftHour(int time) {
int lefttime1 = GetLeftTime(time);
int hour = 0;
if (lefttime1 >= 3600) {
hour = lefttime1 / 3600;
}
return hour;
}
}

View File

@ -154,7 +154,7 @@ public class JobsListener implements Listener {
// }
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(final PlayerJoinEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
@ -173,7 +173,7 @@ public class JobsListener implements Listener {
* necessary to call this twice in case somebody is relying on permissions from this
* plugin on entry to the world.
*/
final JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}

View File

@ -48,6 +48,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.SlimeSplitEvent;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
@ -935,6 +936,25 @@ public class JobsPaymentListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(SlimeSplitEvent event) {
if (!event.getEntity().hasMetadata(mobSpawnerMetadata))
return;
EntityType type = event.getEntityType();
if (type == EntityType.SLIME && ConfigManager.getJobsConfiguration().PreventSlimeSplit) {
event.setCancelled(true);
return;
}
if (type == EntityType.MAGMA_CUBE && ConfigManager.getJobsConfiguration().PreventMagmaCubeSplit) {
event.setCancelled(true);
return;
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureBreed(CreatureSpawnEvent event) {

View File

@ -19,138 +19,136 @@ import com.gamingmesh.jobs.i18n.Language;
* @author hamzaxx
*/
public class ActionBar {
private static int cleanVersion = 182;
private static String version = "";
private static Object packet;
private static Method getHandle;
private static Method sendPacket;
private static Field playerConnection;
private static Class<?> nmsChatSerializer;
private static Class<?> nmsIChatBaseComponent;
private static Class<?> packetType;
private static int cleanVersion = 182;
private static String version = "";
private static Object packet;
private static Method getHandle;
private static Method sendPacket;
private static Field playerConnection;
private static Class<?> nmsChatSerializer;
private static Class<?> nmsIChatBaseComponent;
private static Class<?> packetType;
static {
try {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
static {
try {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
// Translating version to integer for simpler use
try {
cleanVersion = Integer.parseInt(version.replace("v", "").replace("V", "").replace("_", "").replace("r", "").replace("R", ""));
} catch (NumberFormatException e) {
// Fail save if it for some reason can't translate version to integer
if (version.contains("v1_7"))
cleanVersion = 170;
if (version.contains("v1_6"))
cleanVersion = 160;
if (version.contains("v1_5"))
cleanVersion = 150;
if (version.contains("v1_4"))
cleanVersion = 140;
if (version.contains("v1_8_R1"))
cleanVersion = 181;
if (version.contains("v1_8_R2"))
cleanVersion = 182;
if (version.contains("v1_8_R3"))
cleanVersion = 183;
}
// Translating version to integer for simpler use
try {
cleanVersion = Integer.parseInt(version.replace("v", "").replace("V", "").replace("_", "").replace("r", "").replace("R", ""));
} catch (NumberFormatException e) {
// Fail save if it for some reason can't translate version to integer
if (version.contains("v1_7"))
cleanVersion = 170;
if (version.contains("v1_6"))
cleanVersion = 160;
if (version.contains("v1_5"))
cleanVersion = 150;
if (version.contains("v1_4"))
cleanVersion = 140;
if (version.contains("v1_8_R1"))
cleanVersion = 181;
if (version.contains("v1_8_R2"))
cleanVersion = 182;
if (version.contains("v1_8_R3"))
cleanVersion = 183;
}
packetType = Class.forName(getPacketPlayOutChat());
Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
Class<?> typePlayerConnection = Class.forName(getPlayerConnectionClasspath());
nmsChatSerializer = Class.forName(getChatSerializerClasspath());
nmsIChatBaseComponent = Class.forName(getIChatBaseComponentClasspath());
getHandle = typeCraftPlayer.getMethod("getHandle");
playerConnection = typeNMSPlayer.getField("playerConnection");
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath()));
packetType = Class.forName(getPacketPlayOutChat());
Class<?> typeCraftPlayer = Class.forName(getCraftPlayerClasspath());
Class<?> typeNMSPlayer = Class.forName(getNMSPlayerClasspath());
Class<?> typePlayerConnection = Class.forName(getPlayerConnectionClasspath());
nmsChatSerializer = Class.forName(getChatSerializerClasspath());
nmsIChatBaseComponent = Class.forName(getIChatBaseComponentClasspath());
getHandle = typeCraftPlayer.getMethod("getHandle");
playerConnection = typeNMSPlayer.getField("playerConnection");
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath()));
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
}
public static void ShowActionBar(BufferedPayment payment) {
String playername = payment.getOfflinePlayer().getName();
if (!Jobs.actionbartoggle.containsKey(playername) && ConfigManager.getJobsConfiguration().JobsToggleEnabled)
Jobs.actionbartoggle.put(playername, true);
if (playername != null && Jobs.actionbartoggle.size() > 0)
if (Jobs.actionbartoggle.containsKey(playername)) {
Boolean show = Jobs.actionbartoggle.get(playername);
Player abp = (Player) payment.getOfflinePlayer();
if (abp != null && show) {
String Message = Language.getMessage("command.toggle.output.paid");
Message = Message.replace("[amount]", String.valueOf((((int) (payment.getAmount() * 100)) / 100.0)));
Message = Message.replace("[exp]", String.valueOf((((int) (payment.getExp() * 100)) / 100.0)));
ActionBar.send(abp, ChatColor.GREEN + Message);
}
}
}
public static void send(Player receivingPacket, String msg) {
try {
if (msg == null || nmsChatSerializer == null)
return;
if (cleanVersion < 180) {
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
return;
}
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}");
if (cleanVersion > 180) {
packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2);
} else {
packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2);
}
Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player);
sendPacket.invoke(connection, packet);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
public static void ShowActionBar(BufferedPayment payment) {
String playername = payment.getOfflinePlayer().getName();
if (!Jobs.actionbartoggle.containsKey(playername) && ConfigManager.getJobsConfiguration().JobsToggleEnabled)
Jobs.actionbartoggle.put(playername, true);
if (playername != null && Jobs.actionbartoggle.size() > 0)
if (Jobs.actionbartoggle.containsKey(playername)) {
Boolean show = Jobs.actionbartoggle.get(playername);
Player abp = (Player) payment.getOfflinePlayer();
if (abp != null && show) {
String Message = Language.getMessage("command.toggle.output.paid");
Message = Message.replace("[amount]", String.valueOf((((int) (payment.getAmount() * 100)) / 100.0)));
Message = Message.replace("[exp]", String.valueOf((((int) (payment.getExp() * 100)) / 100.0)));
ActionBar.send(abp, ChatColor.GREEN + Message);
} else {
Jobs.actionbartoggle.remove(playername);
}
}
try {
Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player);
sendPacket.invoke(connection, packet);
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
}
public static void send(Player receivingPacket, String msg) {
try {
if (msg == null || nmsChatSerializer == null)
return;
private static String getCraftPlayerClasspath() {
return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer";
}
if (cleanVersion < 180) {
receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
return;
}
private static String getPlayerConnectionClasspath() {
return "net.minecraft.server." + version + ".PlayerConnection";
}
Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}");
if (cleanVersion > 180) {
packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2);
} else {
packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2);
}
Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player);
sendPacket.invoke(connection, packet);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
private static String getNMSPlayerClasspath() {
return "net.minecraft.server." + version + ".EntityPlayer";
}
try {
Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player);
sendPacket.invoke(connection, packet);
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex);
}
private static String getPacketClasspath() {
return "net.minecraft.server." + version + ".Packet";
}
private static String getIChatBaseComponentClasspath() {
return "net.minecraft.server." + version + ".IChatBaseComponent";
}
private static String getChatSerializerClasspath() {
if (cleanVersion < 182) {
return "net.minecraft.server." + version + ".ChatSerializer";
} else {
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
}
}
private static String getCraftPlayerClasspath() {
return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer";
}
private static String getPlayerConnectionClasspath() {
return "net.minecraft.server." + version + ".PlayerConnection";
}
private static String getNMSPlayerClasspath() {
return "net.minecraft.server." + version + ".EntityPlayer";
}
private static String getPacketClasspath() {
return "net.minecraft.server." + version + ".Packet";
}
private static String getIChatBaseComponentClasspath() {
return "net.minecraft.server." + version + ".IChatBaseComponent";
}
private static String getChatSerializerClasspath() {
if (cleanVersion < 182) {
return "net.minecraft.server." + version + ".ChatSerializer";
} else {
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer"; // 1_8_R2 moved to IChatBaseComponent
}
}
private static String getPacketPlayOutChat() {
return "net.minecraft.server." + version + ".PacketPlayOutChat";
}
private static String getPacketPlayOutChat() {
return "net.minecraft.server." + version + ".PacketPlayOutChat";
}
}

View File

@ -15,85 +15,92 @@ import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.i18n.Language;
public class ScheduleUtil {
public static boolean scheduler() {
if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) {
public static boolean scheduler() {
if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
String currenttime = dateFormat.format(date);
String currenttime = dateFormat.format(date);
int Current = Integer.valueOf(currenttime.replace(":", "")).intValue();
int Current = Integer.valueOf(currenttime.replace(":", "")).intValue();
String CurrentDayName = GetWeekDay();
String CurrentDayName = GetWeekDay();
for (Schedule one : ConfigManager.getJobsConfiguration().BoostSchedule) {
for (Schedule one : ConfigManager.getJobsConfiguration().BoostSchedule) {
int From = one.GetFrom();
int Until = one.GetUntil();
int From = one.GetFrom();
int Until = one.GetUntil();
List<String> days = one.GetDays();
List<String> days = one.GetDays();
if (((one.isNextDay() && (Current >= From && Current < one.GetUntil() || Current >= one.GetNextFrom() && Current < one.GetNextUntil()) && !one.isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one.isStarted()) {
if (((one.isNextDay() && (Current >= From && Current < one.GetUntil() || Current >= one.GetNextFrom() && Current < one.GetNextUntil()) && !one
.isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one
.isStarted()) {
if (one.isBroadcastOnStart())
if (one.GetMessageOnStart().size() == 0)
Bukkit.broadcastMessage(Language.getMessage("message.boostStarted"));
else
for (String oneMsg : one.GetMessageOnStart()) {
Bukkit.broadcastMessage(oneMsg);
}
if (one.isBroadcastOnStart())
if (one.GetMessageOnStart().size() == 0)
Bukkit.broadcastMessage(Language.getMessage("message.boostStarted"));
else
for (String oneMsg : one.GetMessageOnStart()) {
Bukkit.broadcastMessage(oneMsg);
}
for (Job onejob : one.GetJobs()) {
onejob.setExpBoost(one.GetExpBoost());
onejob.setMoneyBoost(one.GetMoneyBoost());
}
one.setStarted(true);
one.setStoped(false);
break;
} else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until && ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) {
if (one.isBroadcastOnStop())
if (one.GetMessageOnStop().size() == 0)
Bukkit.broadcastMessage(Language.getMessage("message.boostStoped"));
else
for (String oneMsg : one.GetMessageOnStop()) {
Bukkit.broadcastMessage(oneMsg);
}
one.setStoped(true);
one.setStarted(false);
}
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() {
public void run() {
scheduler();
return;
}
}, 1 * 20L);
for (Job onejob : one.GetJobs()) {
onejob.setExpBoost(one.GetExpBoost());
onejob.setMoneyBoost(one.GetMoneyBoost());
}
one.setStarted(true);
one.setStoped(false);
break;
} else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until
&& ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) {
if (one.isBroadcastOnStop())
if (one.GetMessageOnStop().size() == 0)
Bukkit.broadcastMessage(Language.getMessage("message.boostStoped"));
else
for (String oneMsg : one.GetMessageOnStop()) {
Bukkit.broadcastMessage(oneMsg);
}
for (Job onejob : one.GetJobs()) {
onejob.setExpBoost(1.0);
onejob.setMoneyBoost(1.0);
}
one.setStoped(true);
one.setStarted(false);
}
return true;
}
public static String GetWeekDay() {
Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
switch (dayOfWeek) {
case 2:
return "monday";
case 3:
return "tuesday";
case 4:
return "wednesday";
case 5:
return "thursday";
case 6:
return "friday";
case 7:
return "saturday";
case 1:
return "sunday";
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() {
public void run() {
scheduler();
return;
}
return "all";
}, 30 * 20L);
}
return true;
}
public static String GetWeekDay() {
Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
switch (dayOfWeek) {
case 2:
return "monday";
case 3:
return "tuesday";
case 4:
return "wednesday";
case 5:
return "thursday";
case 6:
return "friday";
case 7:
return "saturday";
case 1:
return "sunday";
}
return "all";
}
}

View File

@ -6,81 +6,81 @@ import com.gamingmesh.jobs.container.NameList;
public class TranslateName {
public static String Translate(String materialName, JobInfo info) {
public static String Translate(String materialName, JobInfo info) {
// Translating name to user friendly
if (ConfigManager.getJobsConfiguration().UseCustomNames)
switch (info.getActionType()) {
case BREAK:
case CRAFT:
case DYE:
case PLACE:
case SMELT:
case REPAIR:
case BREW:
case FISH:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
break;
case BREED:
case KILL:
case MILK:
case TAME:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return materialName = one.getName();
}
}
break;
case ENCHANT:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEnchants) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId()))) {
return one.getName() + " " + info.getMeta();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
break;
case CUSTOMKILL:
break;
case SHEAR:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfColors) {
String ids = one.getMinecraftName();
if (ids.equalsIgnoreCase(String.valueOf(info.getName()))) {
return one.getName();
}
}
break;
}
// Translating name to user friendly
if (ConfigManager.getJobsConfiguration().UseCustomNames)
switch (info.getActionType()) {
case BREAK:
case CRAFT:
case DYE:
case PLACE:
case SMELT:
case REPAIR:
case BREW:
case FISH:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
break;
case BREED:
case KILL:
case MILK:
case TAME:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return materialName = one.getName();
}
}
break;
case ENCHANT:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEnchants) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId()))) {
return one.getName() + " " + info.getMeta();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName();
}
}
break;
case CUSTOMKILL:
break;
case SHEAR:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfColors) {
String ids = one.getMinecraftName();
if (ids.equalsIgnoreCase(String.valueOf(info.getName()))) {
return one.getName();
}
}
break;
}
return materialName;
}
return materialName;
}
}

View File

@ -1,7 +1,7 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin
version: 2.47.2
version: 2.48.0
author: phrstbrn
softdepend: [Vault]
commands: