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

Better way to control archived jobs

Option to define rejoin job cooldown
This commit is contained in:
Zrips 2017-09-01 10:32:56 +03:00
parent 7f461910aa
commit 741bd0ed97
13 changed files with 289 additions and 93 deletions

View File

@ -66,6 +66,7 @@ import com.gamingmesh.jobs.config.TitleManager;
import com.gamingmesh.jobs.config.YmlMaker;
import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.ArchivedJobs;
import com.gamingmesh.jobs.container.BlockProtection;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.CurrencyType;
@ -542,18 +543,22 @@ public class Jobs extends JavaPlugin {
HashMap<Integer, List<JobsDAOData>> playersJobs = Jobs.getJobsDAO().getAllJobs();
HashMap<Integer, PlayerPoints> playersPoints = Jobs.getJobsDAO().getAllPoints();
HashMap<Integer, HashMap<String, Log>> playersLogs = Jobs.getJobsDAO().getAllLogs();
HashMap<Integer, ArchivedJobs> playersArchives = Jobs.getJobsDAO().getAllArchivedJobs();
Iterator<Entry<UUID, PlayerInfo>> it = temp.entrySet().iterator();
while (it.hasNext()) {
Entry<UUID, PlayerInfo> one = it.next();
try {
int id = one.getValue().getID();
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one.getValue(), playersJobs.get(id), playersPoints.get(id), playersLogs.get(id));
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(one.getValue(), playersJobs.get(id), playersPoints.get(id), playersLogs.get(id), playersArchives.get(id));
if (jPlayer == null)
continue;
Jobs.getPlayerManager().addPlayerToCache(jPlayer);
} catch (Exception e) {
e.printStackTrace();
}
}
dao.getMap().clear();
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + Jobs.getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time)
/ 1000d) * 100) / 100D));

View File

