mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Rework /addlevels to use the built-in Bukkit command stuff.
This commit is contained in:
parent
89e5e16aad
commit
a3e9d12f6a
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.general.AddlevelsCommand;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
|
||||
import com.gmail.nossr50.skills.archery.ArcheryCommand;
|
||||
@ -26,6 +27,8 @@ import com.gmail.nossr50.util.Misc;
|
||||
public final class CommandRegistrationHelper {
|
||||
private CommandRegistrationHelper() {};
|
||||
|
||||
private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
|
||||
|
||||
public static void registerSkillCommands() {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill != SkillType.ALL) {
|
||||
@ -48,7 +51,7 @@ public final class CommandRegistrationHelper {
|
||||
command.setAliases(aliasList);
|
||||
command.setDescription(LocaleLoader.getString("Commands.Description.Skill", new Object[] { Misc.getCapitalized(localizedName) }));
|
||||
command.setPermission("mcmmo.skills." + commandName);
|
||||
command.setPermissionMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
command.setPermissionMessage(permissionsMessage);
|
||||
|
||||
switch (skill) {
|
||||
case ACROBATICS:
|
||||
@ -109,4 +112,13 @@ public final class CommandRegistrationHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerAddlevelsCommand() {
|
||||
PluginCommand command = mcMMO.p.getCommand("addlevels");
|
||||
command.setDescription(LocaleLoader.getString("Commands.Description.addlevels"));
|
||||
command.setPermission("mcmmo.commands.addlevels");
|
||||
command.setPermissionMessage(permissionsMessage);
|
||||
command.setUsage(LocaleLoader.getString("Commands.Usage.3", new Object[] {"addlevels", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">" }));
|
||||
command.setExecutor(new AddlevelsCommand());
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -18,15 +17,14 @@ import com.gmail.nossr50.util.Users;
|
||||
public class AddlevelsCommand implements CommandExecutor{
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player;
|
||||
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") + ">" });
|
||||
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels") && !Permissions.mmoedit((Player) sender)) {
|
||||
if (!Permissions.mmoedit(sender)) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -37,10 +35,9 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
}
|
||||
|
||||
if (Misc.isInt(args[1])) {
|
||||
player = (Player) sender;
|
||||
levels = Integer.valueOf(args[1]);
|
||||
skill = SkillTools.getSkillType(args[0]);
|
||||
profile = Users.getPlayer(player).getProfile();
|
||||
profile = Users.getPlayer((Player) sender).getProfile();
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
@ -50,16 +47,16 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
}
|
||||
|
||||
profile.addLevels(skill, levels);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(usage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case 3:
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.addlevels.others") && !Permissions.mmoedit((Player) sender)) {
|
||||
if (!Permissions.hasPermission(sender, "mcmmo.commands.addlevels.others") && !Permissions.mmoedit(sender)) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -69,15 +66,14 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
}
|
||||
|
||||
if (!Misc.isInt(args[2])) {
|
||||
sender.sendMessage(usage);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
|
||||
levels = Integer.valueOf(args[2]);
|
||||
skill = SkillTools.getSkillType(args[1]);
|
||||
|
||||
// If the mcMMOPlayer doesn't exists, create a temporary profile and check if it's present in the database, if not abort the process
|
||||
// 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);
|
||||
|
||||
@ -91,20 +87,18 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
}
|
||||
else {
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
player = mcMMOPlayer.getPlayer();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
profile.addLevels(skill, levels);
|
||||
|
||||
// This is actually not necessary but it can avoid a string building
|
||||
if (!player.isOnline()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
||||
// Check if the player is online before we try to send them a message.
|
||||
if (player.isOnline()) {
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", new Object[] {levels}));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", new Object[] {levels, Misc.getCapitalized(skill.toString())}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,8 +112,7 @@ public class AddlevelsCommand implements CommandExecutor{
|
||||
return true;
|
||||
|
||||
default:
|
||||
sender.sendMessage(usage);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ public class Config extends ConfigLoader {
|
||||
public boolean getCommandMCTopEnabled() { return config.getBoolean("Commands.mctop.Enabled", true); }
|
||||
public boolean getCommandMCRankEnabled() { return config.getBoolean("Commands.mcrank.Enabled", true); }
|
||||
public boolean getCommandAddXPEnabled() { return config.getBoolean("Commands.addxp.Enabled", true); }
|
||||
public boolean getCommandAddLevelsEnabled() { return config.getBoolean("Commands.addlevels.Enabled", true); }
|
||||
public boolean getCommandMCAbilityEnabled() { return config.getBoolean("Commands.mcability.Enabled", true); }
|
||||
public boolean getCommandMCRefreshEnabled() { return config.getBoolean("Commands.mcrefresh.Enabled", true); }
|
||||
public boolean getCommandmcMMOEnabled() { return config.getBoolean("Commands.mcmmo.Enabled", true); }
|
||||
|
@ -392,9 +392,7 @@ public class mcMMO extends JavaPlugin {
|
||||
getCommand("addxp").setExecutor(new AddxpCommand());
|
||||
}
|
||||
|
||||
if (configInstance.getCommandAddLevelsEnabled()) {
|
||||
getCommand("addlevels").setExecutor(new AddlevelsCommand());
|
||||
}
|
||||
CommandRegistrationHelper.registerAddlevelsCommand();
|
||||
|
||||
if (configInstance.getCommandMmoeditEnabled()) {
|
||||
getCommand("mmoedit").setExecutor(new MmoeditCommand());
|
||||
|
@ -79,8 +79,8 @@ public final class Permissions {
|
||||
* @deprecated Use {@link #mmoeditCommand(player)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean mmoedit(Player player) {
|
||||
return hasPermission(player, "mcmmo.tools.mmoedit");
|
||||
public static boolean mmoedit(CommandSender sender) {
|
||||
return hasPermission(sender, "mcmmo.tools.mmoedit");
|
||||
}
|
||||
|
||||
public static boolean mcgod(Player player) {
|
||||
|
@ -362,8 +362,6 @@ Commands:
|
||||
Enabled: true
|
||||
addxp:
|
||||
Enabled: true
|
||||
addlevels:
|
||||
Enabled: true
|
||||
ptp:
|
||||
Enabled: true
|
||||
Cooldown: 30
|
||||
|
@ -686,4 +686,5 @@ Smelting.Listener=Smelting:
|
||||
Smelting.SkillName=SMELTING
|
||||
|
||||
#COMMAND DESCRIPTIONS
|
||||
Commands.Description.Skill=Detailed skill info for {0}
|
||||
Commands.Description.addlevels=Add mcMMO levels to a user
|
||||
Commands.Description.Skill=Detailed mcMMO skill info for {0}
|
||||
|
@ -45,8 +45,6 @@ commands:
|
||||
aliases: []
|
||||
description: Add XP to a user
|
||||
addlevels:
|
||||
aliases: []
|
||||
description: Add levels to a user
|
||||
mcability:
|
||||
aliases: []
|
||||
description: Toggle whether or not abilities get readied on right click
|
||||
|
Loading…
Reference in New Issue
Block a user