mirror of
https://github.com/Zrips/Jobs.git
synced 2025-03-02 03:01:37 +01:00
Better way to control archived jobs
Option to define rejoin job cooldown
This commit is contained in:
parent
7f461910aa
commit
741bd0ed97
@ -66,6 +66,7 @@ import com.gamingmesh.jobs.config.TitleManager;
|
|||||||
import com.gamingmesh.jobs.config.YmlMaker;
|
import com.gamingmesh.jobs.config.YmlMaker;
|
||||||
import com.gamingmesh.jobs.container.ActionInfo;
|
import com.gamingmesh.jobs.container.ActionInfo;
|
||||||
import com.gamingmesh.jobs.container.ActionType;
|
import com.gamingmesh.jobs.container.ActionType;
|
||||||
|
import com.gamingmesh.jobs.container.ArchivedJobs;
|
||||||
import com.gamingmesh.jobs.container.BlockProtection;
|
import com.gamingmesh.jobs.container.BlockProtection;
|
||||||
import com.gamingmesh.jobs.container.Boost;
|
import com.gamingmesh.jobs.container.Boost;
|
||||||
import com.gamingmesh.jobs.container.CurrencyType;
|
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, List<JobsDAOData>> playersJobs = Jobs.getJobsDAO().getAllJobs();
|
||||||
HashMap<Integer, PlayerPoints> playersPoints = Jobs.getJobsDAO().getAllPoints();
|
HashMap<Integer, PlayerPoints> playersPoints = Jobs.getJobsDAO().getAllPoints();
|
||||||
HashMap<Integer, HashMap<String, Log>> playersLogs = Jobs.getJobsDAO().getAllLogs();
|
HashMap<Integer, HashMap<String, Log>> playersLogs = Jobs.getJobsDAO().getAllLogs();
|
||||||
|
HashMap<Integer, ArchivedJobs> playersArchives = Jobs.getJobsDAO().getAllArchivedJobs();
|
||||||
Iterator<Entry<UUID, PlayerInfo>> it = temp.entrySet().iterator();
|
Iterator<Entry<UUID, PlayerInfo>> it = temp.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<UUID, PlayerInfo> one = it.next();
|
Entry<UUID, PlayerInfo> one = it.next();
|
||||||
try {
|
try {
|
||||||
int id = one.getValue().getID();
|
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)
|
if (jPlayer == null)
|
||||||
continue;
|
continue;
|
||||||
Jobs.getPlayerManager().addPlayerToCache(jPlayer);
|
Jobs.getPlayerManager().addPlayerToCache(jPlayer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dao.getMap().clear();
|
dao.getMap().clear();
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + Jobs.getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time)
|
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + Jobs.getPlayerManager().getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time)
|
||||||
/ 1000d) * 100) / 100D));
|
/ 1000d) * 100) / 100D));
|
||||||
|
@ -41,6 +41,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import com.gamingmesh.jobs.api.JobsJoinEvent;
|
import com.gamingmesh.jobs.api.JobsJoinEvent;
|
||||||
import com.gamingmesh.jobs.api.JobsLeaveEvent;
|
import com.gamingmesh.jobs.api.JobsLeaveEvent;
|
||||||
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
|
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
|
||||||
|
import com.gamingmesh.jobs.container.ArchivedJobs;
|
||||||
import com.gamingmesh.jobs.container.Boost;
|
import com.gamingmesh.jobs.container.Boost;
|
||||||
import com.gamingmesh.jobs.container.BoostMultiplier;
|
import com.gamingmesh.jobs.container.BoostMultiplier;
|
||||||
import com.gamingmesh.jobs.container.CurrencyType;
|
import com.gamingmesh.jobs.container.CurrencyType;
|
||||||
@ -64,6 +65,7 @@ public class PlayerManager {
|
|||||||
private ConcurrentHashMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<UUID, JobsPlayer>();
|
private ConcurrentHashMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<UUID, JobsPlayer>();
|
||||||
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
|
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
|
||||||
private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<UUID, JobsPlayer>();
|
private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<UUID, JobsPlayer>();
|
||||||
|
|
||||||
private PointsData PointsDatabase = new PointsData();
|
private PointsData PointsDatabase = new PointsData();
|
||||||
private final String mobSpawnerMetadata = "jobsMobSpawner";
|
private final String mobSpawnerMetadata = "jobsMobSpawner";
|
||||||
|
|
||||||
@ -281,10 +283,11 @@ public class PlayerManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player job info for specific player
|
* Get the player job info for specific player
|
||||||
|
* @param archivedJobs
|
||||||
* @param player - the player who's job you're getting
|
* @param player - the player who's job you're getting
|
||||||
* @return the player job info of the player
|
* @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)
|
if (info == null)
|
||||||
return null;
|
return null;
|
||||||
@ -296,7 +299,6 @@ public class PlayerManager {
|
|||||||
jPlayer.setPlayerUUID(info.getUuid());
|
jPlayer.setPlayerUUID(info.getUuid());
|
||||||
jPlayer.setUserId(info.getID());
|
jPlayer.setUserId(info.getID());
|
||||||
|
|
||||||
// List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getName(), info.getUuid());
|
|
||||||
if (jobs != null)
|
if (jobs != null)
|
||||||
for (JobsDAOData jobdata : jobs) {
|
for (JobsDAOData jobdata : jobs) {
|
||||||
if (Jobs.getJob(jobdata.getJobName()) == null)
|
if (Jobs.getJob(jobdata.getJobName()) == null)
|
||||||
@ -319,6 +321,18 @@ public class PlayerManager {
|
|||||||
if (logs != null)
|
if (logs != null)
|
||||||
jPlayer.setLog(logs);
|
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;
|
return jPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +356,7 @@ public class PlayerManager {
|
|||||||
if (jobsjoinevent.isCancelled())
|
if (jobsjoinevent.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Jobs.getJobsDAO().joinJob(jPlayer, job);
|
Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job));
|
||||||
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
|
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
|
||||||
Jobs.takeSlot(job);
|
Jobs.takeSlot(job);
|
||||||
Jobs.getSignUtil().SignUpdate(job.getName());
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
||||||
@ -413,7 +427,7 @@ public class PlayerManager {
|
|||||||
if (!dao.quitJob(jPlayer, oldjob))
|
if (!dao.quitJob(jPlayer, oldjob))
|
||||||
return false;
|
return false;
|
||||||
oldjob.updateTotalPlayers();
|
oldjob.updateTotalPlayers();
|
||||||
dao.joinJob(jPlayer, newjob);
|
dao.joinJob(jPlayer, jPlayer.getJobProgression(newjob));
|
||||||
newjob.updateTotalPlayers();
|
newjob.updateTotalPlayers();
|
||||||
jPlayer.save();
|
jPlayer.save();
|
||||||
// }
|
// }
|
||||||
|
@ -579,10 +579,10 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
*/
|
*/
|
||||||
public String jobStatsMessage(JobProgression jobProg) {
|
public String jobStatsMessage(JobProgression jobProg) {
|
||||||
String message = Jobs.getLanguage().getMessage("command.stats.output",
|
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,
|
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
||||||
"%jobxp%", Double.toString(Math.round(jobProg.getExperience() * 100.0) / 100.0),
|
"%jobxp%",Math.round(jobProg.getExperience() * 100.0) / 100.0,
|
||||||
"%jobmaxxp%", Integer.toString(jobProg.getMaxExperience()));
|
"%jobmaxxp%", jobProg.getMaxExperience());
|
||||||
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
|
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,15 +613,13 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
* @param jobInfo - jobinfo string line
|
* @param jobInfo - jobinfo string line
|
||||||
* @return the message
|
* @return the message
|
||||||
*/
|
*/
|
||||||
public String jobStatsMessage(String jobInfo) {
|
public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) {
|
||||||
String[] splited = jobInfo.split(":");
|
String message = Jobs.getLanguage().getMessage("command.archive.feedback",
|
||||||
if (Jobs.getJob(splited[0]) == null)
|
"%joblevel%", jobProg.getLevel(),
|
||||||
return "";
|
"%leftjoblevel%", jPlayer.getLevelAfterRejoin(jobProg),
|
||||||
String message = Jobs.getLanguage().getMessage("command.archive.output",
|
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
||||||
"%joblevel%", Integer.valueOf(splited[1]).toString(),
|
"%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0,
|
||||||
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
|
"%jobmaxxp%", jobProg.getMaxExperience());
|
||||||
"%jobname%", Jobs.getJob(splited[0]).getChatColor() + splited[0] + ChatColor.WHITE,
|
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
|
||||||
"%jobxp%", Double.toString(Math.round(Double.valueOf(splited[3]) * 100.0) / 100.0));
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
package com.gamingmesh.jobs.commands.list;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.commands.JobCommand;
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
|
import com.gamingmesh.jobs.container.JobProgression;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
|
import com.gamingmesh.jobs.stuff.RawMessage;
|
||||||
|
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||||
|
|
||||||
public class archive implements Cmd {
|
public class archive implements Cmd {
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ public class archive implements Cmd {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> AllJobs = Jobs.getJobsDAO().getJobsFromArchive(jPlayer);
|
Set<JobProgression> AllJobs = jPlayer.getArchivedJobs().getArchivedJobs();
|
||||||
|
|
||||||
if (AllJobs.isEmpty()) {
|
if (AllJobs.isEmpty()) {
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.archive.error.nojob"));
|
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()));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName()));
|
||||||
for (String jobInfo : AllJobs) {
|
for (JobProgression jobInfo : AllJobs) {
|
||||||
sender.sendMessage(Jobs.getCommandManager().jobStatsMessage(jobInfo));
|
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"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,8 +8,10 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.commands.JobCommand;
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
import com.gamingmesh.jobs.container.Job;
|
import com.gamingmesh.jobs.container.Job;
|
||||||
|
import com.gamingmesh.jobs.container.JobProgression;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
|
||||||
public class join implements Cmd {
|
public class join implements Cmd {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,6 +85,14 @@ public class join implements Cmd {
|
|||||||
return true;
|
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);
|
Jobs.getPlayerManager().joinJob(jPlayer, job);
|
||||||
|
|
||||||
String message = Jobs.getLanguage().getMessage("command.join.success");
|
String message = Jobs.getLanguage().getMessage("command.join.success");
|
||||||
|
@ -194,6 +194,12 @@ public class ConfigManager {
|
|||||||
maxSlots = null;
|
maxSlots = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Long rejoinCd = jobSection.getLong("rejoinCooldown", 0L);
|
||||||
|
if (rejoinCd < 0L) {
|
||||||
|
rejoinCd = 0L;
|
||||||
|
}
|
||||||
|
rejoinCd = rejoinCd * 1000L;
|
||||||
|
|
||||||
String jobShortName = jobSection.getString("shortname", null);
|
String jobShortName = jobSection.getString("shortname", null);
|
||||||
if (jobShortName == null) {
|
if (jobShortName == null) {
|
||||||
Jobs.getPluginLogger().warning("Job " + jobKey + " is missing the shortname property. Skipping job!");
|
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,
|
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.setMoneyEquation(incomeEquation);
|
||||||
job.setXpEquation(expEquation);
|
job.setXpEquation(expEquation);
|
||||||
|
@ -250,7 +250,7 @@ public class LanguageManager {
|
|||||||
c.get("command.archive.help.args", "[playername]");
|
c.get("command.archive.help.args", "[playername]");
|
||||||
Jobs.getGCManager().commandArgs.put("archive", Arrays.asList("[playername]"));
|
Jobs.getGCManager().commandArgs.put("archive", Arrays.asList("[playername]"));
|
||||||
c.get("command.archive.error.nojob", "There is no jobs saved.");
|
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.info", "Gives item by jobs name and item category name. Player name is optional");
|
||||||
c.get("command.give.help.args", "[playername] [jobname] [itemname]");
|
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.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.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.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.join.success", "You have joined the job %jobname%.");
|
||||||
|
|
||||||
c.get("command.leave.help.info", "Leave the selected job.");
|
c.get("command.leave.help.info", "Leave the selected job.");
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -66,6 +66,8 @@ public class Job {
|
|||||||
private List<String> CmdOnLeave = new ArrayList<String>();
|
private List<String> CmdOnLeave = new ArrayList<String>();
|
||||||
// Item for GUI
|
// Item for GUI
|
||||||
private ItemStack GUIitem;
|
private ItemStack GUIitem;
|
||||||
|
// Item for GUI
|
||||||
|
private Long rejoinCd = 0L;
|
||||||
|
|
||||||
private int totalPlayers = -1;
|
private int totalPlayers = -1;
|
||||||
private Double bonus = null;
|
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,
|
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,
|
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.jobName = jobName;
|
||||||
this.jobShortName = jobShortName;
|
this.jobShortName = jobShortName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -115,6 +117,7 @@ public class Job {
|
|||||||
this.CmdOnLeave = CmdOnLeave;
|
this.CmdOnLeave = CmdOnLeave;
|
||||||
this.GUIitem = GUIitem;
|
this.GUIitem = GUIitem;
|
||||||
this.bossbar = bossbar;
|
this.bossbar = bossbar;
|
||||||
|
this.rejoinCd = rejoinCD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBoost(CurrencyType type, double Point) {
|
public void addBoost(CurrencyType type, double Point) {
|
||||||
@ -378,4 +381,12 @@ public class Job {
|
|||||||
public void setPointsEquation(Parser pointsEquation) {
|
public void setPointsEquation(Parser pointsEquation) {
|
||||||
this.pointsEquation = pointsEquation;
|
this.pointsEquation = pointsEquation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getRejoinCd() {
|
||||||
|
return rejoinCd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRejoinCd(Long rejoinCd) {
|
||||||
|
this.rejoinCd = rejoinCd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,15 @@ package com.gamingmesh.jobs.container;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||||
|
|
||||||
public class JobProgression {
|
public class JobProgression {
|
||||||
private Job job;
|
private Job job;
|
||||||
private JobsPlayer jPlayer;
|
private JobsPlayer jPlayer;
|
||||||
private double experience;
|
private double experience;
|
||||||
private int level;
|
private int level;
|
||||||
private transient int maxExperience = -1;
|
private transient int maxExperience = -1;
|
||||||
|
private Long leftOn = null;
|
||||||
|
|
||||||
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
|
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
|
||||||
this.job = job;
|
this.job = job;
|
||||||
@ -223,4 +226,29 @@ public class JobProgression {
|
|||||||
reloadMaxExperience();
|
reloadMaxExperience();
|
||||||
return checkLevelUp();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -42,6 +43,7 @@ public class JobsPlayer {
|
|||||||
// progression of the player in each job
|
// progression of the player in each job
|
||||||
public UUID playerUUID;
|
public UUID playerUUID;
|
||||||
public ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
|
public ArrayList<JobProgression> progression = new ArrayList<JobProgression>();
|
||||||
|
private ArchivedJobs archivedJobs = new ArchivedJobs();
|
||||||
|
|
||||||
private PaymentData paymentLimits = null;
|
private PaymentData paymentLimits = null;
|
||||||
|
|
||||||
@ -80,6 +82,18 @@ public class JobsPlayer {
|
|||||||
this.player = Bukkit.getPlayer(userName);
|
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() {
|
public int getTotalLevels() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (JobProgression job : progression) {
|
for (JobProgression job : progression) {
|
||||||
@ -370,10 +384,10 @@ public class JobsPlayer {
|
|||||||
if (!isInJob(job)) {
|
if (!isInJob(job)) {
|
||||||
int level = 1;
|
int level = 1;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
if (Jobs.getJobsDAO().checkArchive(this, job).size() > 0) {
|
|
||||||
List<Integer> info = Jobs.getJobsDAO().checkArchive(this, job);
|
JobProgression archived = this.getArchivedJobProgression(job);
|
||||||
level = info.get(0);
|
if (archived != null) {
|
||||||
//exp = info.get(1);
|
level = getLevelAfterRejoin(archived);
|
||||||
Jobs.getJobsDAO().deleteArchive(this, job);
|
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
|
* Player leaves a job
|
||||||
* @param job - the job left
|
* @param job - the job left
|
||||||
|
@ -19,6 +19,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
|
import com.gamingmesh.jobs.container.ArchivedJobs;
|
||||||
import com.gamingmesh.jobs.container.BlockProtection;
|
import com.gamingmesh.jobs.container.BlockProtection;
|
||||||
import com.gamingmesh.jobs.container.Convert;
|
import com.gamingmesh.jobs.container.Convert;
|
||||||
import com.gamingmesh.jobs.container.CurrencyType;
|
import com.gamingmesh.jobs.container.CurrencyType;
|
||||||
@ -113,7 +114,8 @@ public abstract class JobsDAO {
|
|||||||
userid("int", TablesFieldsType.number),
|
userid("int", TablesFieldsType.number),
|
||||||
job("text", TablesFieldsType.text),
|
job("text", TablesFieldsType.text),
|
||||||
experience("int", TablesFieldsType.number),
|
experience("int", TablesFieldsType.number),
|
||||||
level("int", TablesFieldsType.number);
|
level("int", TablesFieldsType.number),
|
||||||
|
left("bigint", TablesFieldsType.longNumber);
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
private TablesFieldsType fieldType;
|
private TablesFieldsType fieldType;
|
||||||
@ -634,6 +636,47 @@ public abstract class JobsDAO {
|
|||||||
return map;
|
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() {
|
public HashMap<Integer, HashMap<String, Log>> getAllLogs() {
|
||||||
HashMap<Integer, HashMap<String, Log>> map = new HashMap<Integer, HashMap<String, Log>>();
|
HashMap<Integer, HashMap<String, Log>> map = new HashMap<Integer, HashMap<String, Log>>();
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
@ -941,24 +984,19 @@ public abstract class JobsDAO {
|
|||||||
* @param player - player that wishes to join the job
|
* @param player - player that wishes to join the job
|
||||||
* @param job - job that the player wishes to join
|
* @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();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
PreparedStatement prest = null;
|
PreparedStatement prest = null;
|
||||||
try {
|
try {
|
||||||
int level = 1;
|
int level = job.getLevel();
|
||||||
int exp = 0;
|
Double exp = job.getExperience();
|
||||||
if (checkArchive(jPlayer, job).size() > 0) {
|
|
||||||
List<Integer> info = checkArchive(jPlayer, job);
|
|
||||||
level = info.get(0);
|
|
||||||
deleteArchive(jPlayer, job);
|
|
||||||
}
|
|
||||||
prest = conn.prepareStatement("INSERT INTO `" + prefix + "jobs` (`userid`, `job`, `level`, `experience`) VALUES (?, ?, ?, ?);");
|
prest = conn.prepareStatement("INSERT INTO `" + prefix + "jobs` (`userid`, `job`, `level`, `experience`) VALUES (?, ?, ?, ?);");
|
||||||
prest.setInt(1, jPlayer.getUserId());
|
prest.setInt(1, jPlayer.getUserId());
|
||||||
prest.setString(2, job.getName());
|
prest.setString(2, job.getJob().getName());
|
||||||
prest.setInt(3, level);
|
prest.setInt(3, level);
|
||||||
prest.setInt(4, exp);
|
prest.setInt(4, exp.intValue());
|
||||||
prest.execute();
|
prest.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1141,24 +1179,24 @@ public abstract class JobsDAO {
|
|||||||
* @param job - job that the player wishes to quit
|
* @param job - job that the player wishes to quit
|
||||||
*/
|
*/
|
||||||
public void recordToArchive(JobsPlayer jPlayer, Job job) {
|
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();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
PreparedStatement prest = null;
|
PreparedStatement prest = null;
|
||||||
try {
|
try {
|
||||||
int level = 1;
|
int level = jp.getLevel();
|
||||||
int exp = 0;
|
Double exp = jp.getExperience();
|
||||||
for (JobProgression progression : jPlayer.getJobProgression()) {
|
prest = conn.prepareStatement("INSERT INTO `" + prefix + "archive` (`userid`, `job`, `level`, `experience`, `left`) VALUES (?, ?, ?, ?, ?);");
|
||||||
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 (?, ?, ?, ?);");
|
|
||||||
prest.setInt(1, jPlayer.getUserId());
|
prest.setInt(1, jPlayer.getUserId());
|
||||||
prest.setString(2, job.getName());
|
prest.setString(2, job.getName());
|
||||||
prest.setInt(3, level);
|
prest.setInt(3, level);
|
||||||
prest.setInt(4, exp);
|
prest.setInt(4, exp.intValue());
|
||||||
|
prest.setLong(5, System.currentTimeMillis());
|
||||||
prest.execute();
|
prest.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1167,47 +1205,46 @@ public abstract class JobsDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Check job in archive
|
// * Check job in archive
|
||||||
* @param player - player that wishes to quit the job
|
// * @param player - player that wishes to quit the job
|
||||||
* @param job - job that the player wishes to quit
|
// * @param job - job that the player wishes to quit
|
||||||
*/
|
// */
|
||||||
public synchronized List<Integer> checkArchive(JobsPlayer jPlayer, Job job) {
|
// public synchronized JobProgression getOldJobProgresion(JobsPlayer jPlayer, Job job) {
|
||||||
JobsConnection conn = getConnection();
|
// JobsConnection conn = getConnection();
|
||||||
List<Integer> info = new ArrayList<Integer>();
|
// JobProgression jp = null;
|
||||||
if (conn == null)
|
// if (conn == null)
|
||||||
return info;
|
// return jp;
|
||||||
PreparedStatement prest = null;
|
// PreparedStatement prest = null;
|
||||||
ResultSet res = null;
|
// ResultSet res = null;
|
||||||
try {
|
// try {
|
||||||
prest = conn.prepareStatement("SELECT `level`, `experience` FROM `" + prefix + "archive` WHERE `userid` = ? AND `job` = ?;");
|
// prest = conn.prepareStatement("SELECT `level`, `experience`, `left` FROM `" + prefix + "archive` WHERE `userid` = ? AND `job` = ?;");
|
||||||
prest.setInt(1, jPlayer.getUserId());
|
// prest.setInt(1, jPlayer.getUserId());
|
||||||
prest.setString(2, job.getName());
|
// prest.setString(2, job.getName());
|
||||||
res = prest.executeQuery();
|
// res = prest.executeQuery();
|
||||||
if (res.next()) {
|
// if (res.next()) {
|
||||||
int level = (int) ((res.getInt(1) - (res.getInt(1) * (Jobs.getGCManager().levelLossPercentage / 100.0))));
|
// int level = (int) ((res.getInt(1) - (res.getInt(1) * (Jobs.getGCManager().levelLossPercentage / 100.0))));
|
||||||
if (level < 1)
|
// if (level < 1)
|
||||||
level = 1;
|
// level = 1;
|
||||||
|
//
|
||||||
int maxLevel = 0;
|
// int maxLevel = 0;
|
||||||
if (jPlayer.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
|
// if (jPlayer.havePermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
|
||||||
maxLevel = job.getVipMaxLevel();
|
// maxLevel = job.getVipMaxLevel();
|
||||||
else
|
// else
|
||||||
maxLevel = job.getMaxLevel();
|
// maxLevel = job.getMaxLevel();
|
||||||
|
//
|
||||||
if (Jobs.getGCManager().fixAtMaxLevel && res.getInt(1) == maxLevel)
|
// if (Jobs.getGCManager().fixAtMaxLevel && res.getInt(1) == maxLevel)
|
||||||
level = res.getInt(1);
|
// level = res.getInt(1);
|
||||||
info.add(level);
|
// jp = new JobProgression(job, jPlayer, level, res.getInt("experience"));
|
||||||
info.add(res.getInt(2));
|
// }
|
||||||
}
|
// } catch (SQLException e) {
|
||||||
} catch (SQLException e) {
|
// e.printStackTrace();
|
||||||
e.printStackTrace();
|
// } finally {
|
||||||
} finally {
|
// close(res);
|
||||||
close(res);
|
// close(prest);
|
||||||
close(prest);
|
// }
|
||||||
}
|
// return jp;
|
||||||
return info;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public List<TopList> getGlobalTopList() {
|
public List<TopList> getGlobalTopList() {
|
||||||
return getGlobalTopList(0);
|
return getGlobalTopList(0);
|
||||||
@ -1415,6 +1452,7 @@ public abstract class JobsDAO {
|
|||||||
* @param job - job that the player wishes to quit
|
* @param job - job that the player wishes to quit
|
||||||
*/
|
*/
|
||||||
public synchronized void deleteArchive(JobsPlayer jPlayer, Job job) {
|
public synchronized void deleteArchive(JobsPlayer jPlayer, Job job) {
|
||||||
|
jPlayer.getArchivedJobs().removeArchivedJob(job);
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
|
@ -195,7 +195,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
close(statement);
|
close(statement);
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user