mcMMO/src/main/java/com/gmail/nossr50/commands/general/MmoeditCommand.java

116 lines
4.0 KiB
Java
Raw Normal View History

2012-01-09 20:00:13 +01:00
package com.gmail.nossr50.commands.general;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
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;
import com.gmail.nossr50.commands.CommandHelper;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.datatypes.PlayerProfile;
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 {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
OfflinePlayer modifiedPlayer;
2012-06-12 22:51:57 +02:00
PlayerProfile playerProfile;
int newValue;
SkillType skill;
String skillName;
2012-04-23 01:34:34 +02:00
String usage = ChatColor.RED + "Proper usage is /mmoedit [player] <skill> <level>"; //TODO: Needs more locale.
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
return true;
}
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])) {
modifiedPlayer = (Player) sender;
newValue = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]);
2012-06-12 22:51:57 +02:00
playerProfile = Users.getProfile(modifiedPlayer);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
}
else {
2012-04-27 11:47:11 +02:00
skillName = Misc.getCapitalized(skill.toString());
}
2012-06-12 22:51:57 +02:00
playerProfile.modifySkill(skill, newValue);
sender.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
}
2012-04-23 01:34:34 +02:00
else {
sender.sendMessage(usage);
}
}
else {
sender.sendMessage(usage);
}
return true;
case 3:
2012-06-12 22:51:57 +02:00
if (!Misc.isInt(args[2])) {
sender.sendMessage(usage);
return true;
}
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-06-12 22:51:57 +02:00
newValue = Integer.valueOf(args[2]);
playerProfile = Users.getProfile(args[0]);
2012-06-12 22:51:57 +02:00
if (playerProfile != null) {
Player player = playerProfile.getPlayer();
2012-06-12 22:51:57 +02:00
if (player.isOnline()) {
player.sendMessage(ChatColor.GREEN + "Your level in " + skillName + " was set to " + newValue + "!"); //TODO: Needs more locale.
}
}
else {
2012-06-12 22:51:57 +02:00
playerProfile = new PlayerProfile(null, args[0], false);
if (!playerProfile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
}
2012-06-12 22:51:57 +02:00
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + args[0] + "."); //TODO: Use locale
playerProfile.modifySkill(skill, newValue);
playerProfile.save();
return true;
default:
sender.sendMessage(usage);
return true;
}
}
2012-01-09 20:00:13 +01:00
}