mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-04-03 02:06:23 +02:00
115 lines
4.5 KiB
Java
115 lines
4.5 KiB
Java
package com.gmail.nossr50.commands.general;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
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.Users;
|
|
|
|
public class AddlevelsCommand implements CommandExecutor{
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
OfflinePlayer modifiedPlayer;
|
|
PlayerProfile profile;
|
|
int levels;
|
|
SkillType skill;
|
|
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 (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mmoedit")) {
|
|
return true;
|
|
}
|
|
|
|
switch (args.length) {
|
|
case 2:
|
|
if (sender instanceof Player) {
|
|
if (!SkillTools.isSkill(args[0])) {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
return true;
|
|
}
|
|
|
|
if (Misc.isInt(args[1])) {
|
|
modifiedPlayer = (Player) sender;
|
|
levels = Integer.valueOf(args[1]);
|
|
skill = SkillTools.getSkillType(args[0]);
|
|
profile = Users.getProfile(modifiedPlayer);
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
|
}
|
|
else {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
|
}
|
|
|
|
profile.addLevels(skill, levels);
|
|
}
|
|
}
|
|
else {
|
|
sender.sendMessage(usage);
|
|
}
|
|
|
|
return true;
|
|
|
|
case 3:
|
|
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()) {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
return true;
|
|
}
|
|
|
|
if (!SkillTools.isSkill(args[1])) {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
return true;
|
|
}
|
|
|
|
if (Misc.isInt(args[2])) {
|
|
levels = Integer.valueOf(args[2]);
|
|
skill = SkillTools.getSkillType(args[1]);
|
|
|
|
Users.getProfile(modifiedPlayer).addLevels(skill, levels);
|
|
|
|
if (skill.equals(SkillType.ALL)) {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", new Object[] {playerName}));
|
|
}
|
|
else {
|
|
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", new Object[] {Misc.getCapitalized(skill.toString()), playerName}));
|
|
}
|
|
|
|
if (modifiedPlayer.isOnline()) {
|
|
if (skill.equals(SkillType.ALL)) {
|
|
((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
|
}
|
|
else {
|
|
((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
sender.sendMessage(usage);
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
sender.sendMessage(usage);
|
|
return true;
|
|
}
|
|
}
|
|
}
|