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) if (jPlayer == null)
return; return;
Player player = (Player) jPlayer.getPlayer();
if (player == null) Player player = this.plugin.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player == null) {
return; return;
}
boolean changed = false; boolean changed = false;

View File

@ -52,39 +52,38 @@ public class PlayerManager {
* Handles join of new player * Handles join of new player
* @param playername * @param playername
*/ */
public void playerJoin(final Player player) { public void playerJoin(Player player) {
//synchronized (players) { synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase()); JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) { if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player); jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
players.put(player.getName().toLowerCase(), jPlayer); 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 * Handles player quit
* @param playername * @param playername
*/ */
public void playerQuit(Player player) { public void playerQuit(Player player) {
//synchronized (players) { synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) { if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase()); JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) { if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO()); jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect(); jPlayer.onDisconnect();
} }
} else { } else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase()); JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer != null) { if (jPlayer != null) {
jPlayer.onDisconnect(); 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 /JobsLeaveEvent.class
/NameList.class /NameList.class
/Schedule.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; import com.gamingmesh.jobs.stuff.Perm;
public class JobsPlayer { public class JobsPlayer {
// the player the object belongs to // the player the object belongs to
private String userName; private String userName;
// progression of the player in each job // progression of the player in each job
private UUID playerUUID; private UUID playerUUID;
private ArrayList<JobProgression> progression = new ArrayList<JobProgression>(); private ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
// display honorific // display honorific
private String honorific; private String honorific;
// player save status // player save status
private volatile boolean isSaved = true; private volatile boolean isSaved = true;
// player online status // player online status
private volatile boolean isOnline = false; private volatile boolean isOnline = false;
private OfflinePlayer player = null; private OfflinePlayer player = null;
private double VipSpawnerMultiplier = -1; private double VipSpawnerMultiplier = -1;
// save lock // save lock
public final Object saveLock = new Object(); public final Object saveLock = new Object();
// log
private List<Log> logList = new ArrayList<Log>();
private JobsPlayer(String userName, OfflinePlayer player) { private JobsPlayer(String userName, OfflinePlayer player) {
this.userName = userName; this.userName = userName;
this.player = player; 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); public void updateVipSpawnerMultiplier() {
jPlayer.playerUUID = player.getUniqueId(); if (Perm.hasPermission(this.player, "jobs.vipspawner"))
List<JobsDAOData> list = dao.getAllJobs(player); this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().VIPpayNearSpawnerMultiplier;
//synchronized (jPlayer.saveLock) { else
jPlayer.progression.clear(); this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().payNearSpawnerMultiplier;
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); * Get the MoneyBoost
// calculate the max level * @return the MoneyBoost
// add the progression level. */
jPlayer.progression.add(jobProgression); 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;
}
/** progression.add(new JobProgression(job, this, level, exp, -1, -1));
* Get the player reloadMaxExperience();
* @return the player reloadHonorific();
*/ Jobs.getPermissionHandler().recalculatePermissions(this);
public OfflinePlayer getPlayer() { return true;
return this.player; }
return false;
} }
}
/** /**
* Get the VipSpawnerMultiplier * Player leaves a job
* @return the Multiplier * @param job - the job left
*/ */
public double getVipSpawnerMultiplier() { public boolean leaveJob(Job job) {
if (!this.player.isOnline()) synchronized (saveLock) {
return 1.0; JobProgression prog = getJobProgression(job);
if (VipSpawnerMultiplier < 0) if (prog != null) {
updateVipSpawnerMultiplier(); progression.remove(prog);
return this.VipSpawnerMultiplier; reloadMaxExperience();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
}
return false;
} }
}
public void updateVipSpawnerMultiplier() { /**
if (Perm.hasPermission(this.player, "jobs.vipspawner")) * Leave all jobs
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().VIPpayNearSpawnerMultiplier; * @return on success
else */
this.VipSpawnerMultiplier = ConfigManager.getJobsConfiguration().payNearSpawnerMultiplier; public boolean leaveAllJobs() {
synchronized (saveLock) {
progression.clear();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
;
return true;
} }
}
/** /**
* Get the MoneyBoost * Promotes player in job
* @return the MoneyBoost * @param job - the job being promoted
*/ * @param levels - number of levels to promote
public static double getMoneyBoost(String JobName, OfflinePlayer player) { */
double MoneyBoost = 1.0; public void promoteJob(Job job, int levels, JobsPlayer player) {
if (JobName != null) { synchronized (saveLock) {
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")) { JobProgression prog = getJobProgression(job);
MoneyBoost = ConfigManager.getJobsConfiguration().BoostMoney; if (prog == null)
} return;
} if (levels <= 0)
return MoneyBoost; 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 * Demotes player in job
* @return the MoneyBoost * @param job - the job being deomoted
*/ * @param levels - number of levels to demote
public static double getExpBoost(String JobName, OfflinePlayer player) { */
Double ExpBoost = 1.0; public void demoteJob(Job job, int levels) {
if (player == null || JobName == null) synchronized (saveLock) {
return 1.0; JobProgression prog = getJobProgression(job);
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")) { if (prog == null)
ExpBoost = ConfigManager.getJobsConfiguration().BoostExp; return;
} if (levels <= 0)
return ExpBoost; return;
int newLevel = prog.getLevel() - levels;
if (newLevel < 1) {
newLevel = 1;
}
setLevel(job, newLevel);
} }
}
/** /**
* Reloads max experience for this job. * Sets player to a specific level
*/ * @param job - the job
private void reloadMaxExperience() { * @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) { 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 * Checks if the player is in this job.
* @return the list of job progressions * @param job - the job
*/ * @return true - they are in the job
public List<JobProgression> getJobProgression() { * @return false - they are not in the job
return Collections.unmodifiableList(progression); */
public boolean isInJob(Job job) {
for (JobProgression prog : progression) {
if (prog.getJob().equals(job))
return true;
} }
return false;
}
/** /**
* Check if have permission * Function that reloads your honorific
* @return true if have */
*/ public void reloadHonorific() {
public boolean havePermission(String perm) { StringBuilder builder = new StringBuilder();
if (this.isOnline) int numJobs = progression.size();
return ((Player) player).hasPermission(perm); boolean gotTitle = false;
return false;
}
/** if (numJobs > 0)
* Get the job progression with the certain job for (JobProgression prog : progression) {
* @return the job progression DisplayMethod method = prog.getJob().getDisplayMethod();
*/ if (method.equals(DisplayMethod.NONE))
public JobProgression getJobProgression(Job job) { continue;
for (JobProgression prog : progression) { if (gotTitle) {
if (prog.getJob().equals(job)) builder.append(" ");
return prog; gotTitle = false;
} }
return null; Title title = ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel(), prog.getJob().getName());
}
/** if (numJobs == 1) {
* get the userName if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
* @return the userName if (title != null) {
*/ String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE;
public String getUserName() { if (honorificpart.contains("{level}"))
return userName; honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
} builder.append(honorificpart);
gotTitle = true;
/**
* 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;
} }
return false; }
} if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) {
} if (gotTitle) {
builder.append(" ");
/**
* 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);
}
} }
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(); 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) {
* Performs player save String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE;
* @param dao if (honorificpart.contains("{level}"))
*/ honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
public void save(JobsDAO dao) { builder.append(honorificpart);
synchronized (saveLock) { gotTitle = true;
if (!isSaved()) { }
dao.save(this);
setSaved(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);
}
}
} }
/** honorific = builder.toString().trim();
* Perform connect }
*/
public void onConnect() {
isOnline = true;
}
/** /**
* Perform disconnect * Performs player save
* * @param dao
*/ */
public void onDisconnect() { public void save(JobsDAO dao) {
isOnline = false; synchronized (saveLock) {
if (!isSaved()) {
dao.save(this);
setSaved(true);
}
} }
}
/** /**
* Whether or not player is online * Perform connect
* @return true if online, otherwise false */
*/ public void onConnect() {
public boolean isOnline() { isOnline = true;
return isOnline; }
}
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; import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
public class BufferedEconomy { public class BufferedEconomy {
private JobsPlugin plugin; private JobsPlugin plugin;
private Economy economy; private Economy economy;
private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<BufferedPayment>(); private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<BufferedPayment>();
private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>()); private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>());
private OfflinePlayer ServerAccount = null; private OfflinePlayer ServerAccount = null;
private OfflinePlayer ServerTaxesAccount = null; private OfflinePlayer ServerTaxesAccount = null;
PaymentData PaymentData = new PaymentData(); PaymentData PaymentData = new PaymentData();
public BufferedEconomy(JobsPlugin plugin, Economy economy) { public BufferedEconomy(JobsPlugin plugin, Economy economy) {
this.plugin = plugin; this.plugin = plugin;
this.economy = economy; this.economy = economy;
} }
/** /**
* Add payment to player's payment buffer * Add payment to player's payment buffer
* @param player - player to be paid * @param player - player to be paid
* @param amount - amount to be paid * @param amount - amount to be paid
*/ */
public void pay(JobsPlayer player, double amount, double exp) { public void pay(JobsPlayer player, double amount, double exp) {
if (amount == 0) if (amount == 0)
return; return;
pay(new BufferedPayment(player.getPlayer(), amount, exp)); pay(new BufferedPayment(player.getPlayer(), amount, exp));
} }
/** /**
* Add payment to player's payment buffer * Add payment to player's payment buffer
* @param payment - payment to be paid * @param payment - payment to be paid
*/ */
public void pay(BufferedPayment payment) { public void pay(BufferedPayment payment) {
payments.add(payment); payments.add(payment);
} }
public String format(double money) { public String format(double money) {
return economy.format(money); return economy.format(money);
} }
/** /**
* Payout all players the amount they are going to be paid * Payout all players the amount they are going to be paid
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void payAll() { public void payAll() {
if (payments.isEmpty()) if (payments.isEmpty())
return; return;
synchronized (paymentCache) { synchronized (paymentCache) {
Double TotalAmount = 0.0; Double TotalAmount = 0.0;
Double TaxesAmount = 0.0; Double TaxesAmount = 0.0;
// combine all payments using paymentCache // combine all payments using paymentCache
while (!payments.isEmpty()) { while (!payments.isEmpty()) {
BufferedPayment payment = payments.remove(); BufferedPayment payment = payments.remove();
TotalAmount += payment.getAmount(); TotalAmount += payment.getAmount();
if (ConfigManager.getJobsConfiguration().UseTaxes) { if (ConfigManager.getJobsConfiguration().UseTaxes) {
TaxesAmount += payment.getAmount() * (ConfigManager.getJobsConfiguration().TaxesAmount / 100.0); 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();
} }
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 { public class PaymentData {
Long time = 0L; Long time = 0L;
Long lastAnnouced = 0L; Long lastAnnouced = 0L;
Double Payment = 0.0; Double Payment = 0.0;
public boolean Informed = false; Double Exp = 0.0;
public boolean Informed = false;
public boolean Reseted = false;
public PaymentData(Long time, Double Payment, Long lastAnnouced, boolean Informed) { public PaymentData(Long time, Double Payment, Double Exp, Long lastAnnouced, boolean Informed) {
this.time = time; this.time = time;
this.Payment = Payment; this.Payment = Payment;
this.lastAnnouced = lastAnnouced; this.Exp = Exp;
this.Informed = Informed; this.lastAnnouced = lastAnnouced;
} this.Informed = Informed;
}
public PaymentData() {
} public PaymentData() {
}
public Long GetTime() {
return this.time; public Long GetTime() {
} return this.time;
}
public Double GetAmount() {
return this.Payment; public void setReseted(boolean state) {
} this.Reseted = state;
}
public Double GetAmountBylimit(int limit) {
if (this.Payment > limit) public boolean isReseted() {
return (double) limit; return this.Reseted;
return (int) (this.Payment * 100) / 100.0; }
}
public Double GetAmount() {
public Long GetLastAnnounced() { return this.Payment;
return this.lastAnnouced; }
}
public Double GetAmountBylimit(int limit) {
public boolean IsAnnounceTime(int time) { if (this.Payment > limit)
if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis()) return (double) limit;
return false; return (int) (this.Payment * 100) / 100.0;
SetAnnouncmentTime(); }
return true;
} public Double GetExpBylimit(int limit) {
if (this.Exp > limit)
public void SetAnnouncmentTime() { return (double) limit;
this.lastAnnouced = System.currentTimeMillis(); return (int) (this.Exp * 100) / 100.0;
} }
public void AddNewAmount(Double Payment) { public Long GetLastAnnounced() {
this.time = System.currentTimeMillis(); return this.lastAnnouced;
this.Payment = Payment; }
}
public boolean IsAnnounceTime(int time) {
public void Setinformed() { if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis())
this.Informed = true; return false;
} SetAnnouncmentTime();
return true;
public void SetNotInformed() { }
this.Informed = false;
} public void SetAnnouncmentTime() {
this.lastAnnouced = System.currentTimeMillis();
public void AddAmount(Double Payment) { }
this.Payment = this.Payment + Payment;
} public void AddNewAmount(Double Payment) {
this.time = System.currentTimeMillis();
public int GetLeftTime(int time) { this.Payment = Payment;
int left = 0; }
if (this.time + (time * 1000) > System.currentTimeMillis())
left = (int) ((this.time + (time * 1000) - System.currentTimeMillis()) / 1000); public void Setinformed() {
return left; this.Informed = true;
} }
public boolean IsOverMoneyLimit(int limit) { public void SetNotInformed() {
if (this.Payment < limit) this.Informed = false;
return false; }
return true;
} public void AddAmount(Double Payment) {
this.Payment = this.Payment + Payment;
public boolean IsOverTimeLimit(int time) { }
if (this.time + (time * 1000) > System.currentTimeMillis()) public void AddExpAmount(Double Exp) {
return false; this.Exp = this.Exp + Exp;
}
if (this.Informed)
this.Informed = false; public int GetLeftTime(int time) {
this.time = System.currentTimeMillis(); int left = 0;
this.Payment = 0.0; if (this.time + (time * 1000) > System.currentTimeMillis())
return true; left = (int) ((this.time + (time * 1000) - System.currentTimeMillis()) / 1000);
} return left;
}
public boolean IsReachedLimit(int time, int limit) {
if (IsOverMoneyLimit(limit) && !IsOverTimeLimit(time)) public boolean IsOverMoneyLimit(int limit) {
return true; if (this.Payment < limit)
return false; return false;
} return true;
}
public int GetLeftsec(int time) {
int lefttime1 = GetLeftTime(time); public boolean IsOverExpLimit(int limit) {
int sec = 0; if (this.Exp < limit)
if (lefttime1 >= 3600) { return false;
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600); return true;
if (lefttime1 > 60 && lefttime1 < 3600) { }
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else if (lefttime1 < 60) public boolean IsOverTimeLimit(int time) {
sec = lefttime1; if (this.time + (time * 1000) > System.currentTimeMillis())
} else if (lefttime1 > 60 && lefttime1 < 3600) { return false;
sec = lefttime1 - ((int) (lefttime1 / 60) * 60);
} else if (this.Informed)
sec = lefttime1; this.Informed = false;
return sec;
} this.time = System.currentTimeMillis();
this.Payment = 0.0;
public int GetLeftMin(int time) { this.Exp = 0.0;
int lefttime1 = GetLeftTime(time); this.Reseted = true;
int min = 0; return true;
if (lefttime1 >= 3600) { }
lefttime1 = lefttime1 - ((int) (lefttime1 / 3600) * 3600);
if (lefttime1 > 60 && lefttime1 < 3600) public boolean IsReachedMoneyLimit(int time, int money) {
min = lefttime1 / 60; if (IsOverTimeLimit(time))
} else if (lefttime1 > 60 && lefttime1 < 3600) return true;
min = lefttime1 / 60; if (IsOverMoneyLimit(money))
return min; return true;
} return false;
}
public int GetLeftHour(int time) {
int lefttime1 = GetLeftTime(time); public boolean IsReachedExpLimit(int time, int exp) {
int hour = 0; if (IsOverTimeLimit(time))
if (lefttime1 >= 3600) { return true;
hour = lefttime1 / 3600; if (IsOverExpLimit(exp))
} return true;
return hour; 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) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(final PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
// make sure plugin is enabled // make sure plugin is enabled
if (!plugin.isEnabled()) if (!plugin.isEnabled())
return; return;
@ -173,7 +173,7 @@ public class JobsListener implements Listener {
* necessary to call this twice in case somebody is relying on permissions from this * necessary to call this twice in case somebody is relying on permissions from this
* plugin on entry to the world. * 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); 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.EntityDeathEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.SlimeSplitEvent;
import org.bukkit.event.inventory.BrewEvent; import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; 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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureBreed(CreatureSpawnEvent event) { public void onCreatureBreed(CreatureSpawnEvent event) {

View File

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

View File

@ -15,85 +15,92 @@ import com.gamingmesh.jobs.container.Schedule;
import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.i18n.Language;
public class ScheduleUtil { public class ScheduleUtil {
public static boolean scheduler() { public static boolean scheduler() {
if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) { if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Date date = new Date(); 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 From = one.GetFrom();
int Until = one.GetUntil(); 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.isBroadcastOnStart())
if (one.GetMessageOnStart().size() == 0) if (one.GetMessageOnStart().size() == 0)
Bukkit.broadcastMessage(Language.getMessage("message.boostStarted")); Bukkit.broadcastMessage(Language.getMessage("message.boostStarted"));
else else
for (String oneMsg : one.GetMessageOnStart()) { for (String oneMsg : one.GetMessageOnStart()) {
Bukkit.broadcastMessage(oneMsg); Bukkit.broadcastMessage(oneMsg);
} }
for (Job onejob : one.GetJobs()) { for (Job onejob : one.GetJobs()) {
onejob.setExpBoost(one.GetExpBoost()); onejob.setExpBoost(one.GetExpBoost());
onejob.setMoneyBoost(one.GetMoneyBoost()); onejob.setMoneyBoost(one.GetMoneyBoost());
} }
one.setStarted(true); one.setStarted(true);
one.setStoped(false); one.setStoped(false);
break; 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()) { } else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until
if (one.isBroadcastOnStop()) && ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) {
if (one.GetMessageOnStop().size() == 0) if (one.isBroadcastOnStop())
Bukkit.broadcastMessage(Language.getMessage("message.boostStoped")); if (one.GetMessageOnStop().size() == 0)
else Bukkit.broadcastMessage(Language.getMessage("message.boostStoped"));
for (String oneMsg : one.GetMessageOnStop()) { else
Bukkit.broadcastMessage(oneMsg); for (String oneMsg : one.GetMessageOnStop()) {
} Bukkit.broadcastMessage(oneMsg);
one.setStoped(true); }
one.setStarted(false); for (Job onejob : one.GetJobs()) {
} onejob.setExpBoost(1.0);
onejob.setMoneyBoost(1.0);
} }
one.setStoped(true);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { one.setStarted(false);
public void run() {
scheduler();
return;
}
}, 1 * 20L);
} }
return true;
}
public static String GetWeekDay() { }
Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() {
switch (dayOfWeek) { public void run() {
case 2: scheduler();
return "monday"; return;
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"; }, 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 class TranslateName {
public static String Translate(String materialName, JobInfo info) { public static String Translate(String materialName, JobInfo info) {
// Translating name to user friendly // Translating name to user friendly
if (ConfigManager.getJobsConfiguration().UseCustomNames) if (ConfigManager.getJobsConfiguration().UseCustomNames)
switch (info.getActionType()) { switch (info.getActionType()) {
case BREAK: case BREAK:
case CRAFT: case CRAFT:
case DYE: case DYE:
case PLACE: case PLACE:
case SMELT: case SMELT:
case REPAIR: case REPAIR:
case BREW: case BREW:
case FISH: case FISH:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta(); String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) { if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName(); return one.getName();
} }
} }
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId(); String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) { if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName(); return one.getName();
} }
} }
break; break;
case BREED: case BREED:
case KILL: case KILL:
case MILK: case MILK:
case TAME: case TAME:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId() + ":" + one.getMeta(); String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) { if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName(); return one.getName();
} }
} }
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfEntities) {
String ids = one.getId(); String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) { if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return materialName = one.getName(); return materialName = one.getName();
} }
} }
break; break;
case ENCHANT: case ENCHANT:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfEnchants) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfEnchants) {
String ids = one.getId(); String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId()))) { if (ids.equalsIgnoreCase(String.valueOf(info.getId()))) {
return one.getName() + " " + info.getMeta(); return one.getName() + " " + info.getMeta();
} }
} }
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId() + ":" + one.getMeta(); String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) { if (!one.getMeta().equalsIgnoreCase("") && ids.equalsIgnoreCase(info.getId() + ":" + info.getMeta()) && !one.getId().equalsIgnoreCase("0")) {
return one.getName(); return one.getName();
} }
} }
for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfNames) {
String ids = one.getId(); String ids = one.getId();
if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) { if (ids.equalsIgnoreCase(String.valueOf(info.getId())) && !one.getId().equalsIgnoreCase("0")) {
return one.getName(); return one.getName();
} }
} }
break; break;
case CUSTOMKILL: case CUSTOMKILL:
break; break;
case SHEAR: case SHEAR:
for (NameList one : ConfigManager.getJobsConfiguration().ListOfColors) { for (NameList one : ConfigManager.getJobsConfiguration().ListOfColors) {
String ids = one.getMinecraftName(); String ids = one.getMinecraftName();
if (ids.equalsIgnoreCase(String.valueOf(info.getName()))) { if (ids.equalsIgnoreCase(String.valueOf(info.getName()))) {
return one.getName(); return one.getName();
} }
} }
break; break;
} }
return materialName; return materialName;
} }
} }

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: 2.47.2 version: 2.48.0
author: phrstbrn author: phrstbrn
softdepend: [Vault] softdepend: [Vault]
commands: commands: