2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.experience;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-05-28 19:33:20 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-05-21 15:31:25 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2013-08-20 20:10:49 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-03-12 21:25:42 +01:00
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
public class SkillresetCommand extends ExperienceCommand {
|
|
|
|
private CommandSender sender;
|
|
|
|
private Command command;
|
2013-03-16 21:13:55 +01:00
|
|
|
private int argsLength;
|
2013-03-12 21:25:42 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-03-16 21:13:55 +01:00
|
|
|
this.command = command;
|
|
|
|
this.sender = sender;
|
|
|
|
argsLength = args.length;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!Permissions.skillreset(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (isInvalidSkill(sender, args[0])) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-05-28 19:33:20 +02:00
|
|
|
player = (Player) sender;
|
|
|
|
mcMMOPlayer = UserManager.getPlayer(player);
|
2013-03-12 21:25:42 +01:00
|
|
|
profile = mcMMOPlayer.getProfile();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
editValues();
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (!Permissions.skillresetOthers(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (isInvalidSkill(sender, args[1])) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-20 20:10:49 +02:00
|
|
|
String playerName = Misc.getMatchedPlayerName(args[0]);
|
2013-08-21 16:20:12 +02:00
|
|
|
mcMMOPlayer = UserManager.getPlayer(playerName, true);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
// 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) {
|
2013-08-20 20:10:49 +02:00
|
|
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.unloadedProfile(sender, profile)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
editValues();
|
2013-03-01 06:52:01 +01:00
|
|
|
profile.save(); // Since this is a temporary profile, we save it here.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
profile = mcMMOPlayer.getProfile();
|
2013-03-16 21:13:55 +01:00
|
|
|
player = mcMMOPlayer.getPlayer();
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
editValues();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-08-20 20:10:49 +02:00
|
|
|
handleSenderMessage(sender, playerName);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-12 21:25:42 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean permissionsCheckSelf(CommandSender sender) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean permissionsCheckOthers(CommandSender sender) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void handleCommand(SkillType skill) {
|
2013-03-16 21:13:55 +01:00
|
|
|
if (argsLength == 1 && !Permissions.skillreset(sender, skill) || (argsLength == 2 && !Permissions.skillresetOthers(sender, skill))) {
|
2013-03-12 21:25:42 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
int levelsRemoved = profile.getSkillLevel(skill);
|
|
|
|
float xpRemoved = profile.getSkillXpLevelRaw(skill);
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
profile.modifySkill(skill, 0);
|
2013-05-21 15:31:25 +02:00
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
if (player == null) {
|
|
|
|
return;
|
2013-05-21 15:31:25 +02:00
|
|
|
}
|
2013-10-18 14:31:00 +02:00
|
|
|
|
|
|
|
EventUtils.handleLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false);
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void handlePlayerMessageAll() {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void handlePlayerMessageSkill() {
|
2013-10-15 19:03:33 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skill.getSkillName()));
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|