use of com.gamingmesh.jobs.container.JobProgression in project Jobs by GamingMesh.
the class JobsCommands method jobInfoMessage.
/**
* Displays info about a particular action
* @param player - the player of the job
* @param prog - the job we are displaying info about
* @param type - the type of action
* @return the message
*/
private String jobInfoMessage(JobsPlayer player, Job job, ActionType type) {
StringBuilder message = new StringBuilder();
message.append(Language.getMessage("command.info.output." + type.getName().toLowerCase()));
message.append(":\n");
int level = 1;
JobProgression prog = player.getJobProgression(job);
if (prog != null)
level = prog.getLevel();
int numjobs = player.getJobProgression().size();
List<JobInfo> jobInfo = job.getJobInfo(type);
for (JobInfo info : jobInfo) {
String materialName = info.getName().toLowerCase().replace('_', ' ');
double income = info.getIncome(level, numjobs);
ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED;
double xp = info.getExperience(level, numjobs);
ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY;
String xpString = String.format("%.2f xp", xp);
message.append(" ");
message.append(materialName);
message.append(" -> ");
message.append(xpColor.toString());
message.append(xpString);
message.append(' ');
message.append(incomeColor.toString());
message.append(Jobs.getEconomy().format(income));
message.append('\n');
}
return message.toString();
}
use of com.gamingmesh.jobs.container.JobProgression in project Jobs by GamingMesh.
the class JobsCommands method fireall.
@JobCommand
public boolean fireall(CommandSender sender, String[] args) {
if (args.length < 1) {
sendUsage(sender, "fireall");
return true;
}
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
List<JobProgression> jobs = jPlayer.getJobProgression();
if (jobs.size() == 0) {
sender.sendMessage(Language.getMessage("command.fireall.error.nojobs"));
return true;
}
try {
Jobs.getPlayerManager().leaveAllJobs(jPlayer);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
if (player != null) {
player.sendMessage(Language.getMessage("command.fireall.output.target"));
}
sender.sendMessage(Language.getMessage("command.admin.success"));
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
}
return true;
}
use of com.gamingmesh.jobs.container.JobProgression in project Jobs by GamingMesh.
the class Jobs method action.
/**
* Performed an action
*
* Give correct experience and income
* @param jPlayer - the player
* @param action - the action
* @param multiplier - the payment/xp multiplier
*/
public static void action(JobsPlayer jPlayer, ActionInfo info, double multiplier) {
List<JobProgression> progression = jPlayer.getJobProgression();
int numjobs = progression.size();
// no job
if (numjobs == 0) {
Job jobNone = Jobs.getNoneJob();
if (jobNone != null) {
Double income = jobNone.getIncome(info, 1, numjobs);
if (income != null)
Jobs.getEconomy().pay(jPlayer, income * multiplier);
}
} else {
for (JobProgression prog : progression) {
int level = prog.getLevel();
Double income = prog.getJob().getIncome(info, level, numjobs);
if (income != null) {
Double exp = prog.getJob().getExperience(info, level, numjobs);
if (ConfigManager.getJobsConfiguration().addXpPlayer()) {
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player != null) {
/*
* Minecraft experience is calculated in whole numbers only.
* Calculate the fraction of an experience point and perform a dice roll.
* That way jobs that give fractions of experience points will slowly give
* experience in the aggregate
*/
int expInt = exp.intValue();
double remainder = exp.doubleValue() - expInt;
if (Math.abs(remainder) > Math.random()) {
if (exp.doubleValue() < 0) {
expInt--;
} else {
expInt++;
}
}
player.giveExp(expInt);
}
}
// give income
Jobs.getEconomy().pay(jPlayer, income * multiplier);
int oldLevel = prog.getLevel();
if (prog.addExperience(exp * multiplier))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
}
}
}
}
use of com.gamingmesh.jobs.container.JobProgression in project Jobs by GamingMesh.
the class PermissionHandler method recalculatePermissions.
public void recalculatePermissions(JobsPlayer jPlayer) {
Player player = plugin.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player == null)
return;
boolean changed = false;
// remove old permissions
String permName = "jobs.players." + player.getName();
Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
if (permission != null) {
plugin.getServer().getPluginManager().removePermission(permission);
changed = true;
}
// Permissions should only apply if we have permission to use jobs in this world
if (hasWorldPermission(player, player.getWorld().getName())) {
List<JobProgression> progression = jPlayer.getJobProgression();
// calculate new permissions
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
if (progression.size() == 0) {
Job job = Jobs.getNoneJob();
if (job != null) {
for (JobPermission perm : job.getPermissions()) {
if (perm.getLevelRequirement() <= 0) {
if (perm.getValue()) {
permissions.put(perm.getNode(), true);
} else {
/*
* If the key exists, don't put a false node in
* This is in case we already have a true node there
*/
if (!permissions.containsKey(perm.getNode())) {
permissions.put(perm.getNode(), false);
}
}
}
}
}
} else {
for (JobProgression prog : progression) {
for (JobPermission perm : prog.getJob().getPermissions()) {
if (prog.getLevel() >= perm.getLevelRequirement()) {
/*
* If the key exists, don't put a false node in
* This is in case we already have a true node there
*/
if (perm.getValue()) {
permissions.put(perm.getNode(), true);
} else {
if (!permissions.containsKey(perm.getNode())) {
permissions.put(perm.getNode(), false);
}
}
}
}
}
}
// add new permissions (if applicable)
if (permissions.size() > 0) {
plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
changed = true;
}
}
// If the permissions changed, recalculate them
if (!changed)
return;
// find old attachment
PermissionAttachment attachment = null;
for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
if (pai.getAttachment() != null && pai.getAttachment().getPlugin() instanceof JobsPlugin) {
attachment = pai.getAttachment();
}
}
// create if attachment doesn't exist
if (attachment == null) {
attachment = player.addAttachment(plugin);
attachment.setPermission(permName, true);
}
// recalculate!
player.recalculatePermissions();
}
use of com.gamingmesh.jobs.container.JobProgression in project Jobs by GamingMesh.
the class JobsDAO method save.
/**
* Save player-job information
* @param jobInfo - the information getting saved
*/
public synchronized void save(JobsPlayer player) {
JobsConnection conn = getConnection();
if (conn == null)
return;
try {
PreparedStatement prest = conn.prepareStatement("UPDATE `" + prefix + "jobs` SET `level` = ?, `experience` = ? WHERE `player_uuid` = ? AND `job` = ?;");
for (JobProgression progression : player.getJobProgression()) {
prest.setInt(1, progression.getLevel());
prest.setInt(2, (int) progression.getExperience());
prest.setBytes(3, UUIDUtil.toBytes(player.getPlayerUUID()));
prest.setString(4, progression.getJob().getName());
prest.execute();
}
prest.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
Aggregations