1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

[IMPROVE] Add -s argument for /exp command

This commit is contained in:
Teyir 2022-11-28 14:56:29 +01:00
parent 8343995c8f
commit 5a5b82e630

View File

@ -12,83 +12,96 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class exp implements Cmd { public class exp implements Cmd {
private enum Action { private enum Action {
Set, Add, Take Set, Add, Take
} }
@Override @Override
public boolean perform(Jobs plugin, CommandSender sender, String[] args) { public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length < 4) { if (args.length < 4) {
Jobs.getCommandManager().sendUsage(sender, "exp"); Jobs.getCommandManager().sendUsage(sender, "exp");
return true; return true;
} }
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) { if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0])); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true; return true;
} }
Job job = Jobs.getJob(args[1]); Job job = Jobs.getJob(args[1]);
if (job == null) { if (job == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
return true; return true;
} }
Action action = Action.Add; Action action = Action.Add;
switch (args[2].toLowerCase()) { switch (args[2].toLowerCase()) {
case "add": case "add":
action = Action.Add; action = Action.Add;
break; break;
case "set": case "set":
action = Action.Set; action = Action.Set;
break; break;
case "take": case "take":
action = Action.Take; action = Action.Take;
break; break;
default: default:
break; break;
} }
double amount = 0.0; double amount = 0.0;
try { try {
amount = Double.parseDouble(args[3]); amount = Double.parseDouble(args[3]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true; return true;
} }
try { try {
// check if player already has the job // check if player already has the job
if (jPlayer.isInJob(job)) { if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job); JobProgression prog = jPlayer.getJobProgression(job);
switch (action) { switch (action) {
case Add: case Add:
int oldLevel = prog.getLevel(); int oldLevel = prog.getLevel();
if (prog.addExperience(amount)) if (prog.addExperience(amount))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
break; break;
case Set: case Set:
prog.setExperience(amount); prog.setExperience(amount);
break; break;
case Take: case Take:
prog.takeExperience(amount); prog.takeExperience(amount);
break; break;
default: default:
break; break;
} }
Player player = jPlayer.getPlayer(); Player player = jPlayer.getPlayer();
if (player != null) boolean isSilent = false;
player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog if (player != null) {
.getExperience())); for (String one : args) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success")); if (one.equalsIgnoreCase("-s")) {
} else isSilent = true;
sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob")); break;
} catch (Exception e) { }
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); }
} if (!isSilent) {
return true; player.sendMessage(Jobs.getLanguage().getMessage("command.exp.output.target", "%jobname%", job.getDisplayName(), "%level%", prog.getLevelFormatted(), "%exp%", prog
.getExperience()));
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
} else {
sender.sendMessage(Jobs.getLanguage().getMessage("general.give.output.notonline"));
}
} else {
sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob"));
}
} catch (Exception e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
}
return true;
} }
} }