Convert /ptp to use Bukkit CommandAPI

This commit is contained in:
GJ 2013-02-12 15:05:02 -05:00
parent 92473cc56d
commit adda85a660
4 changed files with 29 additions and 16 deletions

View File

@ -27,6 +27,7 @@ import com.gmail.nossr50.database.commands.McremoveCommand;
import com.gmail.nossr50.database.commands.MmoupdateCommand;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.commands.PartyCommand;
import com.gmail.nossr50.party.commands.PtpCommand;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
import com.gmail.nossr50.skills.axes.AxesCommand;
@ -324,4 +325,14 @@ public final class CommandRegistrationHelper {
command.setPermissionMessage(permissionsMessage);
command.setExecutor(new PartyCommand());
}
public static void registerPtpCommand() {
PluginCommand command = mcMMO.p.getCommand("ptp");
command.setDescription(LocaleLoader.getString("Commands.Description.ptp"));
command.setPermission("mcmmo.commands.ptp;mcmmo.commands.ptp.accept;mcmmo.commands.ptp.acceptall;mcmmo.commands.ptp.toggle");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "ptp", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "ptp", "<toggle|accept|acceptall>"));
command.setExecutor(new PtpCommand());
}
}

View File

@ -290,7 +290,7 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerAdminChatCommand();
CommandRegistrationHelper.registerPartyCommand();
CommandRegistrationHelper.registerPartyChatCommand();
getCommand("ptp").setExecutor(new PtpCommand());
CommandRegistrationHelper.registerPtpCommand();
// Other commands
CommandRegistrationHelper.registerAddxpCommand();

View File

@ -23,16 +23,10 @@ public class PtpCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = LocaleLoader.getString("Commands.Usage.1", "ptp", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">");
if (CommandHelper.noConsoleUsage(sender)) {
return true;
}
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.ptp")) {
return true;
}
switch (args.length) {
case 1:
player = (Player) sender;
@ -42,7 +36,8 @@ public class PtpCommand implements CommandExecutor {
if (args[0].equalsIgnoreCase("toggle")) {
return togglePartyTeleportation();
}
else if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
return acceptAnyTeleportRequest();
}
@ -60,24 +55,30 @@ public class PtpCommand implements CommandExecutor {
return sendTeleportRequest(args[0]);
default:
sender.sendMessage(usage);
return true;
return false;
}
}
private boolean sendTeleportRequest(String args) {
Player target = mcMMO.p.getServer().getPlayer(args);
private boolean sendTeleportRequest(String playerName) {
if (!mcMMO.p.getServer().getOfflinePlayer(playerName).isOnline()) {
player.sendMessage(LocaleLoader.getString("Party.NotOnline", playerName));
return true;
}
McMMOPlayer mcMMOTarget = Users.getPlayer(playerName);
if (mcMMOTarget == null) {
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return true;
}
Player target = mcMMOTarget.getPlayer();
if (player.equals(target)) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Self"));
return true;
}
if (target == null) {
player.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
return true;
}
if (target.isDead()) {
player.sendMessage(LocaleLoader.getString("Party.Teleport.Dead"));
return true;

View File

@ -709,6 +709,7 @@ Commands.Description.mmoedit=Edit mcMMO levels for a user
Commands.Description.mmoupdate=Convert mcMMO database from Flatfile to MySQL
Commands.Description.party=Control various mcMMO party settings
Commands.Description.partychat=Toggle mcMMO party chat on/off or send party chat messages
Commands.Description.ptp=Teleport to an mcMMO party member
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