2013-02-01 19:41:26 +01:00
|
|
|
package com.gmail.nossr50.commands.admin;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-07-06 17:57:17 +02:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-06-04 15:30:51 +02:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-01-31 19:29:42 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class AddxpCommand implements CommandExecutor {
|
2012-04-03 18:43:53 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
Player modifiedPlayer;
|
|
|
|
int xp;
|
|
|
|
SkillType skill;
|
2013-02-02 08:07:35 +01:00
|
|
|
McMMOPlayer mcMMOPlayer;
|
|
|
|
PlayerProfile profile;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-03 18:43:53 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 2:
|
2013-02-02 08:07:35 +01:00
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-02 08:33:59 +01:00
|
|
|
if (!SkillTools.isSkill(args[0])) {
|
2013-02-02 08:07:35 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
2013-01-31 19:29:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-02 08:07:35 +01:00
|
|
|
if (!Misc.isInt(args[1])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
xp = Integer.valueOf(args[1]);
|
|
|
|
skill = SkillTools.getSkillType(args[0]);
|
|
|
|
modifiedPlayer = (Player) sender;
|
|
|
|
mcMMOPlayer = Users.getPlayer(modifiedPlayer);
|
|
|
|
profile = mcMMOPlayer.getProfile();
|
|
|
|
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
2013-02-03 13:56:47 +01:00
|
|
|
for (SkillType type : SkillType.values()) {
|
|
|
|
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
|
|
|
|
continue;
|
2013-02-03 12:45:19 +01:00
|
|
|
}
|
2013-02-03 13:56:47 +01:00
|
|
|
|
|
|
|
mcMMOPlayer.applyXpGain(type, xp);
|
2013-02-03 12:45:19 +01:00
|
|
|
}
|
|
|
|
|
2013-02-02 08:55:49 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
|
2012-04-03 18:43:53 +02:00
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
else {
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.applyXpGain(skill, xp);
|
2013-02-02 08:55:49 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(skill.toString())));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-04-03 18:43:53 +02:00
|
|
|
|
|
|
|
case 3:
|
2013-02-02 08:07:35 +01:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.addxp.others")) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
2013-01-30 18:09:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
if (!SkillTools.isSkill(args[1])) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
2012-04-23 01:34:34 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-02 08:07:35 +01:00
|
|
|
if (!Misc.isInt(args[2])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-02 09:19:58 +01:00
|
|
|
mcMMOPlayer = Users.getPlayer(args[0]);
|
2013-02-02 08:07:35 +01:00
|
|
|
xp = Integer.valueOf(args[2]);
|
|
|
|
skill = SkillTools.getSkillType(args[1]);
|
|
|
|
|
2013-02-02 09:19:58 +01:00
|
|
|
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
|
|
|
if (mcMMOPlayer == null) {
|
|
|
|
profile = new PlayerProfile(args[0], false);
|
|
|
|
|
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-03 12:45:19 +01:00
|
|
|
// TODO: Currently the offline player doesn't level up automatically
|
2013-02-02 09:19:58 +01:00
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
|
|
for (SkillType type : SkillType.values()) {
|
|
|
|
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.setSkillXpLevel(type, profile.getSkillXpLevel(type) + xp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + xp);
|
|
|
|
}
|
|
|
|
|
|
|
|
profile.save(); // Since this is a temporary profile, we save it here.
|
|
|
|
}
|
|
|
|
else {
|
2013-02-03 13:56:47 +01:00
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
|
|
for (SkillType type : SkillType.values()) {
|
|
|
|
if (type.equals(SkillType.ALL) || type.isChildSkill()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcMMOPlayer.applyXpGain(type, xp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mcMMOPlayer.applyXpGain(skill, xp);
|
|
|
|
}
|
2013-02-02 09:19:58 +01:00
|
|
|
|
|
|
|
modifiedPlayer = mcMMOPlayer.getPlayer();
|
2013-02-03 13:56:47 +01:00
|
|
|
|
2013-02-02 09:19:58 +01:00
|
|
|
|
|
|
|
if (modifiedPlayer.isOnline()) {
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
|
|
modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", xp));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
modifiedPlayer.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", xp, Misc.getCapitalized(skill.toString())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-02 08:07:35 +01:00
|
|
|
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
2013-02-02 09:19:58 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
|
2012-04-04 16:34:35 +02:00
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
else {
|
2013-02-02 09:19:58 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", Misc.getCapitalized(skill.toString()), args[0]));
|
2012-04-04 22:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-04-03 18:43:53 +02:00
|
|
|
|
|
|
|
default:
|
2013-02-02 08:07:35 +01:00
|
|
|
return false;
|
2012-02-06 20:24:33 +01:00
|
|
|
}
|
2012-04-03 18:43:53 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|