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;

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;
	double 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 = Double.parseDouble(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(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"));
	    } else
	    sender.sendMessage(Jobs.getLanguage().getMessage("command.exp.error.nojob"));
	} catch (Throwable e) {
	    sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
	}
	return true;
    }
}

@@ -711,147 +711,441 @@
 %0A%0D%0A%09
-Action action = Action.Add;%0D%0A%09double amount = 0;%0D%0A%09String 
+JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args%5B0%5D);%0D%0A%09if (jPlayer == null) %7B%0D%0A%09    sender.sendMessage(Jobs.getLanguage().getMessage(%22general.error.noinfoByPlayer%22, %22%25
 player
-Name = null;%0D%0A%09Job job = null;%0D%0A%0D%0A%09for (String one : args) %7B%0D%0A%09    
+name%25%22, args%5B0%5D));%0D%0A%09    return true;%0D%0A%09%7D%0D%0A%0D%0A%09Job job = Jobs.getJob(args%5B1%5D);%0D%0A%09if (job == null) %7B%0D%0A%09    sender.sendMessage(Jobs.getLanguage().getMessage(%22general.error.job%22));%0D%0A%09    return true;%0D%0A%09%7D%0D%0A%0D%0A%09Action action = Action.Add;%0D%0A%0D%0A%09
 switch (
 one.
@@ -1140,19 +1140,23 @@
 switch (
-one
+args%5B2%5D
 .toLower
@@ -1206,32 +1206,29 @@
 ion.Add;%0D%0A%09%09
-continue
+break
 ;%0D%0A%09    case
@@ -1258,32 +1258,29 @@
 ion.Set;%0D%0A%09%09
-continue
+break
 ;%0D%0A%09    case
@@ -1320,653 +1320,194 @@
 %0D%0A%09%09
-continue;%0D%0A%09    %7D%0D%0A%0D%0A%09    try %7B%0D%0A%09%09amount = Double.parseDouble(one);%0D%0A%09%09continue;%0D%0A%09    %7D catch (NumberFormatException e) %7B%0D%0A%09    %7D%0D%0A%0D%0A%09    if (job == null && Jobs.getJob(one) != null) %7B%0D%0A%09%09job = Jobs.getJob(one);%0D%0A%09%09continue;%0D%0A%09    %7D%0D%0A%09    playerName = one;%0D%0A%09%7D%0D%0A%0D%0A%09if (playerName == null)%0D%0A%09    return false;%0D%0A%0D%0A%09JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(playerName);%0D%0A%09if (jPlayer == null) %7B%0D%0A%09    sender.sendMessage(Jobs.getLanguage().getMessage(%22general.error.noinfoByPlayer%22, %22%25playername%25%22, args%5B0%5D));%0D%0A%09    return true;%0D%0A%09%7D%0D%0A%0D%0A%09if (job == null) %7B%0D%0A%09    sender.sendMessage(Jobs.getLanguage().getMessage(%22general
+break;%0D%0A%09%7D%0D%0A%0D%0A%09double amount = 0.0;%0D%0A%09try %7B%0D%0A%09%09amount = Double.parseDouble(args%5B3%5D);%0D%0A%09%7D catch (Throwable e) %7B%0D%0A%09    sender.sendMessage(Jobs.getLanguage().getMessage(%22general.admin
 .error
-.job
 %22));

Fix exp command when contains string instead of number, continue to next step