Adding new permissions for the /skillreset command.

This commit is contained in:
U-YUE\Sean 2013-01-30 10:56:58 -08:00
parent cbb941116f
commit 4a24ade442
2 changed files with 204 additions and 26 deletions

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.commands.general; package com.gmail.nossr50.commands.general;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -18,47 +20,121 @@ public class SkillResetCommand implements CommandExecutor {
return true; return true;
} }
//ensure they have the skillreset perm // DEPRECATED PERMISSION
if (CommandHelper.noCommandPermissions(sender, "mcmmo.skillreset")) { boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.skillreset");
String usage = LocaleLoader.getString("Commands.Usage.3", new Object[] {"skillreset", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">"});
String perm = "mcmmo.commands.skillreset";
if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm)) {
return true; return true;
} }
SkillType skillType = null; //simple initialization SkillType skillType = null; //simple initialization
PlayerProfile profile = null;
switch (args.length) {
case 1:
//make sure there's only one argument. output at least some kind of error if not
if (args.length == 0 || (args.length != 1 && args[0] != null)) {
}
skillType = getSkillType(sender, args[0], perm, oldPermission);
if (skillType == null) {
return true;
}
//reset the values in the hash table and persist them
profile = Users.getProfile((Player)sender);
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
profile.resetSkill(skillType);
profile.save();
//display a success message to the user
if (skillType == SkillType.ALL)
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[0] }));
//make sure there's only one argument. output at least some kind of error if not
if (args.length == 0 || (args.length != 1 && args[0] != null)) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return true;
} case 2:
perm += ".others";
if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm)) {
return true;
}
OfflinePlayer modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
profile = Users.getProfile(modifiedPlayer);
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
skillType = getSkillType(sender, args[1], perm, oldPermission);
if (skillType == null) {
return true;
}
//reset the values in the hash table and persist them
profile.resetSkill(skillType);
profile.save();
//display a success message to the user
if (skillType == SkillType.ALL)
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[1] }));
return true;
default:
sender.sendMessage(usage);
return true;
}
}
private SkillType getSkillType(CommandSender sender, String name, String perm, boolean oldPermission) {
//parse the skilltype that they sent //parse the skilltype that they sent
try try {
{ //ucase needed to match enum since it's case sensitive. trim to be nice
skillType = SkillType.valueOf(args[0].toUpperCase().trim()); //ucase needed to match enum since it's case sensitive. trim to be nice SkillType type = SkillType.valueOf(name.toUpperCase().trim());
}catch(IllegalArgumentException ex) String lowerName = type.name().toLowerCase();
{
if (type == SkillType.ALL && !checkAll(sender, perm, oldPermission))
return null;
else if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm + "." + name))
return null;
return type;
} catch(IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; return null;
} }
}
//reset the values in the hash table and persist them private boolean checkAll(CommandSender sender, String perm, boolean oldPermission) {
PlayerProfile profile = Users.getProfile((Player)sender); for (SkillType type : SkillType.values()) {
if (type.name().equalsIgnoreCase("all"))
continue;
if (profile == null) { String name = type.name().toLowerCase();
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm + "." + name))
return false;
} }
profile.resetSkill(skillType);
profile.save();
//display a success message to the user
if (skillType == SkillType.ALL)
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[0] }));
return true; return true;
} }
} }

View File

