Cleanup of AddXP command

This commit is contained in:
GJ 2012-04-03 12:43:53 -04:00
parent c8b30b6714
commit 00e5e75092
2 changed files with 115 additions and 66 deletions

View File

@ -45,10 +45,16 @@ public class AddlevelsCommand implements CommandExecutor{
modifiedPlayer = (Player) sender;
levels = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]);
skillName = m.getCapitalized(skill.toString());
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
}
else {
skillName = m.getCapitalized(skill.toString());
}
Users.getProfile(modifiedPlayer).addLevels(skill, levels);
sender.sendMessage(ChatColor.RED + skillName + " has been modified."); //TODO: Needs more locale.
sender.sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale.
}
}
else {
@ -64,17 +70,24 @@ public class AddlevelsCommand implements CommandExecutor{
if (modifiedPlayer != null && m.isInt(args[2]) && Skills.isSkill(args[1])) {
levels = Integer.valueOf(args[2]);
skill = Skills.getSkillType(args[1]);
skillName = m.getCapitalized(skill.toString());
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
}
else {
skillName = m.getCapitalized(skill.toString());
}
Users.getProfile(modifiedPlayer).addLevels(skill, levels);
if (sender instanceof Player) {
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + playerName + "."); //TODO: Use locale
modifiedPlayer.sendMessage(ChatColor.RED + skillName + " has been modified."); //TODO: Needs more locale.
}
else {
System.out.println(m.getCapitalized(skill.toString()) + " has been modified for " + playerName + "."); //TODO: Use locale
System.out.println(skillName + " has been modified for " + playerName + "."); //TODO: Use locale
}
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + levels + " levels in " + skillName + "!"); //TODO: Needs more locale.
}
return true;

View File

@ -10,76 +10,112 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.Skills;
public class AddxpCommand implements CommandExecutor {
private final mcMMO plugin;
private final mcMMO plugin;
public AddxpCommand(mcMMO instance) {
this.plugin = instance;
}
public AddxpCommand(mcMMO instance) {
this.plugin = instance;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player sendingPlayer;
Player modifiedPlayer;
int xp;
SkillType skill;
String skillName;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
sendingPlayer = (Player) sender;
if (sendingPlayer != null && !mcPermissions.getInstance().mmoedit(sendingPlayer)) {
sendingPlayer.sendMessage(mcLocale.getString("mcPlayerListener.NoPermission"));
return true;
}
}
if (player != null && !mcPermissions.getInstance().mmoedit(player)) {
sender.sendMessage("This command requires permissions."); //TODO: Needs more locale.
return true;
}
switch (args.length) {
case 2:
if (sender instanceof Player) {
if (m.isInt(args[1]) && Skills.isSkill(args[0])) {
modifiedPlayer = (Player) sender;
xp = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]);
if (!(sender instanceof Player)) {
if (args.length < 2) {
// No console aliasing yet
// System.out.println("Usage is /"+LoadProperties.addxp+" playername skillname xp");
System.out.println("Usage is /addxp playername skillname xp");
return true;
} else if (args.length == 3) {
if ((plugin.getServer().getPlayer(args[0]) != null) && m.isInt(args[2]) && Skills.isSkill(args[1])) {
int newvalue = Integer.valueOf(args[2]);
Users.getProfile(plugin.getServer().getPlayer(args[0])).addXPOverride(Skills.getSkillType(args[1]), newvalue);
plugin.getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Experience granted!"); //TODO: Needs more locale.
System.out.println(args[1] + " has been modified for " + plugin.getServer().getPlayer(args[0]).getName() + ".");
Skills.XpCheckAll(plugin.getServer().getPlayer(args[0]));
}
} else {
// No console aliasing yet
// System.out.println("Usage is /"+LoadProperties.addxp+" playername skillname xp");
System.out.println("Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
}
return true;
}
Users.getProfile(modifiedPlayer).addXPOverride(skill, xp);
if (!mcPermissions.getInstance().mmoedit(player)) {
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
return true;
}
if (args.length < 2) {
player.sendMessage(ChatColor.RED + "Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
return true;
}
if (args.length == 3) {
if ((plugin.getServer().getPlayer(args[0]) != null) && m.isInt(args[2]) && Skills.isSkill(args[1])) {
int newvalue = Integer.valueOf(args[2]);
Users.getProfile(plugin.getServer().getPlayer(args[0])).addXP(Skills.getSkillType(args[1]), newvalue);
plugin.getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Experience granted!"); //TODO: Needs more locale.
player.sendMessage(ChatColor.RED + args[1] + " has been modified."); //TODO: Needs more locale.
Skills.XpCheckAll(plugin.getServer().getPlayer(args[0]));
}
} else if (args.length == 2 && m.isInt(args[1]) && Skills.isSkill(args[0])) {
int newvalue = Integer.valueOf(args[1]);
Users.getProfile(player).addXP(Skills.getSkillType(args[0]), newvalue);
player.sendMessage(ChatColor.GREEN + "Experience granted!"); //TODO: Needs more locale.
player.sendMessage(ChatColor.RED + args[0] + " has been modified."); //TODO: Needs more locale.
Skills.XpCheckAll(plugin.getServer().getPlayer(args[0]));
} else {
player.sendMessage(ChatColor.RED + "Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
}
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
}
else {
skillName = m.getCapitalized(skill.toString());
}
return true;
}
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
if (skill.equals(SkillType.ALL)) {
Skills.XpCheckAll(modifiedPlayer);
}
else {
Skills.XpCheckSkill(skill, modifiedPlayer);
}
}
}
else {
System.out.println("Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
}
return true;
case 3:
modifiedPlayer = plugin.getServer().getPlayer(args[0]);
String playerName = modifiedPlayer.getName();
if (modifiedPlayer != null && m.isInt(args[2]) && Skills.isSkill(args[1])) {
xp = Integer.valueOf(args[2]);
skill = Skills.getSkillType(args[1]);
Users.getProfile(modifiedPlayer).addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) {
skillName = "all skills";
}
else {
skillName = m.getCapitalized(skill.toString());
}
if (sender instanceof Player) {
sender.sendMessage(ChatColor.RED + skillName + " has been modified for " + playerName + "."); //TODO: Use locale
}
else {
System.out.println(skillName + " has been modified for " + playerName + "."); //TODO: Use locale
}
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
if (skill.equals(SkillType.ALL)) {
Skills.XpCheckAll(modifiedPlayer);
}
else {
Skills.XpCheckSkill(skill, modifiedPlayer);
}
}
return true;
default:
if (sender instanceof Player) {
sender.sendMessage(ChatColor.RED + "Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
}
else {
System.out.println("Usage is /addxp playername skillname xp"); //TODO: Needs more locale.
}
return true;
}
}
}