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.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class AddlevelsCommand implements CommandExecutor{ public class AddlevelsCommand implements CommandExecutor{
@ -22,16 +23,14 @@ public class AddlevelsCommand implements CommandExecutor{
PlayerProfile profile; PlayerProfile profile;
int levels; int levels;
SkillType skill; 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") + ">" }); 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) { switch (args.length) {
case 2: case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) { if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) { if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -61,20 +60,15 @@ public class AddlevelsCommand implements CommandExecutor{
return true; return true;
case 3: 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; return true;
} }
modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]); modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
String playerName = modifiedPlayer.getName();
profile = Users.getProfile(modifiedPlayer); profile = Users.getProfile(modifiedPlayer);
if (profile == null) { // TODO:Not sure if we actually need a null check here
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); if (profile == null || !profile.isLoaded()) {
return true;
}
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; return true;
} }
@ -91,10 +85,10 @@ public class AddlevelsCommand implements CommandExecutor{
Users.getProfile(modifiedPlayer).addLevels(skill, levels); Users.getProfile(modifiedPlayer).addLevels(skill, levels);
if (skill.equals(SkillType.ALL)) { 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 { 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()) { 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.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
//TODO: Any way we can make this work for offline use? //TODO: Any way we can make this work for offline use?
@ -22,16 +23,14 @@ public class AddxpCommand implements CommandExecutor {
Player modifiedPlayer; Player modifiedPlayer;
int xp; int xp;
SkillType skill; 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") + ">" }); 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) { switch (args.length) {
case 2: case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) { if (sender instanceof Player) {
if (!SkillTools.isSkill(args[1])) { if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -72,7 +71,7 @@ public class AddxpCommand implements CommandExecutor {
return true; return true;
case 3: case 3:
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp")) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addxp.others") && !Permissions.mmoedit((Player) sender)) {
return true; return true;
} }
@ -81,12 +80,8 @@ public class AddxpCommand implements CommandExecutor {
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer); McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
PlayerProfile profile = Users.getProfile(modifiedPlayer); PlayerProfile profile = Users.getProfile(modifiedPlayer);
if (profile == null) { // TODO: Not sure if we actually need a null check here
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); if (profile == null || !profile.isLoaded()) {
return true;
}
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; 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.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class MmoeditCommand implements CommandExecutor { public class MmoeditCommand implements CommandExecutor {
@ -21,16 +22,14 @@ public class MmoeditCommand implements CommandExecutor {
int newValue; int newValue;
SkillType skill; SkillType skill;
String skillName; 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") + ">" }); 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) { switch (args.length) {
case 2: case 2:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit") && !Permissions.mmoedit((Player) sender)) {
return true;
}
if (sender instanceof Player) { if (sender instanceof Player) {
if (!SkillTools.isSkill(args[0])) { if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -64,7 +63,7 @@ public class MmoeditCommand implements CommandExecutor {
return true; return true;
case 3: 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; return true;
} }

View File

@ -10,131 +10,89 @@ 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;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; 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; import com.gmail.nossr50.util.Users;
public class SkillResetCommand implements CommandExecutor { public class SkillResetCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noConsoleUsage(sender)) { OfflinePlayer modifiedPlayer;
return true; PlayerProfile profile;
} SkillType skill;
// DEPRECATED PERMISSION
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 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) { switch (args.length) {
case 1: case 1:
//make sure there's only one argument. output at least some kind of error if not if (sender instanceof Player) {
if (args.length == 0 || (args.length != 1 && args[0] != null)) { if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
skill = SkillTools.getSkillType(args[0]);
if (CommandHelper.noCommandPermissions((Player) sender, "mcmmo.commands.skillreset." + skill.toString().toLowerCase()) && !Permissions.skillReset((Player) sender)) {
return true;
}
modifiedPlayer = (Player) sender;
profile = Users.getProfile(modifiedPlayer);
profile.modifySkill(skill, 0);
if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { Misc.getCapitalized(skill.toString()) }));
}
} }
else {
skillType = getSkillType(sender, args[0], perm, oldPermission); sender.sendMessage(usage);
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] }));
return true; return true;
case 2:
perm += ".others";
if (!oldPermission && CommandHelper.noCommandPermissions(sender, perm)) {
return true;
}
OfflinePlayer modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]); case 2:
modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]);
profile = Users.getProfile(modifiedPlayer); 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")); sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; return true;
} }
if (!profile.isLoaded()) { if (!SkillTools.isSkill(args[1])) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true; 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; return true;
} }
//reset the values in the hash table and persist them profile.modifySkill(skill, 0);
profile.resetSkill(skillType);
profile.save();
//display a success message to the user if (modifiedPlayer.isOnline()) {
if (skillType == SkillType.ALL) if (skill == SkillType.ALL) {
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All")); ((Player)modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Reset.All"));
else }
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", new Object[] { args[1] })); 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; return true;
default:
default:
sender.sendMessage(usage); sender.sendMessage(usage);
return true; 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.config.Config;
import com.gmail.nossr50.database.runnables.SQLConversionTask; import com.gmail.nossr50.database.runnables.SQLConversionTask;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class MmoupdateCommand implements CommandExecutor { public class MmoupdateCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// DEPRECATED PERMISSION if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoupdate") && !Permissions.admin((Player) sender)) {
boolean oldPermission = !CommandHelper.noCommandPermissions(sender, "mcmmo.admin");
if (!oldPermission && CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoupdate")) {
return true; return true;
} }

View File

@ -953,26 +953,6 @@ public class PlayerProfile {
save(false); 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 // * 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) { public static SkillType getSkillType(String skillName) {
for (SkillType x : SkillType.values()) { for (SkillType x : SkillType.values()) {
if (x.toString().equals(skillName.toUpperCase())) { if (x.toString().equalsIgnoreCase(skillName)) {
return x; return x;
} }
} }

View File

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