2013-02-01 19:41:26 +01:00
|
|
|
package com.gmail.nossr50.commands.player;
|
2013-01-15 23:55:41 +01:00
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2013-01-15 23:55:41 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.command.TabExecutor;
|
|
|
|
import org.bukkit.util.StringUtil;
|
2013-01-15 23:55:41 +01:00
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
|
2013-02-19 06:56:25 +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-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public class McrankCommand implements TabExecutor {
|
2013-01-16 00:35:21 +01:00
|
|
|
@Override
|
2013-01-16 08:50:18 +01:00
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-02-05 15:18:06 +01:00
|
|
|
switch (args.length) {
|
2013-03-01 06:52:01 +01:00
|
|
|
case 0:
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
2013-03-11 17:48:00 +01:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
if (!Permissions.mcrank(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-02 12:20:02 +01:00
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
display(sender, sender.getName());
|
2013-02-03 22:14:26 +01:00
|
|
|
return true;
|
2013-02-05 15:18:06 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
case 1:
|
|
|
|
if (!Permissions.mcrankOthers(sender)) {
|
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
2013-02-05 15:18:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-24 16:53:01 +01:00
|
|
|
String playerName = args[0];
|
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-24 16:53:01 +01:00
|
|
|
if (mcMMOPlayer != null) {
|
|
|
|
playerName = mcMMOPlayer.getPlayer().getName();
|
|
|
|
|
|
|
|
if (CommandUtils.tooFar(sender, mcMMOPlayer.getPlayer(), Permissions.mcrankFar(sender))) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 23:37:36 +02:00
|
|
|
else if (CommandUtils.inspectOffline(sender, new PlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-02-03 22:35:36 +01:00
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
display(sender, playerName);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
2013-01-16 00:35:21 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
default:
|
|
|
|
return false;
|
2013-01-16 23:37:35 +01:00
|
|
|
}
|
2013-01-16 00:35:21 +01:00
|
|
|
}
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
Set<String> playerNames = UserManager.getPlayers().keySet();
|
|
|
|
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<String>(playerNames.size()));
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
private void display(CommandSender sender, String playerName) {
|
2013-03-20 08:11:16 +01:00
|
|
|
new McrankCommandAsyncTask(playerName, sender).runTaskAsynchronously(mcMMO.p);
|
2013-01-16 00:35:21 +01:00
|
|
|
}
|
|
|
|
}
|