1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +01:00

Action limiting by jobs lvl

This commit is contained in:
Zrips 2016-01-22 14:42:25 +02:00
parent 7b049fe670
commit e172048f1f
9 changed files with 144 additions and 75 deletions

View File

@ -123,8 +123,8 @@ public class GuiTools {
} }
Lore.add(""); Lore.add("");
Lore.add(Language.getDefaultMessage("command.info.gui.leftClick")); Lore.add(Language.getMessage("command.info.gui.leftClick"));
Lore.add(Language.getDefaultMessage("command.info.gui.rightClick")); Lore.add(Language.getMessage("command.info.gui.rightClick"));
ItemStack GuiItem = job.getGuiItem(); ItemStack GuiItem = job.getGuiItem();

View File

@ -183,19 +183,19 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
@JobCommand // @JobCommand
public boolean fixuuid(CommandSender sender, String[] args) throws IOException { // public boolean fixuuid(CommandSender sender, String[] args) throws IOException {
//
if (args.length > 0) { // if (args.length > 0) {
sendUsage(sender, "fixuuid"); // sendUsage(sender, "fixuuid");
return true; // return true;
} // }
//
sender.sendMessage(ChatColor.GOLD + "[Jobs] Starting uuid fix proccess, this can take up to minute depending on your data base size."); // sender.sendMessage(ChatColor.GOLD + "[Jobs] Starting uuid fix proccess, this can take up to minute depending on your data base size.");
Jobs.getJobsDAO().fixUuid(sender); // Jobs.getJobsDAO().fixUuid(sender);
//
return true; // return true;
} // }
@JobCommand @JobCommand
public boolean convert(CommandSender sender, String[] args) throws IOException { public boolean convert(CommandSender sender, String[] args) throws IOException {
@ -316,6 +316,18 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
@JobCommand
public boolean test(CommandSender sender, String[] args) {
if (!(sender instanceof Player))
return false;
Player pSender = (Player) sender;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
Jobs.getJobsDAO().saveLog(jPlayer);
return true;
}
@JobCommand @JobCommand
public boolean leave(CommandSender sender, String[] args) { public boolean leave(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) if (!(sender instanceof Player))
@ -1676,7 +1688,10 @@ public class JobsCommands implements CommandExecutor {
message.append(" "); message.append(" ");
message.append(Language.getMessage("command.info.help.material").replace("%material%", materialName)); message.append(Language.getMessage("command.info.help.material").replace("%material%", materialName));
message.append(" -> "); if (!info.isInLevelRange(prog.getLevel()))
message.append(org.bukkit.ChatColor.RED + " -> ");
else
message.append(" -> ");
message.append(xpColor.toString()); message.append(xpColor.toString());
message.append(xpString); message.append(xpString);
@ -1685,6 +1700,16 @@ public class JobsCommands implements CommandExecutor {
message.append(incomeColor.toString()); message.append(incomeColor.toString());
message.append(Jobs.getEconomy().format(income)); message.append(Jobs.getEconomy().format(income));
if (info.getFromLevel() > 1 && info.getUntilLevel() != -1)
message.append(Language.getMessage("command.info.help.levelRange").replace("%levelFrom%", "" + info.getFromLevel()).replace("%levelUntil%", "" + info
.getUntilLevel()));
if (info.getFromLevel() > 1 && info.getUntilLevel() == -1)
message.append(Language.getMessage("command.info.help.levelFrom").replace("%levelFrom%", "" + info.getFromLevel()));
if (info.getFromLevel() == 1 && info.getUntilLevel() != -1)
message.append(Language.getMessage("command.info.help.levelUntil").replace("%levelUntil%", "" + info.getUntilLevel()));
message.append('\n'); message.append('\n');
} }
return message.toString(); return message.toString();

View File

@ -520,7 +520,22 @@ public class JobConfig {
double income = section.getDouble("income", 0.0); double income = section.getDouble("income", 0.0);
double experience = section.getDouble("experience", 0.0); double experience = section.getDouble("experience", 0.0);
jobInfo.add(new JobInfo(actionType, id, meta, type + subType, income, incomeEquation, experience, expEquation)); int fromlevel = 1;
if (section.isInt("from-level"))
fromlevel = section.getInt("from-level");
int untilLevel = -1;
if (section.isInt("until-level")) {
untilLevel = section.getInt("until-level");
if (untilLevel < fromlevel) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid until-level in " + actionType.getName() + " for type property: " + key
+ "! It will be not set.");
untilLevel = -1;
}
}
jobInfo.add(new JobInfo(actionType, id, meta, type + subType, income, incomeEquation, experience, expEquation, fromlevel, untilLevel));
} }
} }
job.setJobInfo(actionType, jobInfo); job.setJobInfo(actionType, jobInfo);