@ -41,6 +41,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import com.gamingmesh.jobs.api.JobsJoinEvent;
import com.gamingmesh.jobs.api.JobsLeaveEvent;
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
import com.gamingmesh.jobs.container.ArchivedJobs;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.CurrencyType;
@ -64,6 +65,7 @@ public class PlayerManager {
private ConcurrentHashMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<UUID, JobsPlayer>();
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<UUID, JobsPlayer>();
private PointsData PointsDatabase = new PointsData();
private final String mobSpawnerMetadata = "jobsMobSpawner";
@ -281,10 +283,11 @@ public class PlayerManager {
/**
* Get the player job info for specific player
* @param archivedJobs
* @param player - the player who's job you're getting
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List<JobsDAOData> jobs, PlayerPoints points, HashMap<String, Log> logs) {
public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List<JobsDAOData> jobs, PlayerPoints points, HashMap<String, Log> logs, ArchivedJobs archivedJobs) {
if (info == null)
return null;
@ -296,7 +299,6 @@ public class PlayerManager {
jPlayer.setPlayerUUID(info.getUuid());
jPlayer.setUserId(info.getID());
// List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getName(), info.getUuid());
if (jobs != null)
for (JobsDAOData jobdata : jobs) {
if (Jobs.getJob(jobdata.getJobName()) == null)
@ -319,6 +321,18 @@ public class PlayerManager {
if (logs != null)
jPlayer.setLog(logs);
if (archivedJobs != null) {
ArchivedJobs aj = new ArchivedJobs();
for (JobProgression one : archivedJobs.getArchivedJobs()) {
JobProgression jp = new JobProgression(one.getJob(), jPlayer, one.getLevel(), one.getExperience());
jp.reloadMaxExperience();
if (one.getLeftOn() != null && one.getLeftOn() != 0L)
jp.setLeftOn(one.getLeftOn());
aj.addArchivedJob(jp);
}
jPlayer.setArchivedJobs(aj);
}
return jPlayer;
}
@ -342,7 +356,7 @@ public class PlayerManager {
if (jobsjoinevent.isCancelled())
return;
Jobs.getJobsDAO().joinJob(jPlayer, job);
Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job));
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
Jobs.takeSlot(job);
Jobs.getSignUtil().SignUpdate(job.getName());
@ -413,7 +427,7 @@ public class PlayerManager {
if (!dao.quitJob(jPlayer, oldjob))
return false;
oldjob.updateTotalPlayers();
dao.joinJob(jPlayer, newjob);
dao.joinJob(jPlayer, jPlayer.getJobProgression(newjob));
newjob.updateTotalPlayers();
jPlayer.save();
// }

View File

@ -579,10 +579,10 @@ public class JobsCommands implements CommandExecutor {
*/
public String jobStatsMessage(JobProgression jobProg) {
String message = Jobs.getLanguage().getMessage("command.stats.output",
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
"%joblevel%", jobProg.getLevel(),
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
"%jobxp%", Double.toString(Math.round(jobProg.getExperience() * 100.0) / 100.0),
"%jobmaxxp%", Integer.toString(jobProg.getMaxExperience()));
"%jobxp%",Math.round(jobProg.getExperience() * 100.0) / 100.0,
"%jobmaxxp%", jobProg.getMaxExperience());
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
}
@ -613,15 +613,13 @@ public class JobsCommands implements CommandExecutor {
* @param jobInfo - jobinfo string line
* @return the message
*/
public String jobStatsMessage(String jobInfo) {
String[] splited = jobInfo.split(":");
if (Jobs.getJob(splited[0]) == null)
return "";
String message = Jobs.getLanguage().getMessage("command.archive.output",
"%joblevel%", Integer.valueOf(splited[1]).toString(),
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
"%jobname%", Jobs.getJob(splited[0]).getChatColor() + splited[0] + ChatColor.WHITE,
"%jobxp%", Double.toString(Math.round(Double.valueOf(splited[3]) * 100.0) / 100.0));
return message;
public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) {
String message = Jobs.getLanguage().getMessage("command.archive.feedback",
"%joblevel%", jobProg.getLevel(),
"%leftjoblevel%", jPlayer.getLevelAfterRejoin(jobProg),
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
"%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0,
"%jobmaxxp%", jobProg.getMaxExperience());
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
}
}

View File

@ -1,14 +1,18 @@
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.RawMessage;
import com.gamingmesh.jobs.stuff.TimeManage;
public class archive implements Cmd {
@ -32,7 +36,7 @@ public class archive implements Cmd {
return true;
}
List<String> AllJobs = Jobs.getJobsDAO().getJobsFromArchive(jPlayer);
Set<JobProgression> AllJobs = jPlayer.getArchivedJobs().getArchivedJobs();
if (AllJobs.isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.archive.error.nojob"));
@ -40,8 +44,14 @@ public class archive implements Cmd {
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName()));
for (String jobInfo : AllJobs) {
sender.sendMessage(Jobs.getCommandManager().jobStatsMessage(jobInfo));
for (JobProgression jobInfo : AllJobs) {
RawMessage rm = new RawMessage();
if (jobInfo.canRejoin())
rm.add(ChatColor.GREEN + "+" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo), "Click to rejoin this job", "jobs join " + jobInfo.getJob().getName());
else
rm.add(ChatColor.RED + "-" + Jobs.getCommandManager().jobStatsMessageArchive(jPlayer, jobInfo), "You cant join, need to wait " + (TimeManage.to24hourShort(jobInfo.getLeftOn() + jobInfo
.getJob().getRejoinCd() - System.currentTimeMillis())));
rm.show(sender);
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
return true;

View File

@ -8,8 +8,10 @@ import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
public class join implements Cmd {
@Override
@ -83,6 +85,14 @@ public class join implements Cmd {
return true;
}
JobProgression ajp = jPlayer.getArchivedJobProgression(job);
if (ajp != null) {
if (!ajp.canRejoin()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.rejoin", "[time]", ajp.getRejoinTimeMessage()));
return true;
}
}
Jobs.getPlayerManager().joinJob(jPlayer, job);
String message = Jobs.getLanguage().getMessage("command.join.success");

View File

@ -194,6 +194,12 @@ public class ConfigManager {
maxSlots = null;
}
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L);
if (rejoinCd < 0L) {
rejoinCd = 0L;
}
rejoinCd = rejoinCd * 1000L;
String jobShortName = jobSection.getString("shortname", null);
if (jobShortName == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " is missing the shortname property. Skipping job!");
@ -472,7 +478,7 @@ public class ConfigManager {
}
Job job = new Job(jobName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, vipmaxLevel, maxSlots, jobPermissions, jobCommand,
jobConditions, jobItems, jobLimitedItems, JobsCommandOnJoin, JobsCommandOnLeave, GUIitem, bossbar);
jobConditions, jobItems, jobLimitedItems, JobsCommandOnJoin, JobsCommandOnLeave, GUIitem, bossbar, rejoinCd);
job.setMoneyEquation(incomeEquation);
job.setXpEquation(expEquation);

View File

@ -250,7 +250,7 @@ public class LanguageManager {
c.get("command.archive.help.args", "[playername]");
Jobs.getGCManager().commandArgs.put("archive", Arrays.asList("[playername]"));
c.get("command.archive.error.nojob", "There is no jobs saved.");
c.get("command.archive.output", "lvl %joblevel% (%getbackjoblevel%) %jobname%");
c.get("command.archive.feedback", " lvl%joblevel%(%leftjoblevel%) %jobname% : %jobxp%/%jobmaxxp% xp");
c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional");
c.get("command.give.help.args", "[playername] [jobname] [itemname]");
@ -335,6 +335,7 @@ public class LanguageManager {
c.get("command.join.error.alreadyin", "You are already in the job %jobname%.");
c.get("command.join.error.fullslots", "You cannot join the job %jobname%, there are no slots available.");
c.get("command.join.error.maxjobs", "You have already joined too many jobs.");
c.get("command.join.error.rejoin", "&cCan't rejoin this job. Wait [time]");
c.get("command.join.success", "You have joined the job %jobname%.");
c.get("command.leave.help.info", "Leave the selected job.");

View File

@ -0,0 +1,38 @@
package com.gamingmesh.jobs.container;
import java.util.HashSet;
import java.util.Set;
public class ArchivedJobs {
private Set<JobProgression> jobs = new HashSet<JobProgression>();
public Set<JobProgression> getArchivedJobs() {
return jobs;
}
public JobProgression getArchivedJobProgression(Job job) {
for (JobProgression one : jobs) {
if (one.getJob().isSame(job))
return one;
}
return null;
}
public void setArchivedJobs(Set<JobProgression> jobs) {
this.jobs = jobs;
}
public void addArchivedJob(JobProgression job) {
jobs.add(job);
}
public void removeArchivedJob(Job job) {
for (JobProgression one : jobs) {
if (one.getJob().isSame(job)) {
jobs.remove(one);
break;
}
}
}
}

View File

@ -66,6 +66,8 @@ public class Job {
private List<String> CmdOnLeave = new ArrayList<String>();
// Item for GUI
private ItemStack GUIitem;
// Item for GUI
private Long rejoinCd = 0L;
private int totalPlayers = -1;
private Double bonus = null;
@ -96,7 +98,7 @@ public class Job {
*/
public Job(String jobName, String jobShortName, String description, ChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, List<JobItems> jobItems,
List<JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, String bossbar) {
List<JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, String bossbar, Long rejoinCD) {
this.jobName = jobName;
this.jobShortName = jobShortName;
this.description = description;
@ -115,6 +117,7 @@ public class Job {
this.CmdOnLeave = CmdOnLeave;
this.GUIitem = GUIitem;
this.bossbar = bossbar;
this.rejoinCd = rejoinCD;
}
public void addBoost(CurrencyType type, double Point) {
@ -378,4 +381,12 @@ public class Job {
public void setPointsEquation(Parser pointsEquation) {
this.pointsEquation = pointsEquation;
}
public Long getRejoinCd() {
return rejoinCd;
}
public void setRejoinCd(Long rejoinCd) {
this.rejoinCd = rejoinCd;
}
}

View File

@ -20,12 +20,15 @@ package com.gamingmesh.jobs.container;
import java.util.HashMap;
import com.gamingmesh.jobs.stuff.TimeManage;
public class JobProgression {
private Job job;
private JobsPlayer jPlayer;
private double experience;
private int level;
private transient int maxExperience = -1;
private Long leftOn = null;
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
this.job = job;
@ -223,4 +226,29 @@ public class JobProgression {
reloadMaxExperience();
return checkLevelUp();
}
public Long getLeftOn() {
return leftOn;
}
public JobProgression setLeftOn(Long leftOn) {
this.leftOn = leftOn;
return this;
}
public boolean canRejoin() {
if (this.leftOn == null)
return true;
if (this.leftOn + this.getJob().getRejoinCd() < System.currentTimeMillis())
return true;
return false;
}
public String getRejoinTimeMessage() {
if (leftOn == null)
return "";
String msg = (TimeManage.to24hourShort(getLeftOn() + getJob().getRejoinCd() - System.currentTimeMillis()));
return msg;
}
}

View File

@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -42,6 +43,7 @@ public class JobsPlayer {
// progression of the player in each job
public UUID playerUUID;
public ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
private ArchivedJobs archivedJobs = new ArchivedJobs();
private PaymentData paymentLimits = null;
@ -80,6 +82,18 @@ public class JobsPlayer {
this.player = Bukkit.getPlayer(userName);
}
public ArchivedJobs getArchivedJobs() {
return archivedJobs;
}
public JobProgression getArchivedJobProgression(Job job) {
return archivedJobs.getArchivedJobProgression(job);
}
public void setArchivedJobs(ArchivedJobs archivedJob) {
this.archivedJobs = archivedJob;
}
public int getTotalLevels() {
int i = 0;
for (JobProgression job : progression) {
@ -370,10 +384,10 @@ public class JobsPlayer {
if (!isInJob(job)) {
int level = 1;
int exp = 0;
if (Jobs.getJobsDAO().checkArchive(this, job).size() > 0) {
List<Integer> info = Jobs.getJobsDAO().checkArchive(this, job);
level = info.get(0);
//exp = info.get(1);
JobProgression archived = this.getArchivedJobProgression(job);
if (archived != null) {
level = getLevelAfterRejoin(archived);
Jobs.getJobsDAO().deleteArchive(this, job);
}
@ -388,6 +402,29 @@ public class JobsPlayer {
// }
}
public int getLevelAfterRejoin(JobProgression jp) {
if (jp == null)
return 1;
int level = jp.getLevel();
level = (int) ((level - (level * (Jobs.getGCManager().levelLossPercentage / 100.0))));
if (level < 1)
level = 1;
Job job = jp.getJob();
int maxLevel = 0;
if (havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
maxLevel = job.getVipMaxLevel();
else
maxLevel = job.getMaxLevel();
if (Jobs.getGCManager().fixAtMaxLevel && jp.getLevel() == maxLevel)
level = jp.getLevel();
return level;
}
/**
* Player leaves a job
* @param job - the job left

View File

@ -19,6 +19,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ArchivedJobs;
import com.gamingmesh.jobs.container.BlockProtection;
import com.gamingmesh.jobs.container.Convert;
import com.gamingmesh.jobs.container.CurrencyType;
@ -113,7 +114,8 @@ public abstract class JobsDAO {
userid("int", TablesFieldsType.number),
job("text", TablesFieldsType.text),
experience("int", TablesFieldsType.number),
level("int", TablesFieldsType.number);
level("int", TablesFieldsType.number),
left("bigint", TablesFieldsType.longNumber);
private String type;
private TablesFieldsType fieldType;
@ -634,6 +636,47 @@ public abstract class JobsDAO {
return map;
}
public HashMap<Integer, ArchivedJobs> getAllArchivedJobs() {
HashMap<Integer, ArchivedJobs> map = new HashMap<Integer, ArchivedJobs>();
JobsConnection conn = getConnection();
if (conn == null)
return map;
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT * FROM `" + prefix + "archive`;");
res = prest.executeQuery();
while (res.next()) {
int id = res.getInt("userid");
String jobName = res.getString("job");
Double exp = res.getDouble("experience");
int lvl = res.getInt("level");
Long left = res.getLong("left");
Job job = Jobs.getJob(jobName);
if (job == null)
continue;
ArchivedJobs m = map.get(id);
if (m == null)
m = new ArchivedJobs();
JobProgression jp = new JobProgression(job, null, lvl, exp);
if (left != 0L)
jp.setLeftOn(left);
m.addArchivedJob(jp);
map.put(id, m);
}
} catch (Exception e) {
close(res);
close(prest);
} finally {
close(res);
close(prest);
}
return map;
}
public HashMap<Integer, HashMap<String, Log>> getAllLogs() {
HashMap<Integer, HashMap<String, Log>> map = new HashMap<Integer, HashMap<String, Log>>();
JobsConnection conn = getConnection();
@ -941,24 +984,19 @@ public abstract class JobsDAO {
* @param player - player that wishes to join the job
* @param job - job that the player wishes to join
*/
public synchronized void joinJob(JobsPlayer jPlayer, Job job) {
public synchronized void joinJob(JobsPlayer jPlayer, JobProgression job) {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest = null;
try {
int level = 1;
int exp = 0;
if (checkArchive(jPlayer, job).size() > 0) {
List<Integer> info = checkArchive(jPlayer, job);
level = info.get(0);
deleteArchive(jPlayer, job);
}
int level = job.getLevel();
Double exp = job.getExperience();
prest = conn.prepareStatement("INSERT INTO `" + prefix + "jobs` (`userid`, `job`, `level`, `experience`) VALUES (?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId());
prest.setString(2, job.getName());
prest.setString(2, job.getJob().getName());
prest.setInt(3, level);
prest.setInt(4, exp);
prest.setInt(4, exp.intValue());
prest.execute();
} catch (SQLException e) {
e.printStackTrace();
@ -1141,24 +1179,24 @@ public abstract class JobsDAO {
* @param job - job that the player wishes to quit
*/
public void recordToArchive(JobsPlayer jPlayer, Job job) {
JobProgression jp = jPlayer.getJobProgression(job);
if (jp == null)
return;
jp.setLeftOn(System.currentTimeMillis());
jPlayer.getArchivedJobs().addArchivedJob(jp);
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest = null;
try {
int level = 1;
int exp = 0;
for (JobProgression progression : jPlayer.getJobProgression()) {
if (progression.getJob().getName().equalsIgnoreCase(job.getName())) {
level = progression.getLevel();
exp = (int) progression.getExperience();
}
}
prest = conn.prepareStatement("INSERT INTO `" + prefix + "archive` (`userid`, `job`, `level`, `experience`) VALUES (?, ?, ?, ?);");
int level = jp.getLevel();
Double exp = jp.getExperience();
prest = conn.prepareStatement("INSERT INTO `" + prefix + "archive` (`userid`, `job`, `level`, `experience`, `left`) VALUES (?, ?, ?, ?, ?);");
prest.setInt(1, jPlayer.getUserId());
prest.setString(2, job.getName());
prest.setInt(3, level);
prest.setInt(4, exp);
prest.setInt(4, exp.intValue());
prest.setLong(5, System.currentTimeMillis());
prest.execute();
} catch (SQLException e) {
e.printStackTrace();
@ -1167,47 +1205,46 @@ 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 List<Integer> checkArchive(JobsPlayer jPlayer, Job job) {
JobsConnection conn = getConnection();
List<Integer> info = new ArrayList<Integer>();
if (conn == null)
return info;
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT `level`, `experience` 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);
info.add(level);
info.add(res.getInt(2));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(res);
close(prest);
}
return info;
}
// /**
// * 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() {
return getGlobalTopList(0);
@ -1415,6 +1452,7 @@ public abstract class JobsDAO {
* @param job - job that the player wishes to quit
*/
public synchronized void deleteArchive(JobsPlayer jPlayer, Job job) {
jPlayer.getArchivedJobs().removeArchivedJob(job);
JobsConnection conn = getConnection();
if (conn == null)
return;

View File

@ -195,7 +195,7 @@ public class JobsMySQL extends JobsDAO {
return true;
} catch (SQLException e) {
close(statement);
e.printStackTrace();
// e.printStackTrace();
return false;
}
}