2013-02-04 08:38:13 -05:00
|
|
|
package com.gmail.nossr50.commands.admin;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
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 SkillresetCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
PlayerProfile profile;
|
2013-02-04 16:33:34 +01:00
|
|
|
boolean allSkills = false;
|
2013-02-04 08:38:13 -05:00
|
|
|
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
2013-02-04 15:10:07 -05:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset")) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-04 08:38:13 -05:00
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (args[0].equalsIgnoreCase("all")) {
|
|
|
|
allSkills = true;
|
|
|
|
}
|
|
|
|
else if (!SkillTools.isSkill(args[0])) {
|
2013-02-04 08:38:13 -05:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (allSkills) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
|
|
|
if (skillType.isChildSkill()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-04 08:38:13 -05:00
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[0].toLowerCase())) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset." + args[0].toLowerCase())) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
profile = Users.getPlayer((Player) sender).getProfile();
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (allSkills) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
|
|
|
if (skillType.isChildSkill()) {
|
|
|
|
continue;
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
profile.modifySkill(skillType, 0);
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
else {
|
2013-02-07 12:17:18 -05:00
|
|
|
profile.modifySkill(SkillType.getSkill(args[0]), 0);
|
2013-02-04 16:33:34 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[0])));
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2013-02-04 15:10:07 -05:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others")) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (args[1].equalsIgnoreCase("all")) {
|
|
|
|
allSkills = true;
|
|
|
|
}
|
|
|
|
else if (!SkillTools.isSkill(args[1])) {
|
2013-02-04 08:38:13 -05:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (allSkills) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
|
|
|
if (skillType.isChildSkill()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-04 08:38:13 -05:00
|
|
|
|
2013-02-04 15:10:07 -05:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others." + args[1].toLowerCase())) {
|
2013-02-04 16:33:34 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-02-04 15:10:07 -05:00
|
|
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.skillreset.others." + args[1].toLowerCase())) {
|
2013-02-04 16:33:34 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!profile.isLoaded()) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (allSkills) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
|
|
|
if (skillType.isChildSkill()) {
|
|
|
|
continue;
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
profile.modifySkill(skillType, 0);
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-02-07 12:17:18 -05:00
|
|
|
profile.modifySkill(SkillType.getSkill(args[1]), 0);
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
profile.save(); // Since this is a temporary profile, we save it here.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
profile = mcMMOPlayer.getProfile();
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
if (allSkills) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
|
|
|
if (skillType.isChildSkill()) {
|
|
|
|
continue;
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
profile.modifySkill(skillType, 0);
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
2013-02-04 16:33:34 +01:00
|
|
|
|
|
|
|
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.All"));
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
else {
|
2013-02-07 12:17:18 -05:00
|
|
|
profile.modifySkill(SkillType.getSkill(args[1]), 0);
|
2013-02-04 16:33:34 +01:00
|
|
|
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Reset.Single", Misc.getCapitalized(args[1])));
|
2013-02-04 08:38:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
if (allSkills) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(args[1]), args[0]));
|
|
|
|
}
|
|
|
|
|
2013-02-04 08:38:13 -05:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|