2015-02-20 11:53:18 +01:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2015-02-21 06:48:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-02-20 11:53:18 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2015-02-21 06:48:49 +01:00
|
|
|
import org.bukkit.command.TabCompleter;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
2015-02-20 11:53:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created 2015-02-20 for PlotSquared
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2015-02-21 06:48:49 +01:00
|
|
|
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
2015-02-20 11:53:18 +01:00
|
|
|
|
|
|
|
@Override
|
2015-02-21 06:48:49 +01:00
|
|
|
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
|
|
|
|
if (commandSender instanceof Player) {
|
2015-02-23 01:05:25 +01:00
|
|
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
2015-02-21 06:48:49 +01:00
|
|
|
}
|
2015-02-23 01:05:25 +01:00
|
|
|
return MainCommand.onCommand(null, commandLabel, args);
|
2015-02-21 06:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
|
|
|
if (!(commandSender instanceof Player)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
|
|
|
if (strings.length < 1) {
|
|
|
|
if ((strings.length == 0) || "plots".startsWith(s)) {
|
|
|
|
return Arrays.asList("plots");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strings.length > 1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final List<String> tabOptions = new ArrayList<>();
|
|
|
|
final String arg = strings[0].toLowerCase();
|
|
|
|
for (final SubCommand cmd : MainCommand.subCommands) {
|
|
|
|
if (cmd.permission.hasPermission(player)) {
|
|
|
|
if (cmd.cmd.startsWith(arg)) {
|
|
|
|
tabOptions.add(cmd.cmd);
|
|
|
|
} else if (cmd.alias.get(0).startsWith(arg)) {
|
|
|
|
tabOptions.add(cmd.alias.get(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tabOptions.size() > 0) {
|
|
|
|
return tabOptions;
|
|
|
|
}
|
|
|
|
return null;
|
2015-02-20 11:53:18 +01:00
|
|
|
}
|
|
|
|
}
|