mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 20:16:13 +01:00
Allow direct exp manipulation for job
This commit is contained in:
parent
ce62bd578f
commit
a84161585d
1
com/gamingmesh/jobs/MyPet/.gitignore
vendored
Normal file
1
com/gamingmesh/jobs/MyPet/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/MyPetManager.class
|
6
com/gamingmesh/jobs/MythicMobs/.gitignore
vendored
Normal file
6
com/gamingmesh/jobs/MythicMobs/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/MythicMobs2Listener.class
|
||||
/MythicMobsManager.class
|
||||
/MythicMobInterface.class
|
||||
/MythicMobs2.class
|
||||
/MythicMobs4.class
|
||||
/MythicMobs4Listener.class
|
2
com/gamingmesh/jobs/commands/list/.gitignore
vendored
2
com/gamingmesh/jobs/commands/list/.gitignore
vendored
@ -56,3 +56,5 @@
|
||||
/iteminfo.class
|
||||
/area.class
|
||||
/resetlimit.class
|
||||
/exp.class
|
||||
/exp$Action.class
|
||||
|
103
com/gamingmesh/jobs/commands/list/exp.java
Normal file
103
com/gamingmesh/jobs/commands/list/exp.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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]");
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user