From a84161585ddcd5c18e7e46c022e4578c0fe65fd6 Mon Sep 17 00:00:00 2001 From: Zrips Date: Thu, 11 May 2017 17:45:57 +0300 Subject: [PATCH] Allow direct exp manipulation for job --- com/gamingmesh/jobs/MyPet/.gitignore | 1 + com/gamingmesh/jobs/MythicMobs/.gitignore | 6 + com/gamingmesh/jobs/commands/list/.gitignore | 2 + com/gamingmesh/jobs/commands/list/exp.java | 103 ++++++++++++++++++ .../jobs/config/LanguageManager.java | 5 + .../jobs/container/JobProgression.java | 26 ++++- 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 com/gamingmesh/jobs/MyPet/.gitignore create mode 100644 com/gamingmesh/jobs/MythicMobs/.gitignore create mode 100644 com/gamingmesh/jobs/commands/list/exp.java diff --git a/com/gamingmesh/jobs/MyPet/.gitignore b/com/gamingmesh/jobs/MyPet/.gitignore new file mode 100644 index 00000000..f56705c6 --- /dev/null +++ b/com/gamingmesh/jobs/MyPet/.gitignore @@ -0,0 +1 @@ +/MyPetManager.class diff --git a/com/gamingmesh/jobs/MythicMobs/.gitignore b/com/gamingmesh/jobs/MythicMobs/.gitignore new file mode 100644 index 00000000..22440ff8 --- /dev/null +++ b/com/gamingmesh/jobs/MythicMobs/.gitignore @@ -0,0 +1,6 @@ +/MythicMobs2Listener.class +/MythicMobsManager.class +/MythicMobInterface.class +/MythicMobs2.class +/MythicMobs4.class +/MythicMobs4Listener.class diff --git a/com/gamingmesh/jobs/commands/list/.gitignore b/com/gamingmesh/jobs/commands/list/.gitignore index 3dec0a50..f4fbffc2 100644 --- a/com/gamingmesh/jobs/commands/list/.gitignore +++ b/com/gamingmesh/jobs/commands/list/.gitignore @@ -56,3 +56,5 @@ /iteminfo.class /area.class /resetlimit.class +/exp.class +/exp$Action.class diff --git a/com/gamingmesh/jobs/commands/list/exp.java b/com/gamingmesh/jobs/commands/list/exp.java new file mode 100644 index 00000000..5c92d5e2 --- /dev/null +++ b/com/gamingmesh/jobs/commands/list/exp.java @@ -0,0 +1,103 @@ +package com.gamingmesh.jobs.commands.list; + +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.Job; +import com.gamingmesh.jobs.container.JobProgression; +import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.ChatColor; + +public class exp implements Cmd { + + private enum Action { + Set, Add, Take + } + + @Override + @JobCommand(1600) + public boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length < 4) { + Jobs.getCommandManager().sendUsage(sender, "exp"); + return true; + } + + Action action = Action.Add; + int amount = 0; + String playerName = null; + Job job = null; + + for (String one : args) { + switch (one.toLowerCase()) { + case "add": + action = Action.Add; + continue; + case "set": + action = Action.Set; + continue; + case "take": + action = Action.Take; + continue; + } + + try { + amount = Integer.parseInt(one); + continue; + } catch (NumberFormatException e) { + } + + if (job == null && Jobs.getJob(one) != null) { + job = Jobs.getJob(one); + continue; + } + playerName = one; + } + + if (playerName == null) + return false; + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(playerName); + + if (jPlayer == null) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); + return true; + } + + if (job == null) { + sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job")); + return true; + } + + try { + // check if player already has the job + if (jPlayer.isInJob(job)) { + + JobProgression prog = jPlayer.getJobProgression(job); + switch (action) { + case Add: + prog.addExperience(amount); + break; + case Set: + prog.setExperience(amount); + break; + case Take: + prog.takeExperience(amount); + break; + } + + Player player = jPlayer.getPlayer(); + if (player != null) { + player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getChatColor() + job.getName(), "%level%", prog.getLevel(), "%exp%", prog.getExperience())); + } + + sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); + } + } catch (Exception e) { + sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.admin.error")); + } + return true; + } +} diff --git a/com/gamingmesh/jobs/config/LanguageManager.java b/com/gamingmesh/jobs/config/LanguageManager.java index dd3c226d..3135589e 100644 --- a/com/gamingmesh/jobs/config/LanguageManager.java +++ b/com/gamingmesh/jobs/config/LanguageManager.java @@ -407,6 +407,11 @@ public class LanguageManager { c.get("command.promote.help.args", "[playername] [jobname] [levels]"); Jobs.getGCManager().commandArgs.put("promote", Arrays.asList("[playername]", "[jobname]", "[levels]")); c.get("command.promote.output.target", "You have been promoted %levelsgained% levels in %jobname%."); + + c.get("command.exp.help.info", "Change the player exp for job."); + c.get("command.exp.help.args", "[playername] [jobname] [set/add/take] [amount]"); + Jobs.getGCManager().commandArgs.put("exp", Arrays.asList("[playername]", "[jobname]", "take%%set%%add")); + c.get("command.exp.output.target", "&eYour exp was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp."); c.get("command.demote.help.info", "Demote the player X levels in a job."); c.get("command.demote.help.args", "[playername] [jobname] [levels]"); diff --git a/com/gamingmesh/jobs/container/JobProgression.java b/com/gamingmesh/jobs/container/JobProgression.java index f4329da4..77aff390 100644 --- a/com/gamingmesh/jobs/container/JobProgression.java +++ b/com/gamingmesh/jobs/container/JobProgression.java @@ -42,7 +42,7 @@ public class JobProgression { public boolean canLevelUp() { return experience >= maxExperience; } - + /** * Return the job * @return the job @@ -77,11 +77,31 @@ public class JobProgression { * @return - job level up */ public boolean addExperience(double experience) { -// synchronized (jPlayer.saveLock) { jPlayer.setSaved(false); this.experience += experience; return checkLevelUp(); -// } + } + + /** + * Sets experience for this job + * @param experience - the experience in this job + * @return - job level up + */ + public boolean setExperience(double experience) { + jPlayer.setSaved(false); + this.experience = experience; + return checkLevelUp(); + } + + /** + * Takes experience from this job + * @param experience - the experience in this job + * @return - job level up + */ + public boolean takeExperience(double experience) { + jPlayer.setSaved(false); + this.experience -= experience; + return checkLevelUp(); } /**