Update /mchud and /xplock to use the Bukkit CommandAPI

This commit is contained in:
GJ 2013-02-07 08:25:54 -05:00
parent b67a308a34
commit 59219e3f33
6 changed files with 73 additions and 56 deletions

View File

@ -40,6 +40,8 @@ import com.gmail.nossr50.skills.taming.TamingCommand;
import com.gmail.nossr50.skills.unarmed.UnarmedCommand;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.woodcutting.WoodcuttingCommand;
import com.gmail.nossr50.spout.commands.MchudCommand;
import com.gmail.nossr50.spout.commands.XplockCommand;
import com.gmail.nossr50.util.Misc;
public final class CommandRegistrationHelper {
@ -181,7 +183,7 @@ public final class CommandRegistrationHelper {
command.setDescription(LocaleLoader.getString("Commands.Description.xprate"));
command.setPermission("mcmmo.commands.xprate;mcmmo.commands.xprate.reset;mcmmo.commands.xprate.set");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.2", "xprate", "<" + LocaleLoader.getString("Commands.Usage.Rate") + ">", "<" + LocaleLoader.getString("Commands.Usage.True") + "|" + LocaleLoader.getString("Commands.Usage.False")+ ">"));
command.setUsage(LocaleLoader.getString("Commands.Usage.2", "xprate", "<" + LocaleLoader.getString("Commands.Usage.Rate") + ">", "<true|false>"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "xprate", "reset"));
command.setAliases(aliasList);
command.setExecutor(new XprateCommand());
@ -275,7 +277,7 @@ public final class CommandRegistrationHelper {
command.setPermission("mcmmo.chat.adminchat");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "adminchat"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "adminchat", "<" + LocaleLoader.getString("Commands.Usage.On") + "|" + LocaleLoader.getString("Commands.Usage.Off")+ ">"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "adminchat", "<on|off>"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "adminchat", "<" + LocaleLoader.getString("Commands.Usage.Message") + ">"));
command.setExecutor(new AdminChatCommand());
}
@ -286,8 +288,28 @@ public final class CommandRegistrationHelper {
command.setPermission("mcmmo.chat.partychat;mcmmo.commands.party");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "partychat"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "partychat", "<" + LocaleLoader.getString("Commands.Usage.On") + "|" + LocaleLoader.getString("Commands.Usage.Off")+ ">"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "partychat", "<on|off>"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "partychat", "<" + LocaleLoader.getString("Commands.Usage.Message") + ">"));
command.setExecutor(new PartyChatCommand());
}
public static void registerMchudCommand() {
PluginCommand command = mcMMO.p.getCommand("mchud");
command.setDescription(LocaleLoader.getString("Commands.Description.mchud"));
command.setPermission("mcmmo.commands.mchud");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mchud", "<DISABLED | STANDARD | SMALL | RETRO>"));
command.setExecutor(new MchudCommand());
}
public static void registerXplockCommand() {
PluginCommand command = mcMMO.p.getCommand("xplock");
command.setDescription(LocaleLoader.getString("Commands.Description.xplock"));
command.setPermission("mcmmo.commands.xplock");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "xplock"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "xplock", "<on|off>"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "xplock", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">"));
command.setExecutor(new XplockCommand());
}
}

View File

@ -57,7 +57,6 @@ import com.gmail.nossr50.skills.runnables.PartyAutoKick;
import com.gmail.nossr50.skills.runnables.SkillMonitor;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.SpoutTools;
import com.gmail.nossr50.spout.commands.MchudCommand;
import com.gmail.nossr50.spout.commands.XplockCommand;
import com.gmail.nossr50.util.Anniversary;
import com.gmail.nossr50.util.Users;
@ -306,8 +305,8 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerSkillresetCommand();
// Spout commands
getCommand("xplock").setExecutor(new XplockCommand());
getCommand("mchud").setExecutor(new MchudCommand());
CommandRegistrationHelper.registerXplockCommand();
CommandRegistrationHelper.registerMchudCommand();
}
private void scheduleTasks() {

View File

@ -12,30 +12,21 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.huds.HudType;
import com.gmail.nossr50.spout.huds.SpoutHud;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class MchudCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = LocaleLoader.getString("Commands.Usage.1", "mchud", "<DISABLED | STANDARD | SMALL | RETRO>");
String invalid = LocaleLoader.getString("Commands.mchud.Invalid");
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.hasPermission(sender, "mcmmo.commands.mchud")) {
return true;
}
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
Player player = (Player) sender;
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile();
SpoutHud spoutHud = playerProfile.getSpoutHud();
if (spoutHud == null) {
@ -55,12 +46,11 @@ public class MchudCommand implements CommandExecutor {
}
}
player.sendMessage(invalid);
sender.sendMessage(LocaleLoader.getString("Commands.mchud.Invalid"));
return true;
default:
player.sendMessage(usage);
return true;
return false;
}
}
}

View File

@ -20,24 +20,18 @@ import com.gmail.nossr50.util.Users;
public class XplockCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = LocaleLoader.getString("Commands.Usage.1", "xplock", "[skill]");
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock")) {
return true;
}
if (!mcMMO.spoutEnabled || !SpoutConfig.getInstance().getXPBarEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
Player player = (Player) sender;
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
PlayerProfile playerProfile = Users.getPlayer((Player) sender).getProfile();
SpoutHud spoutHud = playerProfile.getSpoutHud();
SkillType lastGained;
if (spoutHud == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
@ -48,45 +42,59 @@ public class XplockCommand implements CommandExecutor {
case 0:
if (spoutHud.getXpBarLocked()) {
spoutHud.toggleXpBarLocked();
player.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true;
}
SkillType lastGained = spoutHud.getLastGained();
lastGained = spoutHud.getLastGained();
if (lastGained != null) {
spoutHud.toggleXpBarLocked();
spoutHud.setSkillLock(lastGained);
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
}
else {
player.sendMessage(usage);
if (lastGained == null) {
return false;
}
spoutHud.toggleXpBarLocked();
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true;
case 1:
if (SkillTools.isSkill(args[0])) {
if (Permissions.hasPermission(player, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(SkillTools.getSkillType(args[0]));
spoutHud.updateXpBar();
if (args[0].equalsIgnoreCase("on")) {
lastGained = spoutHud.getLastGained();
player.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(args[0])));
}
else {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
}
}
else {
player.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(lastGained);
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(lastGained.toString())));
return true;
}
if (args[0].equalsIgnoreCase("off")) {
spoutHud.setXpBarLocked(false);
sender.sendMessage(LocaleLoader.getString("Commands.xplock.unlocked"));
return true;
}
if (!SkillTools.isSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
return true;
}
if (!Permissions.hasPermission(sender, "mcmmo.commands.xplock." + args[0].toLowerCase())) {
sender.sendMessage(command.getPermissionMessage());
}
spoutHud.setXpBarLocked(true);
spoutHud.setSkillLock(SkillTools.getSkillType(args[0]));
spoutHud.updateXpBar();
sender.sendMessage(LocaleLoader.getString("Commands.xplock.locked", Misc.getCapitalized(args[0])));
return true;
default:
player.sendMessage(usage);
return true;
return false;
}
}
}

View File

@ -492,18 +492,14 @@ Commands.Usage.0=[[RED]]Proper usage is /{0}
Commands.Usage.1=[[RED]]Proper usage is /{0} {1}
Commands.Usage.2=[[RED]]Proper usage is /{0} {1} {2}
Commands.Usage.3=[[RED]]Proper usage is /{0} {1} {2} {3}
Commands.Usage.False=false
Commands.Usage.Level=level
Commands.Usage.Message=message
Commands.Usage.Off=off
Commands.Usage.On=on
Commands.Usage.Page=page
Commands.Usage.PartyName=party-name
Commands.Usage.Password=password
Commands.Usage.Player=player
Commands.Usage.Rate=rate
Commands.Usage.Skill=skill
Commands.Usage.True=true
Commands.Usage.XP=xp
mcMMO.NoInvites=[[RED]]You have no invites at this time
mcMMO.NoPermission=[[DARK_RED]]Insufficient permissions.
@ -698,6 +694,7 @@ Commands.Description.addxp=Add mcMMO XP to a user
Commands.Description.inspect=View detailed mcMMO info on another player
Commands.Description.mcability=Toggle mcMMO abilities being readied on right-click on/off
Commands.Description.mcgod=Toggle mcMMO god-mode on/off
Commands.Description.mchud=Change your mcMMO HUD style
Commands.Description.mcmmo=Show a brief description of mcMMO
Commands.Description.mcpurge=Purge users with no mcMMO levels and users who have not connected in over {0} months from the mcMMO database.
Commands.Description.mcrank=Show mcMMO ranking for a player
@ -710,4 +707,5 @@ Commands.Description.mmoupdate=Convert mcMMO database from Flatfile to MySQL
Commands.Description.partychat=Toggle mcMMO party chat on/off or send party chat messages
Commands.Description.Skill=Display detailed mcMMO skill info for {0}
Commands.Description.skillreset=Reset mcMMO levels for a user
Commands.Description.xplock=Lock your mcMMO XP bar to a specific mcMMO skill
Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event

View File

@ -24,7 +24,7 @@ commands:
description: Change your HUD
xplock:
aliases: [mcxplock]
description: Lock your xp bar
description: Lock your mcMMO XP bar
xprate:
aliases: [mcxprate]
description: Modify the xp rate or start an event