Cleaning up from our deprecated permissions.

Also cleaned up the unholy mess that was SkillResetCommand.
This commit is contained in:
GJ 2013-01-31 13:29:42 -05:00
parent bd2cd07f46
commit d3c8a5565a
8 changed files with 97 additions and 153 deletions

View File

@ -13,6 +13,7 @@ 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 AddlevelsCommand implements CommandExecutor{
@ -22,16 +23,14 @@ public class AddlevelsCommand implements CommandExecutor{
PlayerProfile profile;
int levels;
SkillType skill;
// DEPRECATED PERMISSION
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit");
String usage = LocaleLoader.getString("Commands.Usage.3", new Object[] {"addlevels", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">" });
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels")) {
return true;
}
switch (args.length) {
case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -61,20 +60,15 @@ public class AddlevelsCommand implements CommandExecutor{
return true;
case 3:
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels.others")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels.others") && !Permissions.mmoedit((Player) sender)) {
return true;
}
modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
String playerName = modifiedPlayer.getName();
profile = Users.getProfile(modifiedPlayer);
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (!profile.isLoaded()) {
// TODO:Not sure if we actually need a null check here
if (profile == null || !profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
@ -91,10 +85,10 @@ public class AddlevelsCommand implements CommandExecutor{
Users.getProfile(modifiedPlayer).addLevels(skill, levels);
if (skill.equals(SkillType.ALL)) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {playerName}));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {args[0]}));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", new Object[] {Misc.getCapitalized(skill.toString()), playerName}));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", new Object[] {Misc.getCapitalized(skill.toString()), args[0]}));
}
if (modifiedPlayer.isOnline()) {

View File

@ -13,6 +13,7 @@ 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;
//TODO: Any way we can make this work for offline use?
@ -22,16 +23,14 @@ public class AddxpCommand implements CommandExecutor {
Player modifiedPlayer;
int xp;
SkillType skill;
// DEPRECATED PERMISSION
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit");
String usage = LocaleLoader.getString("Commands.Usage.3", new Object[] {"addxp", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.XP") + ">" });
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp")) {
return true;
}
switch (args.length) {
case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) {
if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -72,7 +71,7 @@ public class AddxpCommand implements CommandExecutor {
return true;
case 3:
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp.others") && !Permissions.mmoedit((Player) sender)) {
return true;
}
@ -81,12 +80,8 @@ public class AddxpCommand implements CommandExecutor {
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
PlayerProfile profile = Users.getProfile(modifiedPlayer);
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (!profile.isLoaded()) {
// TODO: Not sure if we actually need a null check here
if (profile == null || !profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}

View File

@ -12,6 +12,7 @@ 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 {
@ -21,16 +22,14 @@ public class MmoeditCommand implements CommandExecutor {
int newValue;
SkillType skill;
String skillName;
// DEPRECATED PERMISSION
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit");
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") + ">" });
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit")) {
return true;
}
switch (args.length) {
case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -64,7 +63,7 @@ public class MmoeditCommand implements CommandExecutor {
return true;
case 3:
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit.others")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit.others") && !Permissions.mmoedit((Player) sender)) {
return true;
}

View File

@ -10,131 +10,89 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
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 SkillResetCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
// DEPRECATED PERMISSION
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.skillreset");
OfflinePlayer modifiedPlayer;
PlayerProfile profile;
SkillType skill;
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;
}
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) {
if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
//reset the values in the hash table and persist them
profile = Users.getProfile((Player)sender);
skill = SkillTools.getSkillType(args[0]);
if (profile == null) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
if (CommandHelper.noCommandPermissions((Player) sender, "mcmmo.commands.skillreset." + skill.toString().toLowerCase()) && !Permissions.skillReset((Player) sender)) {
return true;
}
profile.resetSkill(skillType);
profile.save();
modifiedPlayer = (Player) sender;
profile = Users.getProfile(modifiedPlayer);
profile.modifySkill(skill, 0);
//display a success message to the user
if (skillType == SkillType.ALL)
if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[0] }));
return true;
case 2:
perm += ".others";
if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm)) {
return true;
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { Misc.getCapitalized(skill.toString()) }));
}
}
else {
sender.sendMessage(usage);
}
OfflinePlayer modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
return true;
case 2:
modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
profile = Users.getProfile(modifiedPlayer);
if (profile == null) {
// TODO:Not sure if we actually need a null check here
if (profile == null || !profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
skillType = getSkillType(sender, args[1], perm, oldPermission);
skill = SkillTools.getSkillType(args[1]);
if (skillType == null) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.skillreset.others." + skill.toString().toLowerCase()) && !Permissions.skillReset((Player) sender)) {
return true;
}
//reset the values in the hash table and persist them
profile.resetSkill(skillType);
profile.save();
profile.modifySkill(skill, 0);
//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] }));
if (modifiedPlayer.isOnline()) {
if (skill == SkillType.ALL) {
((Player)modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
((Player)modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { Misc.getCapitalized(skill.toString()) }));
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", new Object[] { Misc.getCapitalized(skill.toString()), args[0] }));
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
try {
//ucase needed to match enum since it's case sensitive. trim to be nice
SkillType type = SkillType.valueOf(name.toUpperCase().trim());
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"));
return null;
}
}
private boolean checkAll(CommandSender sender, String perm, boolean oldPermission) {
for (SkillType type : SkillType.values()) {
if (type.name().equalsIgnoreCase("all"))
continue;
String name = type.name().toLowerCase();
if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm + "." + name))
return false;
}
return true;
}
}

View File

@ -10,15 +10,13 @@ import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.runnables.SQLConversionTask;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class MmoupdateCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// DEPRECATED PERMISSION
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.admin");
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoupdate")) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoupdate") && !Permissions.admin((Player) sender)) {
return true;
}

View File

@ -953,26 +953,6 @@ public class PlayerProfile {
save(false);
}
public void resetSkill(SkillType skillType)
{
if (skillType.isChildSkill()) {
return;
}
//do a single skilltype
if (skillType != SkillType.ALL)
skills.put(skillType, 0);
else //do them all
{
for (SkillType skill : SkillType.values()) //iterate over all items in the enumeration
{
if (skill != SkillType.ALL) // skip the "all" value
skills.put(skill, 0);
}
}
save(false);
}
// /**
// * Adds XP to the player, doesn't calculate for XP Rate
// *

View File

@ -301,7 +301,7 @@ public class SkillTools {
*/
public static SkillType getSkillType(String skillName) {
for (SkillType x : SkillType.values()) {
if (x.toString().equals(skillName.toUpperCase())) {
if (x.toString().equalsIgnoreCase(skillName)) {
return x;
}
}

View File

@ -20,6 +20,10 @@ public final class Permissions {
return hasPermission(player, "mcmmo.motd");
}
/**
* @deprecated Use the permission "mcmmo.all" instead.
*/
@Deprecated
public static boolean admin(Player player) {
return hasPermission(player, "mcmmo.admin");
}
@ -71,6 +75,10 @@ public final class Permissions {
return hasPermission(player, "mcmmo.tools.mcremove");
}
/**
* @deprecated Use {@link #mmoeditCommand(player)} instead.
*/
@Deprecated
public static boolean mmoedit(Player player) {
return hasPermission(player, "mcmmo.tools.mmoedit");
}
@ -548,6 +556,14 @@ public final class Permissions {
* MCMMO.COMMANDS.*
*/
public static boolean mmoeditCommand(Player player) {
return (hasPermission(player, "mcmmo.commands.mmoedit") || mmoedit(player));
}
public static boolean skillResetCommand(Player player) {
return (hasPermission(player, "mcmmo.commands.skillreset") || skillReset(player));
}
public static boolean mcAbility(Player player) {
return hasPermission(player, "mcmmo.commands.ability");
}
@ -564,6 +580,10 @@ public final class Permissions {
return hasPermission(player, "mcmmo.commands.party");
}
/**
* @deprecated Use {@link #skillResetCommand(player)} instead.
*/
@Deprecated
public static boolean skillReset(Player player) {
return hasPermission(player, "mcmmo.skillreset");
}