1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Option to define max level with only permission node

better way in determining max job level
This commit is contained in:
Zrips 2017-09-01 11:33:20 +03:00
parent 7a92aa3ee3
commit 403d29f8a6
7 changed files with 39 additions and 121 deletions

View File

@ -106,12 +106,7 @@ public class GuiManager {
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.working")); Lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
} }
int maxlevel = 0; int maxlevel = job.getMaxLevel(JPlayer);
if (Perm.hasPermission(player, "jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxlevel = job.getVipMaxLevel();
else
maxlevel = job.getMaxLevel();
if (maxlevel > 0) if (maxlevel > 0)
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.max") + maxlevel); Lore.add(Jobs.getLanguage().getMessage("command.info.gui.max") + maxlevel);

View File

@ -142,7 +142,7 @@ public class PermissionManager {
} }
} }
} }
return amount; return amount == null ? 0D : amount;
} }
public boolean hasPermission(JobsPlayer jPlayer, String perm) { public boolean hasPermission(JobsPlayer jPlayer, String perm) {

View File

@ -31,10 +31,7 @@ public class browse implements Cmd {
if (job.getMaxLevel() > 0) { if (job.getMaxLevel() > 0) {
builder.append(ChatColor.WHITE.toString()); builder.append(ChatColor.WHITE.toString());
builder.append(Jobs.getLanguage().getMessage("command.info.help.max")); builder.append(Jobs.getLanguage().getMessage("command.info.help.max"));
if (Perm.hasPermission(sender, "jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0) builder.append(job.getMaxLevel(sender));
builder.append(job.getVipMaxLevel());
else
builder.append(job.getMaxLevel());
} }
if (Jobs.getGCManager().ShowTotalWorkers) if (Jobs.getGCManager().ShowTotalWorkers)

View File

@ -23,6 +23,9 @@ import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -292,6 +295,23 @@ public class Job {
return maxLevel; return maxLevel;
} }
public int getMaxLevel(JobsPlayer player) {
if (player == null)
return getMaxLevel();
return player.getMaxJobLevelAllowed(this);
}
public int getMaxLevel(CommandSender sender) {
if (sender == null)
return getMaxLevel();
if (sender instanceof Player) {
JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
if (player != null)
return player.getMaxJobLevelAllowed(this);
}
return getMaxLevel() > getVipMaxLevel() ? getMaxLevel() : getVipMaxLevel();
}
/** /**
* Function to return the maximum level * Function to return the maximum level
* @return the max level * @return the max level

View File

@ -175,12 +175,7 @@ public class JobProgression {
boolean ret = false; boolean ret = false;
while (canLevelUp()) { while (canLevelUp()) {
int maxLevel = 0; int maxLevel = this.jPlayer.getMaxJobLevelAllowed(this.getJob());
if (jPlayer.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
else
maxLevel = job.getMaxLevel();
// Don't level up at max level // Don't level up at max level
if (job.getMaxLevel() > 0 && level >= maxLevel) if (job.getMaxLevel() > 0 && level >= maxLevel)
break; break;

View File

@ -414,12 +414,7 @@ public class JobsPlayer {
level = 1; level = 1;
Job job = jp.getJob(); Job job = jp.getJob();
int maxLevel = 0; int maxLevel = this.getMaxJobLevelAllowed(job);
if (havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
else
maxLevel = job.getMaxLevel();
if (Jobs.getGCManager().fixAtMaxLevel && jp.getLevel() == maxLevel) if (Jobs.getGCManager().fixAtMaxLevel && jp.getLevel() == maxLevel)
level = jp.getLevel(); level = jp.getLevel();
@ -486,10 +481,7 @@ public class JobsPlayer {
return; return;
int newLevel = prog.getLevel() + levels; int newLevel = prog.getLevel() + levels;
int maxLevel = job.getMaxLevel(); int maxLevel = job.getMaxLevel(this);
if (this.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
if (maxLevel > 0 && newLevel > maxLevel) { if (maxLevel > 0 && newLevel > maxLevel) {
newLevel = maxLevel; newLevel = maxLevel;
@ -551,11 +543,7 @@ public class JobsPlayer {
prog.setJob(newjob); prog.setJob(newjob);
int maxLevel = 0; int maxLevel = getMaxJobLevelAllowed(newjob);
if (this.havePermission("jobs." + newjob.getName() + ".vipmaxlevel"))
maxLevel = newjob.getVipMaxLevel();
else
maxLevel = newjob.getMaxLevel();
if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) { if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) {
prog.setLevel(maxLevel); prog.setLevel(maxLevel);
@ -572,6 +560,18 @@ public class JobsPlayer {
// } // }
} }
public int getMaxJobLevelAllowed(Job job) {
int maxLevel = 0;
if (this.havePermission("jobs." + job.getName() + ".vipmaxlevel"))
maxLevel = job.getVipMaxLevel() > job.getMaxLevel() ? job.getVipMaxLevel() : job.getMaxLevel();
else
maxLevel = job.getMaxLevel();
int tMax = Jobs.getPermissionManager().getMaxPermission(this, "jobs." + job.getName() + ".vipmaxlevel").intValue();
if (tMax > maxLevel)
maxLevel = tMax;
return maxLevel;
}
/** /**
* Checks if the player is in this job. * Checks if the player is in this job.
* @param job - the job * @param job - the job

View File

@ -1205,47 +1205,6 @@ public abstract class JobsDAO {
} }
} }
// /**
// * Check job in archive
// * @param player - player that wishes to quit the job
// * @param job - job that the player wishes to quit
// */
// public synchronized JobProgression getOldJobProgresion(JobsPlayer jPlayer, Job job) {
// JobsConnection conn = getConnection();
// JobProgression jp = null;
// if (conn == null)
// return jp;
// PreparedStatement prest = null;
// ResultSet res = null;
// try {
// prest = conn.prepareStatement("SELECT `level`, `experience`, `left` FROM `" + prefix + "archive` WHERE `userid` = ? AND `job` = ?;");
// prest.setInt(1, jPlayer.getUserId());
// prest.setString(2, job.getName());
// res = prest.executeQuery();
// if (res.next()) {
// int level = (int) ((res.getInt(1) - (res.getInt(1) * (Jobs.getGCManager().levelLossPercentage / 100.0))));
// if (level < 1)
// level = 1;
//
// int maxLevel = 0;
// if (jPlayer.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
// maxLevel = job.getVipMaxLevel();
// else
// maxLevel = job.getMaxLevel();
//
// if (Jobs.getGCManager().fixAtMaxLevel && res.getInt(1) == maxLevel)
// level = res.getInt(1);
// jp = new JobProgression(job, jPlayer, level, res.getInt("experience"));
// }
// } catch (SQLException e) {
// e.printStackTrace();
// } finally {
// close(res);
// close(prest);
// }
// return jp;
// }
public List<TopList> getGlobalTopList() { public List<TopList> getGlobalTopList() {
return getGlobalTopList(0); return getGlobalTopList(0);
} }
@ -1290,54 +1249,6 @@ public abstract class JobsDAO {
return names; return names;
} }
/**
* Get all jobs from archive by player
* @param player - targeted player
* @return info - information about jobs
*/
public synchronized List<String> getJobsFromArchive(JobsPlayer jPlayer) {
JobsConnection conn = getConnection();
if (conn == null)
return null;
List<String> info = new ArrayList<String>();
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT `job`, `level`, `experience` FROM `" + prefix + "archive` WHERE `userid` = ?;");
prest.setInt(1, jPlayer.getUserId());
res = prest.executeQuery();
while (res.next()) {
int level = (int) ((res.getInt(2) - (res.getInt(2) * (Jobs.getGCManager().levelLossPercentage / 100.0))));
if (level < 1)
level = 1;
int maxLevel = 0;
Job job = Jobs.getJob(res.getString(1));
if (job == null)
continue;
if (jPlayer.havePermission("jobs." + job.getName() + ".vipmaxlevel"))
maxLevel = job.getVipMaxLevel();
else
maxLevel = job.getMaxLevel();
if (Jobs.getGCManager().fixAtMaxLevel && res.getInt(2) == maxLevel)
level = res.getInt(2);
info.add(res.getString(1) + ":" + res.getInt(2) + ":" + level + ":" + res.getInt(3));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(res);
close(prest);
}
return info;
}
public PlayerInfo loadPlayerData(UUID uuid) { public PlayerInfo loadPlayerData(UUID uuid) {
PlayerInfo pInfo = null; PlayerInfo pInfo = null;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();