@ -711,6 +711,7 @@ permissions:
mcmmo.commands.mmoedit: true mcmmo.commands.mmoedit: true
mcmmo.commands.mmoedit.others: true mcmmo.commands.mmoedit.others: true
mcmmo.commands.mmoupdate: true mcmmo.commands.mmoupdate: true
mcmmo.commands.skillreset.all: true
mcmmo.commands.defaults: mcmmo.commands.defaults:
description: Implies all default mcmmo.commands permissions. description: Implies all default mcmmo.commands permissions.
children: children:
@ -805,6 +806,107 @@ permissions:
description: Allows access to the party unlock command description: Allows access to the party unlock command
mcmmo.commands.ptp: mcmmo.commands.ptp:
description: Allows access to the ptp command description: Allows access to the ptp command
mcmmo.commands.skillreset.*:
description: Implies access to all mcmmo.commands.skillreset permissions
children:
mcmmo.commands.skillreset.all: true
mcmmo.commands.skillreset.all:
description: Implies access to all mcmmo.commands.skillreset permissions
children:
mcmmo.commands.skillreset: true
mcmmo.commands.skillreset.acrobatics: true
mcmmo.commands.skillreset.archery: true
mcmmo.commands.skillreset.axes: true
mcmmo.commands.skillreset.excavation: true
mcmmo.commands.skillreset.fishing: true
mcmmo.commands.skillreset.herbalism: true
mcmmo.commands.skillreset.mining: true
mcmmo.commands.skillreset.others.all: true
mcmmo.commands.skillreset.repair: true
mcmmo.commands.skillreset.smelting: true
mcmmo.commands.skillreset.swords: true
mcmmo.commands.skillreset.taming: true
mcmmo.commands.skillreset.unarmed: true
mcmmo.commands.skillreset.woodcutting: true
mcmmo.commands.skillreset:
description: Allows access to the skillreset command
mcmmo.commands.skillreset.acrobatics:
description: Allows access to the skillreset command for acrobatics
mcmmo.commands.skillreset.archery:
description: Allows access to the skillreset command for archery
mcmmo.commands.skillreset.axes:
description: Allows access to the skillreset command for axes
mcmmo.commands.skillreset.excavation:
description: Allows access to the skillreset command for excavation
mcmmo.commands.skillreset.fishing:
description: Allows access to the skillreset command for fishing
mcmmo.commands.skillreset.herbalism:
description: Allows access to the skillreset command for herbalism
mcmmo.commands.skillreset.mining:
description: Allows access to the skillreset command for mining
mcmmo.commands.skillreset.others.*:
description: Implies access to all mcmmo.commands.skillreset.others permissions
children:
mcmmo.commands.skillreset.others.all: true
mcmmo.commands.skillreset.others.all:
description: Implies access to all mcmmo.commands.skillreset.others permissions
children:
mcmmo.commands.skillreset.others: true
mcmmo.commands.skillreset.others.acrobatics: true
mcmmo.commands.skillreset.others.archery: true
mcmmo.commands.skillreset.others.axes: true
mcmmo.commands.skillreset.others.excavation: true
mcmmo.commands.skillreset.others.fishing: true
mcmmo.commands.skillreset.others.herbalism: true
mcmmo.commands.skillreset.others.mining: true
mcmmo.commands.skillreset.others.repair: true
mcmmo.commands.skillreset.others.smelting: true
mcmmo.commands.skillreset.others.swords: true
mcmmo.commands.skillreset.others.taming: true
mcmmo.commands.skillreset.others.unarmed: true
mcmmo.commands.skillreset.others.woodcutting: true
mcmmo.commands.skillreset.others:
description: Allows access to the skillreset command for other players
mcmmo.commands.skillreset.others.acrobatics:
description: Allows access to the skillreset command for acrobatics for other players
mcmmo.commands.skillreset.others.archery:
description: Allows access to the skillreset command for archery for other players
mcmmo.commands.skillreset.others.axes:
description: Allows access to the skillreset command for axes for other players
mcmmo.commands.skillreset.others.excavation:
description: Allows access to the skillreset command for excavation for other players
mcmmo.commands.skillreset.others.fishing:
description: Allows access to the skillreset command for fishing for other players
mcmmo.commands.skillreset.others.herbalism:
description: Allows access to the skillreset command for herbalism for other players
mcmmo.commands.skillreset.others.mining:
description: Allows access to the skillreset command for mining for other players
mcmmo.commands.skillreset.others.repair:
description: Allows access to the skillreset command for repair for other players
mcmmo.commands.skillreset.others.smelting:
description: Allows access to the skillreset command for smelting for other players
mcmmo.commands.skillreset.others.swords:
description: Allows access to the skillreset command for swords for other players
mcmmo.commands.skillreset.others.taming:
description: Allows access to the skillreset command for taming for other players
mcmmo.commands.skillreset.others.unarmed:
description: Allows access to the skillreset command for unarmed for other players
mcmmo.commands.skillreset.others.woodcutting:
description: Allows access to the skillreset command for woodcutting for other players
mcmmo.commands.skillreset.mining:
description: Allows access to the skillreset command for mining
mcmmo.commands.skillreset.repair:
description: Allows access to the skillreset command for repair
mcmmo.commands.skillreset.smelting:
description: Allows access to the skillreset command for smelting
mcmmo.commands.skillreset.swords:
description: Allows access to the skillreset command for swords
mcmmo.commands.skillreset.taming:
description: Allows access to the skillreset command for taming
mcmmo.commands.skillreset.unarmed:
description: Allows access to the skillreset command for unarmed
mcmmo.commands.skillreset.woodcutting:
description: Allows access to the skillreset command for woodcutting
mcmmo.chat.*: mcmmo.chat.*:
description: Implies all mcmmo.chat permissions. (Warning, contains adminchat) description: Implies all mcmmo.chat permissions. (Warning, contains adminchat)
children: children: