1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +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 {
private enum Action {
Set, Add, Take
Set, Add, Take
}
@Override
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length < 4) {
Jobs.getCommandManager().sendUsage(sender, "exp");
return true;
}
if (args.length < 4) {
Jobs.getCommandManager().sendUsage(sender, "exp");
return true;
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
Action action = Action.Add;
Action action = Action.Add;
switch (args[2].toLowerCase()) {
case "add":
action = Action.Add;
break;
case "set":
action = Action.Set;
break;
case "take":
action = Action.Take;
break;
default:
break;
}
switch (args[2].toLowerCase()) {
case "add":
action = Action.Add;
break;
case "set":
action = Action.Set;
break;
case "take":
action = Action.Take;
break;
default:
break;
}
double amount = 0.0;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true;
}
double amount = 0.0;
try {
amount = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
return true;
}
try {
// check if player already has the job
if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job);
try {
// check if player already has the job
if (jPlayer.isInJob(job)) {
JobProgression prog = jPlayer.getJobProgression(job);
switch (action) {
case Add:
int oldLevel = prog.getLevel();
if (prog.addExperience(amount))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
break;
case Set:
prog.setExperience(amount);
break;
case Take:
prog.takeExperience(amount);
break;
default:
break;
}
switch (action) {
case Add:
int oldLevel = prog.getLevel();
if (prog.addExperience(amount))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
break;
case Set:
prog.setExperience(amount);
break;
case Take:
prog.takeExperience(amount);
break;
default:
break;
}
Player player = jPlayer.getPlayer();
if (player != null)
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("command.exp.error.nojob"));
} catch (Exception e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
}
return true;
Player player = jPlayer.getPlayer();
boolean isSilent = false;
if (player != null) {
for (String one : args) {
if (one.equalsIgnoreCase("-s")) {
isSilent = true;
break;
}
}
if (!isSilent) {
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;
}
}