From e172048f1faf9abfaece85cbfe2aaa4dc864fd75 Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 22 Jan 2016 14:42:25 +0200 Subject: [PATCH] Action limiting by jobs lvl --- com/gamingmesh/jobs/Gui/GuiTools.java | 4 +- .../jobs/commands/JobsCommands.java | 53 ++++++--- com/gamingmesh/jobs/config/JobConfig.java | 17 ++- .../jobs/config/JobsConfiguration.java | 10 +- com/gamingmesh/jobs/container/Job.java | 7 +- com/gamingmesh/jobs/container/JobInfo.java | 109 ++++++++++-------- com/gamingmesh/jobs/dao/JobsDAO.java | 15 +-- .../jobs/listeners/JobsListener.java | 2 +- plugin.yml | 2 +- 9 files changed, 144 insertions(+), 75 deletions(-) diff --git a/com/gamingmesh/jobs/Gui/GuiTools.java b/com/gamingmesh/jobs/Gui/GuiTools.java index e48cd307..7d3e8156 100644 --- a/com/gamingmesh/jobs/Gui/GuiTools.java +++ b/com/gamingmesh/jobs/Gui/GuiTools.java @@ -123,8 +123,8 @@ public class GuiTools { } Lore.add(""); - Lore.add(Language.getDefaultMessage("command.info.gui.leftClick")); - Lore.add(Language.getDefaultMessage("command.info.gui.rightClick")); + Lore.add(Language.getMessage("command.info.gui.leftClick")); + Lore.add(Language.getMessage("command.info.gui.rightClick")); ItemStack GuiItem = job.getGuiItem(); diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java index ade8df61..e1769c94 100644 --- a/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/com/gamingmesh/jobs/commands/JobsCommands.java @@ -183,19 +183,19 @@ public class JobsCommands implements CommandExecutor { return true; } - @JobCommand - public boolean fixuuid(CommandSender sender, String[] args) throws IOException { - - if (args.length > 0) { - sendUsage(sender, "fixuuid"); - return true; - } - - 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); - - return true; - } +// @JobCommand +// public boolean fixuuid(CommandSender sender, String[] args) throws IOException { +// +// if (args.length > 0) { +// sendUsage(sender, "fixuuid"); +// return true; +// } +// +// 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); +// +// return true; +// } @JobCommand public boolean convert(CommandSender sender, String[] args) throws IOException { @@ -316,6 +316,18 @@ public class JobsCommands implements CommandExecutor { 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 public boolean leave(CommandSender sender, String[] args) { if (!(sender instanceof Player)) @@ -1676,7 +1688,10 @@ public class JobsCommands implements CommandExecutor { message.append(" "); 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(xpString); @@ -1685,6 +1700,16 @@ public class JobsCommands implements CommandExecutor { message.append(incomeColor.toString()); 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'); } return message.toString(); diff --git a/com/gamingmesh/jobs/config/JobConfig.java b/com/gamingmesh/jobs/config/JobConfig.java index 5dd8ce6c..95cc8c77 100644 --- a/com/gamingmesh/jobs/config/JobConfig.java +++ b/com/gamingmesh/jobs/config/JobConfig.java @@ -520,7 +520,22 @@ public class JobConfig { double income = section.getDouble("income", 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); diff --git a/com/gamingmesh/jobs/config/JobsConfiguration.java b/com/gamingmesh/jobs/config/JobsConfiguration.java index b67b2bb7..f2d699f1 100644 --- a/com/gamingmesh/jobs/config/JobsConfiguration.java +++ b/com/gamingmesh/jobs/config/JobsConfiguration.java @@ -470,7 +470,7 @@ public class JobsConfiguration { modifyChatPrefix = getString("modify-chat-prefix", "&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", "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.max", " - &emax level:&f ", 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.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.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.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.none", "%jobname% does not get money from enchanting.", writer, conf, true); GetConfigString("command.info.output.repair.info", "Repair", writer, conf, true); diff --git a/com/gamingmesh/jobs/container/Job.java b/com/gamingmesh/jobs/container/Job.java index 765c2179..7563b63d 100644 --- a/com/gamingmesh/jobs/container/Job.java +++ b/com/gamingmesh/jobs/container/Job.java @@ -220,6 +220,8 @@ public class Job { List jobInfo = getJobInfo(action.getType()); for (JobInfo info : jobInfo) { if (info.getName().equalsIgnoreCase(action.getName()) || info.getName().equalsIgnoreCase(action.getNameWithSub())) { + if (!info.isInLevelRange(level)) + return 0D; return info.getIncome(level, numjobs); } } @@ -237,8 +239,11 @@ public class Job { public Double getExperience(ActionInfo action, int level, int numjobs) { List jobInfo = getJobInfo(action.getType()); 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 null; } diff --git a/com/gamingmesh/jobs/container/JobInfo.java b/com/gamingmesh/jobs/container/JobInfo.java index ee345477..d253fa3e 100644 --- a/com/gamingmesh/jobs/container/JobInfo.java +++ b/com/gamingmesh/jobs/container/JobInfo.java @@ -21,59 +21,76 @@ package com.gamingmesh.jobs.container; import com.gamingmesh.jobs.resources.jfep.Parser; public class JobInfo { - private ActionType actionType; - private int id; - private String meta; - private String name; - private double baseIncome, baseXp; - private Parser moneyEquation, xpEquation; + private ActionType actionType; + private int id; + private String meta; + private String name; + private double baseIncome, baseXp; + 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) { - this.actionType = actionType; - this.id = id; - this.meta = meta; - this.name = name; - this.baseIncome = baseIncome; - this.moneyEquation = moneyEquation; - this.baseXp = baseXp; - this.xpEquation = xpEquation; - } + public JobInfo(ActionType actionType, int id, String meta, String name, double baseIncome, Parser moneyEquation, double baseXp, Parser xpEquation, int fromLevel, + int untilLevel) { + this.actionType = actionType; + this.id = id; + this.meta = meta; + this.name = name; + this.baseIncome = baseIncome; + this.moneyEquation = moneyEquation; + this.baseXp = baseXp; + this.xpEquation = xpEquation; + this.fromLevel = fromLevel; + this.untilLevel = untilLevel; + } - public String getName() { - return this.name; - } + public int getFromLevel() { + return this.fromLevel; + } - public int getId() { - return this.id; - } + public int getUntilLevel() { + return this.untilLevel; + } - public ActionType getActionType() { - return this.actionType; - } + public boolean isInLevelRange(int level) { + return level >= fromLevel && (level <= untilLevel || untilLevel == -1); + } - public String getMeta() { - return this.meta; - } + public String getName() { + return this.name; + } - public double getBaseIncome() { - return this.baseIncome; - } + public int getId() { + return this.id; + } - public double getBaseXp() { - return this.baseXp; - } + public ActionType getActionType() { + return this.actionType; + } - public double getIncome(int level, int numjobs) { - moneyEquation.setVariable("joblevel", level); - moneyEquation.setVariable("numjobs", numjobs); - moneyEquation.setVariable("baseincome", baseIncome); - return moneyEquation.getValue(); - } + public String getMeta() { + return this.meta; + } - public double getExperience(int level, int numjobs) { - xpEquation.setVariable("joblevel", level); - xpEquation.setVariable("numjobs", numjobs); - xpEquation.setVariable("baseexperience", baseXp); - return xpEquation.getValue(); - } + public double getBaseIncome() { + return this.baseIncome; + } + + 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(); + } } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 86f228fd..aa0a1a58 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -643,12 +643,13 @@ public abstract class JobsDAO { if (conn == null) return; 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()) { prest.setInt(1, progression.getLevel()); prest.setInt(2, (int) progression.getExperience()); - prest.setString(3, player.getPlayerUUID().toString()); - prest.setString(4, progression.getJob().getName()); + prest.setString(3, player.getPlayer().getName()); + prest.setString(4, player.getPlayerUUID().toString()); + prest.setString(5, progression.getJob().getName()); prest.execute(); } prest.close(); @@ -661,7 +662,7 @@ public abstract class JobsDAO { * Save player-job information * @param jobInfo - the information getting saved */ - public synchronized void saveLog(JobsPlayer player) { + public void saveLog(JobsPlayer player) { JobsConnection conn = getConnection(); if (conn == null) return; @@ -743,7 +744,7 @@ public abstract class JobsDAO { * Save player-explore information * @param jobexplore - the information getting saved */ - public synchronized void saveExplore() { + public void saveExplore() { if (!Jobs.getExplore().isExploreEnabled()) return; @@ -783,7 +784,7 @@ public abstract class JobsDAO { * Save player-explore information * @param jobexplore - the information getting saved */ - public synchronized void loadExplore() { + public void loadExplore() { if (!Jobs.getExplore().isExploreEnabled()) return; @@ -839,7 +840,7 @@ public abstract class JobsDAO { * @param toplist - toplist by jobs name * @return */ - public synchronized ArrayList toplist(String jobsname, int limit) { + public ArrayList toplist(String jobsname, int limit) { ArrayList jobs = new ArrayList(); JobsConnection conn = getConnection(); if (conn == null) diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 574ce4af..75ba193e 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -554,7 +554,7 @@ public class JobsListener implements Listener { if (meinOk != null) { 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)); } } diff --git a/plugin.yml b/plugin.yml index 43db4b2f..958c18bd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 2.60.0 +version: 2.61.0 author: phrstbrn softdepend: [Vault, CoreProtect, MythicMobs, McMMO] commands: