Changed /mmoedit to use Bukkit command info. Also fixed bug where

/mcrefresh was registered with the info of /mcgod
This commit is contained in:
GJ 2013-02-04 07:54:26 -05:00
parent 958095d11b
commit c3db026fd9
5 changed files with 78 additions and 83 deletions

View File

@ -9,6 +9,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.admin.AddlevelsCommand;
import com.gmail.nossr50.commands.admin.AddxpCommand;
import com.gmail.nossr50.commands.admin.McgodCommand;
import com.gmail.nossr50.commands.admin.McrefreshCommand;
import com.gmail.nossr50.commands.admin.MmoeditCommand;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
@ -28,7 +30,6 @@ import com.gmail.nossr50.util.Misc;
public final class CommandRegistrationHelper {
private CommandRegistrationHelper() {};
private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
public static void registerSkillCommands() {
@ -148,6 +149,15 @@ public final class CommandRegistrationHelper {
command.setPermission("mcmmo.commands.mcrefresh");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
command.setExecutor(new McgodCommand());
command.setExecutor(new McrefreshCommand());
}
public static void registerMmoeditCommand() {
PluginCommand command = mcMMO.p.getCommand("mmoedit");
command.setDescription(LocaleLoader.getString("Commands.Description.mmoedit"));
command.setPermission("mcmmo.commands.mmoedit");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">"));
command.setExecutor(new MmoeditCommand());
}
}

View File

@ -5,13 +5,13 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class MmoeditCommand implements CommandExecutor {
@ -20,87 +20,57 @@ public class MmoeditCommand implements CommandExecutor {
PlayerProfile profile;
int newValue;
SkillType skill;
String skillName;
String usage = LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">");
switch (args.length) {
case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit")) {
return true;
if (!(sender instanceof Player)) {
return false;
}
if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (Misc.isInt(args[1])) {
Player player = (Player) sender;
newValue = Integer.valueOf(args[1]);
skill = SkillTools.getSkillType(args[0]);
profile = Users.getProfile(player);
if (skill.equals(SkillType.ALL)) {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
}
profile.modifySkill(skill, newValue);
}
else {
sender.sendMessage(usage);
}
}
else {
sender.sendMessage(usage);
}
return true;
case 3:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit.others")) {
return true;
}
if (!Misc.isInt(args[2])) {
sender.sendMessage(usage);
return true;
}
skill = SkillTools.getSkillType(args[1]);
if (skill == null) {
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
newValue = Integer.valueOf(args[2]);
McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
if (!Misc.isInt(args[1])) {
return false;
}
if (mcmmoPlayer != null) {
profile = mcmmoPlayer.getProfile();
newValue = Integer.valueOf(args[1]);
skill = SkillTools.getSkillType(args[0]);
profile = Users.getPlayer((Player) sender).getProfile();
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
profile.modifySkill(skill, newValue);
if (skill == SkillType.ALL) {
mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
skillName = Misc.getCapitalized(skill.toString());
mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skillName, newValue));
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0]));
}
if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
}
profile.modifySkill(skill, newValue);
return true;
case 3:
if (Permissions.hasPermission(sender, "mcmmo.commands.mmoedit.others")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!Misc.isInt(args[2])) {
return false;
}
newValue = Integer.valueOf(args[2]);
skill = SkillTools.getSkillType(args[1]);
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
// 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); //Temporary Profile
if (!profile.isLoaded()) {
@ -109,20 +79,36 @@ public class MmoeditCommand implements CommandExecutor {
}
profile.modifySkill(skill, newValue);
profile.save();
profile.save(); // Since this is a temporary profile, we save it here.
}
else {
profile = mcMMOPlayer.getProfile();
Player player = mcMMOPlayer.getPlayer();
if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
profile.modifySkill(skill, newValue);
// Check if the player is online before we try to send them a message.
if (player.isOnline()) {
if (skill == SkillType.ALL) {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
}
else {
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
}
}
}
if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
}
return true;
default:
sender.sendMessage(usage);
return true;
return false;
}
}
}

View File

@ -25,7 +25,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
import com.gmail.nossr50.chat.commands.ACommand;
import com.gmail.nossr50.chat.commands.PCommand;
import com.gmail.nossr50.commands.CommandRegistrationHelper;
import com.gmail.nossr50.commands.admin.MmoeditCommand;
import com.gmail.nossr50.commands.admin.SkillResetCommand;
import com.gmail.nossr50.commands.admin.XprateCommand;
import com.gmail.nossr50.commands.player.InspectCommand;
@ -454,7 +453,7 @@ public class mcMMO extends JavaPlugin {
// Other commands
CommandRegistrationHelper.registerAddxpCommand();
CommandRegistrationHelper.registerAddlevelsCommand();
getCommand("mmoedit").setExecutor(new MmoeditCommand());
CommandRegistrationHelper.registerMmoeditCommand();
getCommand("inspect").setExecutor(new InspectCommand());
getCommand("xprate").setExecutor(new XprateCommand());
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());

View File

@ -690,4 +690,5 @@ Commands.Description.addlevels=Add mcMMO levels to a user
Commands.Description.addxp=Add mcMMO XP to a user
Commands.Description.mcgod=Toggle mcMMO god-mode on/off
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mmoedit=Edit mcMMO levels for a user
Commands.Description.Skill=Display detailed mcMMO skill info for {0}

View File

@ -59,8 +59,7 @@ commands:
aliases: []
description: Remove a user from the database
mmoedit:
aliases: []
description: Edit the skill values for a user
description: Edit the mcMMO skill values for a user
ptp:
aliases: []
description: Teleport to a party member