2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.commands.general;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-04-04 16:34:35 +02:00
|
|
|
import com.gmail.nossr50.commands.CommandHelper;
|
2012-07-07 19:35:32 +02:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-04-04 16:34:35 +02:00
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-05-01 19:58:47 +02:00
|
|
|
import com.gmail.nossr50.util.Skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class MmoeditCommand implements CommandExecutor {
|
2012-04-04 16:34:35 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2012-07-06 15:30:30 +02:00
|
|
|
PlayerProfile profile;
|
2012-04-04 16:34:35 +02:00
|
|
|
int newValue;
|
|
|
|
SkillType skill;
|
|
|
|
String skillName;
|
2013-01-17 05:31:28 +01:00
|
|
|
String usage = LocaleLoader.getString("Commands.Usage.3", new Object[] {"mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">" });
|
2012-04-04 16:34:35 +02:00
|
|
|
|
|
|
|
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
|
|
|
|
return true;
|
2012-02-11 15:01:46 +01:00
|
|
|
}
|
2012-04-04 16:34:35 +02:00
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 2:
|
|
|
|
if (sender instanceof Player) {
|
2012-04-23 01:34:34 +02:00
|
|
|
if (!Skills.isSkill(args[0])) {
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Misc.isInt(args[1])) {
|
2012-07-07 19:35:32 +02:00
|
|
|
Player player = (Player) sender;
|
2012-04-04 16:34:35 +02:00
|
|
|
newValue = Integer.valueOf(args[1]);
|
|
|
|
skill = Skills.getSkillType(args[0]);
|
2012-07-07 19:35:32 +02:00
|
|
|
profile = Users.getProfile(player);
|
2012-04-04 16:34:35 +02:00
|
|
|
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
|
|
skillName = "all skills";
|
|
|
|
}
|
|
|
|
else {
|
2012-04-27 11:47:11 +02:00
|
|
|
skillName = Misc.getCapitalized(skill.toString());
|
2012-04-04 16:34:35 +02:00
|
|
|
}
|
|
|
|
|
2012-07-06 15:30:30 +02:00
|
|
|
profile.modifySkill(skill, newValue);
|
2013-01-17 05:31:28 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", new Object[] {skillName, newValue}));
|
2012-04-04 16:34:35 +02:00
|
|
|
}
|
2012-04-23 01:34:34 +02:00
|
|
|
else {
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
}
|
2012-04-04 16:34:35 +02:00
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
else {
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-04-04 16:34:35 +02:00
|
|
|
|
|
|
|
case 3:
|
2012-06-12 22:51:57 +02:00
|
|
|
if (!Misc.isInt(args[2])) {
|
|
|
|
sender.sendMessage(usage);
|
2012-04-04 16:34:35 +02:00
|
|
|
return true;
|
2012-03-22 21:42:44 +01:00
|
|
|
}
|
2012-04-04 16:34:35 +02:00
|
|
|
|
2012-06-12 22:51:57 +02:00
|
|
|
skill = Skills.getSkillType(args[1]);
|
|
|
|
|
|
|
|
if (skill == null) {
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-12 22:51:57 +02:00
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
|
|
skillName = "all skills";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
skillName = Misc.getCapitalized(skill.toString());
|
|
|
|
}
|
2012-04-04 16:34:35 +02:00
|
|
|
|
2012-06-12 22:51:57 +02:00
|
|
|
newValue = Integer.valueOf(args[2]);
|
2012-07-07 19:35:32 +02:00
|
|
|
McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
|
2012-04-04 16:34:35 +02:00
|
|
|
|
2012-07-07 19:35:32 +02:00
|
|
|
if (mcmmoPlayer != null) {
|
|
|
|
profile = mcmmoPlayer.getProfile();
|
2012-04-04 16:34:35 +02:00
|
|
|
|
2012-10-31 01:59:58 +01:00
|
|
|
if (profile == null) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-07 20:02:54 +02:00
|
|
|
profile.modifySkill(skill, newValue);
|
2013-01-17 05:31:28 +01:00
|
|
|
mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", new Object[] {skillName, newValue}));
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", new Object[] {skillName, args[0]}));
|
2012-04-04 16:34:35 +02:00
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
else {
|
2012-07-07 19:35:32 +02:00
|
|
|
profile = new PlayerProfile(args[0], false); //Temporary Profile
|
2012-06-12 22:51:57 +02:00
|
|
|
|
2012-07-06 15:30:30 +02:00
|
|
|
if (!profile.isLoaded()) {
|
2012-06-12 22:51:57 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 22:12:13 +02:00
|
|
|
|
2012-07-08 00:17:33 +02:00
|
|
|
profile.modifySkill(skill, newValue);
|
2012-07-07 20:02:54 +02:00
|
|
|
profile.save();
|
|
|
|
}
|
2012-07-07 19:35:32 +02:00
|
|
|
return true;
|
2012-04-04 16:34:35 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
sender.sendMessage(usage);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|