View File

@ -470,7 +470,7 @@ public class JobsConfiguration {
modifyChatPrefix = getString("modify-chat-prefix", "&c[", config, writer, true); modifyChatPrefix = getString("modify-chat-prefix", "&c[", config, writer, true);
modifyChatSuffix = getString("modify-chat-suffix", "&c]", config, writer, true); modifyChatSuffix = getString("modify-chat-suffix", "&c]", config, writer, true);
modifyChatSeparator = getString("modify-chat-seperator", " ", config, writer, true); modifyChatSeparator = getString("modify-chat-separator", " ", config, writer, true);
writer.addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names", writer.addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names",
"With this set to true names like Stone:1 will be translated to Granite", "Name list is in ItemList.yml file"); "With this set to true names like Stone:1 will be translated to Granite", "Name list is in ItemList.yml file");
@ -1359,6 +1359,10 @@ public class JobsConfiguration {
GetConfigString("command.info.help.actions", "&eValid actions are: &f%actions%", writer, conf, true); GetConfigString("command.info.help.actions", "&eValid actions are: &f%actions%", writer, conf, true);
GetConfigString("command.info.help.max", " - &emax level:&f ", writer, conf, true); GetConfigString("command.info.help.max", " - &emax level:&f ", writer, conf, true);
GetConfigString("command.info.help.material", "&7%material%", writer, conf, true); GetConfigString("command.info.help.material", "&7%material%", writer, conf, true);
GetConfigString("command.info.help.levelRange", " &a(&e%levelFrom% &a- &e%levelUntil% &alevels)", writer, conf, true);
GetConfigString("command.info.help.levelFrom", " &a(from &e%levelFrom% &alevel)", writer, conf, true);
GetConfigString("command.info.help.levelUntil", " &a(until &e%levelUntil% &alevel)", writer, conf, true);
GetConfigString("command.info.gui.pickjob", "&ePick your job!", writer, conf, true); GetConfigString("command.info.gui.pickjob", "&ePick your job!", writer, conf, true);
GetConfigString("command.info.gui.jobinfo", "&e[jobname] info!", writer, conf, true); GetConfigString("command.info.gui.jobinfo", "&e[jobname] info!", writer, conf, true);
@ -1389,7 +1393,9 @@ public class JobsConfiguration {
GetConfigString("command.info.output.brew.info", "Brew", writer, conf, true); GetConfigString("command.info.output.brew.info", "Brew", writer, conf, true);
GetConfigString("command.info.output.brew.none", "%jobname% does not get money from brewing.", writer, conf, true); GetConfigString("command.info.output.brew.none", "%jobname% does not get money from brewing.", writer, conf, true);
GetConfigString("command.info.output.eat.info", "Eat", writer, conf, true); GetConfigString("command.info.output.eat.info", "Eat", writer, conf, true);
GetConfigString("command.info.output.eat.none", "%jobname% does not get money from eating food.", writer, conf, true); GetConfigString("command.info.output.eat.none", "%jobname% does not get money from eating food.", writer, conf, true);
GetConfigString("command.info.output.dye.info", "Dye", writer, conf, true);
GetConfigString("command.info.output.dye.none", "%jobname% does not get money from dyeing.", writer, conf, true);
GetConfigString("command.info.output.enchant.info", "Enchant", writer, conf, true); GetConfigString("command.info.output.enchant.info", "Enchant", writer, conf, true);
GetConfigString("command.info.output.enchant.none", "%jobname% does not get money from enchanting.", writer, conf, true); GetConfigString("command.info.output.enchant.none", "%jobname% does not get money from enchanting.", writer, conf, true);
GetConfigString("command.info.output.repair.info", "Repair", writer, conf, true); GetConfigString("command.info.output.repair.info", "Repair", writer, conf, true);

View File

@ -220,6 +220,8 @@ public class Job {
List<JobInfo> jobInfo = getJobInfo(action.getType()); List<JobInfo> jobInfo = getJobInfo(action.getType());
for (JobInfo info : jobInfo) { for (JobInfo info : jobInfo) {
if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())) { if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())) {
if (!info.isInLevelRange(level))
return 0D;
return info.getIncome(level, numjobs); return info.getIncome(level, numjobs);
} }
} }
@ -237,8 +239,11 @@ public class Job {
public Double getExperience(ActionInfo action, int level, int numjobs) { public Double getExperience(ActionInfo action, int level, int numjobs) {
List<JobInfo> jobInfo = getJobInfo(action.getType()); List<JobInfo> jobInfo = getJobInfo(action.getType());
for (JobInfo info : jobInfo) { for (JobInfo info : jobInfo) {
if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())) if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())){
if (!info.isInLevelRange(level))
return 0D;
return info.getExperience(level, numjobs); return info.getExperience(level, numjobs);
}
} }
return null; return null;
} }

View File

@ -21,59 +21,76 @@ package com.gamingmesh.jobs.container;
import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.resources.jfep.Parser;
public class JobInfo { public class JobInfo {
private ActionType actionType; private ActionType actionType;
private int id; private int id;
private String meta; private String meta;
private String name; private String name;
private double baseIncome, baseXp; private double baseIncome, baseXp;
private Parser moneyEquation, xpEquation; private Parser moneyEquation, xpEquation;
private int fromLevel;
private int untilLevel;
public JobInfo(ActionType actionType, int id, String meta, String name, double baseIncome, Parser moneyEquation, double baseXp, Parser xpEquation) { public JobInfo(ActionType actionType, int id, String meta, String name, double baseIncome, Parser moneyEquation, double baseXp, Parser xpEquation, int fromLevel,
this.actionType = actionType; int untilLevel) {
this.id = id; this.actionType = actionType;
this.meta = meta; this.id = id;
this.name = name; this.meta = meta;
this.baseIncome = baseIncome; this.name = name;
this.moneyEquation = moneyEquation; this.baseIncome = baseIncome;
this.baseXp = baseXp; this.moneyEquation = moneyEquation;
this.xpEquation = xpEquation; this.baseXp = baseXp;
} this.xpEquation = xpEquation;
this.fromLevel = fromLevel;
this.untilLevel = untilLevel;
}
public String getName() { public int getFromLevel() {
return this.name; return this.fromLevel;
} }
public int getId() { public int getUntilLevel() {
return this.id; return this.untilLevel;
} }
public ActionType getActionType() { public boolean isInLevelRange(int level) {
return this.actionType; return level >= fromLevel && (level <= untilLevel || untilLevel == -1);
} }
public String getMeta() { public String getName() {
return this.meta; return this.name;
} }
public double getBaseIncome() { public int getId() {
return this.baseIncome; return this.id;
} }
public double getBaseXp() { public ActionType getActionType() {
return this.baseXp; return this.actionType;
} }
public double getIncome(int level, int numjobs) { public String getMeta() {
moneyEquation.setVariable("joblevel", level); return this.meta;
moneyEquation.setVariable("numjobs", numjobs); }
moneyEquation.setVariable("baseincome", baseIncome);
return moneyEquation.getValue();
}
public double getExperience(int level, int numjobs) { public double getBaseIncome() {
xpEquation.setVariable("joblevel", level); return this.baseIncome;
xpEquation.setVariable("numjobs", numjobs); }
xpEquation.setVariable("baseexperience", baseXp);
return xpEquation.getValue(); public double getBaseXp() {
} return this.baseXp;
}
public double getIncome(int level, int numjobs) {
moneyEquation.setVariable("joblevel", level);
moneyEquation.setVariable("numjobs", numjobs);
moneyEquation.setVariable("baseincome", baseIncome);
return moneyEquation.getValue();
}
public double getExperience(int level, int numjobs) {
xpEquation.setVariable("joblevel", level);
xpEquation.setVariable("numjobs", numjobs);
xpEquation.setVariable("baseexperience", baseXp);
return xpEquation.getValue();
}
} }

View File

@ -643,12 +643,13 @@ public abstract class JobsDAO {
if (conn == null) if (conn == null)
return; return;
try { try {
PreparedStatement prest = conn.prepareStatement("UPDATE `" + prefix + "jobs` SET `level` = ?, `experience` = ? WHERE `player_uuid` = ? AND `job` = ?;"); PreparedStatement prest = conn.prepareStatement("UPDATE `" + prefix + "jobs` SET `level` = ?, `experience` = ?, `username` = ? WHERE `player_uuid` = ? AND `job` = ?;");
for (JobProgression progression : player.getJobProgression()) { for (JobProgression progression : player.getJobProgression()) {
prest.setInt(1, progression.getLevel()); prest.setInt(1, progression.getLevel());
prest.setInt(2, (int) progression.getExperience()); prest.setInt(2, (int) progression.getExperience());
prest.setString(3, player.getPlayerUUID().toString()); prest.setString(3, player.getPlayer().getName());
prest.setString(4, progression.getJob().getName()); prest.setString(4, player.getPlayerUUID().toString());
prest.setString(5, progression.getJob().getName());
prest.execute(); prest.execute();
} }
prest.close(); prest.close();
@ -661,7 +662,7 @@ public abstract class JobsDAO {
* Save player-job information * Save player-job information
* @param jobInfo - the information getting saved * @param jobInfo - the information getting saved
*/ */
public synchronized void saveLog(JobsPlayer player) { public void saveLog(JobsPlayer player) {
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)
return; return;
@ -743,7 +744,7 @@ public abstract class JobsDAO {
* Save player-explore information * Save player-explore information
* @param jobexplore - the information getting saved * @param jobexplore - the information getting saved
*/ */
public synchronized void saveExplore() { public void saveExplore() {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExplore().isExploreEnabled())
return; return;
@ -783,7 +784,7 @@ public abstract class JobsDAO {
* Save player-explore information * Save player-explore information
* @param jobexplore - the information getting saved * @param jobexplore - the information getting saved
*/ */
public synchronized void loadExplore() { public void loadExplore() {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExplore().isExploreEnabled())
return; return;
@ -839,7 +840,7 @@ public abstract class JobsDAO {
* @param toplist - toplist by jobs name * @param toplist - toplist by jobs name
* @return * @return
*/ */
public synchronized ArrayList<TopList> toplist(String jobsname, int limit) { public ArrayList<TopList> toplist(String jobsname, int limit) {
ArrayList<TopList> jobs = new ArrayList<TopList>(); ArrayList<TopList> jobs = new ArrayList<TopList>();
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)

View File

@ -554,7 +554,7 @@ public class JobsListener implements Listener {
if (meinOk != null) { if (meinOk != null) {
event.setCancelled(true); event.setCancelled(true);
ActionBar.send(player, Language.getDefaultMessage("limitedItem.error.levelup").replace("[jobname]", meinOk)); ActionBar.send(player, Language.getMessage("limitedItem.error.levelup").replace("[jobname]", meinOk));
} }
} }

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.60.0 version: 2.61.0
author: phrstbrn author: phrstbrn
softdepend: [Vault, CoreProtect, MythicMobs, McMMO] softdepend: [Vault, CoreProtect, MythicMobs, McMMO]
commands: commands: